Search in sources :

Example 1 with XenServerUtilitiesHelper

use of com.cloud.hypervisor.xenserver.resource.wrapper.xenbase.XenServerUtilitiesHelper 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 (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: " + 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());
        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)

Aggregations

InternalErrorException (com.cloud.exception.InternalErrorException)1 XenServerUtilitiesHelper (com.cloud.hypervisor.xenserver.resource.wrapper.xenbase.XenServerUtilitiesHelper)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Host (com.xensource.xenapi.Host)1 HostMetrics (com.xensource.xenapi.HostMetrics)1 PIF (com.xensource.xenapi.PIF)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VM (com.xensource.xenapi.VM)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConfigurationException (javax.naming.ConfigurationException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 SAXException (org.xml.sax.SAXException)1