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
18 VMware, Inc.
ThefollowingisanexamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<VCenterServers>
<VCenterServer id="502">
<VCenterServerView id = "2"/>
<Entities>
<Entity id="1062"/>
</Entities>
</VCenterServer>
</VCenterServers>
</Request>
Ifsuccessful,theAPIreturnsanXMLfilethatindicatesthestatus.
ThefollowingisanexampleprogramthatcallstheAPI.
/**
* This method is for adding a new vCenter-Server entity under
* vCenter-Chargeback Hierarchy entity
*
* @param requestFilePath
* @param baseURL
* @param hierachyId
* @param CBEntityId
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleAddNewVCenterServerEntity(String requestFilePath, String
baseURL, int hierachyId, int CBEntityId, long startTime)
throws IOException, JDOMException, NoSuchAlgorithmException,
KeyManagementException, HttpException {
PostMethod post = null;
Document requestDocument = CommonUtil.getXMLDocument(requestFilePath);
NameValuePair[] parameters = {new NameValuePair("startTime",
String.valueOf(startTime))};
String bodyString = CommonUtil.xmlAsString(requestDocument);
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new
FakeSSLCertificateSocketFactory(), 443));
String uri = "https://" + baseURL + "/vCenter-CB/api/hierarchy/" + hierachyId +
"/entity/" + CBEntityId;
HttpClient client = new HttpClient();
System.out.println(uri);
System.out.println(bodyString);
try {
post = new PostMethod(uri);
post.setQueryString(parameters);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}