Search in sources :

Example 11 with PIF

use of com.xensource.xenapi.PIF in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method fillHostInfo.

protected void fillHostInfo(final Connection conn, final StartupRoutingCommand cmd) {
    final StringBuilder caps = new StringBuilder();
    try {
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final Host.Record hr = host.getRecord(conn);
        Map<String, String> details = cmd.getHostDetails();
        if (details == null) {
            details = new HashMap<>();
        }
        String productBrand = hr.softwareVersion.get("product_brand");
        if (productBrand == null) {
            productBrand = hr.softwareVersion.get("platform_name");
        }
        details.put("product_brand", productBrand);
        details.put("product_version", _host.getProductVersion());
        if (hr.softwareVersion.get("product_version_text_short") != null) {
            details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short"));
            cmd.setHypervisorVersion(hr.softwareVersion.get("product_version_text_short"));
            cmd.setHypervisorVersion(_host.getProductVersion());
        }
        if (_privateNetworkName != null) {
            details.put("private.network.device", _privateNetworkName);
        }
        cmd.setHostDetails(details);
        cmd.setName(hr.nameLabel);
        cmd.setGuid(_host.getUuid());
        cmd.setPool(_host.getPool());
        cmd.setDataCenter(Long.toString(_dcId));
        for (final String cap : hr.capabilities) {
            if (cap.length() > 0) {
                caps.append(cap).append(" , ");
            }
        }
        if (caps.length() > 0) {
            caps.delete(caps.length() - 3, caps.length());
        }
        cmd.setCaps(caps.toString());
        cmd.setCpuSockets(_host.getCpuSockets());
        cmd.setCpus(_host.getCpus());
        final HostMetrics hm = host.getMetrics(conn);
        long ram = 0;
        long dom0Ram = 0;
        ram = hm.getMemoryTotal(conn);
        final Set<VM> vms = host.getResidentVMs(conn);
        for (final VM vm : vms) {
            if (vm.getIsControlDomain(conn)) {
                dom0Ram = vm.getMemoryStaticMax(conn);
                break;
            }
        }
        ram = (long) ((ram - dom0Ram - _xsMemoryUsed) * _xsVirtualizationFactor);
        cmd.setMemory(ram);
        cmd.setDom0MinMemory(dom0Ram);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Total Ram: " + ram + " dom0 Ram: " + dom0Ram);
        }
        PIF pif = PIF.getByUuid(conn, _host.getPrivatePif());
        PIF.Record pifr = pif.getRecord(conn);
        if (pifr.IP != null && pifr.IP.length() > 0) {
            cmd.setPrivateIpAddress(pifr.IP);
            cmd.setPrivateMacAddress(pifr.MAC);
            cmd.setPrivateNetmask(pifr.netmask);
        } else {
            cmd.setPrivateIpAddress(_host.getIp());
            cmd.setPrivateMacAddress(pifr.MAC);
            cmd.setPrivateNetmask("255.255.255.0");
        }
        pif = PIF.getByUuid(conn, _host.getPublicPif());
        pifr = pif.getRecord(conn);
        if (pifr.IP != null && pifr.IP.length() > 0) {
            cmd.setPublicIpAddress(pifr.IP);
            cmd.setPublicMacAddress(pifr.MAC);
            cmd.setPublicNetmask(pifr.netmask);
        }
        if (_host.getStoragePif1() != null) {
            pif = PIF.getByUuid(conn, _host.getStoragePif1());
            pifr = pif.getRecord(conn);
            if (pifr.IP != null && pifr.IP.length() > 0) {
                cmd.setStorageIpAddress(pifr.IP);
                cmd.setStorageMacAddress(pifr.MAC);
                cmd.setStorageNetmask(pifr.netmask);
            }
        }
        if (_host.getStoragePif2() != null) {
            pif = PIF.getByUuid(conn, _host.getStoragePif2());
            pifr = pif.getRecord(conn);
            if (pifr.IP != null && pifr.IP.length() > 0) {
                cmd.setStorageIpAddressDeux(pifr.IP);
                cmd.setStorageMacAddressDeux(pifr.MAC);
                cmd.setStorageNetmaskDeux(pifr.netmask);
            }
        }
        final Map<String, String> configs = hr.otherConfig;
        cmd.setIqn(configs.get("iscsi_iqn"));
        cmd.setPod(_pod);
        cmd.setVersion(CitrixResourceBase.class.getPackage().getImplementationVersion());
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e);
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("XenAPIException" + e.toString(), e);
    }
}
Also used : XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) PIF(com.xensource.xenapi.PIF) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VM(com.xensource.xenapi.VM) HostMetrics(com.xensource.xenapi.HostMetrics) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 12 with PIF

use of com.xensource.xenapi.PIF in project cosmic by MissionCriticalCloud.

