2.5
Table Of Contents
- API Programming Guide
- Contents
- About This Book
- vCenter Chargeback Manager APIs
- Understanding the Workflow
- Using vCenter Chargeback Manager with a Billing System
- Index
VMware, Inc. 29
Chapter 3 Using vCenter Chargeback Manager with a Billing System
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}
Add a Billing Policy
Youcandefinecustombillingpoliciesasperyourrequirements.Abillingpolicydefinesanexpressionthatis
usedforidentifyingthecomputingresourcesunitstobeconsideredforcalculatingthecosts.
To add a billing policy
1 CalltheAddBillingPolicyAPIbyspecifyingthefollowingURLinyourprogram:
POST https://<ipaddress>/vCenter-CB/api/billingPolicy
2IntherequestXML,providethefollowingdetails:
Name:Nameofthebillingpolicy.
Description:Abriefdescriptionofthebillingpolicy.
Expression:Theexpressiondefinesattributevaluesthatidentifythecomputingresourceunitstobe
consideredforcostcalculation.Foralistofcomputingresourcesandtheirassociatedattributevalues,
seetheAppendixofthevCenterChargebackManagerAPIReference.Foracomputingresourcethe
expressioncanbethemaximumof
availableattributes.Itcanalsoaccountforthefixedcosts,linked
clonesandthestateofthevirtualmachine.
ThefollowingisanexamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<BillingPolicy>
<Name>New Billing Policy </Name>
<Description>New Flexible Billing Policy Expression</Description>
<Expression>cpu=max(usage, reservation);memory=max(usage,reservation);rest=usage;
</Expression>
</BillingPolicy>
</Request>
ThefollowingisanexampleprogramthatcallstheAPI.ThisprogramassumesthattherequestXMLis
populatedwiththerequiredinformation.
/**
* This method is to add a billing policy in vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleAddBillingPolicy(String requestFilePath, String baseURL) throws
IOException, JDOMException, NoSuchAlgorithmException,
KeyManagementException, HttpException {
PostMethod post = null;
Document requestDocument = CommonUtil.getXMLDocument(requestFilePath);
String bodyString = CommonUtil.xmlAsString(requestDocument);
HttpClient client = new HttpClient();