class volume_create(_BlockStorageInit, OptionalOutput, _VolumeWait): """Create a new volume""" arguments = dict( size=argument.IntArgument('Volume size in GB', '--size'), server_id=argument.ValueArgument('The server to attach the volume to', '--server-id'), name=argument.ValueArgument('Display name', '--name'), description=argument.ValueArgument('Volume description', '--description'), snapshot_id=argument.ValueArgument( 'Associate a snapshot to the new volume', '--snapshot-id'), image_id=argument.ValueArgument('Associate an image to the new volume', '--image-id'), volume_type=argument.ValueArgument( 'default: if combined with --server-id, the default is ' 'automatically configured to match the server, otherwise it is ' 'ext_archipelago', '--volume-type'), metadata=argument.KeyValueArgument( 'Metadata of key=value form (can be repeated)', '--metadata'), project_id=argument.ValueArgument('Assign volume to a project', '--project-id'), wait=argument.FlagArgument( 'Wait volume to be created and ready for use', ('-w', '--wait')), ) required = ('size', 'name') @errors.Generic.all def _run(self, size, name): # Figure out volume type volume_type = self['volume_type'] if not (self['server_id'] or volume_type): for vtype in self.client.list_volume_types(): if vtype['name'] in ('ext_archipelago'): volume_type = vtype['id'] break r = self.client.create_volume(size, name, server_id=self['server_id'], display_description=self['description'], snapshot_id=self['snapshot_id'], imageRef=self['image_id'], volume_type=volume_type, metadata=self['metadata'], project=self['project_id']) self.print_dict(r) r = self.client.get_volume_details(r['id']) if self['wait'] and r['status'] != 'in_use': self.wait_while(r['id'], r['status']) r = self.client.get_volume_details(r['id']) if r['status'] != 'in_use': exit(1) def main(self): super(self.__class__, self)._run() self._run(size=self['size'], name=self['name'])
class snapshot_modify(_BlockStorageInit, OptionalOutput): """Modify a snapshot's properties""" arguments = dict( name=argument.ValueArgument('Rename', '--name'), description=argument.ValueArgument('New description', '--description'), ) required = ['name', 'description'] @errors.Generic.all def _run(self, snapshot_id): self.print_( self.client.update_snapshot( snapshot_id, display_name=self['name'], display_description=self['description']), self.print_dict) def main(self, snapshot_id): super(self.__class__, self)._run() self._run(snapshot_id=snapshot_id)
class snapshot_create(_BlockStorageInit, OptionalOutput): """Create a new snapshot""" arguments = dict( volume_id=argument.ValueArgument('Volume associated to new snapshot', '--volume-id'), name=argument.ValueArgument('Display name', '--name'), description=argument.ValueArgument('New description', '--description'), ) required = ('volume_id', ) @errors.Generic.all def _run(self, volume_id): self.print_( self.client.create_snapshot( volume_id, display_name=self['name'], display_description=self['description']), self.print_dict) def main(self): super(self.__class__, self)._run() self._run(volume_id=self['volume_id'])
class volume_reassign(_BlockStorageInit): """Reassign volume to a different project""" arguments = dict(project_id=argument.ValueArgument('Project to assign', '--project-id'), ) required = ('project_id', ) @errors.Generic.all def _run(self, volume_id, project_id): self.client.reassign_volume(volume_id, project_id) def main(self, volume_id): super(self.__class__, self)._run() self._run(volume_id=volume_id, project_id=self['project_id'])
class volume_modify(_BlockStorageInit, OptionalOutput): """Modify a volume's properties""" arguments = dict(name=argument.ValueArgument('Rename', '--name'), description=argument.ValueArgument( 'New description', '--description'), delete_on_termination=argument.BooleanArgument( 'Delete on termination', '--delete-on-termination')) required = ['name', 'description', 'delete_on_termination'] @errors.Generic.all def _run(self, volume_id): self.print_( self.client.update_volume( volume_id, display_name=self['name'], display_description=self['description'], delete_on_termination=self['delete_on_termination']), self.print_dict) def main(self, volume_id): super(self.__class__, self)._run() self._run(volume_id)
class volume_create(_BlockStorageInit, OptionalOutput): """Create a new volume""" arguments = dict( size=argument.IntArgument('Volume size in GB', '--size'), server_id=argument.ValueArgument('The server for the new volume', '--server-id'), name=argument.ValueArgument('Display name', '--name'), # src_volume_id=argument.ValueArgument( # 'Associate another volume to the new volume', # '--source-volume-id'), description=argument.ValueArgument('Volume description', '--description'), snapshot_id=argument.ValueArgument( 'Associate a snapshot to the new volume', '--snapshot-id'), image_id=argument.ValueArgument('Associate an image to the new volume', '--image-id'), volume_type=argument.ValueArgument('Volume type', '--volume-type'), metadata=argument.KeyValueArgument( 'Metadata of key=value form (can be repeated)', '--metadata'), project_id=argument.ValueArgument('Assign volume to a project', '--project-id'), ) required = ('size', 'server_id', 'name') @errors.Generic.all def _run(self, size, server_id, name): self.print_( self.client.create_volume( size, server_id, name, # source_volid=self['src_volume_id'], display_description=self['description'], snapshot_id=self['snapshot_id'], imageRef=self['image_id'], volume_type=self['volume_type'], metadata=self['metadata'], project=self['project_id']), self.print_dict) def main(self): super(self.__class__, self)._run() self._run(size=self['size'], server_id=self['server_id'], name=self['name'])
def test___init__(self, arg): help, pname, default = 'help', 'pname', 'default' fa = argument.ValueArgument(help, pname, default) self.assertTrue(isinstance(fa, argument.ValueArgument)) arg.assert_called_once_with(1, help, pname, default)