Refactor cliff.Command.run()

* All commands now perform their action in take_action().  Those producing
  output are derived from DisplayCommandBase.

Change-Id: Ic93ba9a2ad449d84242b6aa8624b41379c4fb79a
This commit is contained in:
Dean Troyer 2012-06-01 11:17:30 -05:00
parent 9be5803993
commit 697a5ac6cb
6 changed files with 87 additions and 87 deletions

View File

@ -22,10 +22,10 @@ Server action implementations
import logging
import os
from cliff import command
from cliff import lister
from cliff import show
from openstackclient.common import command
from openstackclient.common import utils
@ -44,7 +44,7 @@ def _format_servers_list_networks(server):
return '; '.join(output)
class ListServer(command.OpenStackCommand, lister.Lister):
class ListServer(lister.Lister):
"""List server command"""
api = 'compute'
@ -98,8 +98,8 @@ class ListServer(command.OpenStackCommand, lister.Lister):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
nova_client = self.app.client_manager.compute
search_opts = {
'all_tenants': parsed_args.all_tenants,
@ -125,7 +125,7 @@ class ListServer(command.OpenStackCommand, lister.Lister):
)
class ShowServer(command.OpenStackCommand, show.ShowOne):
class ShowServer(show.ShowOne):
"""Show server command"""
api = 'compute'
@ -139,8 +139,8 @@ class ShowServer(command.OpenStackCommand, show.ShowOne):
help='Name or ID of server to display')
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
nova_client = self.app.client_manager.compute
server = utils.find_resource(nova_client.servers, parsed_args.server)

View File

@ -21,16 +21,16 @@ Endpoint action implementations
import logging
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as identity_exc
from openstackclient.common import command
from openstackclient.common import exceptions
from openstackclient.common import utils
class CreateEndpoint(command.OpenStackCommand, show.ShowOne):
class CreateEndpoint(show.ShowOne):
"""Create endpoint command"""
api = 'identity'
@ -60,8 +60,8 @@ class CreateEndpoint(command.OpenStackCommand, show.ShowOne):
help='New endpoint internal URL')
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
service = utils.find_resource(
identity_client.services, parsed_args.service)
@ -80,7 +80,7 @@ class CreateEndpoint(command.OpenStackCommand, show.ShowOne):
return zip(*sorted(info.iteritems()))
class DeleteEndpoint(command.OpenStackCommand):
class DeleteEndpoint(command.Command):
"""Delete endpoint command"""
api = 'identity'
@ -94,14 +94,14 @@ class DeleteEndpoint(command.OpenStackCommand):
help='ID of endpoint to delete')
return parser
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
identity_client.endpoints.delete(parsed_args.endpoint)
return
class ListEndpoint(command.OpenStackCommand, lister.Lister):
class ListEndpoint(lister.Lister):
"""List endpoint command"""
api = 'identity'
@ -116,8 +116,8 @@ class ListEndpoint(command.OpenStackCommand, lister.Lister):
help='Additional fields are listed in output')
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
if parsed_args.long:
columns = ('ID', 'Region', 'Service Name', 'Service Type',
@ -139,7 +139,7 @@ class ListEndpoint(command.OpenStackCommand, lister.Lister):
)
class ShowEndpoint(command.OpenStackCommand, show.ShowOne):
class ShowEndpoint(show.ShowOne):
"""Show endpoint command"""
api = 'identity'
@ -172,8 +172,8 @@ class ShowEndpoint(command.OpenStackCommand, show.ShowOne):
help='Show all endpoints for this service')
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
if not parsed_args.all:

View File

