Skip to content

Commit b11fedb

Browse files
author
Terry Howe
committed
show generalized
1 parent 6a5d38e commit b11fedb

36 files changed

+170
-121
lines changed

openstackclient/network/common.py

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,48 @@
1313
# under the License.
1414
#
1515

16+
import json
1617
import logging
18+
import six
1719

1820
from cliff import command
1921
from cliff import lister
2022
from cliff import show
2123

2224

23-
class CreateCommand(show.ShowOne):
25+
class BaseShowCommand(show.ShowOne):
26+
json_indent = None
27+
28+
def dumps(self, value, indent=None):
29+
try:
30+
return json.dumps(value, indent=indent)
31+
except TypeError:
32+
pass
33+
return json.dumps(to_primitive(value))
34+
35+
def format_data(self, data):
36+
# Modify data to make it more readable
37+
if not(self.name in data):
38+
return data
39+
for k, v in data[self.name].iteritems():
40+
if isinstance(v, list):
41+
value = '\n'.join(self.dumps(
42+
i, indent=self.json_indent) if isinstance(i, dict)
43+
else str(i) for i in v)
44+
data[self.name][k] = value
45+
print '***********************************'
46+
print value.__class__.__name__
47+
print str(value)
48+
print '***********************************'
49+
elif isinstance(v, dict):
50+
value = self.dumps(v, indent=self.json_indent)
51+
data[self.name][k] = value
52+
elif v is None:
53+
data[self.name][k] = ''
54+
return data[self.name]
55+
56+
57+
class CreateCommand(BaseShowCommand):
2458

2559
log = logging.getLogger(__name__ + '.CreateCommand')
2660

@@ -131,33 +165,36 @@ def take_action(self, parsed_args):
131165
return neuter.take_action(parsed_args)
132166

133167

134-
class ShowCommand(show.ShowOne):
168+
class ShowCommand(BaseShowCommand):
135169

136170
log = logging.getLogger(__name__ + '.ShowCommand')
137-
name = "id"
138-
metavar = "<id>"
139-
help_text = "Identifier of object to delete"
171+
172+
def __init__(self, app, app_args):
173+
super(ShowCommand, self).__init__(app, app_args)
174+
self.metavar = "<" + self.name + ">"
175+
self.help_text = "Name or identifier of " + \
176+
self.name.replace('_', ' ') + " to show"
177+
self.func = self.name
178+
self.response = self.name
140179

141180
def get_client(self):
142181
return self.app.client_manager.network
143182

144183
def get_parser(self, prog_name):
145184
parser = super(ShowCommand, self).get_parser(prog_name)
146185
parser.add_argument(
147-
self.name,
186+
'identifier',
148187
metavar=self.metavar,
149-
help=self.help_text,
188+
help=self.help_text
150189
)
151190
return parser
152191

153192
def take_action(self, parsed_args):
154193
self.log.debug('take_action(%s)' % parsed_args)
155-
neuter = self.clazz(self.app, self.app_args)
156-
neuter.get_client = self.get_client
157-
parsed_args.show_details = True
158-
parsed_args.request_format = 'json'
159-
parsed_args.fields = []
160-
return neuter.take_action(parsed_args)
194+
method = getattr(self.app.client_manager.network, "show_" + self.func)
195+
data = method(parsed_args.identifier)
196+
data = self.format_data(data)
197+
return zip(*sorted(six.iteritems(data)))
161198

162199

163200
class AddCommand(command.Command):

openstackclient/network/v2_0/floatingip.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@ class ListFloatingIp(common.ListCommand):
5656
class ShowFloatingIp(common.ShowCommand):
5757
"""Show floating IP details"""
5858

59-
clazz = neu2.ShowFloatingIP
60-
help_text = "Identifier of floating IP to show"
59+
name = "floatingip"
60+
61+
def __init__(self, app, app_args):
62+
super(ShowFloatingIp, self).__init__(app, app_args)
63+
self.help_text = "Identitifer of floating IP to show"