the class XenServer56Resource method disableVlanNetwork.

@Override
public void disableVlanNetwork(final Connection conn, final Network network) {
    try {
        final Network.Record networkr = network.getRecord(conn);
        if (!networkr.nameLabel.startsWith("VLAN")) {
            return;
        }
        final String bridge = networkr.bridge.trim();
        for (final PIF pif : networkr.PIFs) {
            final PIF.Record pifr = pif.getRecord(conn);
            if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.getUuid())) {
                continue;
            }
            final VLAN vlan = pifr.VLANMasterOf;
            if (vlan != null) {
                final String vlannum = pifr.VLAN.toString();
                final String device = pifr.device.trim();
                if (vlannum.equals("-1")) {
                    return;
                }
                try {
                    vlan.destroy(conn);
                    final Host host = Host.getByUuid(conn, _host.getUuid());
                    host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
                    host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
                    host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
                    host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
                } catch (final XenAPIException e) {
                    s_logger.trace("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.getUuid() + " due to " + e.toString());
                }
            }
            return;
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to disable VLAN network due to " + e.toString();
        s_logger.warn(msg, e);
    } catch (final Exception e) {
        final String msg = "Unable to disable VLAN network due to " + e.getMessage();
        s_logger.warn(msg, e);
    }
}
Also used : Network(com.xensource.xenapi.Network) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) VLAN(com.xensource.xenapi.VLAN) PIF(com.xensource.xenapi.PIF) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException)

Example 13 with PIF

use of com.xensource.xenapi.PIF in project cosmic by MissionCriticalCloud.

the class CitrixSetupCommandWrapper method execute.

