Search in sources :

Example 26 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(ReadyCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource ReadyCommand: " + _gson.toJson(cmd));
    }
    try {
        VmwareContext context = getServiceContext();
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        if (hyperHost.isHyperHostConnected()) {
            return new ReadyAnswer(cmd);
        } else {
            return new ReadyAnswer(cmd, "Host is not in connect state");
        }
    } catch (Exception e) {
        s_logger.error("Unexpected exception: ", e);
        return new ReadyAnswer(cmd, VmwareHelper.getExceptionMessage(e));
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) 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 27 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext 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 28 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext 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 29 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext 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 30 with VmwareContext

use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.

the class VmwareResource method execute.

/**
     * UnregisterNicCommand is used to remove a portgroup created for this
     * specific nic. The portgroup will have the name set to the UUID of the
     * nic. Introduced to cleanup the portgroups created for each nic that is
     * plugged into an lswitch (Nicira NVP plugin)
     *
     * @param cmd
     * @return
     */
protected Answer execute(UnregisterNicCommand cmd) {
    s_logger.info("Executing resource UnregisterNicCommand: " + _gson.toJson(cmd));
    if (_guestTrafficInfo == null) {
        return new Answer(cmd, false, "No Guest Traffic Info found, unable to determine where to clean up");
    }
    try {
        if (_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) {
            // on the standard switches
            return new Answer(cmd, true, "Nothing to do");
        }
        s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + _guestTrafficInfo.getVirtualSwitchName());
        VmwareContext context = getServiceContext();
        VmwareHypervisorHost host = getHyperHost(context);
        ManagedObjectReference clusterMO = host.getHyperHostCluster();
        // Get a list of all the hosts in this cluster
        @SuppressWarnings("unchecked") List<ManagedObjectReference> hosts = (List<ManagedObjectReference>) context.getVimClient().getDynamicProperty(clusterMO, "host");
        if (hosts == null) {
            return new Answer(cmd, false, "No hosts in cluster, which is pretty weird");
        }
        for (ManagedObjectReference hostMOR : hosts) {
            HostMO hostMo = new HostMO(context, hostMOR);
            hostMo.deletePortGroup(cmd.getNicUuid().toString());
            s_logger.debug("Removed portgroup " + cmd.getNicUuid() + " from host " + hostMo.getHostName());
        }
        return new Answer(cmd, true, "Unregistered resources for NIC " + cmd.getNicUuid());
    } catch (Exception e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "UnregisterVMCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg);
        return new Answer(cmd, false, msg);
    }
}
Also used : ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) ArrayList(java.util.ArrayList) List(java.util.List) 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) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)76 RemoteException (java.rmi.RemoteException)58 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)47 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)45 UnsupportedEncodingException (java.io.UnsupportedEncodingException)35 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)32 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)28 IOException (java.io.IOException)26 CloudException (com.cloud.exception.CloudException)25 ConfigurationException (javax.naming.ConfigurationException)25 InternalErrorException (com.cloud.exception.InternalErrorException)23 ConnectException (java.net.ConnectException)23 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)16 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)14 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)13 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)13 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)12 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)12 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)11 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)10