use of com.vmware.pbm.PbmProfileId in project photon-model by vmware.
the class ClientUtils method getDatastoreFromStoragePolicy.
/**
* Get one of the datastore compatible with storage policy
*/
public static ManagedObjectReference getDatastoreFromStoragePolicy(final Connection connection, List<VirtualMachineDefinedProfileSpec> pbmSpec) throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
if (pbmSpec != null) {
for (VirtualMachineDefinedProfileSpec sp : pbmSpec) {
try {
PbmProfileId pbmProfileId = new PbmProfileId();
pbmProfileId.setUniqueId(sp.getProfileId());
List<String> datastoreNames = ClientUtils.getDatastores(connection, pbmProfileId);
String dsName = datastoreNames.stream().findFirst().orElse(null);
if (dsName != null) {
ManagedObjectReference dsFromSp = new ManagedObjectReference();
dsFromSp.setType(VimNames.TYPE_DATASTORE);
dsFromSp.setValue(dsName);
return dsFromSp;
}
} catch (Exception runtimeFaultFaultMsg) {
// Just ignore. No need to log, as there are alternative paths.
}
}
}
return null;
}
use of com.vmware.pbm.PbmProfileId in project photon-model by vmware.
the class EnumerationClient method retrieveStoragePolicies.
/**
* Retrieve the list of storage profiles from the server.
*/
public List<PbmProfile> retrieveStoragePolicies() throws com.vmware.pbm.RuntimeFaultFaultMsg, InvalidArgumentFaultMsg {
// 1 Get PBM Profile Manager
ManagedObjectReference profileMgr = this.connection.getPbmServiceInstanceContent().getProfileManager();
// 2 Retrieve the list of profile identifiers.
PbmProfileResourceType pbmProfileResourceType = new PbmProfileResourceType();
pbmProfileResourceType.setResourceType(PbmProfileResourceTypeEnum.STORAGE.value());
List<PbmProfileId> profileIds = this.connection.getPbmPort().pbmQueryProfile(profileMgr, pbmProfileResourceType, null);
// 3 Retrieve the list of storage profiles.
if (profileIds != null && !profileIds.isEmpty()) {
return this.connection.getPbmPort().pbmRetrieveContent(profileMgr, profileIds);
}
return new ArrayList<>();
}
Aggregations