1.0.1
Table Of Contents
vCenter Chargeback API Programming Guide
16 VMware, Inc.
<Name>Test_Hierarchy</Name>
<Description>Test Hierarchy</Description>
</Hierarchy>
</Hierarchies>
</Request>
ThefollowingisasampleprogramthatcallstheAddaChargebackHierarchyAPI.Thisprogramassumes
thattherequestXMLispopulatedwiththerequiredinformation.
/**
* This method is to add a vCenter-ChargeBack hierarchy in
* vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @param clientVersion
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
@SuppressWarnings("deprecation")
public static void sampleAddHierarchyMethod(String requestFilePath, String baseURL,String
clientVersion) throws IOException, JDOMException, NoSuchAlgorithmException,
KeyManagementException, HttpException {
PostMethod post = null;
NameValuePair[] parameters = {new NameValuePair("version", clientVersion)};
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/hierarchy";
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();
}
}
}
}
Ifsuccessful,theAPIreturnsthenewhierarchy.
Add a vCenter Server Entity to the Chargeback Hierarchy
ThisAPIhelpsyoucreateavCenterServerentityunderaspecifiedparententityinaChargebackhierarchy.
TheURLforthisAPIis<HTTP_request_method>
<Base_URL>/hierarchy/{hierarchyId}/entity/{parentEntityId}.Youcandefineacalllikethis:
POST https://123.123.123.123/vCenter-CB/api/hierarchy/11/entity/101.
TheAPItakesarequestXMLfileinwhichyoucanspecifythehierarchyidentifier,entitynameand
descriptionforthehierarchy.AsamplerequestXMLisprovidedbelow.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<Hierarchies>