API

awsfabrictasks.conf

class awsfabrictasks.conf.Settings[source]

Bases: object

Settings object inspired by django.conf.settings.

as_dict()[source]

Get all settings (uppercase attributes on this object) as a dict.

pprint()[source]

Prettyprint the settings.

awsfabrictasks.conf.print_settings[source]

Pretty-print the settings as they are seen by the system.

awsfabrictasks.utils

awsfabrictasks.utils.sudo_chattr(remote_path, owner=None, mode=None)[source]

Run sudo_chown() and sudo_chmod() on remote_path. If owner or mode is None, their corresponding function is not called.

awsfabrictasks.utils.sudo_chmod(remote_path, mode)[source]

Run sudo chmod <mode> remote_path.

awsfabrictasks.utils.sudo_chown(remote_path, owner)[source]

Run sudo chown <owner> remote_path.

awsfabrictasks.utils.sudo_mkdir_p(remote_path, **chattr_kw)[source]

sudo mkdir -p <remote_path> followed by :func:`sudo_chattr`(remote_path, **chattr_kw).

awsfabrictasks.utils.sudo_upload_dir(local_dir, remote_dir, **chattr_kw)[source]

Upload all files and directories in local_dir to remote_dir. Directories are created with sudo_mkdir_p() and files are uploaded with sudo_upload_file(). chattr_kw is forwarded in both cases.

awsfabrictasks.utils.sudo_upload_file(local_path, remote_path, **chattr_kw)[source]

Use sudo to upload a file from local_path to remote_path and run sudo_chattr() with the given chattr_kw as arguments.

awsfabrictasks.ubuntu

Ubuntu utilities.

awsfabrictasks.ubuntu.set_locale(locale='en_US')[source]

Set locale to avoid the warnings from perl and others about locale failures.

awsfabrictasks.ec2.api

exception awsfabrictasks.ec2.api.Ec2RegionConnectionError(region)[source]

Bases: exceptions.Exception

Raised when we fail to connect to a region.

exception awsfabrictasks.ec2.api.WaitForStateError[source]

Bases: exceptions.Exception

Raises when wait_for_state() times out.

class awsfabrictasks.ec2.api.Ec2InstanceWrapper(instance)[source]

Bases: object

Wraps a boto.ec2.instance.Instance with convenience functions.

Variables:instance – The boto.ec2.instance.Instance.
Parameters:instance – A boto.ec2.instance.Instance object.
add_instance_to_env()[source]

Add self to fabric.api.env.ec2instances[self.get_ssh_uri()], and register the key-pair for the instance in fabric.api.env.key_filename.

classmethod get_by_instanceid(instanceid)[source]

Connect to AWS and get the EC2 instance with the given instance ID.

Parameters:

instanceid_with_optional_region – Parsed with parse_instanceid() to find the region and name.

Raises:
  • Ec2RegionConnectionError – If connecting to the region fails.
  • LookupError – If the requested instance was not found in the region.
Returns:

A Ec2InstanceWrapper contaning the requested instance.

classmethod get_by_nametag(instancename_with_optional_region)[source]

Connect to AWS and get the EC2 instance with the given Name-tag.

Parameters:

instancename_with_optional_region – Parsed with parse_instancename() to find the region and name.

Raises:
  • Ec2RegionConnectionError – If connecting to the region fails.
  • LookupError – If the requested instance was not found in the region.
Returns:

A Ec2InstanceWrapper contaning the requested instance.

classmethod get_by_tagvalue(tags={}, region=None)[source]

Connect to AWS and get the EC2 instance with the given tag:value pairs.

:param tags
A string like ‘role=testing,fake=yes’ to AND a set of ec2 instance tags
Parameters:

region – optional.

Raises:
  • Ec2RegionConnectionError – If connecting to the region fails.
  • LookupError – If no matching instance was found in the region.
Returns:

A list of :class:`Ec2InstanceWrapper`s containing the matching instances.

classmethod get_from_host_string()[source]

If an instance has been registered in fabric.api.env using add_instance_to_env(), this method can be used to get the instance identified by fabric.api.env.host_string.

get_ssh_key_filename()[source]

