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());
}
}
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();
}
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));
}
}
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);
}
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));
}
Aggregations