Retrieve an Existing Storage Profile from the Server

You can use a script to retrieve an existing storage profile from the storage policy server.
The following code fragment shows the example function
getPbmProfileSpec
that uses the
PbmQueryProfile
and
PbmRetrieveContent
methods to retrieve storage profiles. In the context of the Storage Policy SDK example
VMCreate.java
, the function returns a
VirtualMachineDefinedProfileSpec
to be used to configure storage for a virtual machine.
The function performs the following operations:
  1. Uses the connection to the Storage Policy Server to retrieve a reference to the Profile Manager.
  2. Calls the
    PbmQueryProfile
    method to obtain the list of storage profile identifiers.
  3. Calls the
    PbmRetrieveContent
    method to obtain the list of storage profiles.
  4. Finds the profile that matches the specified profile name.
  5. Creates a
    VirtualMachineDefinedProfileSpec
    and assigns the identifier from the named profile to the
    VirtualMachineDefinedProfileSpec
    . You use the
    VirtualMachineDefinedProfileSpec
    when you configure the virtual machine. See Apply the Storage Profile to a Virtual Machine.
Retrieving a Storage Profile
VirtualMachineDefinedProfileSpec getPbmProfileSpec(String name) throws InvalidArgumentFaultMsg, com.vmware.pbm.RuntimeFaultFaultMsg, RuntimeFaultFaultMsg { // 1 Get PBM Profile Manager PbmServiceInstanceContent spbmsc = connection.getPbmServiceContent(); ManagedObjectReference profileMgr = spbmsc.getProfileManager(); // 2 Retrieve the list of profile identifiers. List<PbmProfileId> profileIds = connection.getPbmPort().pbmQueryProfile(profileMgr, PbmUtil.getStorageResourceType(), null); if (profileIds == null || profileIds.isEmpty()) throw new RuntimeFaultFaultMsg("No storage Profiles exist.", null); // 3 Retrieve the list of storage profiles. List<PbmProfile> pbmProfiles = connection.getPbmPort().pbmRetrieveContent(profileMgr, profileIds); // 4,5 Find the named profile and create a VirtualMachineDefinedProfileSpec // that will use the same profile identifier. for (PbmProfile pbmProfile : pbmProfiles) { if (pbmProfile.getName().equals(name)) { PbmCapabilityProfile profile = (PbmCapabilityProfile) pbmProfile; VirtualMachineDefinedProfileSpec spbmProfile = new VirtualMachineDefinedProfileSpec(); spbmProfile.setProfileId(profile.getProfileId().getUniqueId()); return spbmProfile; } } // Throw exception if none found throw new InvalidArgumentFaultMsg( "Specified storage profile name does not exist.", null); }