Get the SSH indentify filename (.pem-file) for the instance. Searches awsfab_settings.KEYPAIR_PATH for "<instance.key_name>.pem".

Raises LookupError:
 If the key is not found.
get_ssh_uri()[source]

Get the SSH URI for the instance.

Returns:“<instance.tags[‘awsfab-ssh-user’]>@<instance.public_dns_name>”
prettyname()[source]

Return a pretty-formatted name for this instance, using the Name-tag if the instance is tagged with it.

awsfabrictasks.ec2.api.create_hostsfile_from_nametags(nametags=[], suffix='.ec2private', hostsfile_template='\n127.0.0.1 localhost\n\n# The following lines are desirable for IPv6 capable hosts\n::1 ip6-localhost ip6-loopback\nfe00::0 ip6-localnet\nff00::0 ip6-mcastprefix\nff02::1 ip6-allnodes\nff02::2 ip6-allrouters\nff02::3 ip6-allhosts\n\n{custom_hosts}\n')[source]

Create a /etc/hosts file from the list of nametags. The result will be a hostsfile with private_ip_address as IP, and nametag+suffix as hostname.

awsfabrictasks.ec2.api.ec2_rsync(local_dir, remote_dir, rsync_args='-av', sync_content=False)[source]

rsync local_dir into remote_dir on the current EC2 instance (the one returned by Ec2InstanceWrapper.get_from_host_string()).

Parameters:sync_content – Normally the function automatically makes sure local_dir is not suffixed with /, which makes rsync copy local_dir into remote_dir. With sync_content=True, the content of local_dir is synced into remote_dir instead.
awsfabrictasks.ec2.api.parse_instanceid(instanceid_with_optional_region)[source]

Parse instance id with an optional region-name prefixed. Region name is specified by prefixing the instanceid with <regionname>:.

Returns:(region, instanceid) where region defaults to awsfab_settings.DEFAULT_REGION if not prefixed to the id.
awsfabrictasks.ec2.api.parse_instancename(instancename_with_optional_region)[source]

Just like parse_instanceid(), however this is for instance names. We keep them as separate functions in case they diverge in the future.

Returns:(region, instanceid) where region defaults to awsfab_settings.DEFAULT_REGION if not prefixed to the name.
awsfabrictasks.ec2.api.print_ec2_instance(instance, full=False, indentspaces=3)[source]

Print attributes of an ec2 instance.

Parameters:
  • instance – A boto.ec2.instance.Instance object.
  • full – Print all attributes? If not, a subset of the attributes are printed.
  • indentspaces – Number of spaces to indent each line in the output.
awsfabrictasks.ec2.api.wait_for_running_state(instanceid, **kwargs)[source]

Shortcut for wait_for_state(instanceid, 'running', **kwargs).

awsfabrictasks.ec2.api.wait_for_state(instanceid, state_name, sleep_intervals=[15, 5], last_sleep_repeat=40)[source]

Poll the instance with instanceid until its state_name matches the desired state_name.

The first poll is performed without any delay, and the rest of the polls are performed according to sleep_intervals.

Parameters:
  • instanceid – ID of an instance.
  • state_name – The state_name to wait for.
  • sleep_intervals – List of seconds to wait between each poll for state. The first poll is made immediately, then we wait for sleep_intervals[0] seconds before the next poll, and repeat for each item in sleep_intervals. Then we repeat for last_sleep_repeat using the last item in sleep_intervals as the timout for each wait.
  • last_sleep_repeat – Number of times to repeat the last item in sleep_intervals. If this is 20, we will wait for a maximum of sum(sleep_intervals) + sleep_intervals[-1]*20.
awsfabrictasks.ec2.api.wait_for_stopped_state(instanceid, **kwargs)[source]

Shortcut for wait_for_state(instanceid, 'stopped', **kwargs).

awsfabrictasks.decorators

awsfabrictasks.decorators.ec2instance(nametag=None, instanceid=None)[source]

Wraps the decorated function to execute as if it had been invoked with --ec2names or --ec2ids.

Project Versions

Table Of Contents

Previous topic

Tasks

Next topic

awsfab_settings.py — Settings

This Page