1.0.1
Table Of Contents
VMware, Inc. 15
Chapter 2 Understanding the Workflow
<ForceUpdate>false</ForceUpdate>
</VCenterServer>
</VCenterServers>
</Request>
ThefollowingisasampleprogramthatcallstheAddvCenterServerInformationAPI.Thisprogram
assumesthattherequestXMLispopulatedwiththerequiredinformation.
/**
* This method to add the vCenter-Server in vCenter-Chargeback application
*
* @param requestFilePath
* @param baseURL
* @param clientVersion
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
@SuppressWarnings("deprecation")
public static void sampleAddVCenterServerMethod(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/vCenterServer";
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();
}
}
}
}
IfthevCenterServerissuccessfullyadded,theAPIreturnsanXMLthatprovidesthevCenterServer
identifier.
Create a Custom Chargeback Hierarchy
UsetheAddaChargebackHierarchyAPItocreateahierarchywiththegivennameanddescription.
TheURLforthisAPIis<HTTP_request_method> <Base_URL>/hierarchy.Youcandefineasamplecall
likethis:
POST https://123.123.123.123/vCenter-CB/api/hierarchy
TheAPItakesarequestXMLinwhichyoucanspecifythenameanddescriptionforthehierarchy.
A sampleinputXMLisprovidedbelow.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<Hierarchies>
<Hierarchy>