def create_volume(self, vol, snapshot_id=None): ''' Creates a volume and attaches it to this instance If given a snapshot id, populates from the snapshot, else formats the volume first Subsequently mounts the volume to the given mount point ''' # catch this at a higher level if we want to skip if os.path.exists(vol.instance_device): error_message = 'Device %s already exists' % vol.instance_device error_message += '\n run with --ignore-mounted to proceed' raise exceptions.DeviceAlreadyExists(error_message) # we always create a new volume when mounting upon boot # load from a snapshot if we have one log_message = 'Creating a volume of size %s in zone %s from snapshot %s' logger.info(log_message, vol.size, self.availability_zone, snapshot_id) # tell boto about the iops if we want them :) kwargs = dict() if vol.iops: kwargs['iops'] = vol.iops boto_volume = self.con.create_volume(size=vol.size, zone=self.availability_zone, snapshot=snapshot_id, volume_type=vol.volume_type, **kwargs) # tag the volume tags = self.get_tags_for_volume(vol) logger.info('tagging volume %s with tags %s', boto_volume.id, tags) add_tags(boto_volume, tags) logger.info('tags added succesfully') return boto_volume
def make_snapshot(self, vol): # get a snapshot name description = self.get_snapshot_description(vol) logger.info( 'preparing to create a snapshot with description %s', description) # find the volume ID for this device volume_id = self.get_volume_id(vol) # get the tags, note that these are used for finding the right snapshot tags = self.get_tags_for_volume(vol) # Don't freeze more than we need to with vol.freeze(): logger.info('creating snapshot') snapshot = self.con.create_snapshot( volume_id, description=description) logger.info('succesfully created snapshot with id %s', snapshot.id) # Add tags logger.info('tagging snapshot %s with tags %s', snapshot.id, tags) add_tags(snapshot, tags) return snapshot
def make_snapshot(self, vol): # get a snapshot name description = self.get_snapshot_description(vol) logger.info('preparing to create a snapshot with description %s', description) # find the volume ID for this device volume_id = self.get_volume_id(vol) # get the tags, note that these are used for finding the right snapshot tags = self.get_tags_for_volume(vol) # Don't freeze more than we need to with vol.freeze(): logger.info('creating snapshot') snapshot = self.con.create_snapshot(volume_id, description=description) logger.info('succesfully created snapshot with id %s', snapshot.id) # Add tags logger.info('tagging snapshot %s with tags %s', snapshot.id, tags) add_tags(snapshot, tags) return snapshot
def create_volume(self, vol, snapshot_id=None): ''' Creates a volume and attaches it to this instance If given a snapshot id, populates from the snapshot, else formats the volume first Subsequently mounts the volume to the given mount point ''' # catch this at a higher level if we want to skip if os.path.exists(vol.instance_device): error_message = 'Device %s already exists' % vol.instance_device error_message += '\n run with --ignore-mounted to proceed' raise exceptions.DeviceAlreadyExists(error_message) # we always create a new volume when mounting upon boot # load from a snapshot if we have one log_message = 'Creating a volume of size %s in zone %s from snapshot %s' logger.info(log_message, vol.size, self.availability_zone, snapshot_id) # tell boto about the iops if we want them :) kwargs = dict() if vol.iops: kwargs['iops'] = vol.iops boto_volume = self.con.create_volume(size=vol.size, zone=self.availability_zone, snapshot=snapshot_id, volume_type=vol.volume_type, **kwargs ) # tag the volume tags = self.get_tags_for_volume(vol) logger.info('tagging volume %s with tags %s', boto_volume.id, tags) add_tags(boto_volume, tags) logger.info('tags added succesfully') return boto_volume