openstackclient/network/v2_0/fw/firewall.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,4 @@ class SetFirewall(common.SetCommand):
8989
class ShowFirewall(common.ShowCommand):
9090
"""Show firewall details"""
9191

92-
clazz = neu2.ShowFirewall
9392
name = 'firewall'
94-
metavar = '<firewall>'
95-
help_text = 'Name or ID of firewall to show'

openstackclient/network/v2_0/gateway.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class SetGateway(common.SetCommand):
6666
class ShowGateway(common.ShowCommand):
6767
"""Show gateway details"""
6868

69-
clazz = neu2.ShowNetworkGateway
70-
name = 'id'
71-
metavar = '<gateway>'
72-
help_text = 'Name or ID of gateway to show'
69+
name = 'gateway'
70+
71+
def __init__(self, app, app_args):
72+
super(ShowGateway, self).__init__(app, app_args)
73+
self.func = "network_gatway"

openstackclient/network/v2_0/lb/healthmonitor.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ class SetHealthMonitor(common.SetCommand):
9696
class ShowHealthMonitor(common.ShowCommand):
9797
"""Show load balancer health monitor details"""
9898

99-
clazz = neu2.ShowHealthMonitor
100-
name = 'id'
101-
metavar = '<healthmonitor>'
102-
help_text = 'Name or ID of health monitor to show'
99+
name = 'health_monitor'
103100

104101

105102
class AddPool(common.AddCommand):

openstackclient/network/v2_0/lb/member.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,4 @@ class SetMember(common.SetCommand):
7575
class ShowMember(common.ShowCommand):
7676
"""Show load balancer member details"""
7777

78-
clazz = neu2.ShowMember
79-
name = 'id'
80-
metavar = '<member>'
81-
help_text = 'Name or ID of member to show'
78+
name = 'member'

openstackclient/network/v2_0/lb/pool.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ class ShowPool(common.ShowCommand):
107107
"""Show load balancer pool details"""
108108

109109
name = 'pool'
110-
metavar = '<pool>'
111-
help_text = 'Name or ID of pool to show'
112110

113111
def get_parser(self, prog_name):
114112
parser = super(ShowPool, self).get_parser(prog_name)

openstackclient/network/v2_0/lb/vip.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,4 @@ class SetVip(common.SetCommand):
8989
class ShowVip(common.ShowCommand):
9090
"""Show load balancer VIP details"""
9191

92-
clazz = neu2.ShowVip
93-
name = 'id'
94-
metavar = '<vip>'
95-
help_text = 'Name or ID of VIP to show'
92+
name = 'vip'

openstackclient/network/v2_0/network.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ class SetNetwork(common.SetCommand):
9898
class ShowNetwork(common.ShowCommand):
9999
"""Show network details"""
100100

101-
clazz = neu2.ShowNetwork
102-
name = 'id'
103-
metavar = '<network>'
104-
help_text = 'Name or ID of network to show'
101+
name = 'network'
105102

106103

107104
class AddGatewayNetwork(common.AddCommand):

openstackclient/network/v2_0/port.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def get_parser(self, prog_name):
9797

9898
def take_action(self, parsed_args):
9999
self.log.debug('take_action(%s)' % parsed_args)
100+
parsed_args.request_format = 'json'
101+
parsed_args.fields = []
102+
parsed_args.page_size = None
103+
parsed_args.sort_key = []
104+
parsed_args.sort_dir = []
100105
if parsed_args.router:
101106
parsed_args.id = parsed_args.router
102107
neuter = neu2.ListRouterPort(self.app, self.app_args)
@@ -139,10 +144,7 @@ def get_parser(self, prog_name):
139144
class ShowPort(common.ShowCommand):
140145
"""Show port details"""
141146

142-
clazz = neu2.ShowPort
143-
name = 'id'
144-
metavar = '<port>'
145-
help_text = 'Name or ID of port to show'
147+
name = "port"
146148

147149

148150
class AddPort(common.RemoveCommand):

0 commit comments

Comments
 (0)