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
API Programming Guide
38 VMware, Inc.
HttpClient client = new HttpClient();
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new
FakeSSLCertificateSocketFactory(), 443));
String uri = "https://" + baseURL + "/vCenter-CB/api/search";
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}
Get a Report as XML
GetareportintheXMLformatusingtheExportReportAPI.
1UsethefollowingsyntaxtocalltheExportReportAPI.
GET <API base URL>/report/{reportId}/export?exportFormat=XML
Forexample,
GET https://123.123.123.123/vCenter-CB/api/report/10/export?exportFormat=XML
TheAPIqueuestheexportreportrequestasataskandreturnsthestatusofthequeuedtask.Youcan
checkthestatusofthequeuedtaskusingtheGetQueuedTaskStatusAPI.Aftertheexportedreportis
ready,theExportReportAPIreturnsthereportinXMLformat.
2In
theresponseXML,checktheComputeDatasectionforthecostdetails.
ForadetaileddescriptionofalltheelementsintheresponseXML,seethevCenterChargebackManager
APIReferenceGuide.
ThefollowingisanexampleprogramthatcallstheAPI.ThisprogramassumesthattherequestXMLis
populatedwith
therequiredinformation.
/**
* This method get report as XML vCenter-ChargeBack
*
* @param reportId
* @param baseURL
* @throws IOException
* @throws HttpException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws JDOMException
*/
public static void sampleGetReportAsXml(int reportId, String baseURL) throws
HttpException, IOException, KeyManagementException, NoSuchAlgorithmException,
JDOMException {
GetMethod get = null;
HttpClient client = new HttpClient();
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new
FakeSSLCertificateSocketFactory(), 443));
String uri = "https://" + baseURL + "/vCenter-CB/api/report/" + reportId + "/export";
NameValuePair[] parameters = {new NameValuePair("exportFormat", "XML")};
try {
get = new GetMethod(uri);
get.setQueryString(parameters);
client.executeMethod(get);
System.out.println(get.getResponseBodyAsString());
} finally {
if (get != null) {
get.releaseConnection();
} } }