Search in sources :

Example 16 with Host

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

the class NotAValidCommand method testScaleVmCommand.

@Test
public void testScaleVmCommand() {
    final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
    final VirtualMachineTO machineTO = Mockito.mock(VirtualMachineTO.class);
    final Connection conn = Mockito.mock(Connection.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final Host host = Mockito.mock(Host.class);
    final ScaleVmCommand scaleVm = new ScaleVmCommand(machineTO);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.getHost()).thenReturn(xsHost);
    when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
    try {
        when(citrixResourceBase.isDmcEnabled(conn, host)).thenReturn(true);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(scaleVm, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : 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) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.xensource.xenapi.Host) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 17 with Host

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

the class XenServer620SP1Resource method getGPUGroupDetails.

@Override
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final Connection conn) throws XenAPIException, XmlRpcException {
    final HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
    final Host host = Host.getByUuid(conn, _host.getUuid());
    final Set<PGPU> pgpus = host.getPGPUs(conn);
    final Iterator<PGPU> iter = pgpus.iterator();
    while (iter.hasNext()) {
        final PGPU pgpu = iter.next();
        final GPUGroup gpuGroup = pgpu.getGPUGroup(conn);
        final Set<VGPUType> enabledVGPUTypes = gpuGroup.getEnabledVGPUTypes(conn);
        final String groupName = gpuGroup.getNameLabel(conn);
        HashMap<String, VgpuTypesInfo> gpuCapacity = new HashMap<String, VgpuTypesInfo>();
        if (groupDetails.get(groupName) != null) {
            gpuCapacity = groupDetails.get(groupName);
        }
        // Get remaining capacity of all the enabled VGPU in a PGPU
        if (enabledVGPUTypes != null) {
            final Iterator<VGPUType> it = enabledVGPUTypes.iterator();
            while (it.hasNext()) {
                final VGPUType type = it.next();
                final Record record = type.getRecord(conn);
                Long remainingCapacity = pgpu.getRemainingCapacity(conn, type);
                Long maxCapacity = pgpu.getSupportedVGPUMaxCapacities(conn).get(type);
                VgpuTypesInfo entry;
                if ((entry = gpuCapacity.get(record.modelName)) != null) {
                    remainingCapacity += entry.getRemainingCapacity();
                    maxCapacity += entry.getMaxCapacity();
                    entry.setRemainingCapacity(remainingCapacity);
                    entry.setMaxVmCapacity(maxCapacity);
                    gpuCapacity.put(record.modelName, entry);
                } else {
                    final VgpuTypesInfo vgpuTypeRecord = new VgpuTypesInfo(null, record.modelName, record.framebufferSize, record.maxHeads, record.maxResolutionX, record.maxResolutionY, maxCapacity, remainingCapacity, maxCapacity);
                    gpuCapacity.put(record.modelName, vgpuTypeRecord);
                }
            }
        }
        groupDetails.put(groupName, gpuCapacity);
    }
    return groupDetails;
}
Also used : HashMap(java.util.HashMap) VGPUType(com.xensource.xenapi.VGPUType) Host(com.xensource.xenapi.Host) PGPU(com.xensource.xenapi.PGPU) Record(com.xensource.xenapi.VGPUType.Record) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo) GPUGroup(com.xensource.xenapi.GPUGroup)

Example 18 with Host

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

the class XenServerConnectionPool method connect.