@ -21,14 +21,14 @@ Role action implementations
import logging
from cliff import command
from cliff import lister
from cliff import show
from openstackclient.common import command
from openstackclient.common import utils
class AddRole(command.OpenStackCommand, show.ShowOne):
class AddRole(show.ShowOne):
"""Add role to tenant:user"""
api = 'identity'
@ -55,8 +55,8 @@ class AddRole(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
role = utils.find_resource(
identity_client.roles, parsed_args.role)
@ -75,7 +75,7 @@ class AddRole(command.OpenStackCommand, show.ShowOne):
return zip(*sorted(info.iteritems()))
class CreateRole(command.OpenStackCommand, show.ShowOne):
class CreateRole(show.ShowOne):
"""Create new role"""
api = 'identity'
@ -90,8 +90,8 @@ class CreateRole(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
role = identity_client.roles.create(
parsed_args.role_name,
@ -102,7 +102,7 @@ class CreateRole(command.OpenStackCommand, show.ShowOne):
return zip(*sorted(info.iteritems()))
class DeleteRole(command.OpenStackCommand):
class DeleteRole(command.Command):
"""Delete existing role"""
api = 'identity'
@ -117,8 +117,8 @@ class DeleteRole(command.OpenStackCommand):
)
return parser
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
role = utils.find_resource(
identity_client.roles, parsed_args.role)
@ -126,14 +126,14 @@ class DeleteRole(command.OpenStackCommand):
return
class ListRole(command.OpenStackCommand, lister.Lister):
class ListRole(lister.Lister):
"""List roles"""
api = 'identity'
log = logging.getLogger(__name__ + '.ListRole')
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
columns = ('ID', 'Name')
data = self.app.client_manager.identity.roles.list()
return (columns,
@ -144,7 +144,7 @@ class ListRole(command.OpenStackCommand, lister.Lister):
)
class ListUserRole(command.OpenStackCommand, lister.Lister):
class ListUserRole(lister.Lister):
"""List user-role assignments"""
api = 'identity'
@ -165,8 +165,8 @@ class ListUserRole(command.OpenStackCommand, lister.Lister):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
columns = ('ID', 'Name', 'Tenant ID', 'User ID')
identity_client = self.app.client_manager.identity
@ -198,7 +198,7 @@ class ListUserRole(command.OpenStackCommand, lister.Lister):
)
class RemoveRole(command.OpenStackCommand):
class RemoveRole(command.Command):
"""Remove role from tenant:user"""
api = 'identity'
@ -225,8 +225,8 @@ class RemoveRole(command.OpenStackCommand):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
role = utils.find_resource(
identity_client.roles, parsed_args.role)
@ -241,7 +241,7 @@ class RemoveRole(command.OpenStackCommand):
)
class ShowRole(command.OpenStackCommand, show.ShowOne):
class ShowRole(show.ShowOne):
"""Show single role"""
api = 'identity'
@ -256,8 +256,8 @@ class ShowRole(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
role = utils.find_resource(
identity_client.roles, parsed_args.role)

View File

@ -21,16 +21,16 @@ Service action implementations
import logging
from cliff import command
from cliff import lister
from cliff import show
from keystoneclient import exceptions as identity_exc
from openstackclient.common import command
from openstackclient.common import exceptions
from openstackclient.common import utils
class CreateService(command.OpenStackCommand, show.ShowOne):
class CreateService(show.ShowOne):
"""Create service command"""
api = 'identity'
@ -55,8 +55,8 @@ class CreateService(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
service = identity_client.services.create(
parsed_args.name,
@ -69,7 +69,7 @@ class CreateService(command.OpenStackCommand, show.ShowOne):
return zip(*sorted(info.iteritems()))
class DeleteService(command.OpenStackCommand):
class DeleteService(command.Command):
"""Delete service command"""
api = 'identity'
@ -84,14 +84,14 @@ class DeleteService(command.OpenStackCommand):
)
return parser
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
identity_client.services.delete(parsed_args.service)
return
class ListService(command.OpenStackCommand, lister.Lister):
class ListService(lister.Lister):
"""List service command"""
api = 'identity'
@ -106,8 +106,8 @@ class ListService(command.OpenStackCommand, lister.Lister):
help='Additional fields are listed in output')
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
if parsed_args.long:
columns = ('ID', 'Name', 'Type', 'Description')
else:
@ -121,7 +121,7 @@ class ListService(command.OpenStackCommand, lister.Lister):
)
class ShowService(command.OpenStackCommand, show.ShowOne):
class ShowService(show.ShowOne):
"""Show service command"""
api = 'identity'
@ -135,8 +135,8 @@ class ShowService(command.OpenStackCommand, show.ShowOne):
help='Type, name or ID of service to display')
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
try:
# search for the usual ID or name

View File

