Search in sources :

Example 11 with Host

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

the class CitrixResourceBase method getIscsiSR.

public SR getIscsiSR(final Connection conn, final String srNameLabel, final String target, String path, final String chapInitiatorUsername, final String chapInitiatorPassword, final boolean resignature, final String srType, final boolean ignoreIntroduceException) {
    synchronized (srNameLabel.intern()) {
        final Map<String, String> deviceConfig = new HashMap<String, String>();
        try {
            if (path.endsWith("/")) {
                path = path.substring(0, path.length() - 1);
            }
            final String[] tmp = path.split("/");
            if (tmp.length != 3) {
                final String msg = "Wrong iscsi path " + path + " it should be /targetIQN/LUN";
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
            final String targetiqn = tmp[1].trim();
            final String lunid = tmp[2].trim();
            String scsiid = "";
            //Throws an exception if SR already exists and is attached
            checkIfIscsiSrExisits(conn, srNameLabel, target, targetiqn, lunid);
            // We now know the SR is not attached to the XenServer. We probe the
            // LUN to see if an SR was already exists on it, if so, we just
            // attach it or else we create a brand new SR
            deviceConfig.put("target", target);
            deviceConfig.put("targetIQN", targetiqn);
            if (StringUtils.isNotBlank(chapInitiatorUsername) && StringUtils.isNotBlank(chapInitiatorPassword)) {
                deviceConfig.put("chapuser", chapInitiatorUsername);
                deviceConfig.put("chappassword", chapInitiatorPassword);
            }
            final Host host = Host.getByUuid(conn, _host.getUuid());
            final Map<String, String> smConfig = new HashMap<String, String>();
            SR sr = null;
            String pooluuid = null;
            if (SRType.LVMOISCSI.equals(srType)) {
                scsiid = probeScisiId(conn, host, deviceConfig, srType, srNameLabel, lunid, smConfig);
                deviceConfig.put("SCSIid", scsiid);
                String result = SR.probe(conn, host, deviceConfig, srType, smConfig);
                if (result.indexOf("<UUID>") != -1) {
                    pooluuid = result.substring(result.indexOf("<UUID>") + 6, result.indexOf("</UUID>")).trim();
                }
            }
            if (pooluuid == null || pooluuid.length() != 36) {
                sr = SR.create(conn, host, deviceConfig, new Long(0), srNameLabel, srNameLabel, srType, "user", true, smConfig);
            } else {
                if (resignature) {
                    // We resignature the SR for managed storage if needed. At the end of this
                    // we have an SR which is ready to be attached. For VHDoISCSI SR,
                    // we don't need to resignature
                    pooluuid = resignatureIscsiSr(conn, host, deviceConfig, srNameLabel, smConfig);
                }
                sr = introduceAndPlugIscsiSr(conn, pooluuid, srNameLabel, srType, smConfig, deviceConfig, ignoreIntroduceException);
            }
            sr.scan(conn);
            return sr;
        } catch (final XenAPIException e) {
            final String msg = "Unable to create Iscsi SR  " + deviceConfig + " due to  " + e.toString();
            s_logger.warn(msg, e);
            throw new CloudRuntimeException(msg, e);
        } catch (final Exception e) {
            final String msg = "Unable to create Iscsi SR  " + deviceConfig + " 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 12 with Host

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

the class CitrixResourceBase method cleanupTemplateSR.

public void cleanupTemplateSR(final Connection conn) {
    Set<PBD> pbds = null;
    try {
        final Host host = Host.getByUuid(conn, _host.getUuid());
        pbds = host.getPBDs(conn);
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to get the SRs " + e.toString(), e);
        throw new CloudRuntimeException("Unable to get SRs " + e.toString(), e);
    } catch (final Exception e) {
        throw new CloudRuntimeException("Unable to get SRs " + e.getMessage(), e);
    }
    for (final PBD pbd : pbds) {
        SR sr = null;
        SR.Record srRec = null;
        try {
            sr = pbd.getSR(conn);
            srRec = sr.getRecord(conn);
        } catch (final Exception e) {
            s_logger.warn("pbd.getSR get Exception due to ", e);
            continue;
        }
        final String type = srRec.type;
        if (srRec.shared) {
            continue;
        }
        if (SRType.NFS.equals(type) || SRType.ISO.equals(type) && srRec.nameDescription.contains("template")) {
            try {
                pbd.unplug(conn);
                pbd.destroy(conn);
                sr.forget(conn);
            } catch (final Exception e) {
                s_logger.warn("forget SR catch Exception due to ", e);
            }
        }
    }
}
Also used : PBD(com.xensource.xenapi.PBD) 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 13 with Host

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

the class CitrixResourceBase method getLocalEXTSR.

protected SR getLocalEXTSR(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.FILE.equals(srRec.type) || SRType.EXT.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 EXTSR in host:" + _host.getUuid() + e.toString();
        s_logger.warn(msg);
    } catch (final XmlRpcException e) {
        final String msg = "Unable to get local EXTSR 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)

Example 14 with Host

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

the class CitrixResourceBase method getControlDomain.

protected Pair<VM, VM.Record> getControlDomain(final Connection conn) throws XenAPIException, XmlRpcException {
    final Host host = Host.getByUuid(conn, _host.getUuid());
    Set<VM> vms = null;
    vms = host.getResidentVMs(conn);
    for (final VM vm : vms) {
        if (vm.getIsControlDomain(conn)) {
            return new Pair<VM, VM.Record>(vm, vm.getRecord(conn));
        }
    }
    throw new CloudRuntimeException("Com'on no control domain?  What the crap?!#@!##$@");
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VM(com.xensource.xenapi.VM) Host(com.xensource.xenapi.Host) Pair(com.cloud.utils.Pair)

Example 15 with Host

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

the class NotAValidCommand method testClusterVMMetaDataSyncCommand.

@Test
public void testClusterVMMetaDataSyncCommand() {
    final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
    final Connection conn = Mockito.mock(Connection.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final Pool pool = PowerMockito.mock(Pool.class);
    final Pool.Record poolr = Mockito.mock(Pool.Record.class);
    final Host.Record hostr = Mockito.mock(Host.Record.class);
    final Host master = Mockito.mock(Host.class);
    final ClusterVMMetaDataSyncCommand vmDataSync = new ClusterVMMetaDataSyncCommand(10, 1l);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.getHost()).thenReturn(xsHost);
        when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
        PowerMockito.mockStatic(Pool.Record.class);
        when(pool.getRecord(conn)).thenReturn(poolr);
        poolr.master = master;
        when(poolr.master.getRecord(conn)).thenReturn(hostr);
        hostr.uuid = uuid;
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(vmDataSync, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.xensource.xenapi.Host) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Pool(com.xensource.xenapi.Pool) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

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