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:
- Uses the connection to the Storage Policy Server to retrieve a reference to the Profile Manager.
- Calls thePbmQueryProfilemethod to obtain the list of storage profile identifiers.
- Calls thePbmRetrieveContentmethod to obtain the list of storage profiles.
- Finds the profile that matches the specified profile name.
- Creates aVirtualMachineDefinedProfileSpecand assigns the identifier from the named profile to theVirtualMachineDefinedProfileSpec. You use theVirtualMachineDefinedProfileSpecwhen 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); }