From 6f2963d75204acd515089b70496f2ca3d0397f60 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Fri, 8 Jan 2016 23:16:43 +0900 Subject: [PATCH] refactor: Avoid overriding run() in cliff command cliff Command subclasses are suggested to override take_action. run() method is reserved for extending base classes. Thus, this commit changes to implement take_action() instead of run(). Closes-Bug: #1532258 Change-Id: Id845a80dbad2f436df5a55c9be502068e6f7b291 --- neutronclient/common/extension.py | 8 ++++---- neutronclient/neutron/v2_0/__init__.py | 10 ++-------- neutronclient/neutron/v2_0/agentscheduler.py | 8 ++++---- neutronclient/neutron/v2_0/bgp/speaker.py | 8 ++++---- neutronclient/neutron/v2_0/flavor/flavor.py | 4 ++-- neutronclient/neutron/v2_0/floatingip.py | 4 ++-- neutronclient/neutron/v2_0/fw/firewallpolicy.py | 4 ++-- neutronclient/neutron/v2_0/lb/healthmonitor.py | 4 ++-- neutronclient/neutron/v2_0/nsx/networkgateway.py | 4 ++-- neutronclient/neutron/v2_0/purge.py | 2 +- neutronclient/neutron/v2_0/quota.py | 2 +- neutronclient/neutron/v2_0/router.py | 6 +++--- 12 files changed, 29 insertions(+), 35 deletions(-) diff --git a/neutronclient/common/extension.py b/neutronclient/common/extension.py index f7e361bed..90f44a79b 100644 --- a/neutronclient/common/extension.py +++ b/neutronclient/common/extension.py @@ -54,14 +54,14 @@ class ClientExtensionList(NeutronClientExtension, neutronV20.ListCommand): class ClientExtensionDelete(NeutronClientExtension, neutronV20.DeleteCommand): - def run(self, parsed_args): + def take_action(self, parsed_args): # NOTE(mdietz): Calls 'execute' to provide a consistent pattern # for any implementers adding extensions with # regard to any other extension verb. return self.execute(parsed_args) def execute(self, parsed_args): - return super(ClientExtensionDelete, self).run(parsed_args) + return super(ClientExtensionDelete, self).take_action(parsed_args) class ClientExtensionCreate(NeutronClientExtension, neutronV20.CreateCommand): @@ -76,11 +76,11 @@ class ClientExtensionCreate(NeutronClientExtension, neutronV20.CreateCommand): class ClientExtensionUpdate(NeutronClientExtension, neutronV20.UpdateCommand): - def run(self, parsed_args): + def take_action(self, parsed_args): # NOTE(mdietz): Calls 'execute' to provide a consistent pattern # for any implementers adding extensions with # regard to any other extension verb. return self.execute(parsed_args) def execute(self, parsed_args): - return super(ClientExtensionUpdate, self).run(parsed_args) + return super(ClientExtensionUpdate, self).take_action(parsed_args) diff --git a/neutronclient/neutron/v2_0/__init__.py b/neutronclient/neutron/v2_0/__init__.py index d740aac3e..14a354865 100644 --- a/neutronclient/neutron/v2_0/__init__.py +++ b/neutronclient/neutron/v2_0/__init__.py @@ -397,12 +397,6 @@ class NeutronCommand(command.Command): shadow_resource = None parent_id = None - # TODO(amotoki): Remove take_action here. It should be an abstract method - # as cliff.command.Command does. To do this, we need to avoid overriding - # run() directly. - def take_action(self, parsed_args): - return self.get_data(parsed_args) - @property def cmd_resource(self): if self.shadow_resource: @@ -517,7 +511,7 @@ class UpdateCommand(NeutronCommand): self.add_known_arguments(parser) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)', parsed_args) self.set_extra_attrs(parsed_args) neutron_client = self.get_client() @@ -574,7 +568,7 @@ class DeleteCommand(NeutronCommand): self.add_known_arguments(parser) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)', parsed_args) self.set_extra_attrs(parsed_args) neutron_client = self.get_client() diff --git a/neutronclient/neutron/v2_0/agentscheduler.py b/neutronclient/neutron/v2_0/agentscheduler.py index 24287b710..dacfab863 100644 --- a/neutronclient/neutron/v2_0/agentscheduler.py +++ b/neutronclient/neutron/v2_0/agentscheduler.py @@ -40,7 +40,7 @@ class AddNetworkToDhcpAgent(neutronV20.NeutronCommand): help=_('Network to add.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() _net_id = neutronV20.find_resourceid_by_name_or_id( @@ -66,7 +66,7 @@ class RemoveNetworkFromDhcpAgent(neutronV20.NeutronCommand): help=_('Network to remove.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() _net_id = neutronV20.find_resourceid_by_name_or_id( @@ -142,7 +142,7 @@ class AddRouterToL3Agent(neutronV20.NeutronCommand): help=_('Router to add.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() _id = neutronV20.find_resourceid_by_name_or_id( @@ -168,7 +168,7 @@ class RemoveRouterFromL3Agent(neutronV20.NeutronCommand): help=_('Router to remove.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() _id = neutronV20.find_resourceid_by_name_or_id( diff --git a/neutronclient/neutron/v2_0/bgp/speaker.py b/neutronclient/neutron/v2_0/bgp/speaker.py index f2a3df7db..1a70734e5 100755 --- a/neutronclient/neutron/v2_0/bgp/speaker.py +++ b/neutronclient/neutron/v2_0/bgp/speaker.py @@ -153,7 +153,7 @@ class AddPeerToSpeaker(neutronv20.NeutronCommand): help=_('ID or name of the BGP peer to add.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() _speaker_id = get_bgp_speaker_id(neutron_client, parsed_args.bgp_speaker) @@ -182,7 +182,7 @@ class RemovePeerFromSpeaker(neutronv20.NeutronCommand): help=_('ID or name of the BGP peer to remove.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() _speaker_id = get_bgp_speaker_id(neutron_client, parsed_args.bgp_speaker) @@ -211,7 +211,7 @@ class AddNetworkToSpeaker(neutronv20.NeutronCommand): help=_('ID or name of the network to add.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() _speaker_id = get_bgp_speaker_id(neutron_client, parsed_args.bgp_speaker) @@ -239,7 +239,7 @@ class RemoveNetworkFromSpeaker(neutronv20.NeutronCommand): help=_('ID or name of the network to remove.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() _speaker_id = get_bgp_speaker_id(neutron_client, parsed_args.bgp_speaker) diff --git a/neutronclient/neutron/v2_0/flavor/flavor.py b/neutronclient/neutron/v2_0/flavor/flavor.py index 30e3ae414..57ec8fa3b 100644 --- a/neutronclient/neutron/v2_0/flavor/flavor.py +++ b/neutronclient/neutron/v2_0/flavor/flavor.py @@ -118,7 +118,7 @@ class AssociateFlavor(neutronV20.NeutronCommand): 'flavor.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() flavor_id = neutronV20.find_resourceid_by_name_or_id( neutron_client, 'flavor', parsed_args.flavor) @@ -151,7 +151,7 @@ class DisassociateFlavor(neutronV20.NeutronCommand): 'flavor.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() flavor_id = neutronV20.find_resourceid_by_name_or_id( neutron_client, 'flavor', parsed_args.flavor) diff --git a/neutronclient/neutron/v2_0/floatingip.py b/neutronclient/neutron/v2_0/floatingip.py index e361a293a..f20889688 100644 --- a/neutronclient/neutron/v2_0/floatingip.py +++ b/neutronclient/neutron/v2_0/floatingip.py @@ -115,7 +115,7 @@ class AssociateFloatingIP(neutronV20.NeutronCommand): help=argparse.SUPPRESS) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() update_dict = {} @@ -139,7 +139,7 @@ class DisassociateFloatingIP(neutronV20.NeutronCommand): help=_('ID of the floating IP to disassociate.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() neutron_client.update_floatingip(parsed_args.floatingip_id, diff --git a/neutronclient/neutron/v2_0/fw/firewallpolicy.py b/neutronclient/neutron/v2_0/fw/firewallpolicy.py index 08d623ab9..a01fc726f 100644 --- a/neutronclient/neutron/v2_0/fw/firewallpolicy.py +++ b/neutronclient/neutron/v2_0/fw/firewallpolicy.py @@ -179,7 +179,7 @@ class FirewallPolicyInsertRule(neutronv20.UpdateCommand): self.add_known_arguments(parser) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() body = self.args2body(parsed_args) _id = neutronv20.find_resourceid_by_name_or_id(neutron_client, @@ -217,7 +217,7 @@ class FirewallPolicyRemoveRule(neutronv20.UpdateCommand): self.add_known_arguments(parser) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() body = self.args2body(parsed_args) _id = neutronv20.find_resourceid_by_name_or_id(neutron_client, diff --git a/neutronclient/neutron/v2_0/lb/healthmonitor.py b/neutronclient/neutron/v2_0/lb/healthmonitor.py index ee5d70bb5..6fea0a12a 100644 --- a/neutronclient/neutron/v2_0/lb/healthmonitor.py +++ b/neutronclient/neutron/v2_0/lb/healthmonitor.py @@ -124,7 +124,7 @@ class AssociateHealthMonitor(neutronV20.NeutronCommand): help=_('ID of the pool to be associated with the health monitor.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() body = {'health_monitor': {'id': parsed_args.health_monitor_id}} pool_id = neutronV20.find_resourceid_by_name_or_id( @@ -150,7 +150,7 @@ class DisassociateHealthMonitor(neutronV20.NeutronCommand): help=_('ID of the pool to be associated with the health monitor.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() pool_id = neutronV20.find_resourceid_by_name_or_id( neutron_client, 'pool', parsed_args.pool_id) diff --git a/neutronclient/neutron/v2_0/nsx/networkgateway.py b/neutronclient/neutron/v2_0/nsx/networkgateway.py index 46d83e9a5..c7df5130c 100644 --- a/neutronclient/neutron/v2_0/nsx/networkgateway.py +++ b/neutronclient/neutron/v2_0/nsx/networkgateway.py @@ -234,7 +234,7 @@ class NetworkGatewayInterfaceCommand(neutronV20.NeutronCommand): class ConnectNetworkGateway(NetworkGatewayInterfaceCommand): """Add an internal network interface to a router.""" - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() (gateway_id, network_id) = self.retrieve_ids(neutron_client, @@ -252,7 +252,7 @@ class ConnectNetworkGateway(NetworkGatewayInterfaceCommand): class DisconnectNetworkGateway(NetworkGatewayInterfaceCommand): """Remove a network from a network gateway.""" - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() (gateway_id, network_id) = self.retrieve_ids(neutron_client, diff --git a/neutronclient/neutron/v2_0/purge.py b/neutronclient/neutron/v2_0/purge.py index 6d8e9d9b9..61762963f 100644 --- a/neutronclient/neutron/v2_0/purge.py +++ b/neutronclient/neutron/v2_0/purge.py @@ -125,7 +125,7 @@ class Purge(neutronV20.NeutronCommand): help=_('ID of Tenant owning the resources to be deleted.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): neutron_client = self.get_client() self.any_failures = False diff --git a/neutronclient/neutron/v2_0/quota.py b/neutronclient/neutron/v2_0/quota.py index a88f0c628..985e61921 100644 --- a/neutronclient/neutron/v2_0/quota.py +++ b/neutronclient/neutron/v2_0/quota.py @@ -52,7 +52,7 @@ class DeleteQuota(neutronV20.NeutronCommand): help=argparse.SUPPRESS, nargs='?') return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() tenant_id = get_tenant_id(parsed_args, neutron_client) diff --git a/neutronclient/neutron/v2_0/router.py b/neutronclient/neutron/v2_0/router.py index c372f98ae..76022e77d 100644 --- a/neutronclient/neutron/v2_0/router.py +++ b/neutronclient/neutron/v2_0/router.py @@ -161,7 +161,7 @@ class RouterInterfaceCommand(neutronV20.NeutronCommand): 'subnet.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() @@ -236,7 +236,7 @@ class SetGatewayRouter(neutronV20.NeutronCommand): 'You can repeat this option.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() _router_id = neutronV20.find_resourceid_by_name_or_id( @@ -273,7 +273,7 @@ class RemoveGatewayRouter(neutronV20.NeutronCommand): help=_('ID or name of the router.')) return parser - def run(self, parsed_args): + def take_action(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() _router_id = neutronV20.find_resourceid_by_name_or_id(