Skip to content

Commit 697a5ac

Browse files
author
Dean Troyer
committed
Refactor cliff.Command.run()
* All commands now perform their action in take_action(). Those producing output are derived from DisplayCommandBase. Change-Id: Ic93ba9a2ad449d84242b6aa8624b41379c4fb79a
1 parent 9be5803 commit 697a5ac

6 files changed

Lines changed: 87 additions & 87 deletions

File tree

‎openstackclient/compute/v2/server.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import logging
2323
import os
2424

25+
from cliff import command
2526
from cliff import lister
2627
from cliff import show
2728

28-
from openstackclient.common import command
2929
from openstackclient.common import utils
3030

3131

@@ -44,7 +44,7 @@ def _format_servers_list_networks(server):
4444
return '; '.join(output)
4545

4646

47-
class ListServer(command.OpenStackCommand, lister.Lister):
47+
class ListServer(lister.Lister):
4848
"""List server command"""
4949

5050
api = 'compute'
@@ -98,8 +98,8 @@ def get_parser(self, prog_name):
9898
)
9999
return parser
100100

101-
def get_data(self, parsed_args):
102-
self.log.debug('get_data(%s)' % parsed_args)
101+
def take_action(self, parsed_args):
102+
self.log.debug('take_action(%s)' % parsed_args)
103103
nova_client = self.app.client_manager.compute
104104
search_opts = {
105105
'all_tenants': parsed_args.all_tenants,
@@ -125,7 +125,7 @@ def get_data(self, parsed_args):
125125
)
126126

127127

128-
class ShowServer(command.OpenStackCommand, show.ShowOne):
128+
class ShowServer(show.ShowOne):
129129
"""Show server command"""
130130

131131
api = 'compute'
@@ -139,8 +139,8 @@ def get_parser(self, prog_name):
139139
help='Name or ID of server to display')
140140
return parser
141141

142-
def get_data(self, parsed_args):
143-
self.log.debug('get_data(%s)' % parsed_args)
142+
def take_action(self, parsed_args):
143+
self.log.debug('take_action(%s)' % parsed_args)
144144
nova_client = self.app.client_manager.compute
145145
server = utils.find_resource(nova_client.servers, parsed_args.server)
146146

‎openstackclient/identity/v2_0/endpoint.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
import logging
2323

24+
from cliff import command
2425
from cliff import lister
2526
from cliff import show
2627

2728
from keystoneclient import exceptions as identity_exc
28-
from openstackclient.common import command
2929
from openstackclient.common import exceptions
3030
from openstackclient.common import utils
3131

3232

33-
class CreateEndpoint(command.OpenStackCommand, show.ShowOne):
33+
class CreateEndpoint(show.ShowOne):
3434
"""Create endpoint command"""
3535

3636
api = 'identity'
@@ -60,8 +60,8 @@ def get_parser(self, prog_name):
6060
help='New endpoint internal URL')
6161
return parser
6262

63-
def get_data(self, parsed_args):
64-
self.log.debug('get_data(%s)' % parsed_args)
63+
def take_action(self, parsed_args):
64+
self.log.debug('take_action(%s)' % parsed_args)
6565
identity_client = self.app.client_manager.identity
6666
service = utils.find_resource(
6767
identity_client.services, parsed_args.service)
@@ -80,7 +80,7 @@ def get_data(self, parsed_args):
8080
return zip(*sorted(info.iteritems()))
8181

8282

83-
class DeleteEndpoint(command.OpenStackCommand):
83+
class DeleteEndpoint(command.Command):
8484
"""Delete endpoint command"""
8585

8686
api = 'identity'
@@ -94,14 +94,14 @@ def get_parser(self, prog_name):
9494
help='ID of endpoint to delete')
9595
return parser
9696

97-
def run(self, parsed_args):
98-
self.log.debug('run(%s)' % parsed_args)
97+
def take_action(self, parsed_args):
98+
self.log.debug('take_action(%s)' % parsed_args)
9999
identity_client = self.app.client_manager.identity
100100
identity_client.endpoints.delete(parsed_args.endpoint)
101101
return
102102

103103

104-
class ListEndpoint(command.OpenStackCommand, lister.Lister):
104+
class ListEndpoint(lister.Lister):
105105
"""List endpoint command"""
106106

107107
api = 'identity'
@@ -116,8 +116,8 @@ def get_parser(self, prog_name):
116116
help='Additional fields are listed in output')
117117
return parser
118118

119-
def get_data(self, parsed_args):
120-
self.log.debug('get_data(%s)' % parsed_args)
119+
def take_action(self, parsed_args):
120+
self.log.debug('take_action(%s)' % parsed_args)
121121
identity_client = self.app.client_manager.identity
122122
if parsed_args.long:
123123
columns = ('ID', 'Region', 'Service Name', 'Service Type',
@@ -139,7 +139,7 @@ def get_data(self, parsed_args):
139139
)
140140

