Search in sources :

Example 16 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareResource method executeInVR.

@Override
public ExecutionResult executeInVR(String routerIP, String script, String args, Duration timeout) {
    Pair<Boolean, String> result;
    //TODO: Password should be masked, cannot output to log directly
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Run command on VR: " + routerIP + ", script: " + script + " with args: " + args);
    }
    try {
        VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        result = SshHelper.sshExecute(routerIP, DefaultDomRSshPort, "root", mgr.getSystemVMKeyFile(), null, "/opt/cloud/bin/" + script + " " + args, VRScripts.CONNECTION_TIMEOUT, VRScripts.CONNECTION_TIMEOUT, timeout);
    } catch (Exception e) {
        String msg = "Command failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg);
        result = new Pair<Boolean, String>(false, msg);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(script + " execution result: " + result.first().toString());
    }
    return new ExecutionResult(result.first(), result.second());
}
Also used : VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) ExecutionResult(com.cloud.utils.ExecutionResult) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) Pair(com.cloud.utils.Pair)

Example 17 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareCleanupMaid method gcLeftOverVMs.

public static synchronized void gcLeftOverVMs(VmwareContext context) {
    List<VmwareCleanupMaid> l = s_leftoverDummyVMs.get(context.getServerAddress());
    VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    assert (mgr != null);
    if (l != null && l.size() > 0) {
        for (VmwareCleanupMaid cleanupMaid : l) {
            try {
                VirtualMachineMO vmMo = null;
                if (cleanupMaid.getDatacenterMorValue() != null) {
                    DatacenterMO dcMo = new DatacenterMO(context, "Datacenter", cleanupMaid.getDatacenterMorValue());
                    vmMo = dcMo.findVm(cleanupMaid.getVmName());
                } else {
                    assert (cleanupMaid.getHostMorValue() != null);
                    HostMO hostMo = new HostMO(context, "HostSystem", cleanupMaid.getHostMorValue());
                    ClusterMO clusterMo = new ClusterMO(context, hostMo.getHyperHostCluster());
                    vmMo = clusterMo.findVmOnHyperHost(cleanupMaid.getVmName());
                }
                if (vmMo != null) {
                    s_logger.info("Found left over dummy VM " + cleanupMaid.getVmName() + ", destroy it");
                    vmMo.destroy();
                }
            } catch (Throwable e) {
                s_logger.warn("Unable to destroy left over dummy VM " + cleanupMaid.getVmName());
            } finally {
            // FIXME                    mgr.popCleanupCheckpoint(cleanupMaid.getCheckPoint());
            }
        }
        l.clear();
    }
}
Also used : VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 18 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareResource method getWorkerName.

@Override
@DB
public String getWorkerName(VmwareContext context, Command cmd, int workerSequence) {
    VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    String vmName = mgr.composeWorkerName();
    assert (cmd != null);
    context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    // TODO: Fix this? cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
    return vmName;
}
Also used : VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) DB(com.cloud.utils.db.DB)

Example 19 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareResource method createFileInVR.

@Override
public ExecutionResult createFileInVR(String routerIp, String filePath, String fileName, String content) {
    VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    File keyFile = mgr.getSystemVMKeyFile();
    try {
        SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes("UTF-8"), fileName, null);
    } catch (Exception e) {
        s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e);
        return new ExecutionResult(false, e.getMessage());
    }
    return new ExecutionResult(true, null);
}
Also used : VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) ExecutionResult(com.cloud.utils.ExecutionResult) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) File(java.io.File) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 20 with VmwareManager

use of com.cloud.hypervisor.vmware.manager.VmwareManager in project cloudstack by apache.

the class VmwareResource method configureVnc.

protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervisorHost hyperHost, String vmName, String vncPassword, String keyboardLayout) throws Exception {
    VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
    VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
    if (!mgr.beginExclusiveOperation(600))
        throw new Exception("Unable to begin exclusive operation, lock time out");
    try {
        int maxVncPorts = 64;
        int vncPort = 0;
        Random random = new Random();
        HostMO vmOwnerHost = vmMo.getRunningHost();
        ManagedObjectReference morParent = vmOwnerHost.getParentMor();
        HashMap<String, Integer> portInfo;
        if (morParent.getType().equalsIgnoreCase("ClusterComputeResource")) {
            ClusterMO clusterMo = new ClusterMO(vmOwnerHost.getContext(), morParent);
            portInfo = clusterMo.getVmVncPortsOnCluster();
        } else {
            portInfo = vmOwnerHost.getVmVncPortsOnHost();
        }
        // allocate first at 5900 - 5964 range
        Collection<Integer> existingPorts = portInfo.values();
        int val = random.nextInt(maxVncPorts);
        int startVal = val;
        do {
            if (!existingPorts.contains(5900 + val)) {
                vncPort = 5900 + val;
                break;
            }
            val = (++val) % maxVncPorts;
        } while (val != startVal);
        if (vncPort == 0) {
            s_logger.info("we've run out of range for ports between 5900-5964 for the cluster, we will try port range at 59000-60000");
            Pair<Integer, Integer> additionalRange = mgr.getAddiionalVncPortRange();
            maxVncPorts = additionalRange.second();
            val = random.nextInt(maxVncPorts);
            startVal = val;
            do {
                if (!existingPorts.contains(additionalRange.first() + val)) {
                    vncPort = additionalRange.first() + val;
                    break;
                }
                val = (++val) % maxVncPorts;
            } while (val != startVal);
        }
        if (vncPort == 0) {
            throw new Exception("Unable to find an available VNC port on host");
        }
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Configure VNC port for VM " + vmName + ", port: " + vncPort + ", host: " + vmOwnerHost.getHyperHostName());
        }
        return VmwareHelper.composeVncOptions(optionsToMerge, true, vncPassword, vncPort, keyboardLayout);
    } finally {
        try {
            mgr.endExclusiveOperation();
        } catch (Throwable e) {
            assert (false);
            s_logger.error("Unexpected exception ", e);
        }
    }
}
Also used : VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) Random(java.util.Random) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)24 RemoteException (java.rmi.RemoteException)21 CloudException (com.cloud.exception.CloudException)14 InternalErrorException (com.cloud.exception.InternalErrorException)14 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 IOException (java.io.IOException)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 ConnectException (java.net.ConnectException)14 ConfigurationException (javax.naming.ConfigurationException)14 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)9 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)8 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)7 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)6 Pair (com.cloud.utils.Pair)4 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)3 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)3 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)2 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)2 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)2