summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-07-23 15:25:26 +0000
committerGerrit Code Review <review@openstack.org>2013-07-23 15:25:26 +0000
commitf175d122473f0bf94abc694a30e3388597b35e26 (patch)
treeb80f6a1a78c8b81b39b79451be18eef4cec5925b /openstackclient/volume
parent7b47579dad1faf0b48a9402cf018de49361d6f12 (diff)
parent818c94875221f606ed56f276c1cbd320a9106754 (diff)
downloadpython-openstackclient-f175d122473f0bf94abc694a30e3388597b35e26.tar.gz
Merge "Clean up properties (metadata) formatting"
Diffstat (limited to 'openstackclient/volume')
-rw-r--r--openstackclient/volume/v1/type.py46
-rw-r--r--openstackclient/volume/v1/volume.py82
2 files changed, 76 insertions, 52 deletions
diff --git a/openstackclient/volume/v1/type.py b/openstackclient/volume/v1/type.py
index dab21d99..0d9fdb39 100644
--- a/openstackclient/volume/v1/type.py
+++ b/openstackclient/volume/v1/type.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2013 OpenStack, LLC.
+# Copyright 2012-2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -26,7 +26,7 @@ from openstackclient.common import utils
class CreateVolumeType(show.ShowOne):
- """Create volume type command"""
+ """Create new volume type"""
log = logging.getLogger(__name__ + '.CreateVolumeType')
@@ -37,6 +37,13 @@ class CreateVolumeType(show.ShowOne):
metavar='<name>',
help='New volume type name',
)
+ parser.add_argument(
+ '--property',
+ metavar='<key=value>',
+ action=parseractions.KeyValueAction,
+ help='Property to add for this volume type '
+ '(repeat option to set multiple properties)',
+ )
return parser
def take_action(self, parsed_args):
@@ -45,6 +52,13 @@ class CreateVolumeType(show.ShowOne):
volume_type = volume_client.volume_types.create(
parsed_args.name
)
+ if parsed_args.property:
+ volume_type.set_keys(parsed_args.property)
+ # Map 'extra_specs' column to 'properties'
+ volume_type._info.update(
+ {'properties': utils.format_dict(
+ volume_type._info.pop('extra_specs'))}
+ )
info = {}
info.update(volume_type._info)
@@ -52,7 +66,7 @@ class CreateVolumeType(show.ShowOne):
class DeleteVolumeType(command.Command):
- """Delete volume type command"""
+ """Delete volume type"""
log = logging.getLogger(__name__ + '.DeleteVolumeType')
@@ -75,7 +89,7 @@ class DeleteVolumeType(command.Command):
class ListVolumeType(lister.Lister):
- """List volume type command"""
+ """List volume types"""
log = logging.getLogger(__name__ + '.ListVolumeType')
@@ -92,18 +106,20 @@ class ListVolumeType(lister.Lister):
self.log.debug('take_action(%s)' % parsed_args)
if parsed_args.long:
columns = ('ID', 'Name', 'Extra Specs')
+ column_headers = ('ID', 'Name', 'Properties')
else:
columns = ('ID', 'Name')
+ column_headers = columns
data = self.app.client_manager.volume.volume_types.list()
- return (columns,
+ return (column_headers,
(utils.get_item_properties(
s, columns,
- formatters={'Extra Specs': _format_type_list_extra_specs},
+ formatters={'Extra Specs': utils.format_dict},
) for s in data))
class SetVolumeType(command.Command):
- """Set volume type command"""
+ """Set volume type property"""
log = logging.getLogger(__name__ + '.SetVolumeType')
@@ -136,7 +152,7 @@ class SetVolumeType(command.Command):
class UnsetVolumeType(command.Command):
- """Unset volume type command"""
+ """Unset volume type property"""
log = logging.getLogger(__name__ + '.UnsetVolumeType')
@@ -173,17 +189,3 @@ class UnsetVolumeType(command.Command):
else:
self.app.log.error("No changes requested\n")
return
-
-
-def _format_type_list_extra_specs(vol_type):
- """Return a string containing the key value pairs
-
- :param server: a single VolumeType resource
- :rtype: a string formatted to key=value
- """
-
- keys = vol_type.get_keys()
- output = ""
- for s in keys:
- output = output + s + "=" + keys[s] + "; "
- return output
diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py
index f1e421f4..b74fe452 100644
--- a/openstackclient/volume/v1/volume.py
+++ b/openstackclient/volume/v1/volume.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2013 OpenStack, LLC.
+# Copyright 2012-2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -26,7 +26,7 @@ from openstackclient.common import utils
class CreateVolume(show.ShowOne):
- """Create volume command"""
+ """Create new volume"""
log = logging.getLogger(__name__ + '.CreateVolume')
@@ -119,12 +119,16 @@ class CreateVolume(show.ShowOne):
parsed_args.property,
parsed_args.image
)
+ # Map 'metadata' column to 'properties'
+ volume._info.update(
+ {'properties': utils.format_dict(volume._info.pop('metadata'))}
+ )
return zip(*sorted(volume._info.iteritems()))
class DeleteVolume(command.Command):
- """Delete volume command"""
+ """Delete volume"""
log = logging.getLogger(__name__ + '.DeleteVolume')
@@ -157,7 +161,7 @@ class DeleteVolume(command.Command):
class ListVolume(lister.Lister):
- """List volume command"""
+ """List volumes"""
log = logging.getLogger(__name__ + '.ListVolume')
@@ -190,12 +194,42 @@ class ListVolume(lister.Lister):
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
- columns = ('ID', 'Status', 'Display Name', 'Size',
- 'Volume Type', 'Bootable', 'Attached to')
if parsed_args.long:
- columns = ('ID', 'Status', 'Display Name', 'Size',
- 'Volume Type', 'Bootable', 'Attached to', 'Meta-data')
-
+ columns = (
+ 'ID',
+ 'Display Name',
+ 'Status',
+ 'Size',
+ 'Volume Type',
+ 'Bootable',
+ 'Attached to',
+ 'Metadata',
+ )
+ column_headers = (
+ 'ID',
+ 'Display Name',
+ 'Status',
+ 'Size',
+ 'Type',
+ 'Bootable',
+ 'Attached',
+ 'Properties',
+ )
+ else:
+ columns = (
+ 'ID',
+ 'Display Name',
+ 'Status',
+ 'Size',
+ 'Attached to',
+ )
+ column_headers = (
+ 'ID',
+ 'Display Name',
+ 'Status',
+ 'Size',
+ 'Attached',
+ )
search_opts = {
'all_tenants': parsed_args.all_tenants,
'display_name': parsed_args.name,
@@ -205,15 +239,15 @@ class ListVolume(lister.Lister):
volume_client = self.app.client_manager.volume
data = volume_client.volumes.list(search_opts=search_opts)
- return (columns,
+ return (column_headers,
(utils.get_item_properties(
s, columns,
- formatters={'Meta-data': _format_meta_data},
+ formatters={'Metadata': utils.format_dict},
) for s in data))
class SetVolume(command.Command):
- """Set volume command"""
+ """Set volume properties"""
log = logging.getLogger(__name__ + '.SetVolume')
@@ -249,7 +283,6 @@ class SetVolume(command.Command):
volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
if parsed_args.property:
- print "property: %s" % parsed_args.property
volume_client.volumes.set_metadata(volume.id, parsed_args.property)
kwargs = {}
@@ -258,7 +291,6 @@ class SetVolume(command.Command):
if parsed_args.description:
kwargs['display_description'] = parsed_args.description
if kwargs:
- print "kwargs: %s" % kwargs
volume_client.volumes.update(volume.id, **kwargs)
if not kwargs and not parsed_args.property:
@@ -268,7 +300,7 @@ class SetVolume(command.Command):
class ShowVolume(show.ShowOne):
- """Show volume command"""
+ """Show specific volume"""
log = logging.getLogger(__name__ + '.ShowVolume')
@@ -285,12 +317,16 @@ class ShowVolume(show.ShowOne):
self.log.debug('take_action(%s)' % parsed_args)
volume_client = self.app.client_manager.volume
volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
+ # Map 'metadata' column to 'properties'
+ volume._info.update(
+ {'properties': utils.format_dict(volume._info.pop('metadata'))}
+ )
return zip(*sorted(volume._info.iteritems()))
class UnsetVolume(command.Command):
- """Unset volume command"""
+ """Unset volume properties"""
log = logging.getLogger(__name__ + '.UnsetVolume')
@@ -325,17 +361,3 @@ class UnsetVolume(command.Command):
else:
self.app.log.error("No changes requested\n")
return
-
-
-def _format_meta_data(volume):
- """Return a string containing the key value pairs
-
- :param server: a single volume resource
- :rtype: a string formatted to key=value
- """
-
- keys = volume.metadata
- output = ""
- for s in keys:
- output = output + s + "=" + keys[s] + "; "
- return output