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
VMware, Inc. 29
Chapter 3 Using vCenter Chargeback with a Billing System
ThefollowingisanexampleprogramthatcallstheAPI.ThisprogramassumesthattherequestXMLis
populatedwiththerequiredinformation.
/**
* This method get list of hierarchies from vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws HttpException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws JDOMException
*/
public static void sampleGetHierarchies(String requestFilePath, String baseURL) throws
HttpException, IOException, KeyManagementException,
NoSuchAlgorithmException, JDOMException {
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/search";
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}
Get Details of a Hierarchy
AftertheSearchAPIretrievesthenewhierarchies,youcangetmoredetailsaboutaspecifichierarchyby
callingtheGetHierarchyAPI.
To get details of a hierarchy
1 CalltheGetHierarchyAPIbyusingthefollowingURLinyourprogram.
GET <API base URL>/hierarchy/{hierarchyId}
Iftheoperationissuccessful,theresponseXMLcontainsdetailsofthehierarchy.
ThefollowingisanexampleprogramthatcallstheAPI.ThisprogramassumesthattherequestXMLis
populatedwiththerequiredinformation.
/**
* This method get hierarchy from vCenter-ChargeBack
*
* @param hierarchyId
* @param baseURL
* @throws IOException
* @throws HttpException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws JDOMException
*/
public static void sampleGetHierarchy(int hierarchyId, String baseURL) throws
HttpException, IOException, KeyManagementException, NoSuchAlgorithmException,
JDOMException {
GetMethod get = null;
HttpClient client = new HttpClient();