Create a Tag-Based Storage Profile
The following figure shows a storage profile specification and the associated tag metadata.
The subprofile capability instance identifier (PbmCapabilityInstance.id) is set to the storage policy tag metadata identifier (PbmCapabilityMetadata.id).
The capability property instance (PbmCapabilityPropertyInstance) specifies both an identifier and a value. Both properties are set to the tag metadata id and allowedValue properties.
Tag-Based Storage Profile Specification
The following example demonstrates how to create a storage requirements profile based on a storage policy tag. The example is divided into two sections:
Retrieve Tag Metadata
The following example shows a code fragment that retrieves metadata for a tag category. Given the list of metadata obtained from the Storage Policy Server, the function traverses the list and returns the metadata associated with the specified category. This function is defined in the PbmUtil package in the Storage Policy SDK.
Example: getTagCategoryMeta (PbmUtil Package)
 
public static PbmCapabilityMetadata getTagCategoryMeta(
String tagCategoryName, List<PbmCapabilityMetadataPerCategory> schema) {
for (PbmCapabilityMetadataPerCategory cat : schema)
if (cat.getSubCategory().equals("tag"))
for (PbmCapabilityMetadata cap : cat.getCapabilityMetadata())
if (cap.getId().getId().equals(tagCategoryName))
return cap;
return null;
}
 
Create a Storage Profile
The example performs the following operations.
1
2
3
4
5
6
7
The following example is based on the Storage Policy SDK sample file CreateProfile.java.
Example: Tag-Based Storage Profile Creation
 
// Get PBM Profile Manager and PBM Capability Metadata
spbmsc = connection.getPbmServiceContent();
ManagedObjectReference profileMgr = spbmsc.getProfileManager();
 
List<PbmCapabilityMetadataPerCategory> metadata =
connection.getPbmPort().pbmFetchCapabilityMetadata(
profileMgr,PbmUtil.getStorageResourceType(), null);
 
// Step 1: Create Property Instance with tags from the specified Category
PbmCapabilityMetadata tagCategoryInfo = PbmUtil.getTagCategoryMeta(tagCategoryName, metadata);
 
// Fetch Property Metadata of the Tag Category
List<PbmCapabilityPropertyMetadata> propMetaList = tagCategoryInfo.getPropertyMetadata();
PbmCapabilityPropertyMetadata propMeta = propMetaList.get(0);
 
// Create a New Property Instance based on the Tag Category ID
PbmCapabilityPropertyInstance prop = new PbmCapabilityPropertyInstance();
prop.setId(propMeta.getId());
 
// Fetch Allowed Tag Values Metadata; cast the xsd:any property (allowedValue) to a discrete set
PbmCapabilityDiscreteSet tagSetMeta = (PbmCapabilityDiscreteSet) propMeta.getAllowedValue();
// Create a New Discrete Set for holding Tag Values
PbmCapabilityDiscreteSet tagSet = new PbmCapabilityDiscreteSet();
for (Object obj : tagSetMeta.getValues()) {
tagSet.getValues().add(((PbmCapabilityDescription) obj).getValue());
}
prop.setValue(tagSet);
 
// Step 2: Associate Property Instance with a Rule
PbmCapabilityConstraintInstance rule = new PbmCapabilityConstraintInstance();
rule.getPropertyInstance().add(prop);
 
// Step 3: Associate Rule with a Capability Instance
PbmCapabilityInstance capability = new PbmCapabilityInstance();
capability.setId(tagCategoryInfo.getId());
capability.getConstraint().add(rule);
 
// Step 4: Add Rule to a RuleSet
PbmCapabilitySubProfile ruleSet = new PbmCapabilitySubProfile();
ruleSet.getCapability().add(capability);
 
// Step 5: Add Rule-Set to Capability Constraints
PbmCapabilitySubProfileConstraints constraints = new PbmCapabilitySubProfileConstraints();
ruleSet.setName("Rule-Set " + (constraints.getSubProfiles().size() + 1));
constraints.getSubProfiles().add(ruleSet);
 
// Step 6: Build Capability-Based Profile
PbmCapabilityProfileCreateSpec spec = new PbmCapabilityProfileCreateSpec();
spec.setName(profileName);
spec.setDescription("Tag Based Storage Profile Created by SDK Samples. Rule based on tags from Category "
+ tagCategoryName);
spec.setResourceType(PbmUtil.getStorageResourceType());
spec.setConstraints(constraints);
 
// Step 7: Create Storage Profile
PbmProfileId profile = connection.getPbmPort().pbmCreate(profileMgr, spec);