use of com.cloud.hypervisor.vmware.util.VmwareContext 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("-", ""));
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) {
if (t instanceof RemoteException) {
hostService.invalidateServiceContext(context);
}
String msg = "Unable to execute CopyVolumeCommand due to exception";
s_logger.error(msg, t);
return new CopyCmdAnswer("copy volume secondary to primary failed due to exception: " + VmwareHelper.getExceptionMessage(t));
}
}
use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.
the class VmwareStorageProcessor method createTemplateFromSnapshot.
@Override
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
SnapshotObjectTO snapshot = (SnapshotObjectTO) cmd.getSrcTO();
TemplateObjectTO template = (TemplateObjectTO) cmd.getDestTO();
DataStoreTO imageStore = template.getDataStore();
String details;
String uniqeName = UUID.randomUUID().toString();
VmwareContext context = hostService.getServiceContext(cmd);
try {
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("Only support create template from snapshot, when the dest store is nfs");
}
NfsTO nfsSvr = (NfsTO) imageStore;
Ternary<String, Long, Long> result = createTemplateFromSnapshot(template.getPath(), uniqeName, nfsSvr.getUrl(), snapshot.getPath(), template.getId(), (long) cmd.getWait() * 1000, _nfsVersion);
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(result.first());
newTemplate.setPhysicalSize(result.second());
newTemplate.setSize(result.third());
newTemplate.setFormat(ImageFormat.OVA);
newTemplate.setName(uniqeName);
return new CopyCmdAnswer(newTemplate);
} catch (Throwable e) {
if (e instanceof RemoteException) {
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpecpted exception ", e);
details = "create template from snapshot exception: " + VmwareHelper.getExceptionMessage(e);
return new CopyCmdAnswer(details);
}
}
use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.
the class VmwareStorageProcessor method handleDatastoreAndVmdkDetach.
public void handleDatastoreAndVmdkDetach(String datastoreName, String iqn, String storageHost, int storagePort) throws Exception {
VmwareContext context = hostService.getServiceContext(null);
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
removeVmfsDatastore(hyperHost, datastoreName, storageHost, storagePort, trimIqn(iqn));
}
use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.
the class VmwareSecondaryStorageContextFactory method getContext.
public static VmwareContext getContext(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
VmwareContext context = s_pool.getContext(vCenterAddress, vCenterUserName);
if (context == null) {
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
} else {
// Validate current context and verify if vCenter session timeout value of the context matches the timeout value set by Admin
if (!context.validate() || (context.getVimClient().getVcenterSessionTimeout() != s_vCenterSessionTimeout)) {
s_logger.info("Validation of the context faild. dispose and create a new one");
context.close();
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
}
}
if (context != null) {
context.registerStockObject("username", vCenterUserName);
context.registerStockObject("password", vCenterPassword);
}
return context;
}
use of com.cloud.hypervisor.vmware.util.VmwareContext in project cloudstack by apache.
the class VmwareContextFactory method create.
public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
assert (vCenterAddress != null);
assert (vCenterUserName != null);
assert (vCenterPassword != null);
String serviceUrl = "https://" + vCenterAddress + "/sdk/vimService";
if (s_logger.isDebugEnabled())
s_logger.debug("initialize VmwareContext. url: " + serviceUrl + ", username: " + vCenterUserName + ", password: " + StringUtils.getMaskedPasswordForDisplay(vCenterPassword));
VmwareClient vimClient = new VmwareClient(vCenterAddress + "-" + s_seq++);
vimClient.setVcenterSessionTimeout(s_vmwareMgr.getVcenterSessionTimeout());
vimClient.connect(serviceUrl, vCenterUserName, vCenterPassword);
VmwareContext context = new VmwareContext(vimClient, vCenterAddress);
context.registerStockObject(VmwareManager.CONTEXT_STOCK_NAME, s_vmwareMgr);
context.registerStockObject("serviceconsole", s_vmwareMgr.getServiceConsolePortGroupName());
context.registerStockObject("manageportgroup", s_vmwareMgr.getManagementPortGroupName());
context.registerStockObject("noderuninfo", String.format("%d-%d", s_clusterMgr.getManagementNodeId(), s_clusterMgr.getCurrentRunId()));
context.setPoolInfo(s_pool, VmwareContextPool.composePoolKey(vCenterAddress, vCenterUserName));
return context;
}
Aggregations