user-info.py: fix printing strings with nice utf-8 chars
Change-Id: Ia3491772abf5580e31b8c24346a3c402f6781e0a
This commit is contained in:
parent
b73c54056e
commit
9da4de873d
|
@ -19,6 +19,7 @@
|
|||
# Update: 2016-04-04 - all regions from keystone v3 api
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
import os
|
||||
import argparse
|
||||
import keystoneclient
|
||||
|
@ -119,11 +120,11 @@ def main():
|
|||
user = keystone.users.find(name=username)
|
||||
user_projects = keystone.projects.list(user=user)
|
||||
|
||||
print "User: {} [{}]: {} projects".format(user.name,
|
||||
print u"User: {} [{}]: {} projects".format(user.name,
|
||||
user.id,
|
||||
len(user_projects))
|
||||
for project in user_projects:
|
||||
print " Project: {} [{}] - {}".format(project.name,
|
||||
print u" Project: {} [{}] - {}".format(project.name,
|
||||
project.id,
|
||||
project.description)
|
||||
|
||||
|
@ -179,7 +180,7 @@ def main():
|
|||
if servers:
|
||||
print " Servers:"
|
||||
for id, server in servers.items():
|
||||
print " Server: {} [{}] - {}".format(server.name, server.id, server.status)
|
||||
print u" Server: {} [{}] - {}".format(server.name, server.id, server.status)
|
||||
volumes_attached = getattr(server,'os-extended-volumes:volumes_attached')
|
||||
for volume_attached in volumes_attached:
|
||||
volume_id = volume_attached['id']
|
||||
|
@ -190,40 +191,40 @@ def main():
|
|||
attached_server_id = attachment['server_id']
|
||||
attached_device = attachment['device']
|
||||
if attached_server_id == server.id:
|
||||
print " Volume: {}: {} [{}] {}GB - {}".format(attached_device, volume_name, volume.id, volume.size, volume.status.upper())
|
||||
print u" Volume: {}: {} [{}] {}GB - {}".format(attached_device, volume_name, volume.id, volume.size, volume.status.upper())
|
||||
# remove volume from list
|
||||
volumes.pop(volume_id)
|
||||
else:
|
||||
print " ERROR: Volume {} [{}] not attached to Server {} [{}]".format(volume_name, volume.id, server.name, server.id)
|
||||
print u" ERROR: Volume {} [{}] not attached to Server {} [{}]".format(volume_name, volume.id, server.name, server.id)
|
||||
|
||||
if volumes:
|
||||
print " Other Volumes:"
|
||||
for id, volume in volumes.items():
|
||||
volume_name = volume.name.rstrip() if volume.name else 'None'
|
||||
print " Volume: {} [{}] {}GB - {}".format(volume_name, volume.id, volume.size, volume.status.upper())
|
||||
print u" Volume: {} [{}] {}GB - {}".format(volume_name, volume.id, volume.size, volume.status.upper())
|
||||
for attachment in volume.attachments:
|
||||
attached_server_id = attachment['server_id']
|
||||
if attached_server_id in servers:
|
||||
server_attached = servers[attached_server_id]
|
||||
print " Attached to: {} [{}]:{}".format(server_attached.name, server_attached.id, attachment['device'])
|
||||
print u" Attached to: {} [{}]:{}".format(server_attached.name, server_attached.id, attachment['device'])
|
||||
else:
|
||||
print " ERROR: attached to unknown Server [{}]:{}".format(attached_server_id, attachment['device'])
|
||||
print u" ERROR: attached to unknown Server [{}]:{}".format(attached_server_id, attachment['device'])
|
||||
|
||||
if volume_snapshots:
|
||||
print " Volume Snapshots:"
|
||||
for id, v_snapshot in volume_snapshots.items():
|
||||
v_snapshot_name = v_snapshot.name.rstrip() if v_snapshot.name else 'None'
|
||||
print " Snapshot: {} [{}] (Volume: [{}]) {}GB - {}".format(v_snapshot_name, v_snapshot.id, v_snapshot.volume_id, v_snapshot.size, v_snapshot.status.upper())
|
||||
print u" Snapshot: {} [{}] (Volume: [{}]) {}GB - {}".format(v_snapshot_name, v_snapshot.id, v_snapshot.volume_id, v_snapshot.size, v_snapshot.status.upper())
|
||||
|
||||
if floatingips:
|
||||
print " Floating IPs:"
|
||||
for id, floatingip in floatingips.items():
|
||||
print " IP: {} [{}] - {}".format(floatingip['floating_ip_address'], floatingip['id'], floatingip['status'])
|
||||
print u" IP: {} [{}] - {}".format(floatingip['floating_ip_address'], floatingip['id'], floatingip['status'])
|
||||
|
||||
if routers:
|
||||
print " Routers:"
|
||||
for id, router in routers.items():
|
||||
print " Router: {} [{}] - {}".format(router['name'], router['id'], router['status'])
|
||||
print u" Router: {} [{}] - {}".format(router['name'], router['id'], router['status'])
|
||||
resp = neutron.list_ports(device_id=id)
|
||||
ifaces = resp['ports']
|
||||
for iface in ifaces:
|
||||
|
@ -232,21 +233,21 @@ def main():
|
|||
if device_owner == 'network:router_gateway':
|
||||
resp = neutron.show_network(iface['network_id'])
|
||||
iface_net = resp['network']
|
||||
print " Interface: {} (Gateway External Network: {} [{}])".format(iface['id'], iface_net['name'], iface_net['id'])
|
||||
print u" Interface: {} (Gateway External Network: {} [{}])".format(iface['id'], iface_net['name'], iface_net['id'])
|
||||
elif device_owner == 'network:router_interface':
|
||||
print " Interface: {} ({})".format(iface['id'], ",".join(iface_info))
|
||||
print u" Interface: {} ({})".format(iface['id'], ",".join(iface_info))
|
||||
else:
|
||||
print " Interface: {} ({}) ({})".format(iface['id'], device_owner, ",".join(iface_info))
|
||||
print u" Interface: {} ({}) ({})".format(iface['id'], device_owner, ",".join(iface_info))
|
||||
|
||||
if networks:
|
||||
print " Networks:"
|
||||
for id, network in networks.items():
|
||||
print " Network: {} [{}] - {}".format(network['name'], network['id'], network['status'])
|
||||
print u" Network: {} [{}] - {}".format(network['name'], network['id'], network['status'])
|
||||
for subnet_id in network['subnets']:
|
||||
resp = neutron.show_subnet(subnet_id)
|
||||
subnet = resp['subnet']
|
||||
subnet_ipranges = ["IPRange: %s-%s" % (i['start'],i['end']) for i in subnet['allocation_pools']]
|
||||
print " Subnet: {} [{}] (CIDR: {})".format(subnet['name'], subnet['id'], subnet['cidr'])
|
||||
print u" Subnet: {} [{}] (CIDR: {})".format(subnet['name'], subnet['id'], subnet['cidr'])
|
||||
resp = neutron.list_ports(network_id=id)
|
||||
ports = resp['ports']
|
||||
for port in ports:
|
||||
|
@ -254,14 +255,14 @@ def main():
|
|||
device_owner = port['device_owner']
|
||||
if device_id in servers:
|
||||
server = servers[device_id]
|
||||
print " Port: {} (Server: {} [{}])".format(port['id'], server.name, server.id, port['status'])
|
||||
print u" Port: {} (Server: {} [{}])".format(port['id'], server.name, server.id, port['status'])
|
||||
elif device_id in routers:
|
||||
router = routers[device_id]
|
||||
print " Port: {} (Router: {} [{}])".format(port['id'], router['name'], router['id'], port['status'])
|
||||
print u" Port: {} (Router: {} [{}])".format(port['id'], router['name'], router['id'], port['status'])
|
||||
elif device_owner == 'network:dhcp':
|
||||
print " Port: {} (DHCP)".format(port['id'])
|
||||
print u" Port: {} (DHCP)".format(port['id'])
|
||||
else:
|
||||
print " Port: {} ({} [])".format(port['id'], device_owner, device_id, port['status'])
|
||||
print u" Port: {} ({} [])".format(port['id'], device_owner, device_id, port['status'])
|
||||
|
||||
except keystoneclient.exceptions.NotFound as e:
|
||||
print "ERROR: Username", username, "not found:", e.message
|
||||
|
@ -271,6 +272,13 @@ def main():
|
|||
print "ERROR: not found:", e.message
|
||||
sys.exit(1)
|
||||
|
||||
except UnicodeEncodeError as e:
|
||||
print "UnicodeEncodeError"
|
||||
print '-'*60
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
print '-'*60
|
||||
sys.exit(1)
|
||||
|
||||
except Exception as e:
|
||||
print "ERROR:", e.message
|
||||
sys.exit(1)
|
||||
|
|
Loading…
Reference in New Issue