public Connection connect(String hostUuid, String poolUuid, String ipAddress, String username, Queue<String> password, int wait) {
    XenServerConnection mConn = null;
    if (hostUuid == null || poolUuid == null || ipAddress == null || username == null || password == null) {
        String msg = "Connect some parameter are null hostUuid:" + hostUuid + " ,poolUuid:" + poolUuid + " ,ipAddress:" + ipAddress;
        s_logger.debug(msg);
        throw new CloudRuntimeException(msg);
    }
    synchronized (poolUuid.intern()) {
        mConn = getConnect(poolUuid);
        if (mConn != null) {
            try {
                Host host = Host.getByUuid(mConn, hostUuid);
                if (!host.getEnabled(mConn)) {
                    String msg = "Cannot connect this host " + ipAddress + " due to the host is not enabled";
                    s_logger.debug(msg);
                    if (mConn.getIp().equalsIgnoreCase(ipAddress)) {
                        removeConnect(poolUuid);
                        mConn = null;
                    }
                    throw new CloudRuntimeException(msg);
                }
                return mConn;
            } catch (CloudRuntimeException e) {
                throw e;
            } catch (Exception e) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("connect through IP(" + mConn.getIp() + " for pool(" + poolUuid + ") is broken due to " + e.toString());
                }
                removeConnect(poolUuid);
                mConn = null;
            }
        }
        if (mConn == null) {
            try {
                Connection conn = new Connection(getURL(ipAddress), 5, _connWait);
                Session sess = loginWithPassword(conn, username, password, APIVersion.latest().toString());
                Host host = sess.getThisHost(conn);
                Boolean hostenabled = host.getEnabled(conn);
                if (sess != null) {
                    try {
                        Session.logout(conn);
                    } catch (Exception e) {
                        s_logger.debug("Caught exception during logout", e);
                    }
                    conn.dispose();
                }
                if (!hostenabled) {
                    String msg = "Unable to create master connection, due to master Host " + ipAddress + " is not enabled";
                    s_logger.debug(msg);
                    throw new CloudRuntimeException(msg);
                }
                mConn = new XenServerConnection(getURL(ipAddress), ipAddress, username, password, _retries, _interval, wait, _connWait);
                loginWithPassword(mConn, username, password, APIVersion.latest().toString());
            } catch (Types.HostIsSlave e) {
                String maddress = e.masterIPAddress;
                mConn = new XenServerConnection(getURL(maddress), maddress, username, password, _retries, _interval, wait, _connWait);
                try {
                    Session session = loginWithPassword(mConn, username, password, APIVersion.latest().toString());
                    Host host = session.getThisHost(mConn);
                    if (!host.getEnabled(mConn)) {
                        String msg = "Unable to create master connection, due to master Host " + maddress + " is not enabled";
                        s_logger.debug(msg);
                        throw new CloudRuntimeException(msg);
                    }
                } catch (Exception e1) {
                    String msg = "Unable to create master connection to host(" + maddress + ") , due to " + e1.toString();
                    s_logger.debug(msg);
                    throw new CloudRuntimeException(msg, e1);
                }
            } catch (CloudRuntimeException e) {
                throw e;
            } catch (Exception e) {
                String msg = "Unable to create master connection to host(" + ipAddress + ") , due to " + e.toString();
                s_logger.debug(msg);
                throw new CloudRuntimeException(msg, e);
            }
            addConnect(poolUuid, mConn);
        }
    }
    return mConn;
}
Also used : Types(com.xensource.xenapi.Types) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) Session(com.xensource.xenapi.Session) SSLSession(javax.net.ssl.SSLSession)

Example 19 with Host

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

the class CitrixResourceBase method setupHeartbeatSr.

public String setupHeartbeatSr(final Connection conn, final SR sr, final boolean force) throws XenAPIException, XmlRpcException {
    final SR.Record srRec = sr.getRecord(conn);
    final String srUuid = srRec.uuid;
    if (!srRec.shared || !SRType.LVMOHBA.equals(srRec.type) && !SRType.LVMOISCSI.equals(srRec.type) && !SRType.NFS.equals(srRec.type)) {
        return srUuid;
    }
    String result = null;
    final Host host = Host.getByUuid(conn, _host.getUuid());
    final Set<String> tags = host.getTags(conn);
    if (force || !tags.contains("cloud-heartbeat-" + srUuid)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Setting up the heartbeat sr for host " + _host.getIp() + " and sr " + srUuid);
        }
        final Set<PBD> pbds = sr.getPBDs(conn);
        for (final PBD pbd : pbds) {
            final PBD.Record pbdr = pbd.getRecord(conn);
            if (!pbdr.currentlyAttached && pbdr.host.getUuid(conn).equals(_host.getUuid())) {
                pbd.plug(conn);
                break;
            }
        }
        result = callHostPluginThroughMaster(conn, "vmopspremium", "setup_heartbeat_sr", "host", _host.getUuid(), "sr", srUuid);
        if (result == null || !result.split("#")[1].equals("0")) {
            throw new CloudRuntimeException("Unable to setup heartbeat sr on SR " + srUuid + " due to " + result);
        }
        if (!tags.contains("cloud-heartbeat-" + srUuid)) {
            tags.add("cloud-heartbeat-" + srUuid);
            host.setTags(conn, tags);
        }
    }
    result = callHostPluginPremium(conn, "setup_heartbeat_file", "host", _host.getUuid(), "sr", srUuid, "add", "true");
    if (result == null || !result.split("#")[1].equals("0")) {
        throw new CloudRuntimeException("Unable to setup heartbeat file entry on SR " + srUuid + " due to " + result);
    }
    return srUuid;
}
Also used : PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Host(com.xensource.xenapi.Host) SR(com.xensource.xenapi.SR)

Example 20 with Host

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

the class XenServer620Resource method hostHasHotFix.

protected boolean hostHasHotFix(final Connection conn, final String hotFixUuid) {
    try {
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final Host.Record re = host.getRecord(conn);
        final Set<HostPatch> patches = re.patches;
        final PoolPatch poolPatch = PoolPatch.getByUuid(conn, hotFixUuid);
        for (final HostPatch patch : patches) {
            final PoolPatch pp = patch.getPoolPatch(conn);
            if (pp.equals(poolPatch) && patch.getApplied(conn)) {
                return true;
            }
        }
    } catch (final Exception e) {
        s_logger.debug("can't get patches information for hotFix: " + hotFixUuid);
    }
    return false;
}
Also used : HostPatch(com.xensource.xenapi.HostPatch) PoolPatch(com.xensource.xenapi.PoolPatch) Host(com.xensource.xenapi.Host)

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