Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def make_snapshot_public(self):
        ''' Makes a snapshot public '''

        snapshot = utils.get_snapshot(self._conn, self._snapshot_id)
        log.debug('Snapshot details: %s', vars(snapshot))

        log.info('Making snapshot %s public', self._snapshot_id)
        return snapshot.share(groups=['all'])
Ejemplo n.º 4
0
    def make_snapshot_non_public(self):
        ''' Removes the 'all' group permission from the snapshot '''

        snapshot = utils.get_snapshot(self._conn, self._snapshot_id)
        log.debug('Snapshot details: %s', vars(snapshot))

        log.info('Making snapshot %s non-public', self._snapshot_id)
        return snapshot.unshare(groups=['all'])
Ejemplo n.º 5
0
 def make_snapshot_non_public(self):
     ''' Removes the 'all' group permission from the snapshot '''
     
     snapshot = utils.get_snapshot(self._conn, self._snapshot_id)
     log.debug('Snapshot details: %s', vars(snapshot))
     
     log.info('Making snapshot %s non-public', self._snapshot_id)
     return snapshot.unshare(groups=['all'])
Ejemplo n.º 6
0
    def make_snapshot_public(self):
        ''' Makes a snapshot public '''
        
        snapshot = utils.get_snapshot(self._conn, self._snapshot_id)
        log.debug('Snapshot details: %s', vars(snapshot))

        log.info('Making snapshot %s public', self._snapshot_id)
        return snapshot.share(groups=['all'])
Ejemplo n.º 7
0
    def share_snapshot_with_accounts(self, account_ids):
        ''' Shares a snapshot with the supplied list of AWS Account IDs '''
        
        snapshot = utils.get_snapshot(self._conn, self._snapshot_id)
        log.debug('Snapshot details: %s', vars(snapshot))

        log.info('Sharing snapshot %s with AWS Accounts %s', self._snapshot_id, account_ids)
        return snapshot.share(user_ids=account_ids)
Ejemplo n.º 8
0
    def share_snapshot_with_accounts(self, account_ids):
        ''' Shares a snapshot with the supplied list of AWS Account IDs '''

        snapshot = utils.get_snapshot(self._conn, self._snapshot_id)
        log.debug('Snapshot details: %s', vars(snapshot))

        log.info('Sharing snapshot %s with AWS Accounts %s', self._snapshot_id,
                 account_ids)
        return snapshot.share(user_ids=account_ids)