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
This commit is contained in:
@@ -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)
|
||||
|
@@ -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()
|
||||
|
@@ -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(
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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,
|
||||
|
@@ -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,
|
||||
|
@@ -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)
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user