def __init__(self, ami_id, ami_region): self._ami_id = ami_id self._ami_region = ami_region log.info("Looking for AMI %s in region %s", self._ami_id, self._ami_region) try: self._conn = ec2.connect_to_region(self._ami_region) except boto.exception.NoAuthHandlerFound: log.error('Could not connect to region %s' % self._ami_region) log.critical( 'No AWS credentials found. To configure Boto, please read: http://boto.readthedocs.org/en/latest/boto_config_tut.html' ) raise DistamiException('No AWS credentials found.') self._image = utils.wait_for_ami_to_be_available( self._conn, self._ami_id) log.debug('AMI details: %s', vars(self._image)) # Get current launch permissions self._launch_perms = self._image.get_launch_permissions() log.debug("Current launch permissions: %s", self._launch_perms) # Figure out the underlying snapshot ami = utils.get_ami(self._conn, self._ami_id) bdm = self._image.block_device_mapping[ami.root_device_name] log.debug('Block device mapping for %s: %s', ami.root_device_name, vars(bdm)) self._snapshot_id = bdm.snapshot_id log.info("Found AMI %s with snapshot %s", self._ami_id, self._snapshot_id)
def copy_to_region(self, region): ''' Copies this AMI to another region ''' dest_conn = ec2.connect_to_region(region) log.info('Copying AMI to %s', region) cp_ami = dest_conn.copy_image(self._ami_region, self._ami_id, self._image.name, self._image.description) copied_ami_id = cp_ami.image_id # Wait for AMI to finish copying before returning copied_image = utils.wait_for_ami_to_be_available( dest_conn, copied_ami_id) # Copy AMI tags to new AMI log.info('Copying tags to %s in %s', copied_ami_id, region) if self._image.tags: dest_conn.create_tags(copied_ami_id, self._image.tags) else: log.info('AMI tags empty, nothing to copy') # Also copy snapshot tags to new snapshot ami = utils.get_ami(self._conn, self._ami_id) copied_snapshot_id = copied_image.block_device_mapping[ ami.root_device_name].snapshot_id snapshot = utils.get_snapshot(self._conn, self._snapshot_id) log.info('Copying tags to %s in %s', copied_snapshot_id, region) if snapshot.tags: dest_conn.create_tags(copied_snapshot_id, snapshot.tags) else: log.info('Snapshot tags empty, nothing to copy') log.info('Copy to %s complete', region) return copied_ami_id
def copy_to_region(self, region): ''' Copies this AMI to another region ''' dest_conn = ec2.connect_to_region(region) log.info('Copying AMI to %s', region) cp_ami = dest_conn.copy_image(self._ami_region, self._ami_id, self._image.name, self._image.description) copied_ami_id = cp_ami.image_id # Wait for AMI to finish copying before returning copied_image = utils.wait_for_ami_to_be_available(dest_conn, copied_ami_id) # Copy AMI tags to new AMI log.info('Copying tags to %s in %s', copied_ami_id, region) if self._image.tags: dest_conn.create_tags(copied_ami_id, self._image.tags) else: log.info('AMI tags empty, nothing to copy') # Also copy snapshot tags to new snapshot copied_snapshot_id = copied_image.block_device_mapping['/dev/sda1'].snapshot_id snapshot = utils.get_snapshot(self._conn, self._snapshot_id) log.info('Copying tags to %s in %s', copied_snapshot_id, region) if snapshot.tags: dest_conn.create_tags(copied_snapshot_id, snapshot.tags) else: log.info('Snapshot tags empty, nothing to copy') log.info('Copy to %s complete', region) return copied_ami_id
def __init__(self, ami_id, ami_region): self._ami_id = ami_id self._ami_region = ami_region log.info("Looking for AMI %s in region %s", self._ami_id, self._ami_region) self._conn = ec2.connect_to_region(self._ami_region) self._image = utils.wait_for_ami_to_be_available(self._conn, self._ami_id) log.debug('AMI details: %s', vars(self._image)) # Get current launch permissions self._launch_perms = self._image.get_launch_permissions() log.debug("Current launch permissions: %s", self._launch_perms) # Figure out the underlying snapshot bdm = self._image.block_device_mapping['/dev/sda1'] log.debug('Block device mapping for /dev/sda1: %s', vars(bdm)) self._snapshot_id = bdm.snapshot_id log.info("Found AMI %s with snapshot %s", self._ami_id, self._snapshot_id)
def __init__(self, ami_id, ami_region): self._ami_id = ami_id self._ami_region = ami_region log.info("Looking for AMI %s in region %s", self._ami_id, self._ami_region) self._conn = ec2.connect_to_region(self._ami_region) self._image = utils.wait_for_ami_to_be_available( self._conn, self._ami_id) log.debug('AMI details: %s', vars(self._image)) # Get current launch permissions self._launch_perms = self._image.get_launch_permissions() log.debug("Current launch permissions: %s", self._launch_perms) # Figure out the underlying snapshot bdm = self._image.block_device_mapping['/dev/sda1'] log.debug('Block device mapping for /dev/sda1: %s', vars(bdm)) self._snapshot_id = bdm.snapshot_id log.info("Found AMI %s with snapshot %s", self._ami_id, self._snapshot_id)
def __init__(self, ami_id, ami_region): self._ami_id = ami_id self._ami_region = ami_region log.info("Looking for AMI %s in region %s", self._ami_id, self._ami_region) try: self._conn = ec2.connect_to_region(self._ami_region) except boto.exception.NoAuthHandlerFound: log.error('Could not connect to region %s' % self._ami_region) log.critical('No AWS credentials found. To configure Boto, please read: http://boto.readthedocs.org/en/latest/boto_config_tut.html') raise DistamiException('No AWS credentials found.') self._image = utils.wait_for_ami_to_be_available(self._conn, self._ami_id) log.debug('AMI details: %s', vars(self._image)) # Get current launch permissions self._launch_perms = self._image.get_launch_permissions() log.debug("Current launch permissions: %s", self._launch_perms) # Figure out the underlying snapshot bdm = self._image.block_device_mapping['/dev/sda1'] log.debug('Block device mapping for /dev/sda1: %s', vars(bdm)) self._snapshot_id = bdm.snapshot_id log.info("Found AMI %s with snapshot %s", self._ami_id, self._snapshot_id)