Group Project

To apply much of what we have learned, and to learn new concepts, we will be doing a project together. The project that we will be doing is to create a clone of the c script available at http://treeluvin.com/bluehost/c

The intent of this exercise is learning and is not meant to diminish the fine work put into creating this wonderfully useful utility. This project is a good candidate for teaching and learning for the following reasons:

Contents

Automatic SSH Session

We worked as a group to try to come up with a generic feel for how everything will be put together.

Program Flow/Outline

This is the flow of a single execution of the script:

  1. Start up and parse options

    • What domain are we targeting?
    • Any special settings?
    • help message
  2. Authentication with our own BH credentials to access the customer account

    • First time run, store username with option to store password.
    • If password is not stored, prompt on command line.
  3. Using the credentials, access the CPM and grab customer credentials, box IP

  4. Check for SSH access, enable if necessary

  5. Run the SSH command

  6. De-activate SSH access if necessary

A good portion of the functions will be implemented as functions defined in a CustomerAccount class. The functions specific to this class will be the retrieval of CPM information and the changing of the SSH shell. The method that launches SSH may also be implemented as part of this class.

The logic that drives the command line client will be implemented as part of a function that is only called when the script is run as a command.

Specific Problems

CPM URLs will be accessed using the urllib2 module, both for the information retrieval and the POST methods to make changes.

urllib2 is a good choice because it has both Basic auth support, and cookie support. Both are requirements for doing anything with CPM.

Once retrieved, the CPM page(s) will be parsed and processed using the BeautifulSoup module. This module is not part of the standard Python library, but is fairly common for use in parsing web pages. This will also allow us to easily grab other values provided by the CPM if we ever decide to extend the functionality of this program.

SSH is a command, and needs to be launched at some point. The problem is that SSH can't take the password as a command line argument. This is a security feature of SSH, and several other authentication-related commands. This causes a problem for scripting its use. Fortunately, there is a piece of software called expect. There is an expect command, along with libexpect, as well as Python bindings for libexpect, packaged as the Python package pexpect.

Development Model

We will approach the development of this program similar to an Open Source development model. Features and ideas are welcome from anyone in the group, or anyone who decides to try out the software.

We will be using the git content tracker for version control. Each developer will have his or her own repository, and the rest of the group can pull from each other.

It is recommended to not use your customer account for development, nor your Linux workstation at work. This is because neither environment has git installed by default. If you don't run Linux or Mac at home, I can provide you with a shell account for development.

Git in and of itself is a beast all on its own. If you've never worked with git, there are lots of resources available to you. I recommend the following (in no particular order):

Also, if you have any questions, you can hit either the official git mailing list, the python class mailing list, or ask me when you see me.

References

Here are links to the Python modules mentioned specifically in our planning session: