1.5
Table Of Contents
- vCenter Chargeback API Programming Guide
- Contents
- About This Book
- vCenter Chargeback APIs
- Understanding the Workflow
- Using vCenter Chargeback with a Billing System
- Index
vCenter Chargeback API Programming Guide
22 VMware, Inc.
<ComputingResource id="9" />
<ComputingResource id="10" />
</ComputingResources>
</MetaData>
<Configuration>
<!-- Report configuration is an optional section, not particularly relavant for API
users -->
</Configuration>
</Report>
</Reports>
</Request>
vCenterChargebackqueuesthisreportrequestasataskandreturnsanXMLthatindicatesthestatusof
thetask.YoucanusetheGetQueuedTaskStatusAPItotracktheprogressofthetask.Formore
informationontheGetQueuedTaskStatusAPI,seethevCenterChargebackAPI
ReferenceGuide.
ThefollowingisanexampleprogramthatcallstheAPI.
/**
* This method is to generate report for a vCenter-ChargeBack hierarchy
* entity in vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleGenerateReportMethod(String requestFilePath, String baseURL)
throws IOException, JDOMException, NoSuchAlgorithmException,
KeyManagementException, HttpException {
PostMethod post = null;
Document requestDocument = CommonUtil.getXMLDocument(requestFilePath);
String bodyString = CommonUtil.xmlAsString(requestDocument);
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new
FakeSSLCertificateSocketFactory(), 443));
String uri = "https://" + baseURL + "/vCenter-CB/api/report";
HttpClient client = new HttpClient();
System.out.println(uri);
System.out.println(bodyString);
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}