From abfb0115277471dd584daed18e09eeecf768b527 Mon Sep 17 00:00:00 2001 From: TerryHowe Date: Mon, 6 Jul 2015 11:22:05 -0600 Subject: Support multiple volume qos delete Also make sure that we are using the singular qos_spec when we should and the plural qos_specs otherwise. Change-Id: If4bbeb6fc245d7d80dc3d7dccfe9f949e802653c --- openstackclient/tests/volume/v1/test_qos_specs.py | 16 ++--- openstackclient/tests/volume/v2/test_qos_specs.py | 16 ++--- openstackclient/volume/v1/qos_specs.py | 75 +++++++++++------------ openstackclient/volume/v2/qos_specs.py | 75 +++++++++++------------ 4 files changed, 90 insertions(+), 92 deletions(-) (limited to 'openstackclient') diff --git a/openstackclient/tests/volume/v1/test_qos_specs.py b/openstackclient/tests/volume/v1/test_qos_specs.py index 226fe673..c2e6c0af 100644 --- a/openstackclient/tests/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/volume/v1/test_qos_specs.py @@ -56,7 +56,7 @@ class TestQosAssociate(TestQos): volume_fakes.type_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('volume_type', volume_fakes.type_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -210,7 +210,7 @@ class TestQosDelete(TestQos): volume_fakes.qos_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id) + ('qos_specs', [volume_fakes.qos_id]) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -223,7 +223,7 @@ class TestQosDelete(TestQos): volume_fakes.qos_name ] verifylist = [ - ('qos_specs', volume_fakes.qos_name) + ('qos_specs', [volume_fakes.qos_name]) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -255,7 +255,7 @@ class TestQosDisassociate(TestQos): '--volume-type', volume_fakes.type_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('volume_type', volume_fakes.type_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -278,7 +278,7 @@ class TestQosDisassociate(TestQos): '--all' ] verifylist = [ - ('qos_specs', volume_fakes.qos_id) + ('qos_spec', volume_fakes.qos_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -351,7 +351,7 @@ class TestQosSet(TestQos): '--property', 'iops=9001' ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('property', volume_fakes.qos_specs) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -386,7 +386,7 @@ class TestQosShow(TestQos): volume_fakes.qos_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id) + ('qos_spec', volume_fakes.qos_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -434,7 +434,7 @@ class TestQosUnset(TestQos): ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('property', ['iops', 'foo']) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) diff --git a/openstackclient/tests/volume/v2/test_qos_specs.py b/openstackclient/tests/volume/v2/test_qos_specs.py index 6a550988..4222ed07 100644 --- a/openstackclient/tests/volume/v2/test_qos_specs.py +++ b/openstackclient/tests/volume/v2/test_qos_specs.py @@ -56,7 +56,7 @@ class TestQosAssociate(TestQos): volume_fakes.type_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('volume_type', volume_fakes.type_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -210,7 +210,7 @@ class TestQosDelete(TestQos): volume_fakes.qos_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id) + ('qos_specs', [volume_fakes.qos_id]) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -223,7 +223,7 @@ class TestQosDelete(TestQos): volume_fakes.qos_name ] verifylist = [ - ('qos_specs', volume_fakes.qos_name) + ('qos_specs', [volume_fakes.qos_name]) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -255,7 +255,7 @@ class TestQosDisassociate(TestQos): '--volume-type', volume_fakes.type_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('volume_type', volume_fakes.type_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -278,7 +278,7 @@ class TestQosDisassociate(TestQos): '--all' ] verifylist = [ - ('qos_specs', volume_fakes.qos_id) + ('qos_spec', volume_fakes.qos_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -351,7 +351,7 @@ class TestQosSet(TestQos): '--property', 'iops=9001' ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('property', volume_fakes.qos_specs) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -386,7 +386,7 @@ class TestQosShow(TestQos): volume_fakes.qos_id ] verifylist = [ - ('qos_specs', volume_fakes.qos_id) + ('qos_spec', volume_fakes.qos_id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -434,7 +434,7 @@ class TestQosUnset(TestQos): ] verifylist = [ - ('qos_specs', volume_fakes.qos_id), + ('qos_spec', volume_fakes.qos_id), ('property', ['iops', 'foo']) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) diff --git a/openstackclient/volume/v1/qos_specs.py b/openstackclient/volume/v1/qos_specs.py index eacb9706..8e909e3d 100644 --- a/openstackclient/volume/v1/qos_specs.py +++ b/openstackclient/volume/v1/qos_specs.py @@ -34,8 +34,8 @@ class AssociateQos(command.Command): def get_parser(self, prog_name): parser = super(AssociateQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) parser.add_argument( @@ -48,12 +48,12 @@ class AssociateQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) volume_type = utils.find_resource(volume_client.volume_types, parsed_args.volume_type) - volume_client.qos_specs.associate(qos_specs.id, volume_type.id) + volume_client.qos_specs.associate(qos_spec.id, volume_type.id) return @@ -97,9 +97,9 @@ class CreateQos(show.ShowOne): if parsed_args.property: specs.update(parsed_args.property) - qos_specs = volume_client.qos_specs.create(parsed_args.name, specs) + qos_spec = volume_client.qos_specs.create(parsed_args.name, specs) - return zip(*sorted(six.iteritems(qos_specs._info))) + return zip(*sorted(six.iteritems(qos_spec._info))) class DeleteQos(command.Command): @@ -111,19 +111,18 @@ class DeleteQos(command.Command): parser = super(DeleteQos, self).get_parser(prog_name) parser.add_argument( 'qos_specs', - metavar='', - help='QoS specification to delete (name or ID)', + metavar='', + nargs="+", + help='QoS specification(s) to delete (name or ID)', ) return parser def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) - - volume_client.qos_specs.delete(qos_specs.id) - + for qos in parsed_args.qos_specs: + qos_spec = utils.find_resource(volume_client.qos_specs, qos) + volume_client.qos_specs.delete(qos_spec.id) return @@ -135,8 +134,8 @@ class DisassociateQos(command.Command): def get_parser(self, prog_name): parser = super(DisassociateQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) volume_type_group = parser.add_mutually_exclusive_group() @@ -157,15 +156,15 @@ class DisassociateQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) if parsed_args.volume_type: volume_type = utils.find_resource(volume_client.volume_types, parsed_args.volume_type) - volume_client.qos_specs.disassociate(qos_specs.id, volume_type.id) + volume_client.qos_specs.disassociate(qos_spec.id, volume_type.id) elif parsed_args.all: - volume_client.qos_specs.disassociate_all(qos_specs.id) + volume_client.qos_specs.disassociate_all(qos_spec.id) return @@ -206,8 +205,8 @@ class SetQos(command.Command): def get_parser(self, prog_name): parser = super(SetQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) parser.add_argument( @@ -222,11 +221,11 @@ class SetQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) if parsed_args.property: - volume_client.qos_specs.set_keys(qos_specs.id, + volume_client.qos_specs.set_keys(qos_spec.id, parsed_args.property) else: self.app.log.error("No changes requested\n") @@ -242,8 +241,8 @@ class ShowQos(show.ShowOne): def get_parser(self, prog_name): parser = super(ShowQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to display (name or ID)', ) return parser @@ -251,19 +250,19 @@ class ShowQos(show.ShowOne): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) - qos_associations = volume_client.qos_specs.get_associations(qos_specs) + qos_associations = volume_client.qos_specs.get_associations(qos_spec) if qos_associations: associations = [association.name for association in qos_associations] - qos_specs._info.update({ + qos_spec._info.update({ 'associations': utils.format_list(associations) }) - qos_specs._info.update({'specs': utils.format_dict(qos_specs.specs)}) + qos_spec._info.update({'specs': utils.format_dict(qos_spec.specs)}) - return zip(*sorted(six.iteritems(qos_specs._info))) + return zip(*sorted(six.iteritems(qos_spec._info))) class UnsetQos(command.Command): @@ -274,8 +273,8 @@ class UnsetQos(command.Command): def get_parser(self, prog_name): parser = super(UnsetQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) parser.add_argument( @@ -291,11 +290,11 @@ class UnsetQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) if parsed_args.property: - volume_client.qos_specs.unset_keys(qos_specs.id, + volume_client.qos_specs.unset_keys(qos_spec.id, parsed_args.property) else: self.app.log.error("No changes requested\n") diff --git a/openstackclient/volume/v2/qos_specs.py b/openstackclient/volume/v2/qos_specs.py index 7f02fa4a..ac78ca15 100644 --- a/openstackclient/volume/v2/qos_specs.py +++ b/openstackclient/volume/v2/qos_specs.py @@ -34,8 +34,8 @@ class AssociateQos(command.Command): def get_parser(self, prog_name): parser = super(AssociateQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) parser.add_argument( @@ -48,12 +48,12 @@ class AssociateQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) volume_type = utils.find_resource(volume_client.volume_types, parsed_args.volume_type) - volume_client.qos_specs.associate(qos_specs.id, volume_type.id) + volume_client.qos_specs.associate(qos_spec.id, volume_type.id) return @@ -97,9 +97,9 @@ class CreateQos(show.ShowOne): if parsed_args.property: specs.update(parsed_args.property) - qos_specs = volume_client.qos_specs.create(parsed_args.name, specs) + qos_spec = volume_client.qos_specs.create(parsed_args.name, specs) - return zip(*sorted(six.iteritems(qos_specs._info))) + return zip(*sorted(six.iteritems(qos_spec._info))) class DeleteQos(command.Command): @@ -111,19 +111,18 @@ class DeleteQos(command.Command): parser = super(DeleteQos, self).get_parser(prog_name) parser.add_argument( 'qos_specs', - metavar='', - help='QoS specification to delete (name or ID)', + metavar='', + nargs="+", + help='QoS specification(s) to delete (name or ID)', ) return parser def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) - - volume_client.qos_specs.delete(qos_specs.id) - + for qos in parsed_args.qos_specs: + qos_spec = utils.find_resource(volume_client.qos_specs, qos) + volume_client.qos_specs.delete(qos_spec.id) return @@ -135,8 +134,8 @@ class DisassociateQos(command.Command): def get_parser(self, prog_name): parser = super(DisassociateQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) volume_type_group = parser.add_mutually_exclusive_group() @@ -157,15 +156,15 @@ class DisassociateQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) if parsed_args.volume_type: volume_type = utils.find_resource(volume_client.volume_types, parsed_args.volume_type) - volume_client.qos_specs.disassociate(qos_specs.id, volume_type.id) + volume_client.qos_specs.disassociate(qos_spec.id, volume_type.id) elif parsed_args.all: - volume_client.qos_specs.disassociate_all(qos_specs.id) + volume_client.qos_specs.disassociate_all(qos_spec.id) return @@ -206,8 +205,8 @@ class SetQos(command.Command): def get_parser(self, prog_name): parser = super(SetQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) parser.add_argument( @@ -222,11 +221,11 @@ class SetQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) if parsed_args.property: - volume_client.qos_specs.set_keys(qos_specs.id, + volume_client.qos_specs.set_keys(qos_spec.id, parsed_args.property) else: self.app.log.error("No changes requested\n") @@ -242,8 +241,8 @@ class ShowQos(show.ShowOne): def get_parser(self, prog_name): parser = super(ShowQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to display (name or ID)', ) return parser @@ -251,19 +250,19 @@ class ShowQos(show.ShowOne): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) - qos_associations = volume_client.qos_specs.get_associations(qos_specs) + qos_associations = volume_client.qos_specs.get_associations(qos_spec) if qos_associations: associations = [association.name for association in qos_associations] - qos_specs._info.update({ + qos_spec._info.update({ 'associations': utils.format_list(associations) }) - qos_specs._info.update({'specs': utils.format_dict(qos_specs.specs)}) + qos_spec._info.update({'specs': utils.format_dict(qos_spec.specs)}) - return zip(*sorted(six.iteritems(qos_specs._info))) + return zip(*sorted(six.iteritems(qos_spec._info))) class UnsetQos(command.Command): @@ -274,8 +273,8 @@ class UnsetQos(command.Command): def get_parser(self, prog_name): parser = super(UnsetQos, self).get_parser(prog_name) parser.add_argument( - 'qos_specs', - metavar='', + 'qos_spec', + metavar='', help='QoS specification to modify (name or ID)', ) parser.add_argument( @@ -291,11 +290,11 @@ class UnsetQos(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) volume_client = self.app.client_manager.volume - qos_specs = utils.find_resource(volume_client.qos_specs, - parsed_args.qos_specs) + qos_spec = utils.find_resource(volume_client.qos_specs, + parsed_args.qos_spec) if parsed_args.property: - volume_client.qos_specs.unset_keys(qos_specs.id, + volume_client.qos_specs.unset_keys(qos_spec.id, parsed_args.property) else: self.app.log.error("No changes requested\n") -- cgit v1.2.1