def get_PmInfo(token): request_header = {} request_header['X-Auth-Token'] = token.id request_header['Content-Type'] = 'application/json' # url_para_obj = _kwargs_to_url_parameter_object(**kwargs) allInfo = [] project_id = token.project['id'] serverList = nova_connection(project_id, '/os-hypervisors', method='GET', header=request_header) # print serverList for single in serverList['data']['hypervisors']: id = single['id'] info = \ nova_connection(project_id, '/os-hypervisors/' + str(id), method='GET', header=request_header)['data'][ 'hypervisor'] singleInfo = {} singleInfo['id'] = id singleInfo['name'] = single['hypervisor_hostname'] singleInfo['vcpus_used'] = info['vcpus_used'] singleInfo['local_gb_used'] = info['local_gb_used'] singleInfo['memory_mb'] = info['memory_mb'] singleInfo['vcpus'] = info['vcpus'] singleInfo['memory_mb_used'] = info['memory_mb_used'] singleInfo['local_gb'] = info['local_gb'] allInfo.append(singleInfo) return allInfo
def get_VMonPM(token): project_id = token.project['id'] request_header = {} request_header['X-Auth-Token'] = token.id request_header['Content-Type'] = 'application/json' vm_opInfo = {} pmList = nova_connection(project_id, '/servers/detail', method='GET', header=request_header) #print pmList if pmList['status'] == "success": for single in pmList['data']['servers']: pm_name = single['OS-EXT-SRV-ATTR:hypervisor_hostname'] if vm_opInfo.has_key(pm_name) == False: vm_opInfo[pm_name] = [] temp = {} temp['name'] = single['name'] temp['id'] = single['id'] if (single['addresses'] == {}): temp['ip'] = "" vm_opInfo[pm_name].append(temp) continue temp1 = single['addresses']['tenant-net'] temp['ip'] = temp1[0]['addr'] vm_opInfo[pm_name].append(temp) #print pm_name #print vm_opInfo[pm_name] allInfo = {} serList = nova_connection(project_id, '/os-hypervisors', method='GET', header=request_header) #print serList for single in serList['data']['hypervisors']: id = single['id'] info = \ nova_connection(project_id, '/os-hypervisors/' + str(id), method='GET', header=request_header)['data'][ 'hypervisor'] host_name = info['hypervisor_hostname'] host_ip = info['host_ip'] ip_end = host_ip.split('.')[3] #print ip_end if vm_opInfo.has_key(host_name) == False: continue if allInfo.has_key(ip_end) == False: allInfo[ip_end] = [] allInfo[ip_end].append(vm_opInfo[host_name]) #print host_ip #print allInfo[host_ip] # return allInfo for append in the formation.txt for VM info return allInfo
def get_allVMList(token): project_id = token.project['id'] request_header = {} request_header['X-Auth-Token'] = token.id request_header['Content-Type'] = 'application/json' PM_vmInfo = {} ''' url_para_obj = _kwargs_to_url_parameter_object(**kwargs) tenantList=ceilometer_api.keystone_connection('tenants', method='GET', header=request_header) print tenantList for tenantIdinfo in tenantList['data']['tenants']: ''' serverList = nova_connection(project_id, '/servers/detail', method='GET', header=request_header) # print tenantIdinfo['name'] # print serverList if serverList['status'] == "success": for single in serverList['data']['servers']: PM_name = single['OS-EXT-SRV-ATTR:host'] if PM_vmInfo.has_key(PM_name) == False: PM_vmInfo[PM_name] = [] temp = {} temp['name'] = single['name'] temp['id'] = single['id'] temp['instance_name'] = single['OS-EXT-SRV-ATTR:instance_name'] PM_vmInfo[PM_name].append(temp) return PM_vmInfo
def get_server_list(token): assert isinstance(token, openstack_auth_token_class) token_string = token.id project_id = token.project['id'] request_header = {'X-Auth-Token': token_string, 'Content-Type': 'application/json'} return nova_connection(project_id,'servers/detail', 'GET', request_header)
def get_VMonPM(token): project_id = token.project['id'] request_header = {} request_header['X-Auth-Token'] = token.id request_header['Content-Type'] = 'application/json' vm_opInfo = {} pmList = nova_connection(project_id, '/servers/detail', method='GET', header=request_header) #print pmList if pmList['status'] == "success": for single in pmList['data']['servers']: pm_name = single['OS-EXT-SRV-ATTR:hypervisor_hostname'] if vm_opInfo.has_key(pm_name) == False: vm_opInfo[pm_name] = [] temp = {} temp['name'] = single['name'] temp['id'] = single['id'] if (single['addresses']=={}): temp['ip']="" vm_opInfo[pm_name].append(temp) continue temp1 = single['addresses']['tenant-net'] temp['ip'] = temp1[0]['addr'] vm_opInfo[pm_name].append(temp) #print pm_name #print vm_opInfo[pm_name] allInfo = {} serList = nova_connection(project_id, '/os-hypervisors', method='GET', header=request_header) #print serList for single in serList['data']['hypervisors']: id = single['id'] info = \ nova_connection(project_id, '/os-hypervisors/' + str(id), method='GET', header=request_header)['data'][ 'hypervisor'] host_name = info['hypervisor_hostname'] host_ip = info['host_ip'] ip_end = host_ip.split('.')[3] #print ip_end if vm_opInfo.has_key(host_name)==False: continue if allInfo.has_key(ip_end) == False: allInfo[ip_end] = [] allInfo[ip_end].append(vm_opInfo[host_name]) #print host_ip #print allInfo[host_ip] # return allInfo for append in the formation.txt for VM info return allInfo
def getVM_TopoInfo(request): token = request.session['token'] project_id = token.project['id'] request_header = {} request_header['X-Auth-Token'] = token.id request_header['Content-Type'] = 'application/json' vm_topo = [] vm_ip = [] pmList = nova_connection(project_id, '/servers/detail', method='GET', header=request_header) if pmList['status'] == "success": for single in pmList['data']['servers']: if (single['addresses']=={}): continue temp1 = single['addresses']['tenant-net'] ip = temp1[0]['addr'] vm_ip.append(ip) #print vm_ip #for i in vm_ip: # print i #print #SSH files paramiko.util.log_to_file('paramiko.log') s = paramiko.SSHClient() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for pm in range(len(settings.VM_TOPO_SERVER)) : s.connect(hostname=settings.VM_TOPO_SERVER[pm], port=settings.VM_TOPO_SERVER_PORT, username=settings.VM_TOPO_SERVER_USER[pm], password=settings.VM_TOPO_SERVER_PASSWD[pm]) stdin, stdout, stderr = s.exec_command('cat ' + settings.VM_TOPO_FILE) res = stdout.read() to = res.split('\n') vm_topo.extend(to) while '' in vm_topo : vm_topo.remove('') #for single in vm_topo : # print single #print "#####################" #print len(vm_topo) for vm in range(len(vm_topo)) : ip = [] ip = vm_topo[vm].split() for i in range(len(ip)) : if ip[i] not in vm_ip : ip[i] = 'externNet' temp = ip[0]+' '+ip[1]+',' vm_topo[vm] = temp #delete the repeat item there has 10 21 or 21 10 can not be deleted vm_topo = list(set(vm_topo)) for i in range(len(vm_topo)) : if vm_topo[i] == 'externNet externNet,' : del vm_topo[i] for single in vm_topo : print single return HttpResponse(vm_topo)
def get_server_list(token): assert isinstance(token, openstack_auth_token_class) token_string = token.id project_id = token.project['id'] request_header = { 'X-Auth-Token': token_string, 'Content-Type': 'application/json' } return nova_connection(project_id, 'servers/detail', 'GET', request_header)
def getVM_TopoInfo(request): token = request.session['token'] project_id = token.project['id'] request_header = {} request_header['X-Auth-Token'] = token.id request_header['Content-Type'] = 'application/json' vm_topo = [] vm_ip = [] pmList = nova_connection(project_id, '/servers/detail', method='GET', header=request_header) if pmList['status'] == "success": for single in pmList['data']['servers']: if (single['addresses'] == {}): continue temp1 = single['addresses']['tenant-net'] ip = temp1[0]['addr'] vm_ip.append(ip) #print vm_ip #for i in vm_ip: # print i #print #SSH files paramiko.util.log_to_file('paramiko.log') s = paramiko.SSHClient() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for pm in range(len(settings.VM_TOPO_SERVER)): s.connect(hostname=settings.VM_TOPO_SERVER[pm], port=settings.VM_TOPO_SERVER_PORT, username=settings.VM_TOPO_SERVER_USER[pm], password=settings.VM_TOPO_SERVER_PASSWD[pm]) stdin, stdout, stderr = s.exec_command('cat ' + settings.VM_TOPO_FILE) res = stdout.read() to = res.split('\n') vm_topo.extend(to) while '' in vm_topo: vm_topo.remove('') #for single in vm_topo : # print single #print "#####################" #print len(vm_topo) for vm in range(len(vm_topo)): ip = [] ip = vm_topo[vm].split() for i in range(len(ip)): if ip[i] not in vm_ip: ip[i] = 'externNet' temp = ip[0] + ' ' + ip[1] + ',' vm_topo[vm] = temp #delete the repeat item there has 10 21 or 21 10 can not be deleted vm_topo = list(set(vm_topo)) for i in range(len(vm_topo)): if vm_topo[i] == 'externNet externNet,': del vm_topo[i] for single in vm_topo: print single return HttpResponse(vm_topo)