def all_bonding(vmid): vm = get_vm(vmid) addr = vm['mgraddr'] result = [] bond_dic = {} nics = FabricUtilNFV.getInterfaces(addr, vm['sshid'], vm['sshpw'], None) logger.debug(json.dumps(nics, indent=4)) nicinfo = FabricUtilNFV.getIfConfig(addr, vm['sshid'], vm['sshpw'], "") #bonging 정보만 추출. for nic in nics: if "address" in nic and nic["address"] == 'dhcp': nic["ipaddr"] = nicinfo[nic["ethName"]] if nic["ethName"].startswith("bond"): nic['ethernets'] = [] nic['config'] = FabricUtilNFV.get_vyatta_conf(vmid, "$SHOW interfaces") bond_dic[nic["ethName"]] = nic elif nic.has_key('bond-group'): bond_dic[nic["bond-group"]]['ethernets'].append(nic["ethName"]) for bond_id in bond_dic: result.append(bond_dic[bond_id]) return result
def update_nic(vmid, params): pdiff = PyUtils.diff_vyatta_conf(params['before'], params['after']) if len(pdiff) == 0: logger.debug("NIC 수정사항이 없습니다.") return {"success": "success", "msg": "수정 사항이 없습니다."} vms = read_repository("vms") for vm in vms: print vm['_id'] + " : " + vmid if '_id' in vm and vmid == vm['_id']: break if vm == None: raise ValueError("get_vm not found: " + vmid) pEthName = params['after']['ethName'] addr = vm['mgraddr'] env.hosts = [ addr ] env.user = vm['sshid'] env.password = vm['sshpw'] env.shell = '/bin/vbash -ic' results = execute(update_nic_task, hosts=[addr], ethName = pEthName, diff=pdiff) # vms.json 파일도 변경해주기. modified = False for key in pdiff: if "disable" == key: vm["interfaces"][pEthName]["disable"] = pdiff[key] modified = True if "hw-id" == key: vm["interfaces"][pEthName]["macaddr"] = pdiff[key] modified = True if "address" == key: modified = True if pdiff[key] == "dhcp": nicinfo = FabricUtilNFV.getIfConfig(addr, vm['sshid'], vm['sshpw'], pEthName) vm["interfaces"][pEthName]["ipaddr"] = nicinfo[pEthName] else: vm["interfaces"][pEthName]["ipaddr"] = pdiff[key] if modified: write_repository('vms', vms) return results[addr]
def get_bonding(vmid, bondid): vm = get_vm(vmid) addr = vm['mgraddr'] results = {} nics = FabricUtilNFV.getInterfaces(addr, vm['sshid'], vm['sshpw'], None) bonding = {} nicinfo = FabricUtilNFV.getIfConfig(addr, vm['sshid'], vm['sshpw'], "") for nic in nics: logger.debug(bondid + ": " + nic['ethName']) if bondid == nic['ethName']: nic['config'] = FabricUtilNFV.get_vyatta_conf(vmid, "$SHOW interfaces") if "address" in nic and nic["address"] == 'dhcp': nic["ipaddr"] = nicinfo[nic['ethName']] bonding[bondid] = nic bonding['ethernets'] = [] bonding['disables'] = [] results['success'] = 'success' elif nic.has_key('bond-group') and bondid == nic['bond-group']: bonding['ethernets'].append(nic['ethName']) elif nic.has_key('bond-group'): bonding['disables'].append(nic['ethName']) if results.has_key('success'): results['msg'] = json.dumps(bonding) else: results['success'] = 'fail' results['errmsg'] = 'bonding not found.' return results