Skip to content

Commit

Permalink
Merge "Use consistent formating for printing tables"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jun 23, 2015
2 parents 13e555f + 3ea8d3e commit 973f7a5
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions devops/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,32 @@ def print_table(self, headers, columns):

def do_list(self):
env_list = Environment.list().values('name', 'created')
columns = []
for env in env_list:
column = collections.OrderedDict({'NAME': env['name']})
if self.params.list_ips:
cur_env = Environment.get(name=env['name'])
admin_ip = ''
if 'admin' in [node.name for node in cur_env.get_nodes()]:
admin_ip = (cur_env.get_node(name='admin').
get_ip_address_by_network_name('admin'))
print('{0}\t{1}'.format(env['name'], admin_ip))
elif self.params.timestamps:
created_text = env['created'].strftime('%Y-%m-%d_%H:%M:%S')
print('{0} {1}'.format(env['name'], created_text))
else:
print(env['name'])
column['ADMIN IP'] = admin_ip
if self.params.timestamps:
column['CREATED'] = env['created'].strftime(
'%Y-%m-%d_%H:%M:%S')
columns.append(column)

return env_list
self.print_table(headers="keys", columns=columns)

def node_dict(self, node):
return {'name': node.name,
'vnc': node.get_vnc_port()}

def do_show(self):
print('%5s %25s' % ("VNC", "NODE-NAME"))
for item in map(lambda x: self.node_dict(x), self.env.get_nodes()):
print ('%5s %25s' % (item['vnc'], item['name']))
headers = ("VNC", "NODE-NAME")
columns = [(node.get_vnc_port(), node.name)
for node in self.env.get_nodes()]
self.print_table(headers=headers, columns=columns)

def do_erase(self):
self.env.erase()
Expand Down Expand Up @@ -128,9 +130,10 @@ def do_snapshot_delete(self):
node.erase_snapshot(name=self.params.snapshot_name)

def do_net_list(self):
print("%15s %10s" % ("NETWORK NAME", "IP NET"))
for network in self.env.get_networks():
print("%15s %10s" % (network.name, network.ip_network))
headers = ("NETWORK NAME", "IP NET")
columns = [(net.name, net.ip_network)
for net in self.env.get_networks()]
self.print_table(headers=headers, columns=columns)

def do_timesync(self):
if not self.params.node_name:
Expand Down

0 comments on commit 973f7a5

Please sign in to comment.