Create a Storage Profile

The example performs the following operations.

  1. Retrieve a reference to the Storage Policy Profile Manger.
  2. Verify that there is vSAN Storage Policy support.
  3. Retrieve the vSAN storage capability metadata.
  4. Add capabilities to be used as requirements.
  5. Add the requirement capabilities to a subprofile. A subprofile corresponds to a rule set in the vSphere Web Client.
  6. Specify the subprofile as capability constraints.
  7. Build a profile specification.
  8. Create the storage profile.

When you create a storage profile, the PbmCreate method returns a profile ID (PbmProfileId). The Profile Manager maintains a list of profiles. To obtain a profile from the list, use the PbmQueryProfile and PbmRetrieveContent methods. See Retrieve an Existing Storage Profile from the Server.

vSAN Storage Profile Creation

// 1: Get PBM Profile Manager & Associated Capability Metadata
spbmsc = connection.getPbmServiceContent();
ManagedObjectReference profileMgr = spbmsc.getProfileManager();

// 2: Verify that there is vSAN Storage Policy support
Boolean vSanCapabale = false;
List<PbmCapabilityVendorResourceTypeInfo> vendorInfo =
     connection.getPbmPort().pbmFetchVendorInfo(profileMgr, null);
for (PbmCapabilityVendorResourceTypeInfo vendor : vendorInfo)
     for (PbmCapabilityVendorNamespaceInfo vnsi : vendor.getVendorNamespaceInfo())
          if (vnsi.getNamespaceInfo().getNamespace().equals("vSan")) {
              vSanCapabale = true;
              break;
          }

if (!vSanCapabale)
     throw new RuntimeFaultFaultMsg(
"Cannot create storage profile. vSAN Provider not found.", null);

// 3: Get PBM Supported Capability Metadata
List<PbmCapabilityMetadataPerCategory> metadata =
     connection.getPbmPort().pbmFetchCapabilityMetadata(profileMgr,
             PbmUtil.getStorageResourceType(), null);
// 4: Add Provider Specific Capabilities
List<PbmCapabilityInstance> capabilities = new ArrayList<PbmCapabilityInstance>();
capabilities.add(buildCapability("stripeWidth", stripeWidth, metadata));

// 5: Add Capabilities to a RuleSet (subprofile)
PbmCapabilitySubProfile ruleSet = new PbmCapabilitySubProfile();
ruleSet.getCapability().addAll(capabilities);

// 6: Add Rule-Set (subprofile) to Capability Constraints
PbmCapabilitySubProfileConstraints constraints = new PbmCapabilitySubProfileConstraints();
ruleSet.setName("Rule-Set " + (constraints.getSubProfiles().size() + 1));
constraints.getSubProfiles().add(ruleSet);

// 7: Build Capability-Based Profile
PbmCapabilityProfileCreateSpec spec = new PbmCapabilityProfileCreateSpec();
spec.setName(profileName);
spec.setDescription("Storage Profile Created by SDK Samples. Rule based on vSAN capability");
spec.setResourceType(PbmUtil.getStorageResourceType());
spec.setConstraints(constraints);

// 8: Create Storage Profile
PbmProfileId profile = connection.getPbmPort().pbmCreate(profileMgr, spec);
System.out.println("Profile " + profileName + " created with ID: " + profile.getUniqueId());