2.5

API Programming Guide
18 VMware, Inc.
</DataSourceUrl>
<DataSourceName>vim_vcdb</DataSourceName>
<DataSourceUserName>sa</DataSourceUserName>
<DataSourcePassword>xxxx</DataSourcePassword>
<DataSourceType id="1" />
<DataSourceAuthType id="1" />
<ForceUpdate>false</ForceUpdate>
</VCenterServer>
</VCenterServers>
</Request>
IfthevCenterServerissuccessfullyadded,theAPIreturnsanXMLresponsethatprovidesthevCenter
ServerID.
ThefollowingisanexampleprogramthatcallstheAPI.
/**
* This method is to add the vCenter-Server in vCenter-Chargeback application
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleAddVCenterServerMethod(String requestFilePath, String baseURL)
throws IOException, JDOMException, NoSuchAlgorithmException,
KeyManagementException, HttpException {
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/vCenterServer?version=2.5";
System.out.println(uri);
System.out.println(bodyString);
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}
Add a Custom Chargeback Hierarchy
UsetheAddaChargebackHierarchyAPItocreateahierarchywiththegivennameanddescription.
To add a custom Chargeback hierarchy
1 CalltheAPIbyusingthefollowingsyntax.
<HTTP_request_method> <Base_URL>/hierarchy
Forexample,youcandefineacalllikethis:
POST https://123.123.123.123/vCenter-CB/api/hierarchy
2IntherequestXML,specifyanameandadescriptionforthehierarchy.