use of com.cloud.hypervisor.vmware.mo.StoragepodMO in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(ModifyStoragePoolCommand cmd) {
try {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
StorageFilerTO pool = cmd.getPool();
if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS && pool.getType() != StoragePoolType.PreSetup && pool.getType() != StoragePoolType.DatastoreCluster) {
throw new Exception("Unsupported storage pool type " + pool.getType());
}
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
if (morDatastore == null) {
morDatastore = hyperHost.mountDatastore((pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup || pool.getType() == StoragePoolType.DatastoreCluster), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""), true);
}
assert (morDatastore != null);
DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDatastore);
HypervisorHostHelper.createBaseFolder(dsMo, hyperHost, pool.getType());
long capacity = 0;
long available = 0;
List<ModifyStoragePoolAnswer> childDatastoresModifyStoragePoolAnswers = new ArrayList<>();
if (pool.getType() == StoragePoolType.DatastoreCluster) {
StoragepodMO datastoreClusterMo = new StoragepodMO(getServiceContext(), morDatastore);
StoragePodSummary dsClusterSummary = datastoreClusterMo.getDatastoreClusterSummary();
capacity = dsClusterSummary.getCapacity();
available = dsClusterSummary.getFreeSpace();
List<ManagedObjectReference> childDatastoreMors = datastoreClusterMo.getDatastoresInDatastoreCluster();
for (ManagedObjectReference childDsMor : childDatastoreMors) {
DatastoreMO childDsMo = new DatastoreMO(getServiceContext(), childDsMor);
Map<String, TemplateProp> tInfo = new HashMap<>();
DatastoreSummary summary = childDsMo.getDatastoreSummary();
;
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, summary.getCapacity(), summary.getFreeSpace(), tInfo);
StoragePoolInfo poolInfo = answer.getPoolInfo();
poolInfo.setName(summary.getName());
String datastoreClusterPath = pool.getPath();
int pathstartPosition = datastoreClusterPath.lastIndexOf('/');
String datacenterName = datastoreClusterPath.substring(0, pathstartPosition + 1);
String childPath = datacenterName + summary.getName();
poolInfo.setHostPath(childPath);
String uuid = childDsMo.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID);
if (uuid == null) {
uuid = UUID.nameUUIDFromBytes(((pool.getHost() + childPath)).getBytes()).toString();
}
poolInfo.setUuid(uuid);
poolInfo.setLocalPath(cmd.LOCAL_PATH_PREFIX + File.separator + uuid);
answer.setPoolInfo(poolInfo);
answer.setPoolType(summary.getType());
answer.setLocalDatastoreName(morDatastore.getValue());
childDsMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, uuid);
HypervisorHostHelper.createBaseFolderInDatastore(childDsMo, hyperHost.getHyperHostDatacenter());
childDatastoresModifyStoragePoolAnswers.add(answer);
}
} else {
HypervisorHostHelper.createBaseFolderInDatastore(dsMo, hyperHost.getHyperHostDatacenter());
DatastoreSummary summary = dsMo.getDatastoreSummary();
capacity = summary.getCapacity();
available = summary.getFreeSpace();
}
Map<String, TemplateProp> tInfo = new HashMap<>();
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
answer.setDatastoreClusterChildren(childDatastoresModifyStoragePoolAnswers);
if (cmd.getAdd() && (pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup) && pool.getType() != StoragePoolType.DatastoreCluster) {
answer.setPoolType(dsMo.getDatastoreType());
answer.setLocalDatastoreName(morDatastore.getValue());
}
return answer;
} catch (Throwable e) {
return new Answer(cmd, false, createLogMessageException(e, cmd));
}
}
use of com.cloud.hypervisor.vmware.mo.StoragepodMO in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(GetStorageStatsCommand cmd) {
try {
VmwareContext context = getServiceContext();
VmwareHypervisorHost hyperHost = getHyperHost(context);
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getStorageId());
if (morDs != null) {
long capacity = 0;
long free = 0;
if (cmd.getPooltype() == StoragePoolType.DatastoreCluster) {
StoragepodMO datastoreClusterMo = new StoragepodMO(getServiceContext(), morDs);
StoragePodSummary summary = datastoreClusterMo.getDatastoreClusterSummary();
capacity = summary.getCapacity();
free = summary.getFreeSpace();
} else {
DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
DatastoreSummary summary = datastoreMo.getDatastoreSummary();
capacity = summary.getCapacity();
free = summary.getFreeSpace();
}
long used = capacity - free;
s_logger.debug(String.format("Datastore summary info: [storageId: %s, ], localPath: %s, poolType: %s, capacity: %s, free: %s, used: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), toHumanReadableSize(capacity), toHumanReadableSize(free), toHumanReadableSize(used)));
if (capacity <= 0) {
s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help");
}
return new GetStorageStatsAnswer(cmd, capacity, used);
} else {
String msg = String.format("Could not find datastore for GetStorageStatsCommand: [storageId: %s, localPath: %s, poolType: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype());
s_logger.error(msg);
return new GetStorageStatsAnswer(cmd, msg);
}
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
String msg = String.format("Unable to execute GetStorageStatsCommand(storageId : [%s], localPath: [%s], poolType: [%s]) due to [%s]", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), VmwareHelper.getExceptionMessage(e));
s_logger.error(msg, e);
return new GetStorageStatsAnswer(cmd, msg);
}
}
Aggregations