def vm_detail(): vmlist = config_memcache.get_vmlist() detail = [] list_static_vm_account = [] list_static_vm_name = [] list_static_vm_hostname = [] list_static_vm_instancename = [] list_static_vm_serviceofferingname = [] list_vm_account = [] list_vm_name = [] list_vm_hostname = [] list_vm_instancename = [] list_vm_serviceofferingname = [] for vm_list in vmlist: list_static_vm_account.append('account') list_static_vm_name.append('vm_name') list_static_vm_hostname.append('vm_hostname') list_static_vm_instancename.append('vm_instancename') list_static_vm_serviceofferingname.append('vm_serviceofferingname') list_vm_name.append(vm_list['displayname']) if 'displayname' in vm_list else list_vm_name.append('-') list_vm_hostname.append(vm_list['hostname']) if 'hostname' in vm_list else list_vm_hostname.append('-') list_vm_instancename.append(vm_list['instancename']) if 'instancename' in vm_list else list_vm_instancename.append('-') list_vm_serviceofferingname.append(vm_list['serviceofferingname']) if 'serviceofferingname' in vm_list else list_vm_serviceofferingname.append('-') list_vm_account.append(vm_list['account']) dict_vm_name = dict(zip(list_static_vm_name, list_vm_name)) dict_vm_hostname = dict(zip(list_static_vm_hostname, list_vm_hostname)) dict_vm_instancename = dict(zip(list_static_vm_instancename, list_vm_instancename)) dict_vm_serviceoffering = dict(zip(list_static_vm_serviceofferingname, list_vm_serviceofferingname)) dict_vm_account = dict(zip(list_static_vm_account, list_vm_account)) dict_vm_name.update(dict_vm_hostname) dict_vm_name.update(dict_vm_instancename) dict_vm_name.update(dict_vm_serviceoffering) dict_vm_name.update(dict_vm_account) detail.append(dict_vm_name) dict_map = dict() for details in detail: if details['account'] in dict_map: dict_map[details['account']].append(details) else: dict_map[details['account']] = [details['account']] dict_map[details['account']].append(details) for key in dict_map.keys(): del dict_map[key][0] return json.dumps(dict_map)
def net_detail(): network = config_memcache.get_network() vmlist = config_memcache.get_vmlist() portfor = config_memcache.get_portforward() detail = [] list_static_vm_name = [] list_static_vm_instancename = [] list_vm_name = [] list_vm_instancename = [] for list_net in network: for vm_list in vmlist: for vm_nic in vm_list['nic']: net_id = list_net.get('id') if net_id in vm_nic['networkid']: for list_port in portfor: if list_port['networkid'] == net_id: list_static_vm_name.append('vm_name') list_static_vm_instancename.append('vm_instancename') list_vm_name.append(vm_list['displayname']) if 'displayname' in vm_list else list_vm_name.append('-') list_vm_instancename.append(vm_list['instancename']) if 'instancename' in vm_list else list_vm_instancename.append('-') dict_vm_name = dict(zip(list_static_vm_name, list_vm_name)) dict_vm_instancename = dict(zip(list_static_vm_instancename, list_vm_instancename)) dict_ip = {'ip':list_port['ipaddress']} dict_public = {'public':list_port['publicport']} dict_private = {'private':list_port['privateport']} dict_account = {'account':list_net['account']} dict_vm_name.update(dict_vm_instancename) dict_vm_name.update(dict_ip) dict_vm_name.update(dict_public) dict_vm_name.update(dict_private) dict_vm_name.update(dict_account) detail.append(dict_vm_name) dict_map_account = dict() dict_map_acc_vm = dict() for details in detail: if details['account'] in dict_map_account: dict_map_account[details['account']].append(details) else: dict_map_account[details['account']] = [details['account']] dict_map_account[details['account']].append(details) for key in dict_map_account.keys(): del dict_map_account[key][0] for dict_map_accounts in dict_map_account: make_vm = dict_map_account[dict_map_accounts] dict_map_vm = dict() for make_vms in make_vm: if make_vms['vm_name'] in dict_map_vm: dict_map_vm[make_vms['vm_name']].append(make_vms) else: dict_map_vm[make_vms['vm_name']] = [make_vms['vm_name']] dict_map_vm[make_vms['vm_name']].append(make_vms) for key in dict_map_vm: del dict_map_vm[key][0] dict_map_acc_vm[dict_map_accounts] = dict_map_vm list_detail_account = list() dict_pair_network = dict() dict_account = dict() num_account_network = 0 num_vm = 0 for dict_map_acc_vms in dict_map_acc_vm: make_ins = dict_map_acc_vm[dict_map_acc_vms] list_detail_vm = [] for vm_name in make_ins: value_vm = make_ins[vm_name] list_detail_network= [] num_vm_network = 0 num_vm+=1 for value_vms in value_vm: num_vm_network+=1 num_account_network+=1 dict_pair_ip = {'ip':value_vms['ip']} dict_pair_public = {'public':value_vms['public']} dict_pair_private = {'private':value_vms['private']} dict_pair_instance = {'instancename':value_vms['vm_instancename']} dict_pair_num_network = {'num_vm_network':num_vm_network} dict_pair_ip.update(dict_pair_public) dict_pair_ip.update(dict_pair_private) list_detail_network.append(dict_pair_ip) dict_pair_vm = {'vm_name':vm_name} dict_pair_network['detail_network'] = list_detail_network dict_pair_vm.update(dict_pair_instance) dict_pair_vm.update(dict_pair_network) dict_pair_vm.update(dict_pair_num_network) list_detail_vm.append(dict_pair_vm) dict_pair_account = {'account':dict_map_acc_vms} dict_pair_num_vm = {'num_account_network':num_account_network+num_vm} dict_account['detail_vm'] = list_detail_vm dict_pair_account.update(dict_account) dict_pair_account.update(dict_pair_num_vm) list_detail_account.append(dict_pair_account) num_account_network = 0 num_vm = 0 return json.dumps(list_detail_account)