@Override
public Answer execute(final SetupCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
        if (poolRecs.size() != 1) {
            throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + citrixResourceBase.getHost().getUuid());
        }
        final Host master = poolRecs.values().iterator().next().master;
        citrixResourceBase.setupServer(conn, master);
        final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
        citrixResourceBase.setupServer(conn, host);
        if (!citrixResourceBase.setIptables(conn)) {
            s_logger.warn("set xenserver Iptable failed");
            return null;
        }
        final boolean r = citrixResourceBase.launchHeartBeat(conn);
        if (!r) {
            return null;
        }
        citrixResourceBase.cleanupTemplateSR(conn);
        try {
            if (command.useMultipath()) {
                // the config value is set to true
                host.addToOtherConfig(conn, "multipathing", "true");
                host.addToOtherConfig(conn, "multipathhandle", "dmp");
            }
        } catch (final Types.MapDuplicateKey e) {
            s_logger.debug("multipath is already set");
        }
        if (command.needSetup()) {
            final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "setup_iscsi", "uuid", citrixResourceBase.getHost().getUuid());
            if (!result.contains("> DONE <")) {
                s_logger.warn("Unable to setup iscsi: " + result);
                return new SetupAnswer(command, result);
            }
            Pair<PIF, PIF.Record> mgmtPif = null;
            final Set<PIF> hostPifs = host.getPIFs(conn);
            for (final PIF pif : hostPifs) {
                final PIF.Record rec = pif.getRecord(conn);
                if (rec.management) {
                    if (rec.VLAN != null && rec.VLAN != -1) {
                        final String msg = new StringBuilder("Unsupported configuration.  Management network is on a VLAN.  host=").append(citrixResourceBase.getHost().getUuid()).append("; pif=").append(rec.uuid).append("; vlan=").append(rec.VLAN).toString();
                        s_logger.warn(msg);
                        return new SetupAnswer(command, msg);
                    }
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Management network is on pif=" + rec.uuid);
                    }
                    mgmtPif = new Pair<>(pif, rec);
                    break;
                }
            }
            if (mgmtPif == null) {
                final String msg = "Unable to find management network for " + citrixResourceBase.getHost().getUuid();
                s_logger.warn(msg);
                return new SetupAnswer(command, msg);
            }
            final Map<Network, Network.Record> networks = Network.getAllRecords(conn);
            if (networks == null) {
                final String msg = "Unable to setup as there are no networks in the host: " + citrixResourceBase.getHost().getUuid();
                s_logger.warn(msg);
                return new SetupAnswer(command, msg);
            }
            for (final Network.Record network : networks.values()) {
                if (network.nameLabel.equals("cloud-private")) {
                    for (final PIF pif : network.PIFs) {
                        final PIF.Record pr = pif.getRecord(conn);
                        if (citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) {
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug("Found a network called cloud-private. host=" + citrixResourceBase.getHost().getUuid() + ";  Network=" + network.uuid + "; " + "pif=" + pr.uuid);
                            }
                            if (pr.VLAN != null && pr.VLAN != -1) {
                                final String msg = new StringBuilder("Unsupported configuration.  Network cloud-private is on a VLAN.  Network=").append(network.uuid).append(" ; pif=").append(pr.uuid).toString();
                                s_logger.warn(msg);
                                return new SetupAnswer(command, msg);
                            }
                            if (!pr.management && pr.bondMasterOf != null && pr.bondMasterOf.size() > 0) {
                                if (pr.bondMasterOf.size() > 1) {
                                    final String msg = new StringBuilder("Unsupported configuration.  Network cloud-private has more than one bond.  Network=").append(network.uuid).append("; pif=").append(pr.uuid).toString();
                                    s_logger.warn(msg);
                                    return new SetupAnswer(command, msg);
                                }
                                final Bond bond = pr.bondMasterOf.iterator().next();
                                final Set<PIF> slaves = bond.getSlaves(conn);
                                for (final PIF slave : slaves) {
                                    final PIF.Record spr = slave.getRecord(conn);
                                    if (spr.management) {
                                        if (!citrixResourceBase.transferManagementNetwork(conn, host, slave, spr, pif)) {
                                            final String msg = new StringBuilder("Unable to transfer management network.  slave=" + spr.uuid + "; master=" + pr.uuid + "; host=" + citrixResourceBase.getHost().getUuid()).toString();
                                            s_logger.warn(msg);
                                            return new SetupAnswer(command, msg);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return new SetupAnswer(command, false);
    } catch (final XmlRpcException e) {
        s_logger.warn("Unable to setup", e);
        return new SetupAnswer(command, e.getMessage());
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to setup", e);
        return new SetupAnswer(command, e.getMessage());
    } catch (final Exception e) {
        s_logger.warn("Unable to setup", e);
        return new SetupAnswer(command, e.getMessage());
    }
}
Also used : Types(com.xensource.xenapi.Types) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) PIF(com.xensource.xenapi.PIF) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SetupAnswer(com.cloud.agent.api.SetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.xensource.xenapi.Network) Pool(com.xensource.xenapi.Pool) Bond(com.xensource.xenapi.Bond) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 14 with PIF

use of com.xensource.xenapi.PIF in project cloudstack by apache.

the class CitrixResourceBase method fillHostInfo.

protected void fillHostInfo(final Connection conn, final StartupRoutingCommand cmd) {
    final StringBuilder caps = new StringBuilder();
    try {
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final Host.Record hr = host.getRecord(conn);
        Map<String, String> details = cmd.getHostDetails();
        if (details == null) {
            details = new HashMap<String, String>();
        }
        String productBrand = hr.softwareVersion.get("product_brand");
        if (productBrand == null) {
            productBrand = hr.softwareVersion.get("platform_name");
        }
        details.put("product_brand", productBrand);
        details.put("product_version", _host.getProductVersion());
        if (isUefiSupported(_host.getProductVersion())) {
            details.put(com.cloud.host.Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString());
        }
        if (hr.softwareVersion.get("product_version_text_short") != null) {
            details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short"));
            cmd.setHypervisorVersion(hr.softwareVersion.get("product_version_text_short"));
            cmd.setHypervisorVersion(_host.getProductVersion());
        }
        if (_privateNetworkName != null) {
            details.put("private.network.device", _privateNetworkName);
        }
        cmd.setHostDetails(details);
        cmd.setName(hr.nameLabel);
        cmd.setGuid(_host.getUuid());
        cmd.setPool(_host.getPool());
        cmd.setDataCenter(Long.toString(_dcId));
        for (final String cap : hr.capabilities) {
            if (cap.length() > 0) {
                caps.append(cap).append(" , ");
            }
        }
        if (caps.length() > 0) {
            caps.delete(caps.length() - 3, caps.length());
        }
        cmd.setCaps(caps.toString());
        cmd.setSpeed(_host.getSpeed());
        cmd.setCpuSockets(_host.getCpuSockets());
        cmd.setCpus(_host.getCpus());
        final HostMetrics hm = host.getMetrics(conn);
        long ram = 0;
        long dom0Ram = 0;
        ram = hm.getMemoryTotal(conn);
        final Set<VM> vms = host.getResidentVMs(conn);
        for (final VM vm : vms) {
            if (vm.getIsControlDomain(conn)) {
                dom0Ram = vm.getMemoryStaticMax(conn);
                break;
            }
        }
        ram = (long) ((ram - dom0Ram - _xsMemoryUsed) * _xsVirtualizationFactor);
        cmd.setMemory(ram);
        cmd.setDom0MinMemory(dom0Ram);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Total Ram: " + toHumanReadableSize(ram) + " dom0 Ram: " + toHumanReadableSize(dom0Ram));
        }
        PIF pif = PIF.getByUuid(conn, _host.getPrivatePif());
        PIF.Record pifr = pif.getRecord(conn);
        if (pifr.IP != null && pifr.IP.length() > 0) {
            cmd.setPrivateIpAddress(pifr.IP);
            cmd.setPrivateMacAddress(pifr.MAC);
            cmd.setPrivateNetmask(pifr.netmask);
        } else {
            cmd.setPrivateIpAddress(_host.getIp());
            cmd.setPrivateMacAddress(pifr.MAC);
            cmd.setPrivateNetmask("255.255.255.0");
        }
        pif = PIF.getByUuid(conn, _host.getPublicPif());
        pifr = pif.getRecord(conn);
        if (pifr.IP != null && pifr.IP.length() > 0) {
            cmd.setPublicIpAddress(pifr.IP);
            cmd.setPublicMacAddress(pifr.MAC);
            cmd.setPublicNetmask(pifr.netmask);
        }
        if (_host.getStoragePif1() != null) {
            pif = PIF.getByUuid(conn, _host.getStoragePif1());
            pifr = pif.getRecord(conn);
            if (pifr.IP != null && pifr.IP.length() > 0) {
                cmd.setStorageIpAddress(pifr.IP);
                cmd.setStorageMacAddress(pifr.MAC);
                cmd.setStorageNetmask(pifr.netmask);
            }
        }
        if (_host.getStoragePif2() != null) {
            pif = PIF.getByUuid(conn, _host.getStoragePif2());
            pifr = pif.getRecord(conn);
            if (pifr.IP != null && pifr.IP.length() > 0) {
                cmd.setStorageIpAddressDeux(pifr.IP);
                cmd.setStorageMacAddressDeux(pifr.MAC);
                cmd.setStorageNetmaskDeux(pifr.netmask);
            }
        }
        final Map<String, String> configs = hr.otherConfig;
        cmd.setIqn(configs.get("iscsi_iqn"));
        cmd.setPod(_pod);
        cmd.setVersion(CitrixResourceBase.class.getPackage().getImplementationVersion());
        try {
            final String cmdLine = "xe sm-list | grep \"resigning of duplicates\"";
            final XenServerUtilitiesHelper xenServerUtilitiesHelper = getXenServerUtilitiesHelper();
            Pair<Boolean, String> result = xenServerUtilitiesHelper.executeSshWrapper(_host.getIp(), 22, _username, null, getPwdFromQueue(), cmdLine);
            boolean supportsClonedVolumes = result != null && result.first() != null && result.first() && result.second() != null && result.second().length() > 0;
            cmd.setSupportsClonedVolumes(supportsClonedVolumes);
        } catch (NumberFormatException ex) {
            s_logger.warn("Issue sending 'xe sm-list' via SSH to XenServer host: " + ex.getMessage());
        }
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("XML RPC Exception: " + e.getMessage(), e);
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("XenAPIException: " + e.toString(), e);
    } catch (final Exception e) {
        throw new CloudRuntimeException("Exception: " + e.toString(), e);
    }
}
Also used : XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) PIF(com.xensource.xenapi.PIF) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VM(com.xensource.xenapi.VM) HostMetrics(com.xensource.xenapi.HostMetrics) XenServerUtilitiesHelper(com.cloud.hypervisor.xenserver.resource.wrapper.xenbase.XenServerUtilitiesHelper) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 15 with PIF

use of com.xensource.xenapi.PIF in project cloudstack by apache.

the class XsLocalNetwork method getPif.

public PIF getPif(final Connection conn) throws XenAPIException, XmlRpcException {
    if (_p == null) {
        final Network.Record nr = getNetworkRecord(conn);
        for (final PIF pif : nr.PIFs) {
            final PIF.Record pr = pif.getRecord(conn);
            if (_citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Found a network called " + nr.nameLabel + " on host=" + _citrixResourceBase.getHost().getIp() + ";  Network=" + nr.uuid + "; pif=" + pr.uuid);
                }
                _p = pif;
                _pr = pr;
                break;
            }
        }
    }
    return _p;
}
Also used : Network(com.xensource.xenapi.Network) PIF(com.xensource.xenapi.PIF)

Aggregations

PIF (com.xensource.xenapi.PIF)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 Network (com.xensource.xenapi.Network)12 Host (com.xensource.xenapi.Host)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)9 XmlRpcException (org.apache.xmlrpc.XmlRpcException)6 VLAN (com.xensource.xenapi.VLAN)5 Bond (com.xensource.xenapi.Bond)4 Connection (com.xensource.xenapi.Connection)4 SetupAnswer (com.cloud.agent.api.SetupAnswer)2 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)2 HostMetrics (com.xensource.xenapi.HostMetrics)2 Pool (com.xensource.xenapi.Pool)2 Types (com.xensource.xenapi.Types)2 VM (com.xensource.xenapi.VM)2 Answer (com.cloud.agent.api.Answer)1 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)1 OvsFetchInterfaceCommand (com.cloud.agent.api.OvsFetchInterfaceCommand)1 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)1