From: Stavros Sachtouris Date: Mon, 18 Nov 2013 16:56:01 +0000 (+0200) Subject: Apply naming conventions to 1st level image cmds X-Git-Tag: 0.12rc1~20^2~16 X-Git-Url: https://code.grnet.gr/git/kamaki/commitdiff_plain/00b1248ea57e87217588734eab78763baa019a11 Apply naming conventions to 1st level image cmds Refs: #4583 --- diff --git a/kamaki/cli/commands/cyclades.py b/kamaki/cli/commands/cyclades.py index 1bd2680..13bd78f 100644 --- a/kamaki/cli/commands/cyclades.py +++ b/kamaki/cli/commands/cyclades.py @@ -479,13 +479,13 @@ class server_modify(_init_cyclades, _optional_output_cmd): '--firewall'), metadata_to_set=KeyValueArgument( 'Set metadata in key=value form (can be repeated)', - '--set-metadata'), + '--metadata-set'), metadata_to_delete=RepeatableArgument( - 'Delete metadata by key (can be repeated)', '--del-metadata') + 'Delete metadata by key (can be repeated)', '--metadata-del') ) required = [ 'server_name', 'flavor_id', 'firewall_profile', 'metadata_to_set', - 'metadata_to_del'] + 'metadata_to_delete'] @errors.generic.all @errors.cyclades.connection @@ -698,76 +698,6 @@ class server_addr(_init_cyclades, _optional_json): @command(server_cmds) -class server_metadata_list(_init_cyclades, _optional_json): - """Get server metadata""" - - @errors.generic.all - @errors.cyclades.connection - @errors.cyclades.server_id - @errors.cyclades.metadata - def _run(self, server_id, key=''): - self._print( - self.client.get_server_metadata(int(server_id), key), - self.print_dict) - - def main(self, server_id, key=''): - super(self.__class__, self)._run() - self._run(server_id=server_id, key=key) - - -@command(server_cmds) -class server_metadata_set(_init_cyclades, _optional_json): - """Set / update virtual server metadata - Metadata should be given in key/value pairs in key=value format - For example: /server metadata set key1=value1 key2=value2 - Old, unreferenced metadata will remain intact - """ - - @errors.generic.all - @errors.cyclades.connection - @errors.cyclades.server_id - def _run(self, server_id, keyvals): - assert keyvals, 'Please, add some metadata ( key=value)' - metadata = dict() - for keyval in keyvals: - k, sep, v = keyval.partition('=') - if sep and k: - metadata[k] = v - else: - raiseCLIError( - 'Invalid piece of metadata %s' % keyval, - importance=2, details=[ - 'Correct metadata format: key=val', - 'For example:', - '/server metadata set ' - 'key1=value1 key2=value2']) - self._print( - self.client.update_server_metadata(int(server_id), **metadata), - self.print_dict) - - def main(self, server_id, *key_equals_val): - super(self.__class__, self)._run() - self._run(server_id=server_id, keyvals=key_equals_val) - - -@command(server_cmds) -class server_metadata_delete(_init_cyclades, _optional_output_cmd): - """Delete virtual server metadata""" - - @errors.generic.all - @errors.cyclades.connection - @errors.cyclades.server_id - @errors.cyclades.metadata - def _run(self, server_id, key): - self._optional_output( - self.client.delete_server_metadata(int(server_id), key)) - - def main(self, server_id, key): - super(self.__class__, self)._run() - self._run(server_id=server_id, key=key) - - -@command(server_cmds) class server_stats(_init_cyclades, _optional_json): """Get virtual server statistics""" diff --git a/kamaki/cli/commands/image.py b/kamaki/cli/commands/image.py index b028a6d..90e9e77 100644 --- a/kamaki/cli/commands/image.py +++ b/kamaki/cli/commands/image.py @@ -284,18 +284,8 @@ class image_list(_init_image, _optional_json, _name_filter, _id_filter): @command(image_cmds) -class image_meta(_init_image): - """Manage image metadata and custom properties""" - - -@command(image_cmds) class image_info(_init_image, _optional_json): - """Get image metadata - Image metadata include: - - image file information (location, size, etc.) - - image information (id, name, etc.) - - image os properties (os, fs, etc.) - """ + """Get image metadata""" @errors.generic.all @errors.plankton.connection @@ -312,47 +302,41 @@ class image_info(_init_image, _optional_json): @command(image_cmds) -class image_meta_set(_init_image, _optional_output_cmd): +class image_modify(_init_image, _optional_json): """Add / update metadata and properties for an image The original image preserves the values that are not affected """ arguments = dict( - name=ValueArgument('Set a new name', ('--name')), - disk_format=ValueArgument('Set a new disk format', ('--disk-format')), + image_name=ValueArgument('Change name', '--name'), + disk_format=ValueArgument('Change disk format', '--disk-format'), container_format=ValueArgument( - 'Set a new container format', ('--container-format')), - status=ValueArgument('Set a new status', ('--status')), - publish=FlagArgument('publish the image', ('--publish')), - unpublish=FlagArgument('unpublish the image', ('--unpublish')), - properties=KeyValueArgument( + 'Change container format', '--container-format'), + status=ValueArgument('Change status', '--status'), + publish=FlagArgument('Publish the image', '--publish'), + unpublish=FlagArgument('Unpublish the image', '--unpublish'), + property_to_set=KeyValueArgument( 'set property in key=value form (can be repeated)', - ('-p', '--property')) + ('-p', '--property-set')), + property_to_del=RepeatableArgument( + 'Delete property by key (can be repeated)', '--property-del') ) - - def _check_empty(self): - for term in ( - 'name', 'disk_format', 'container_format', 'status', 'publish', - 'unpublish', 'properties'): - if self[term]: - if self['publish'] and self['unpublish']: - raiseCLIError( - '--publish and --unpublish are mutually exclusive') - return - raiseCLIError( - 'Nothing to update, please use arguments (-h for a list)') + required = [ + 'image_name', 'disk_format', 'container_format', 'status', 'publish', + 'unpublish', 'property_to_set'] @errors.generic.all @errors.plankton.connection @errors.plankton.id def _run(self, image_id): - self._check_empty() meta = self.client.get_meta(image_id) - for k, v in self['properties'].items(): + for k, v in self['property_to_set'].items(): meta['properties'][k.upper()] = v + for k in self['property_to_del']: + meta['properties'][k.upper()] = None self._optional_output(self.client.update_image( image_id, - name=self['name'], + name=self['image_name'], disk_format=self['disk_format'], container_format=self['container_format'], status=self['status'], @@ -365,46 +349,6 @@ class image_meta_set(_init_image, _optional_output_cmd): @command(image_cmds) -class image_meta_delete(_init_image, _optional_output_cmd): - """Remove/empty image metadata and/or custom properties""" - - arguments = dict( - disk_format=FlagArgument('Empty disk format', ('--disk-format')), - container_format=FlagArgument( - 'Empty container format', ('--container-format')), - status=FlagArgument('Empty status', ('--status')), - properties=RepeatableArgument( - 'Property keys to remove', ('-p', '--property')) - ) - - def _check_empty(self): - for t in ('disk_format', 'container_format', 'status', 'properties'): - if self[t]: - return - raiseCLIError( - 'Nothing to update, please use arguments (-h for a list)') - - @errors.generic.all - @errors.plankton.connection - @errors.plankton.id - def _run(self, image_id): - self._check_empty() - meta = self.client.get_meta(image_id) - for k in self['properties']: - meta['properties'].pop(k.upper(), None) - self._optional_output(self.client.update_image( - image_id, - disk_format='' if self['disk_format'] else None, - container_format='' if self['container_format'] else None, - status='' if self['status'] else None, - **meta['properties'])) - - def main(self, image_id): - super(self.__class__, self)._run() - self._run(image_id=image_id) - - -@command(image_cmds) class image_register(_init_image, _optional_json): """(Re)Register an image file to an Image service The image file must be stored at a pithos repository