use of com.vmware.vim25.DatastoreSummary in project CloudStack-archive by CloudStack-extras.
the class HostMO method getLocalDatastoreOnHost.
public List<Pair<ManagedObjectReference, String>> getLocalDatastoreOnHost() throws Exception {
List<Pair<ManagedObjectReference, String>> dsList = new ArrayList<Pair<ManagedObjectReference, String>>();
ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "name", "summary" });
if (ocs != null) {
for (ObjectContent oc : ocs) {
DatastoreSummary dsSummary = (DatastoreSummary) VmwareHelper.getPropValue(oc, "summary");
if (dsSummary.getMultipleHostAccess() == false && dsSummary.isAccessible() && dsSummary.getType().equalsIgnoreCase("vmfs")) {
ManagedObjectReference morDs = oc.getObj();
String name = (String) VmwareHelper.getPropValue(oc, "name");
dsList.add(new Pair<ManagedObjectReference, String>(morDs, name));
}
}
}
return dsList;
}
use of com.vmware.vim25.DatastoreSummary in project CloudStack-archive by CloudStack-extras.
the class HostMO method getHostLocalDatastore.
public ManagedObjectReference[] getHostLocalDatastore() throws Exception {
ServiceUtil serviceUtil = _context.getServiceUtil();
ManagedObjectReference[] datastores = (ManagedObjectReference[]) serviceUtil.getDynamicProperty(_mor, "datastore");
List<ManagedObjectReference> l = new ArrayList<ManagedObjectReference>();
if (datastores != null) {
for (ManagedObjectReference mor : datastores) {
DatastoreSummary summary = (DatastoreSummary) serviceUtil.getDynamicProperty(mor, "summary");
if (summary.getType().equalsIgnoreCase("VMFS") && !summary.getMultipleHostAccess())
l.add(mor);
}
}
return l.toArray(new ManagedObjectReference[1]);
}
use of com.vmware.vim25.DatastoreSummary in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(ModifyStoragePoolCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource ModifyStoragePoolCommand: " + _gson.toJson(cmd));
}
try {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
StorageFilerTO pool = cmd.getPool();
if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS) {
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.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""));
}
assert (morDatastore != null);
DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary();
long capacity = summary.getCapacity();
long available = summary.getFreeSpace();
Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
if (cmd.getAdd() && pool.getType() == StoragePoolType.VMFS) {
answer.setLocalDatastoreName(morDatastore.getValue());
}
return answer;
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new Answer(cmd, false, msg);
}
}
use of com.vmware.vim25.DatastoreSummary in project cloudstack by apache.
the class VmwareResource method initializeLocalStorage.
private List<StartupStorageCommand> initializeLocalStorage() {
List<StartupStorageCommand> storageCmds = new ArrayList<StartupStorageCommand>();
VmwareContext context = getServiceContext();
try {
VmwareHypervisorHost hyperHost = getHyperHost(context);
if (hyperHost instanceof HostMO) {
HostMO hostMo = (HostMO) hyperHost;
List<Pair<ManagedObjectReference, String>> dsList = hostMo.getLocalDatastoreOnHost();
for (Pair<ManagedObjectReference, String> dsPair : dsList) {
DatastoreMO dsMo = new DatastoreMO(context, dsPair.first());
String poolUuid = dsMo.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID);
if (poolUuid == null || poolUuid.isEmpty()) {
poolUuid = UUID.randomUUID().toString();
dsMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, poolUuid);
}
DatastoreSummary dsSummary = dsMo.getSummary();
String address = hostMo.getHostName();
StoragePoolInfo pInfo = new StoragePoolInfo(poolUuid, address, dsMo.getMor().getValue(), "", StoragePoolType.VMFS, dsSummary.getCapacity(), dsSummary.getFreeSpace());
StartupStorageCommand cmd = new StartupStorageCommand();
cmd.setName(poolUuid);
cmd.setPoolInfo(pInfo);
// give storage host the same UUID as the local storage pool itself
cmd.setGuid(poolUuid);
cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
cmd.setDataCenter(_dcId);
cmd.setPod(_pod);
cmd.setCluster(_cluster);
s_logger.info("Add local storage startup command: " + _gson.toJson(cmd));
storageCmds.add(cmd);
}
} else {
s_logger.info("Cluster host does not support local storage, skip it");
}
} catch (Exception e) {
String msg = "initializing local storage failed due to : " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg);
invalidateServiceContext();
throw new CloudRuntimeException(msg);
}
return storageCmds;
}
use of com.vmware.vim25.DatastoreSummary in project cloudstack by apache.
the class HostMO method getHostLocalDatastore.
public ManagedObjectReference[] getHostLocalDatastore() throws Exception {
List<ManagedObjectReference> datastores = _context.getVimClient().getDynamicProperty(_mor, "datastore");
List<ManagedObjectReference> l = new ArrayList<ManagedObjectReference>();
if (datastores != null) {
for (ManagedObjectReference mor : datastores) {
DatastoreSummary summary = (DatastoreSummary) _context.getVimClient().getDynamicProperty(mor, "summary");
if (summary.getType().equalsIgnoreCase("VMFS") && !summary.isMultipleHostAccess())
l.add(mor);
}
}
return l.toArray(new ManagedObjectReference[1]);
}
Aggregations