From fbbf78efbb7c134f4080c5bc8d42a37a18894cf5 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 14 Dec 2010 15:23:04 -0800 Subject: [PATCH] intialize only get xenserver info --- .../xen/resource/CitrixResourceBase.java | 231 ++++++------------ .../vm/hypervisor/xenserver/network_info.sh | 11 +- scripts/vm/hypervisor/xenserver/vmops | 13 +- 3 files changed, 76 insertions(+), 179 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index f1cbdc29688..91463bcfe5b 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -334,62 +334,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } } - protected void cleanupDiskMounts() { - Connection conn = getConnection(); - - Map srs; - try { - srs = SR.getAllRecords(conn); - } catch (XenAPIException e) { - s_logger.warn("Unable to get the SRs " + e.toString(), e); - throw new CloudRuntimeException("Unable to get SRs " + e.toString(), e); - } catch (XmlRpcException e) { - throw new CloudRuntimeException("Unable to get SRs " + e.getMessage()); - } - - for (Map.Entry sr : srs.entrySet()) { - SR.Record rec = sr.getValue(); - if (SRType.NFS.equals(rec.type) || (SRType.ISO.equals(rec.type) && rec.nameLabel.endsWith("iso"))) { - if (rec.PBDs == null || rec.PBDs.size() == 0) { - cleanSR(sr.getKey(), rec); - continue; - } - - for (PBD pbd : rec.PBDs) { - - if (isRefNull(pbd)) { - continue; - } - PBD.Record pbdr = null; - try { - pbdr = pbd.getRecord(conn); - } catch (XenAPIException e) { - s_logger.warn("Unable to get pbd record " + e.toString()); - } catch (XmlRpcException e) { - s_logger.warn("Unable to get pbd record " + e.getMessage()); - } - - if (pbdr == null) { - continue; - } - - try { - if (pbdr.host.getUuid(conn).equals(_host.uuid)) { - if (!pbdr.currentlyAttached) { - pbdPlug(conn, pbd); - } - } - - } catch (XenAPIException e) { - s_logger.warn("Catch XenAPIException due to" + e.toString(), e); - } catch (XmlRpcException e) { - s_logger.warn("Catch XmlRpcException due to" + e.getMessage(), e); - } - } - } - } - } - protected Pair getVmByNameLabel(Connection conn, Host host, String nameLabel, boolean getRecord) throws XmlRpcException, XenAPIException { Set vms = host.getResidentVMs(conn); for (VM vm : vms) { @@ -2520,6 +2464,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR // snapshots dir fails, let Ready command // succeed. callHostPlugin("vmopsSnapshot", "unmountSnapshotsDir", "dcId", dcId.toString()); + + _localGateway = callHostPlugin("vmops", "getgateway", "mgmtIP", _host.ip); + if (_localGateway == null || _localGateway.isEmpty()) { + String msg = "can not get gateway for host :" + _host.uuid; + s_logger.warn(msg); + return new ReadyAnswer(cmd, msg); + } return new ReadyAnswer(cmd); } @@ -3506,49 +3457,43 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR return true; } - protected Nic getManageMentNetwork(Connection conn, String name) throws XmlRpcException, XenAPIException { - if( name == null) { - return null; - } - Set networks = Network.getByNameLabel(conn, name); - for (Network network : networks) { - Network.Record nr = network.getRecord(conn); - for (PIF pif : nr.PIFs) { - PIF.Record pr = pif.getRecord(conn); - if (_host.uuid.equals(pr.host.getUuid(conn))) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found a network called " + name + " on host=" + _host.ip + "; Network=" + nr.uuid + "; pif=" + pr.uuid); - } - if (!pr.management && pr.bondMasterOf != null && pr.bondMasterOf.size() > 0) { - if (pr.bondMasterOf.size() > 1) { - String msg = new StringBuilder("Unsupported configuration. Network " + name + " has more than one bond. Network=").append(nr.uuid) - .append("; pif=").append(pr.uuid).toString(); - s_logger.warn(msg); - return null; - } - Bond bond = pr.bondMasterOf.iterator().next(); - Set slaves = bond.getSlaves(conn); - for (PIF slave : slaves) { - PIF.Record spr = slave.getRecord(conn); - if (spr.management) { - Host host = Host.getByUuid(conn, _host.uuid); - if (!transferManagementNetwork(conn, host, slave, spr, pif)) { - String msg = new StringBuilder("Unable to transfer management network. slave=" + spr.uuid + "; master=" + pr.uuid + "; host=" - + _host.uuid).toString(); - s_logger.warn(msg); - return null; - } - break; - } - } - } - - return new Nic(network, nr, pif, pr); + protected Nic getManageMentNetwork(Connection conn) throws XmlRpcException, XenAPIException { + PIF mgmtPif = null; + PIF.Record mgmtPifRec = null; + Host host = Host.getByUuid(conn, _host.uuid); + Set hostPifs = host.getPIFs(conn); + for (PIF pif : hostPifs) { + PIF.Record rec = pif.getRecord(conn); + if (rec.management) { + if (rec.VLAN != null && rec.VLAN != -1) { + String msg = new StringBuilder("Unsupported configuration. Management network is on a VLAN. host=").append(_host.uuid).append("; pif=").append(rec.uuid) + .append("; vlan=").append(rec.VLAN).toString(); + s_logger.warn(msg); + throw new CloudRuntimeException(msg); } + if (s_logger.isDebugEnabled()) { + s_logger.debug("Management network is on pif=" + rec.uuid); + } + mgmtPif = pif; + mgmtPifRec = rec; + break; } } - - return null; + if (mgmtPif == null) { + String msg = "Unable to find management network for " + _host.uuid; + s_logger.warn(msg); + throw new CloudRuntimeException(msg); + } + Bond bond = mgmtPifRec.bondSlaveOf; + if ( !isRefNull(bond) ) { + String msg = "Management interface is on slave(" +mgmtPifRec.uuid + ") of bond(" + + bond.getUuid(conn) + ") on host(" +_host.uuid + "), please move management interface to bond!"; + s_logger.warn(msg); + throw new CloudRuntimeException(msg); + } + Network nk = mgmtPifRec.network; + Network.Record nkRec = nk.getRecord(conn); + return new Nic(nk, nkRec, mgmtPif, mgmtPifRec); } @@ -3813,8 +3758,8 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR protected SR getLocalLVMSR() { Connection conn = getConnection(); - try { + Map map = SR.getAllRecords(conn); for (Map.Entry entry : map.entrySet()) { SR.Record srRec = entry.getValue(); @@ -3954,45 +3899,15 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR _host.speed = hc.getSpeed(conn).intValue(); break; } - - _localGateway = callHostPlugin("vmops", "getgateway", "mgmtIP", myself.getAddress(conn)); - if (_localGateway == null || _localGateway.isEmpty()) { - s_logger.warn("can not get gateway for host :" + _host.uuid); - return false; - } - + Nic privateNic = getManageMentNetwork(conn); + _privateNetworkName = privateNic.nr.nameLabel; + _host.privatePif = privateNic.pr.uuid; + _host.privateNetwork = privateNic.nr.uuid; + _canBridgeFirewall = can_bridge_firewall(); _host.systemvmisouuid = null; - Nic privateNic = null; - privateNic = getManageMentNetwork(conn, "cloud-private"); - if (privateNic == null) { - privateNic = getManageMentNetwork(conn, _privateNetworkName); - } else { - _privateNetworkName = "cloud-private"; - } - String name = _privateNetworkName; - - if (privateNic == null) { - s_logger.debug("Unable to find any private network. Trying to determine that by route for host " + _host.ip); - name = callHostPlugin("vmops", "getnetwork", "mgmtIP", myself.getAddress(conn)); - if (name == null || name.isEmpty()) { - s_logger.warn("Unable to determine the private network for host " + _host.ip); - return false; - } - _privateNetworkName = name; - privateNic = getManageMentNetwork(conn, name); - if (privateNic == null) { - s_logger.warn("Unable to get private network " + name); - return false; - } - name = privateNic.nr.nameLabel; - } - - _host.privatePif = privateNic.pr.uuid; - _host.privateNetwork = privateNic.nr.uuid; - Nic guestNic = null; if (_guestNetworkName != null && !_guestNetworkName.equals(_privateNetworkName)) { guestNic = getLocalNetwork(conn, _guestNetworkName); @@ -4021,23 +3936,34 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR _host.publicPif = publicNic.pr.uuid; _host.publicNetwork = publicNic.nr.uuid; - - Nic storageNic1 = getLocalNetwork(conn, _storageNetworkName1); - if (storageNic1 == null) { - storageNic1 = privateNic; - _storageNetworkName1 = _privateNetworkName; + Nic storageNic1 = null; + if (_storageNetworkName1 != null && !_storageNetworkName1.equals(_guestNetworkName)) { + storageNic1 = getLocalNetwork(conn, _storageNetworkName1); + if (storageNic1 == null) { + s_logger.warn("Unable to find storage network 1: " + _storageNetworkName1 + " for host " + _host.ip); + throw new IllegalArgumentException("Unable to find public network " + _storageNetworkName1 + " for host " + _host.ip); + } + } else { + storageNic1 = guestNic; + _storageNetworkName1 = _guestNetworkName; } _host.storageNetwork1 = storageNic1.nr.uuid; _host.storagePif1 = storageNic1.pr.uuid; - Nic storageNic2 = getLocalNetwork(conn, _storageNetworkName2); - if (storageNic2 == null) { - storageNic2 = privateNic; - _storageNetworkName2 = _privateNetworkName; + Nic storageNic2 = null; + if (_storageNetworkName2 != null && !_storageNetworkName2.equals(_guestNetworkName)) { + storageNic2 = getLocalNetwork(conn, _storageNetworkName2); + if (storageNic2 == null) { + s_logger.warn("Unable to find storage network 2: " + _storageNetworkName2 + " for host " + _host.ip); + throw new IllegalArgumentException("Unable to find public network " + _storageNetworkName2 + " for host " + _host.ip); + } + } else { + storageNic2 = guestNic; + _storageNetworkName2 = _guestNetworkName; } - _host.storageNetwork2 = storageNic2.nr.uuid; - _host.storagePif2 = storageNic2.pr.uuid; - + _host.storageNetwork1 = storageNic2.nr.uuid; + _host.storagePif1 = storageNic2.pr.uuid; + s_logger.info("Private Network is " + _privateNetworkName + " for host " + _host.ip); s_logger.info("Guest Network is " + _guestNetworkName + " for host " + _host.ip); s_logger.info("Public Network is " + _publicNetworkName + " for host " + _host.ip); @@ -4172,8 +4098,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR StartupRoutingCommand cmd = new StartupRoutingCommand(); fillHostInfo(cmd); - cleanupDiskMounts(); - Map changes = null; synchronized (_vms) { _vms.clear(); @@ -4494,13 +4418,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } protected void fillHostInfo(StartupRoutingCommand cmd) { - long speed = 0; - int cpus = 0; - long ram = 0; - Connection conn = getConnection(); - - long dom0Ram = 0; final StringBuilder caps = new StringBuilder(); try { @@ -4538,13 +4456,11 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR cmd.setSpeed(_host.speed); cmd.setCpus(_host.cpus); - long free = 0; - HostMetrics hm = host.getMetrics(conn); + long ram = 0; + long dom0Ram = 0; ram = hm.getMemoryTotal(conn); - free = hm.getMemoryFree(conn); - Set vms = host.getResidentVMs(conn); for (VM vm : vms) { if (vm.getIsControlDomain(conn)) { @@ -4552,14 +4468,13 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR break; } } - // assume the memory Virtualization overhead is 1/64 ram = (ram - dom0Ram) * 63/64; cmd.setMemory(ram); cmd.setDom0MinMemory(dom0Ram); if (s_logger.isDebugEnabled()) { - s_logger.debug("Total Ram: " + ram + " Free Ram: " + free + " dom0 Ram: " + dom0Ram); + s_logger.debug("Total Ram: " + ram + " dom0 Ram: " + dom0Ram); } PIF pif = PIF.getByUuid(conn, _host.privatePif); diff --git a/scripts/vm/hypervisor/xenserver/network_info.sh b/scripts/vm/hypervisor/xenserver/network_info.sh index 788e9d4fe67..f26992d9d31 100755 --- a/scripts/vm/hypervisor/xenserver/network_info.sh +++ b/scripts/vm/hypervisor/xenserver/network_info.sh @@ -6,27 +6,23 @@ set -e usage() { echo "$0 [-g |-d] " echo " -g output the gateway for this ip address" - echo " -l output the name-label for the network for this address" exit 1 } gflag= -lflag= -while getopts 'gl' OPTION +while getopts 'g' OPTION do case $OPTION in g) gflag=1 ;; - l) lflag=1 - ;; ?) usage exit 1 ;; esac done -if [ "$gflag$lflag" != "1" ] +if [ "$gflag" != "1" ] then usage fi @@ -41,10 +37,7 @@ defaultdev=$(ip route | grep default | awk '{print $NF}') if [ "$device" == "$defaultdev" ] then gateway=$(ip route | grep default | awk '{print $3}') - uuid=$(xe network-list bridge=$defaultdev | grep uuid | head -1 | awk '{print $NF}') - name=$(xe network-param-get param-name=name-label uuid=$uuid) fi [ -n "$gflag" ] && echo $gateway && exit 0 -[ -n "$lflag" ] && echo $name && exit 0 diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index 9a21cc4f108..8f976ba53d2 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -91,17 +91,6 @@ def getgateway(session, args): return txt -@echo -def getnetwork(session, args): - mgmt_ip = args['mgmtIP'] - try: - cmd = ["bash", "/opt/xensource/bin/network_info.sh", "-l", mgmt_ip] - txt = util.pread2(cmd) - except: - txt = '' - - return txt - @echo def preparemigration(session, args): uuid = args['uuid'] @@ -1059,5 +1048,5 @@ def network_rules(session, args): if __name__ == "__main__": - XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats, "getvncport": getvncport, "getgateway": getgateway, "getnetwork": getnetwork, "preparemigration": preparemigration, "setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver, "ipassoc": ipassoc, "vm_data": vm_data, "savePassword": savePassword, "saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile, "networkUsage": networkUsage, "network_rules":network_rules, "can_bridge_firewall":can_bridge_firewall, "default_network_rules":default_network_rules, "destroy_network_rules_for_vm":destroy_network_rules_for_vm, "default_network_rules_systemvm":default_network_rules_systemvm, "get_rule_logs_for_vms":get_rule_logs_for_vms, "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn}) + XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats, "getvncport": getvncport, "getgateway": getgateway, "preparemigration": preparemigration, "setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver, "ipassoc": ipassoc, "vm_data": vm_data, "savePassword": savePassword, "saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile, "networkUsage": networkUsage, "network_rules":network_rules, "can_bridge_firewall":can_bridge_firewall, "default_network_rules":default_network_rules, "destroy_network_rules_for_vm":destroy_network_rules_for_vm, "default_network_rules_systemvm":default_network_rules_systemvm, "get_rule_logs_for_vms":get_rule_logs_for_vms, "setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn})