def info_server(mgr_or_client, server): if type(server) in (unicode, str): server = server_show(mgr_or_client, server) s_name = server['name'] s_info = dict(id=server['id'], status=server.get('status'), security_groups=server.get('security_groups')) """ addr_dict = {} for net_name, net_addr_info in server['addresses'].items(): addr_dict[net_name] = dict() for adr in net_addr_info: # _type = adr['OS-EXT-IPS:type'] _ver_type = "IPv%s-%s" % (adr['version'], adr['OS-EXT-IPS:type']) addr_dict[net_name][_ver_type] = adr['addr'] """ s_info['networks'] = mdata.get_server_address(server) img = image_show(mgr_or_client, server['image']['id']) s_info['image'] = img['name'] return s_name, s_info
def show_toplogy(cli_mgr, return_topo=False, prefix=None, router_id=None, delete_resources=False): tenant_name = cli_mgr.manager.credentials.tenant_name FMT_ROUTER = "%s>> {router_type} router: {name} {id}" % (' ' * 2) FMT_ROUTER_O = "%s>> router: {name} {id}" % (' ' * 2) FMT_X_GW1 = "%sGW: snat_enabled: {enable_snat}" % (' ' * 5) FMT_X_GW2 = "%sfixed_ip: {external_fixed_ips}" % (' ' * (5 + 4)) FMT_X_ROUT = "%sroutes: {routes}" % (' ' * (5 + 4)) FMT_INTERFACE = "%s>> interface: {name} {id}" % (' ' * 6) # FMT_SUBNETS = "%s subnets: {subnets}" % (' ' * 8) FMT_SNET_ADDR = "%s subnet: {id} {name} cidr={cidr} gw={gateway_ip}" % ( ' ' * 8) FMT_SERVER = "%s>> server: {name} {id}" % (' ' * 10) FMT_SERV_ADDR = "%s>> network: %s " topo = [] topo_line = ["\nNetwork topology of tenant[%s]" % tenant_name] s_list = cli_mgr.nova('server-list-with-detail') if router_id: router_list = cli_mgr.qsvc('router-list', id=router_id) else: router_list = cli_mgr.qsvc('router-list') if prefix: ser_name = "^%s" % prefix s_list = utils.fgrep(s_list, name=ser_name) router_list = utils.fgrep(router_list, name=ser_name) sorted(router_list, key=itemgetter('name')) for router in router_list: rtr = _g_by_attr(router, ('id', 'name', 'router_type', 'distributed')) rtr['_networks'] = [] if 'distributed' in router and router['distributed']: rtr['router_type'] = 'distributed' try: topo_line.append(FMT_ROUTER.format(**rtr)) except: topo_line.append(FMT_ROUTER_O.format(**rtr)) if type(router['external_gateway_info']) is dict: xnet_info = router['external_gateway_info'] rtr['gateway'] = xnet_info topo_line.append(FMT_X_GW1.format(**xnet_info)) try: topo_line.append(FMT_X_GW2.format(**xnet_info)) except: utils.log_msg("GW does not have external_fixed_ips: %s" % xnet_info) rtr['routes'] = router['routes'] if (type(router['routes']) in [list, tuple] and len(router['routes']) > 0): topo_line.append(FMT_X_ROUT.format(**router)) rp_list = cli_mgr.qsvc('router-port-list', router['id']) for rp in rp_list: network = cli_mgr.qsvc('net-show', rp['network_id']) netwk = _g_by_attr(network, ('name', 'id')) subnet_list = network['subnets'] netwk['port_id'] = rp['id'] netwk['_servers'] = [] topo_line.append(FMT_INTERFACE.format(**netwk)) netwk['subnets'] = [] for subnet_id in subnet_list: subnet = cli_mgr.qsvc('subnet-show', subnet_id) subnet = _g_by_attr(subnet, ('id', 'cidr', 'gateway_ip', 'allocation_pools', 'name')) topo_line.append(FMT_SNET_ADDR.format(**subnet)) netwk['subnets'].append(subnet) if_name = network['name'] if_servers = [s for s in s_list if if_name in s['addresses']] for s in if_servers: addr_dict = mdata.get_server_address(s) no_if = len(addr_dict) serv = _g_by_attr(s, ('name', 'id')) serv['#interface'] = no_if topo_line.append( FMT_SERVER.format(**s) + " #interface=%s" % no_if) if if_name in addr_dict: serv['interface'] = addr_dict[if_name] topo_line.append( FMT_SERV_ADDR % (' ' * 14, addr_dict[if_name])) netwk['_servers'].append(serv) rtr['_networks'].append(netwk) topo.append(rtr) print("\n".join(topo_line)) if delete_resources: _delete_topology(cli_mgr, topo) return topo if return_topo else {}