Bellatrix utility functions
Common utilities, meant to be used as ‘building blocks’. Every block has a different use, being possible in some cases to composite them.
Every command is a simple function that returns the list of commands to be executed into a list of strings. If any of the commands fails, the execution will be interrupted. It’s convenient that you add a small test at the very end of each set.
For example:
It’s an example of a single-purposed operation that performs a test at the end. Should something happened to the operation, ‘cat new_file’ will fail. Additionally you will be able to verify the content of the file in the logging output.
Return the “sudo apt-get install” command
Parameters: | package (string) – The new package to install |
---|
Applies the chmod command.
Parameters: |
|
---|
Copy a file using -f so it doesn’t fail if the destination exists.
Parameters: |
|
---|
Creates a new soft link.
Parameters: |
|
---|
Generate a new Python virtual environment using virtualenv
Parameters: | env_name (string) – Name of the new virtual environment. |
---|
Creates a Django project.
Parameters: |
|
---|
Execute a command within a virtualenv environment
Parameters: | env (str) – Name of the new virtual environment. |
---|
:type cmd : list :param cmd: List of commands to be executed.
Given a list of commands it will return a single one concatenated by ‘&&’ so they will be executed in sequence until any of them fails.
Parameters: | cmds (list) – List of strings that contains commands. |
---|---|
Return type: | string |
Returns: | A single string with the commands concatenated. |
Install a Python package into a virtualenv.
Parameters: |
|
---|
Install Nginx in Ubuntu using the repo they provide as described in http://wiki.nginx.org/Install#Ubuntu_PPA
Resizes the logical volume to new_size specified in the start command. This is necessary for some operating systems that do not automatically resize to this value.
Parameters: | device (string) – logical volume to resize, e.g. /dev/xvda1 in RedHat family systems |
---|
Created a new directory. “-p” flag is used so the command generates the same result regardless whether the directory exists or not.
Parameters: | directory (string) – directory to be created. |
---|
Install a Python package using pip.
Parameters: |
|
---|
EC2 utilities wrapping boto methods
boto reference in: http://boto.cloudhackers.com/ec2_tut.html
Will create an AMI from the instance in the running or stopped state.
Parameters: |
|
---|---|
Return type: | string |
Returns: | The new image id |
get DNS name for an instance. This operation could take some time as the startup for new instances is not immediate
AMI’s and instances put into this list will be skipped in the shutdown process
set account permissions to a set of ami’s
Copy the file specified by src (or contained in src if it is a directory) to the specified S3 bucket, pre-pending the optional key_prefix to the relative path of each file within src.
Function originally taken from here: http://www.gordontillman.info/computers/41-web-application-development/88-using-python-boto-library-with-s3 @param bucket: The name of the bucket we are working with. It must already exist. @type bucket: string @param key_prefix: This will be prepended to every source path that we copy. Can be empty. Often is. @type key_prefix: string @param src: This is the source file or directory. @type src: string @param s3_conn: This is an active S3 connection. @type s3_conn: boto.s3.connection.S3Connection @param filter: Only files with extensions listed in this filter will be candidates for copying. You can have an empty string in this list to copy files with NO file extension. @type filter: list of strings @param acl: One of the supported ACL policies. @type acl: string @param pretend: If true, we just log what we would do, but we don’t do it. @type pretend: boolean @param starting_with: An option source file path. If specified, skips all the files preceeding it until this file is reached. @type starting_with: string @raise boto.exception.S3ResponseError: If you specify a non-existing bucket
general utility functions
get ‘myname’ from a xml structure like this one when you call this method with ‘name’: <?xml version=”1.0” encoding=”UTF-8” ?> <root> <name>myname</name> </root>
“Return list from file ignoring blanks and comments