@ -21,14 +21,14 @@ Tenant action implementations
import logging
from cliff import command
from cliff import lister
from cliff import show
from openstackclient.common import command
from openstackclient.common import utils
class CreateTenant(command.OpenStackCommand, show.ShowOne):
class CreateTenant(show.ShowOne):
"""Create tenant command"""
api = 'identity'
@ -62,8 +62,8 @@ class CreateTenant(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
tenant = identity_client.tenants.create(
parsed_args.tenant_name,
@ -76,7 +76,7 @@ class CreateTenant(command.OpenStackCommand, show.ShowOne):
return zip(*sorted(info.iteritems()))
class DeleteTenant(command.OpenStackCommand):
class DeleteTenant(command.Command):
"""Delete tenant command"""
api = 'identity'
@ -91,8 +91,8 @@ class DeleteTenant(command.OpenStackCommand):
)
return parser
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
tenant = utils.find_resource(
identity_client.tenants, parsed_args.tenant)
@ -100,7 +100,7 @@ class DeleteTenant(command.OpenStackCommand):
return
class ListTenant(command.OpenStackCommand, lister.Lister):
class ListTenant(lister.Lister):
"""List tenant command"""
api = 'identity'
@ -116,8 +116,8 @@ class ListTenant(command.OpenStackCommand, lister.Lister):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
if parsed_args.long:
columns = ('ID', 'Name', 'Description', 'Enabled')
else:
@ -131,7 +131,7 @@ class ListTenant(command.OpenStackCommand, lister.Lister):
)
class SetTenant(command.OpenStackCommand):
class SetTenant(command.Command):
"""Set tenant command"""
api = 'identity'
@ -170,8 +170,8 @@ class SetTenant(command.OpenStackCommand):
)
return parser
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
tenant = utils.find_resource(
identity_client.tenants, parsed_args.tenant)
@ -190,7 +190,7 @@ class SetTenant(command.OpenStackCommand):
return
class ShowTenant(command.OpenStackCommand, show.ShowOne):
class ShowTenant(show.ShowOne):
"""Show tenant command"""
api = 'identity'
@ -205,8 +205,8 @@ class ShowTenant(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
tenant = utils.find_resource(
identity_client.tenants, parsed_args.tenant)

View File

@ -21,14 +21,14 @@ User action implementations
import logging
from cliff import command
from cliff import lister
from cliff import show
from openstackclient.common import command
from openstackclient.common import utils
class CreateUser(command.OpenStackCommand, show.ShowOne):
class CreateUser(show.ShowOne):
"""Create user command"""
api = 'identity'
@ -72,8 +72,8 @@ class CreateUser(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
if parsed_args.tenant:
tenant_id = utils.find_resource(
@ -93,7 +93,7 @@ class CreateUser(command.OpenStackCommand, show.ShowOne):
return zip(*sorted(info.iteritems()))
class DeleteUser(command.OpenStackCommand):
class DeleteUser(command.Command):
"""Delete user command"""
api = 'identity'
@ -108,8 +108,8 @@ class DeleteUser(command.OpenStackCommand):
)
return parser
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
user = utils.find_resource(
identity_client.users, parsed_args.user)
@ -117,7 +117,7 @@ class DeleteUser(command.OpenStackCommand):
return
class ListUser(command.OpenStackCommand, lister.Lister):
class ListUser(lister.Lister):
"""List user command"""
api = 'identity'
@ -138,8 +138,8 @@ class ListUser(command.OpenStackCommand, lister.Lister):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
if parsed_args.long:
columns = ('ID', 'Name', 'TenantId', 'Email', 'Enabled')
else:
@ -153,7 +153,7 @@ class ListUser(command.OpenStackCommand, lister.Lister):
)
class SetUser(command.OpenStackCommand):
class SetUser(command.Command):
"""Set user command"""
api = 'identity'
@ -202,8 +202,8 @@ class SetUser(command.OpenStackCommand):
)
return parser
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
user = utils.find_resource(
identity_client.users, parsed_args.user)
@ -226,7 +226,7 @@ class SetUser(command.OpenStackCommand):
return
class ShowUser(command.OpenStackCommand, show.ShowOne):
class ShowUser(show.ShowOne):
"""Show user command"""
api = 'identity'
@ -241,8 +241,8 @@ class ShowUser(command.OpenStackCommand, show.ShowOne):
)
return parser
def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
identity_client = self.app.client_manager.identity
user = utils.find_resource(
identity_client.users, parsed_args.user)