Search in sources :

Example 6 with VmwareManager

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

the class VmwareResource method execute.

protected Answer execute(GetVncPortCommand cmd) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Executing resource GetVncPortCommand: " + _gson.toJson(cmd));
    }
    try {
        VmwareContext context = getServiceContext();
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        assert (hyperHost instanceof HostMO);
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getName());
        if (vmMo == null) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Unable to find the owner VM for GetVncPortCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter");
            }
            vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getName());
            if (vmMo == null) {
                throw new Exception("Unable to find VM in vSphere, vm: " + cmd.getName());
            }
        }
        Pair<String, Integer> portInfo = vmMo.getVncPort(mgr.getManagementPortGroupByHost((HostMO) hyperHost));
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Found vnc port info. vm: " + cmd.getName() + " host: " + portInfo.first() + ", vnc port: " + portInfo.second());
        }
        return new GetVncPortAnswer(cmd, portInfo.first(), portInfo.second());
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "GetVncPortCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        return new GetVncPortAnswer(cmd, msg);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) RemoteException(java.rmi.RemoteException) 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 7 with VmwareManager

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

the class VmwareResource method execute.

protected Answer execute(CreateVolumeFromSnapshotCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource CreateVolumeFromSnapshotCommand: " + _gson.toJson(cmd));
    }
    String details = null;
    boolean success = false;
    String newVolumeName = UUID.randomUUID().toString();
    try {
        VmwareContext context = getServiceContext();
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        return mgr.getStorageManager().execute(this, cmd);
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        details = "CreateVolumeFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(details, e);
    }
    return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) RemoteException(java.rmi.RemoteException) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Example 8 with VmwareManager

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

the class VmwareResource method execute.

protected Answer execute(DeleteVMSnapshotCommand cmd) {
    try {
        VmwareContext context = getServiceContext();
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        return mgr.getStorageManager().execute(this, cmd);
    } catch (Exception e) {
        e.printStackTrace();
        return new DeleteVMSnapshotAnswer(cmd, false, "");
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) 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 9 with VmwareManager

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

the class VmwareResource method execute.

protected Answer execute(CreateVMSnapshotCommand cmd) {
    try {
        VmwareContext context = getServiceContext();
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        return mgr.getStorageManager().execute(this, cmd);
    } catch (Exception e) {
        e.printStackTrace();
        return new CreateVMSnapshotAnswer(cmd, false, "");
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) 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 10 with VmwareManager

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

the class VmwareResource method fillHostNetworkInfo.

private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        assert (hyperHost instanceof HostMO);
        VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        VmwareHypervisorHostNetworkSummary summary = hyperHost.getHyperHostNetworkSummary(mgr.getManagementPortGroupByHost((HostMO) hyperHost));
        if (summary == null) {
            throw new Exception("No ESX(i) host found");
        }
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Startup report on host network info. " + _gson.toJson(summary));
        }
        cmd.setPrivateIpAddress(summary.getHostIp());
        cmd.setPrivateNetmask(summary.getHostNetmask());
        cmd.setPrivateMacAddress(summary.getHostMacAddress());
        cmd.setStorageIpAddress(summary.getHostIp());
        cmd.setStorageNetmask(summary.getHostNetmask());
        cmd.setStorageMacAddress(summary.getHostMacAddress());
    } catch (Throwable e) {
        String msg = "querying host network info failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        throw new CloudRuntimeException(msg);
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VmwareHypervisorHostNetworkSummary(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) 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)

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