Search in sources :

Example 16 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(MigrateVmToPoolCommand cmd) {
    final String vmName = cmd.getVmName();
    VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
    try {
        VirtualMachineMO vmMo = getVirtualMachineMO(vmName, hyperHost);
        if (vmMo == null) {
            s_logger.info("VM " + vmName + " was not found in the cluster of host " + hyperHost.getHyperHostName() + ". Looking for the VM in datacenter.");
            ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
            DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), dcMor);
            vmMo = dcMo.findVm(vmName);
            if (vmMo == null) {
                String msg = "VM " + vmName + " does not exist in VMware datacenter";
                s_logger.error(msg);
                throw new CloudRuntimeException(msg);
            }
        }
        return migrateAndAnswer(vmMo, null, hyperHost, cmd);
    } catch (Throwable e) {
        // hopefully only CloudRuntimeException :/
        if (e instanceof Exception) {
            return new Answer(cmd, (Exception) e);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("problem", e);
        }
        s_logger.error(e.getLocalizedMessage());
        return new Answer(cmd, false, "unknown problem: " + e.getLocalizedMessage());
    }
}
Also used : SetupPersistentNetworkAnswer(com.cloud.agent.api.SetupPersistentNetworkAnswer) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) GetVmVncTicketAnswer(com.cloud.agent.api.GetVmVncTicketAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) 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) AttachIsoAnswer(com.cloud.agent.api.AttachIsoAnswer) 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) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) 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) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) 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) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) 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) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 17 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareResource method acquireVirtualMachineVncTicket.

public String acquireVirtualMachineVncTicket(String vmInternalCSName) throws Exception {
    VmwareContext context = getServiceContext();
    VmwareHypervisorHost hyperHost = getHyperHost(context);
    DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), hyperHost.getHyperHostDatacenter());
    VirtualMachineMO vmMo = dcMo.findVm(vmInternalCSName);
    return vmMo.acquireVncTicket();
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 18 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareStorageProcessor method copyVolumeFromImageCacheToPrimary.

@Override
public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
    VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
    VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        NfsTO srcStore = (NfsTO) srcVolume.getDataStore();
        DataStoreTO destStore = destVolume.getDataStore();
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
        String uuid = destStore.getUuid();
        ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, uuid);
        if (morDatastore == null) {
            URI uri = new URI(destStore.getUrl());
            morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), destStore.getUuid().replace("-", ""), true);
            if (morDatastore == null) {
                throw new Exception("Unable to mount storage pool on host. storeUrl: " + uri.getHost() + ":/" + uri.getPath());
            }
        }
        Pair<String, String> result = copyVolumeFromSecStorage(hyperHost, srcVolume.getPath(), new DatastoreMO(context, morDatastore), srcStore.getUrl(), (long) cmd.getWait() * 1000, _nfsVersion);
        deleteVolumeDirOnSecondaryStorage(result.first(), srcStore.getUrl(), _nfsVersion);
        VolumeObjectTO newVolume = new VolumeObjectTO();
        newVolume.setPath(result.second());
        return new CopyCmdAnswer(newVolume);
    } catch (Throwable t) {
        return new CopyCmdAnswer(hostService.createLogMessageException(t, cmd));
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 19 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareStorageProcessor method setUpManagedStorageCopyTemplateFromSnapshot.

private void setUpManagedStorageCopyTemplateFromSnapshot(CopyCommand cmd) throws Exception {
    VmwareContext context = hostService.getServiceContext(cmd);
    VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
    ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
    ClusterMO clusterMO = new ClusterMO(context, morCluster);
    List<Pair<ManagedObjectReference, String>> lstHosts = clusterMO.getClusterHosts();
    final Map<String, String> options = cmd.getOptions();
    final String storageHost = options.get(DiskTO.STORAGE_HOST);
    final int storagePortNumber = Integer.parseInt(options.get(DiskTO.STORAGE_PORT));
    final String iScsiName = options.get(DiskTO.IQN);
    final String snapshotPath = options.get(DiskTO.VMDK);
    final String chapInitiatorUsername = options.get(DiskTO.CHAP_INITIATOR_USERNAME);
    final String chapInitiatorSecret = options.get(DiskTO.CHAP_INITIATOR_SECRET);
    final String chapTargetUsername = options.get(DiskTO.CHAP_TARGET_USERNAME);
    final String chapTargetSecret = options.get(DiskTO.CHAP_TARGET_SECRET);
    String datastoreName = getManagedDatastoreNameFromPath(snapshotPath);
    HostDiscoveryMethod hostDiscoveryMethod = getHostDiscoveryMethod(context, storageHost, lstHosts);
    List<HostMO> hostsUsingStaticDiscovery = hostDiscoveryMethod.getHostsUsingStaticDiscovery();
    if (hostsUsingStaticDiscovery != null && hostsUsingStaticDiscovery.size() > 0) {
        final List<HostInternetScsiHbaStaticTarget> lstTargets = getTargets(storageHost, storagePortNumber, trimIqn(iScsiName), chapInitiatorUsername, chapInitiatorSecret, chapTargetUsername, chapTargetSecret);
        addRemoveInternetScsiTargetsToAllHosts(true, lstTargets, hostsUsingStaticDiscovery);
    }
    rescanAllHosts(context, lstHosts, true, true);
    Pair<ManagedObjectReference, String> firstHost = lstHosts.get(0);
    HostMO firstHostMO = new HostMO(context, firstHost.first());
    HostDatastoreSystemMO firstHostDatastoreSystemMO = firstHostMO.getHostDatastoreSystemMO();
    ManagedObjectReference morDs = firstHostDatastoreSystemMO.findDatastoreByName(datastoreName);
    DatastoreMO datastoreMO = new DatastoreMO(context, morDs);
    mountVmfsDatastore(datastoreMO, lstHosts);
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHbaStaticTarget(com.vmware.vim25.HostInternetScsiHbaStaticTarget) HostDatastoreSystemMO(com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 20 with VmwareHypervisorHost

use of com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost in project cloudstack by apache.

the class VmwareStorageProcessor method handleDatastoreAndVmdkDetach.

public void handleDatastoreAndVmdkDetach(Command cmd, String datastoreName, String iqn, String storageHost, int storagePort) throws Exception {
    VmwareContext context = hostService.getServiceContext(null);
    VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
    removeVmfsDatastore(cmd, hyperHost, datastoreName, storageHost, storagePort, trimIqn(iqn));
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)

Aggregations

VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)85 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)65 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)65 RemoteException (java.rmi.RemoteException)59 UnsupportedEncodingException (java.io.UnsupportedEncodingException)57 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)48 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)46 CloudException (com.cloud.exception.CloudException)40 InternalErrorException (com.cloud.exception.InternalErrorException)40 IOException (java.io.IOException)40 ConnectException (java.net.ConnectException)40 ConfigurationException (javax.naming.ConfigurationException)40 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)31 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)27 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)23 Pair (com.cloud.utils.Pair)15 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)12 Answer (com.cloud.agent.api.Answer)11 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)10 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)10