def get_net_id(no): token = get_token(vcip, username, password) result = get_networks(vcip, token) for x in result['value']: if x['name'] == 'VLAN' + str(no): return x['network']
def edit_nic(no): net_id = get_net_id(no) # print('网络唯一ID:' + str(net_id)) vm_id = get_vmhost_id(no) # print('虚拟机唯一ID:' + str(vm_id)) token = get_token(vcip, username, password) # print('为虚拟机'+str(vm_id)+'关联端口组'+str(net_id)) add_vm_nic(vcip, token, vm_id, net_id)
def get_vmhost_id(no): token = get_token(vcip, username, password) vm_list = get_vms(vcip, token) for x in vm_list: if x['name'] == 'CentOS_' + str(no): return x['vm']
def vSphere_power_on(VLANID): token = get_token(vcip,username,password) vm_list = get_vms(vcip,token) # print(vm_list) for vm in vm_list: if vm['name'] == 'CentOS_'+ str(VLANID): vmid = vm['vm'] poweron_vm(vcip,token,vmid)
def get_vm_id(): token = get_token(vcip, username, password) vm_list = get_vms(vcip, token) vm_ids = [] for vm in vm_list: if 'CentOS_' in vm['name']: vm_ids.append(int(vm['name'].replace('CentOS_', ''))) return vm_ids
def get_network_id(): token = get_token(vcip, username, password) result = get_networks(vcip, token) vlanid = [] for x in result['value']: if 'VLAN' in x['name']: vlanid.append(int(x['name'].replace('VLAN', ''))) return vlanid