Search in sources :

Example 1 with PbmProfileId

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;
}
Also used : PbmProfileId(com.vmware.pbm.PbmProfileId) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with PbmProfileId

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<>();
}
Also used : PbmProfileId(com.vmware.pbm.PbmProfileId) ArrayList(java.util.ArrayList) PbmProfileResourceType(com.vmware.pbm.PbmProfileResourceType) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

PbmProfileId (com.vmware.pbm.PbmProfileId)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 PbmProfileResourceType (com.vmware.pbm.PbmProfileResourceType)1 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 VirtualMachineDefinedProfileSpec (com.vmware.vim25.VirtualMachineDefinedProfileSpec)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1