141141

142-
class ShowEndpoint(command.OpenStackCommand, show.ShowOne):
142+
class ShowEndpoint(show.ShowOne):
143143
"""Show endpoint command"""
144144

145145
api = 'identity'
@@ -172,8 +172,8 @@ def get_parser(self, prog_name):
172172
help='Show all endpoints for this service')
173173
return parser
174174

175-
def get_data(self, parsed_args):
176-
self.log.debug('get_data(%s)' % parsed_args)
175+
def take_action(self, parsed_args):
176+
self.log.debug('take_action(%s)' % parsed_args)
177177
identity_client = self.app.client_manager.identity
178178

179179
if not parsed_args.all:

‎openstackclient/identity/v2_0/role.py‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222
import logging
2323

24+
from cliff import command
2425
from cliff import lister
2526
from cliff import show
2627

27-
from openstackclient.common import command
2828
from openstackclient.common import utils
2929

3030

31-
class AddRole(command.OpenStackCommand, show.ShowOne):
31+
class AddRole(show.ShowOne):
3232
"""Add role to tenant:user"""
3333

3434
api = 'identity'
@@ -55,8 +55,8 @@ def get_parser(self, prog_name):
5555
)
5656
return parser
5757

58-
def get_data(self, parsed_args):
59-
self.log.debug('get_data(%s)' % parsed_args)
58+
def take_action(self, parsed_args):
59+
self.log.debug('take_action(%s)' % parsed_args)
6060
identity_client = self.app.client_manager.identity
6161
role = utils.find_resource(
6262
identity_client.roles, parsed_args.role)
@@ -75,7 +75,7 @@ def get_data(self, parsed_args):
7575
return zip(*sorted(info.iteritems()))
7676

7777

78-
class CreateRole(command.OpenStackCommand, show.ShowOne):
78+
class CreateRole(show.ShowOne):
7979
"""Create new role"""
8080

8181
api = 'identity'
@@ -90,8 +90,8 @@ def get_parser(self, prog_name):
9090
)
9191
return parser
9292

93-
def get_data(self, parsed_args):
94-
self.log.debug('get_data(%s)' % parsed_args)
93+
def take_action(self, parsed_args):
94+
self.log.debug('take_action(%s)' % parsed_args)
9595
identity_client = self.app.client_manager.identity
9696
role = identity_client.roles.create(
9797
parsed_args.role_name,
@@ -102,7 +102,7 @@ def get_data(self, parsed_args):
102102
return zip(*sorted(info.iteritems()))
103103

104104

105-
class DeleteRole(command.OpenStackCommand):
105+
class DeleteRole(command.Command):
106106
"""Delete existing role"""
107107

108108
api = 'identity'
@@ -117,23 +117,23 @@ def get_parser(self, prog_name):
117117
)
118118
return parser
119119

120-
def run(self, parsed_args):
121-
self.log.debug('run(%s)' % parsed_args)
120+
def take_action(self, parsed_args):
121+
self.log.debug('take_action(%s)' % parsed_args)
122122
identity_client = self.app.client_manager.identity
123123
role = utils.find_resource(
124124
identity_client.roles, parsed_args.role)
125125
identity_client.roles.delete(role.id)
126126
return
127127

128128

129-
class ListRole(command.OpenStackCommand, lister.Lister):
129+
class ListRole(lister.Lister):
130130
"""List roles"""
131131

132132
api = 'identity'
133133
log = logging.getLogger(__name__ + '.ListRole')
134134

135-
def get_data(self, parsed_args):
136-
self.log.debug('get_data(%s)' % parsed_args)
135+
def take_action(self, parsed_args):
136+
self.log.debug('take_action(%s)' % parsed_args)
137137
columns = ('ID', 'Name')
138138
data = self.app.client_manager.identity.roles.list()
139139
return (columns,
@@ -144,7 +144,7 @@ def get_data(self, parsed_args):
144144
)
145145

146146

147-
class ListUserRole(command.OpenStackCommand, lister.Lister):
147+
class ListUserRole(lister.Lister):
148148
"""List user-role assignments"""
149149

150150
api = 'identity'
@@ -165,8 +165,8 @@ def get_parser(self, prog_name):
165165
)
166166
return parser
167167

168-
def get_data(self, parsed_args):
169-
self.log.debug('get_data(%s)' % parsed_args)
168+
def take_action(self, parsed_args):
169+
self.log.debug('take_action(%s)' % parsed_args)
170170
columns = ('ID', 'Name', 'Tenant ID', 'User ID')
171171
identity_client = self.app.client_manager.identity
172172

