Create a VSAN Requirements Profile
The following example demonstrates how to create a storage requirements profile based on vSphere VSAN storage capabilities. The example creates a requirement profile for VSAN stripe width.
The following figure shows the data objects used for a profile specification.
Storage Profile Specification
The following example is based on the Storage Policy SDK sample file CreateVSANProfile.java.This example is divided into two code fragments:
Create an Individual Storage Requirement – The code fragment is a function that creates a single storage capability instance for a subprofile (rule).
Create a Storage Profile – The code fragment builds a profile specification and creates the profile.
Create an Individual Storage Requirement
The following example builds a property instance for a capability. The property instance represents a single storage requirement. The code performs the following steps:
1
2
3
4
Example:  
PbmCapabilityInstance buildCapability(String capabilityName, Object value,
List<PbmCapabilityMetadataPerCategory> metadata)
throws InvalidArgumentFaultMsg {
 
// Retrieve the metadata for the capability (stripeWidth)
PbmCapabilityMetadata capabilityMeta = PbmUtil.getCapabilityMeta(capabilityName, metadata);
if (capabilityMeta == null)
throw new InvalidArgumentFaultMsg("Specified Capability does not exist", null);
 
// Create a New Property Instance based on the Stripe Width Capability
PbmCapabilityPropertyInstance prop = new PbmCapabilityPropertyInstance();
prop.setId(capabilityName);
prop.setValue(value);
 
// Associate Property Instance with a Rule (subprofile)
PbmCapabilityConstraintInstance rule = new PbmCapabilityConstraintInstance();
rule.getPropertyInstance().add(prop);
 
// Associate Rule (subprofile) with a Capability Instance
PbmCapabilityInstance capability = new PbmCapabilityInstance();
capability.setId(capabilityMeta.getId());
capability.getConstraint().add(rule);
 
return capability;
}
Create a Storage Profile
The example performs the following operations.
1
2
3
4
5
6
7
8
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 Storage Policy Server.
Example: 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());