Bases: object
Settings object inspired by django.conf.settings.
Clear all settings (intended for testing). Deletes all uppercase attributes.
Bases: exceptions.KeyError
Raised when getLoglevelFromString() gets an invalid loglevelstring.
x.__init__(...) initializes x; see help(type(x)) for signature
Compute the hex-digested md5 checksum of the given localfile.
Parameters: | localfile – Path to a file on the local filesystem. |
---|
Configure a stdout/stderr logger (logging.StreamHandler) with the given loggername and level. If you are configuring logging for a task, use configureStreamLoggerForTask().
This is suitable for log-configuration for a single task, where the user specifies a loglevel.
Returns: | The configured logger. |
---|
Configure logging for a task.
Shortcut for:
configureStreamLogger(modulename + '.' + taskname, loglevel)
Example (note that what you put in the loglevel docs for your task depends on how you use the logger):
@task
mytask(loglevel='INFO'):
"""
Does some task.
:param loglevel:
Controls the amount of output:
QUIET --- No output.
INFO --- Only produce output for changes.
DEBUG --- One line of output for each file.
Defaults to "INFO".
"""
log = configureStreamLoggerForTask(__name__, 's3_syncupload_dir',
getLoglevelFromString(loglevel))
log.info('Hello world')
Return path suffixed with / (path is unchanged if it is already suffixed with /).
Lookup loglevelstring in loglevel_stringmap.
Raises InvalidLogLevel: | |
---|---|
If loglevelstring is not in loglevel_stringmap. | |
Returns: | The loglevel. |
Return type: | int |
Return the content-type for the given filename. Uses mimetypes.guess_type().
Return True if data is one of:: 'true', 'True', True. Otherwise, return False.
rsync uses / in the source directory to determine if we should sync a directory or the contents of a directory. How rsync works:
This is error-prone, and the consequences can be severe if combined with --delete. Therefore, we use a boolean to distinguish between these two methods of specifying source directory, and reformat the path using force_slashend() and force_noslashend().
Parameters: |
|
---|
Run sudo_chown() and sudo_chmod() on remote_path. If owner or mode is None, their corresponding function is not called.
sudo mkdir -p <remote_path> followed by :func:`sudo_chattr`(remote_path, **chattr_kw).
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.
Use sudo to upload a file from local_path to remote_path and run sudo_chattr() with the given chattr_kw as arguments.
Create a tempfile containing string_to_upload, and use sudo_upload_file() to upload the tempfile. Removes the tempfile when the upload is complete or if it fails.
Parameters: |
|
---|
Map of strings to loglevels (for the logging module)
Ubuntu utilities.
Bases: exceptions.Exception
Raised when we fail to connect to a region.
Bases: exceptions.LookupError
Base class for instance lookup errors.
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: awsfabrictasks.ec2.api.InstanceLookupError
Raised when multiple instances with the same nametag is discovered. (see: Ec2InstanceWrapper.get_by_nametag())
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: awsfabrictasks.ec2.api.InstanceLookupError
Raised when no instace with the requested name is found in Ec2InstanceWrapper.get_by_nametag().
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: awsfabrictasks.ec2.api.InstanceLookupError
Raised when more than one instance is found when expecting exactly one instance.
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: exceptions.Exception
Raises when wait_for_state() times out.
x.__init__(...) initializes x; see help(type(x)) for signature
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 self to fabric.api.env.ec2instances[self.get_ssh_uri()], and register the key-pair for the instance in fabric.api.env.key_filename.
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: |
|
Returns: | A Ec2InstanceWrapper contaning the requested instance. |
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: |
|
Returns: | A Ec2InstanceWrapper contaning the requested instance. |
Connect to AWS and get the EC2 instance with the given tag:value pairs.
Parameters: | region – optional. |
---|---|
Raises: |
|
Returns: | A list of :class:`Ec2InstanceWrapper`s containing the matching instances. |
Use get_by_tagvalue() to find instances by tags, but raise LookupError if not exactly one instance is found.
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 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. |
Bases: object
Launch instances configured in awsfab_settings.EC2_LAUNCH_CONFIGS.
Example:
launcher = Ec2LaunchInstance(extra_tags={'Name': 'mytest'})
launcher.confirm()
instance = launcher.run_instance()
Note that this class is optimized for the following use case:
- Create one or more instances (initialize one or more Ec2LaunchInstance).
- Confirm using confirm() or confirm_many().
- Launch each instance using meth:Ec2LaunchInstance.run_instance or Ec2LaunchInstance.run_many_instances().
- Use Ec2LaunchInstance.wait_for_running_state_many() to wait for all instances to launch.
- Do something with the running instances.
Example of launching many instances:
a = Ec2LaunchInstance(extra_tags={‘Name’: ‘a’}) b = Ec2LaunchInstance(extra_tags={‘Name’: ‘b’}) Ec2LaunchInstance.confirm_many([a, b]) Ec2LaunchInstance.run_many_instances([a, b]) # Note: that we can start doing stuff with a and b that does not # require the instances to be running, such as setting tags. Ec2LaunchInstance.wait_for_running_state_many([a, b])
Initialize the launcher. Runs create_config_ask_if_none().
Parameters: |
|
---|
Use prettyprint() to show the user their choices, and ask for confirmation. Runs fabric.api.abort() if the user does not confirm the choices.
Loop through Use prettyprint() to show the user their choices, and ask for confirmation. Runs fabric.api.abort() if the user does not confirm the choices.
Set kw and conf using configname. Prompt the user for a configname if bool(configname) is False.
Merge tags from the awsfab_settings.EC2_LAUNCH_CONFIGS config, and the extra_tags parameter for __init__, and return the resulting dict.
Run/launch the configured instance, and add the tags to the instance (get_all_tags()).
Returns: | The launched instance. |
---|
Loop through launchers and run run_instance().
Parameters: |
|
---|
Loop through launchers and run wait_for_running_state().
Parameters: |
|
---|
A config dict from awsfab_settings.EC2_LAUNCH_CONFIGS.
See the docs for the __init__ parameter.
See the docs for the __init__ parameter.
The instance launced by run_instance(). None when run_instance() has not been invoked.
Keyword arguments for run_instances().
Number of times to retry when adding tags gets EC2ResponseError.
Number of seconds to sleep before retrying when adding tags gets EC2ResponseError.
Deprecated since version 1.0.13: Use ec2_rsync_upload() instead.
rsync remote_dir on the current EC2 instance (the one returned by Ec2InstanceWrapper.get_from_host_string()) into local_dir.
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. |
---|
Returns the rsync command used by ec2_rsync_download(). Takes the same parameters as ec2_rsync_download(), except for the first parameter, instancewrapper, which is a Ec2InstanceWrapper object.
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. |
---|
Returns the rsync command used by ec2_rsync_upload(). Takes the same parameters as ec2_rsync_upload(), except for the first parameter, instancewrapper, which is a Ec2InstanceWrapper object.
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. |
---|
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. |
---|
Print attributes of an ec2 instance.
Parameters: |
|
---|
Shortcut for wait_for_state(instanceid, 'running', **kwargs).
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: |
|
---|
Bases: exceptions.Exception
Raised when we fail to connect to S3.
Bases: exceptions.Exception
Base class for all S3 errors. Never raised directly.
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: awsfabrictasks.s3.api.S3FileErrorBase
Raised when an S3File does not exist.
Parameters: | s3file – A S3File object. |
---|
Bases: awsfabrictasks.s3.api.S3ErrorBase
Base class for all S3File errors. Never raised directly.
Parameters: | s3file – A S3File object. |
---|
Bases: awsfabrictasks.s3.api.S3FileErrorBase
Raised when trying to overwrite an existing S3File, unless overwriting is requested.
Parameters: | s3file – A S3File object. |
---|
Bases: awsfabrictasks.s3.api.S3FileErrorBase
Raised when trying to use S3File metadata before performing a HEAD request.
Parameters: | s3file – A S3File object. |
---|
Bases: object
S3 connection wrapper.
Parameters: | bucket – A boto.rds.bucket.DBInstance object. |
---|
Get the requested bucket.
Shortcut for:
S3ConnectionWrapper.get_connection().connection.get_bucket(bucketname)
Parameters: | bucketname – Name of an S3 bucket. |
---|
Same as get_bucket(), however the bucketname is filtered through settingsformat_bucketname().
Bases: object
Simplifies working with keys in S3 buckets.
Delete the key/file from the bucket.
Raises S3FileDoesNotExist: | |
---|---|
If the key does not exist in the bucket. |
Return True if the file at the path given in localfile has an md5 hex-digested checksum matching the etag of this S3 key.
Bases: object
Makes it easy to sync files to and from S3. This class does not make any changes to the local filesyste, or S3, it only makes it easy to write function that works with hierarkies of files synced locally and on S3.
A good example is the sourcecode for awsfabrictasks.s3.tasks.s3_syncupload_dir().
Parameters: |
|
---|
Iterate over all files both local and within the S3 prefix. Yields S3SyncIterFile objects.
How it works:
- Uses dirlist_absfilenames() to get all local files in the local_dir.
- Uses s3list_s3filedict() to get all S3 files in the s3prefix.
- Uses these two sets of information to create S3SyncIterFile objects.
Bases: object
Objects of this class is yielded by S3Sync.iterfiles(). Contains info about where the file exists, its local and S3 path (even if it does not exist).
Returns True if localexists and s3exists.
create_localdir() and download the file at s3path to localpath.
Local file exists?
The local path. Always set. Use localexists if you want to know if the local file exists.
S3 file exists?
Get all the files within the given dirpath as a set of absolute filenames.
Iterate over items given bucket, yielding items formatted for output.
Parameters: |
|
---|
Convert a local filepath into a S3 path within the given s3prefix.
Parameters: |
|
---|
Example:: >>> localpath_to_s3path(‘/mydir’, ‘/mydir/hello/world.txt’, ‘my/test’) ‘my/test/hello/world.txt’
Get all the keys with the given prefix as a dict with key-name as key and the key-object wrappen in a S3File as value.
Convert a s3 filepath into a local filepath within the given localdir.
Parameters: |
|
---|
Example:: >>> s3path_to_localpath(‘mydir/’, ‘mydir/hello/world.txt’, ‘/my/test’) ‘/my/test/hello/world.txt’