Search in sources :

Example 31 with Host

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

the class CitrixResourceBase method initializeLocalSR.

protected StartupStorageCommand initializeLocalSR(final Connection conn) {
    final SR lvmsr = getLocalLVMSR(conn);
    if (lvmsr != null) {
        try {
            _host.setLocalSRuuid(lvmsr.getUuid(conn));
            final String lvmuuid = lvmsr.getUuid(conn);
            final long cap = lvmsr.getPhysicalSize(conn);
            if (cap > 0) {
                final long avail = cap - lvmsr.getPhysicalUtilisation(conn);
                lvmsr.setNameLabel(conn, lvmuuid);
                final String name = "Cloud Stack Local LVM Storage Pool for " + _host.getUuid();
                lvmsr.setNameDescription(conn, name);
                final Host host = Host.getByUuid(conn, _host.getUuid());
                final String address = host.getAddress(conn);
                final StoragePoolInfo pInfo = new StoragePoolInfo(lvmuuid, address, SRType.LVM.toString(), SRType.LVM.toString(), StoragePoolType.LVM, cap, avail);
                final StartupStorageCommand cmd = new StartupStorageCommand();
                cmd.setPoolInfo(pInfo);
                cmd.setGuid(_host.getUuid());
                cmd.setDataCenter(Long.toString(_dcId));
                cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
                return cmd;
            }
        } catch (final XenAPIException e) {
            final String msg = "build local LVM info err in host:" + _host.getUuid() + e.toString();
            s_logger.warn(msg);
        } catch (final XmlRpcException e) {
            final String msg = "build local LVM info err in host:" + _host.getUuid() + e.getMessage();
            s_logger.warn(msg);
        }
    }
    final SR extsr = getLocalEXTSR(conn);
    if (extsr != null) {
        try {
            final String extuuid = extsr.getUuid(conn);
            _host.setLocalSRuuid(extuuid);
            final long cap = extsr.getPhysicalSize(conn);
            if (cap > 0) {
                final long avail = cap - extsr.getPhysicalUtilisation(conn);
                extsr.setNameLabel(conn, extuuid);
                final String name = "Cloud Stack Local EXT Storage Pool for " + _host.getUuid();
                extsr.setNameDescription(conn, name);
                final Host host = Host.getByUuid(conn, _host.getUuid());
                final String address = host.getAddress(conn);
                final StoragePoolInfo pInfo = new StoragePoolInfo(extuuid, address, SRType.EXT.toString(), SRType.EXT.toString(), StoragePoolType.EXT, cap, avail);
                final StartupStorageCommand cmd = new StartupStorageCommand();
                cmd.setPoolInfo(pInfo);
                cmd.setGuid(_host.getUuid());
                cmd.setDataCenter(Long.toString(_dcId));
                cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
                return cmd;
            }
        } catch (final XenAPIException e) {
            final String msg = "build local EXT info err in host:" + _host.getUuid() + e.toString();
            s_logger.warn(msg);
        } catch (final XmlRpcException e) {
            final String msg = "build local EXT info err in host:" + _host.getUuid() + e.getMessage();
            s_logger.warn(msg);
        }
    }
    return null;
}
Also used : StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 32 with Host

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

the class CitrixResourceBase method createNfsSRbyURI.

protected SR createNfsSRbyURI(final Connection conn, final URI uri, final boolean shared) {
    try {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Creating a " + (shared ? "shared SR for " : "not shared SR for ") + uri);
        }
        final Map<String, String> deviceConfig = new HashMap<String, String>();
        String path = uri.getPath();
        path = path.replace("//", "/");
        deviceConfig.put("server", uri.getHost());
        deviceConfig.put("serverpath", path);
        final String name = UUID.nameUUIDFromBytes(new String(uri.getHost() + path).getBytes()).toString();
        if (!shared) {
            final Set<SR> srs = SR.getByNameLabel(conn, name);
            for (final SR sr : srs) {
                final SR.Record record = sr.getRecord(conn);
                if (SRType.NFS.equals(record.type) && record.contentType.equals("user") && !record.shared) {
                    removeSRSync(conn, sr);
                }
            }
        }
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final Map<String, String> smConfig = new HashMap<String, String>();
        smConfig.put("nosubdir", "true");
        final SR sr = SR.create(conn, host, deviceConfig, new Long(0), name, uri.getHost() + uri.getPath(), SRType.NFS.toString(), "user", shared, smConfig);
        if (!checkSR(conn, sr)) {
            throw new Exception("no attached PBD");
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(logX(sr, "Created a SR; UUID is " + sr.getUuid(conn) + " device config is " + deviceConfig));
        }
        sr.scan(conn);
        return sr;
    } catch (final XenAPIException e) {
        final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.toString();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    } catch (final Exception e) {
        final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.getMessage();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    }
}
Also used : HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) 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) SR(com.xensource.xenapi.SR)