@@ -198,7 +198,7 @@ def get_data(self, parsed_args):
198198
)
199199

200200

201-
class RemoveRole(command.OpenStackCommand):
201+
class RemoveRole(command.Command):
202202
"""Remove role from tenant:user"""
203203

204204
api = 'identity'
@@ -225,8 +225,8 @@ def get_parser(self, prog_name):
225225
)
226226
return parser
227227

228-
def get_data(self, parsed_args):
229-
self.log.debug('get_data(%s)' % parsed_args)
228+
def take_action(self, parsed_args):
229+
self.log.debug('take_action(%s)' % parsed_args)
230230
identity_client = self.app.client_manager.identity
231231
role = utils.find_resource(
232232
identity_client.roles, parsed_args.role)
@@ -241,7 +241,7 @@ def get_data(self, parsed_args):
241241
)
242242

243243

244-
class ShowRole(command.OpenStackCommand, show.ShowOne):
244+
class ShowRole(show.ShowOne):
245245
"""Show single role"""
246246

247247
api = 'identity'
@@ -256,8 +256,8 @@ def get_parser(self, prog_name):
256256
)
257257
return parser
258258

259-
def get_data(self, parsed_args):
260-
self.log.debug('get_data(%s)' % parsed_args)
259+
def take_action(self, parsed_args):
260+
self.log.debug('take_action(%s)' % parsed_args)
261261
identity_client = self.app.client_manager.identity
262262
role = utils.find_resource(
263263
identity_client.roles, parsed_args.role)

‎openstackclient/identity/v2_0/service.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
import logging
2323

24+
from cliff import command
2425
from cliff import lister
2526
from cliff import show
2627

2728
from keystoneclient import exceptions as identity_exc
28-
from openstackclient.common import command
2929
from openstackclient.common import exceptions
3030
from openstackclient.common import utils
3131

3232

33-
class CreateService(command.OpenStackCommand, show.ShowOne):
33+
class CreateService(show.ShowOne):
3434
"""Create service command"""
3535

3636
api = 'identity'
@@ -55,8 +55,8 @@ def get_parser(self, prog_name):
5555
)
5656
return parser
5757

58-
def get_data(self, parsed_args):
59-
self.log.debug('get_data(%s)' % parsed_args)
58+
def take_action(self, parsed_args):
59+
self.log.debug('take_action(%s)' % parsed_args)
6060
identity_client = self.app.client_manager.identity
6161
service = identity_client.services.create(
6262
parsed_args.name,
@@ -69,7 +69,7 @@ def get_data(self, parsed_args):
6969
return zip(*sorted(info.iteritems()))
7070

7171

72-
class DeleteService(command.OpenStackCommand):
72+
class DeleteService(command.Command):
7373
"""Delete service command"""
7474

7575
api = 'identity'
@@ -84,14 +84,14 @@ def get_parser(self, prog_name):
8484
)
8585
return parser
8686

87-
def run(self, parsed_args):
88-
self.log.debug('run(%s)' % parsed_args)
87+
def take_action(self, parsed_args):
88+
self.log.debug('take_action(%s)' % parsed_args)
8989
identity_client = self.app.client_manager.identity
9090
identity_client.services.delete(parsed_args.service)
9191
return
9292

9393

94-
class ListService(command.OpenStackCommand, lister.Lister):
94+
class ListService(lister.Lister):
9595
"""List service command"""
9696

9797
api = 'identity'
@@ -106,8 +106,8 @@ def get_parser(self, prog_name):
106106
help='Additional fields are listed in output')
107107
return parser
108108

109-
def get_data(self, parsed_args):
110-
self.log.debug('get_data(%s)' % parsed_args)
109+
def take_action(self, parsed_args):
110+
self.log.debug('take_action(%s)' % parsed_args)
111111
if parsed_args.long:
112112
columns = ('ID', 'Name', 'Type', 'Description')
113113
else:
@@ -121,7 +121,7 @@ def get_data(self, parsed_args):
121121
)
122122

123123

124-
class ShowService(command.OpenStackCommand, show.ShowOne):
124+
class ShowService(show.ShowOne):
125125
"""Show service command"""
126126

127127
api = 'identity'
@@ -135,8 +135,8 @@ def get_parser(self, prog_name):
135135
help='Type, name or ID of service to display')
136136
return parser
137137

138-
def get_data(self, parsed_args):
139-
self.log.debug('get_data(%s)' % parsed_args)
138+
def take_action(self, parsed_args):
139+
self.log.debug('take_action(%s)' % parsed_args)
140140
identity_client = self.app.client_manager.identity
141141
try:
142142
# search for the usual ID or name

0 commit comments

Comments
 (0)