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. 21
Chapter 2 Understanding the Workflow
Add a Fixed Cost
Afixedcostisadefinitecostthatcanbechargedonanentity.UsingtheAddFixedCostAPI,youcancreate
fixedcostsforentities.
To add a fixed cost
1 CalltheAPIusingthefollowingsyntax.
<HTTP_request_method> <Base_URL>/fixedCost
Forexample,youcandefineacalllikethis:
POST https://123.123.123.123/vCenter-CB/api/fixedCost
2IntherequestXML,specifyanameandadescriptionforthefixedcost.
ThefollowingisanexamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<FixedCosts>
<FixedCost>
<Name>Fixed Cost 1</Name>
<Description>Fixed Cost 1 description</Description>
<Currency id="1"/>
</FixedCost>
</FixedCosts>
</Request>
Ifthetaskissuccessful,theAPIreturnsanXMLfilethatprovidesdetailsofthenewfixedcost.
ThefollowingisanexampleprogramthatcallstheAPI.
/**
* This method is to add a fixed cost in vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleAddFixedCost(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();
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new
FakeSSLCertificateSocketFactory(), 443));
String uri = "https://" + baseURL + "/vCenter-CB/api/fixedCost";
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}