Example 33 with Host

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

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 34 with Host

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

the class XenServerStorageProcessor method getNfsSR.

protected SR getNfsSR(final Connection conn, final StorageFilerTO pool) {
    final Map<String, String> deviceConfig = new HashMap<String, String>();
    try {
        final String server = pool.getHost();
        String serverpath = pool.getPath();
        serverpath = serverpath.replace("//", "/");
        final Set<SR> srs = SR.getAll(conn);
        for (final SR sr : srs) {
            if (!SRType.NFS.equals(sr.getType(conn))) {
                continue;
            }
            final Set<PBD> pbds = sr.getPBDs(conn);
            if (pbds.isEmpty()) {
                continue;
            }
            final PBD pbd = pbds.iterator().next();
            final Map<String, String> dc = pbd.getDeviceConfig(conn);
            if (dc == null) {
                continue;
            }
            if (dc.get("server") == null) {
                continue;
            }
            if (dc.get("serverpath") == null) {
                continue;
            }
            if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) {
                throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:" + dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + hypervisorResource.getHost().getUuid());
            }
        }
        deviceConfig.put("server", server);
        deviceConfig.put("serverpath", serverpath);
        final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
        final Map<String, String> smConfig = new HashMap<String, String>();
        smConfig.put("nosubdir", "true");
        final SR sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), Long.toString(pool.getId()), SRType.NFS.toString(), "user", true, smConfig);
        sr.scan(conn);
        return sr;
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
    }
}
Also used : PBD(com.xensource.xenapi.PBD) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 35 with Host

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

the class CitrixResourceBase method getLocalLVMSR.

protected SR getLocalLVMSR(final Connection conn) {
    try {
        final Map<SR, SR.Record> map = SR.getAllRecords(conn);
        if (map != null && !map.isEmpty()) {
            for (final Map.Entry<SR, SR.Record> entry : map.entrySet()) {
                final SR.Record srRec = entry.getValue();
                if (SRType.LVM.equals(srRec.type)) {
                    final Set<PBD> pbds = srRec.PBDs;
                    if (pbds == null) {
                        continue;
                    }
                    for (final PBD pbd : pbds) {
                        final Host host = pbd.getHost(conn);
                        if (!isRefNull(host) && host.getUuid(conn).equals(_host.getUuid())) {
                            if (!pbd.getCurrentlyAttached(conn)) {
                                pbd.plug(conn);
                            }
                            final SR sr = entry.getKey();
                            sr.scan(conn);
                            return sr;
                        }
                    }
                }
            }
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to get local LVMSR in host:" + _host.getUuid() + e.toString();
        s_logger.warn(msg);
    } catch (final XmlRpcException e) {
        final String msg = "Unable to get local LVMSR in host:" + _host.getUuid() + e.getCause();
        s_logger.warn(msg);
    }
    return null;
}
Also used : PBD(com.xensource.xenapi.PBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) Map(java.util.Map) HashMap(java.util.HashMap) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Aggregations

Host (com.xensource.xenapi.Host)47 XenAPIException (com.xensource.xenapi.Types.XenAPIException)35 XmlRpcException (org.apache.xmlrpc.XmlRpcException)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 HashMap (java.util.HashMap)24 Connection (com.xensource.xenapi.Connection)17 SR (com.xensource.xenapi.SR)17 IOException (java.io.IOException)15 ConfigurationException (javax.naming.ConfigurationException)14 InternalErrorException (com.cloud.exception.InternalErrorException)13 MalformedURLException (java.net.MalformedURLException)13 URISyntaxException (java.net.URISyntaxException)12 TimeoutException (java.util.concurrent.TimeoutException)12 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)12 SAXException (org.xml.sax.SAXException)12 VM (com.xensource.xenapi.VM)11 PBD (com.xensource.xenapi.PBD)10 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)7 Map (java.util.Map)7 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)6