1.0.1

VMware, Inc. 13
Chapter 2 Understanding the Workflow
ThefollowingisasampleprogramthatcallstheLoginAPI.ThisprogramassumesthattherequestXML
ispopulatedwiththerequiredinformation.
/**
* This method is for Login to vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @param clientVersion
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
@SuppressWarnings("deprecation")
public static void sampleLoginMethod(String requestFilePath, String baseURL, String
clientVersion) throws IOException, JDOMException,
NoSuchAlgorithmException, KeyManagementException, HttpException {
PostMethod post = null;
// String uri=baseURL+"/login";
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/login";
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();
}
}
}
}
Iftheloginsucceeds,theAPIreturnsaresponseXMLthatindicatesthestatusoftheoperation.
Add vCenter Server Information
UsetheAddvCenterServerAPItoaddvCenterserversinstancesinyourvirtualizedenvironmenttovCenter
Chargeback.Thishelpsdeterminethecomputingresourcesutilizationforthevirtualmachinesandcalculate
thetotalcosts.
TheURLforthisAPIis<HTTP_request_method> <Base_URL>/vCenterServer.Youcandefinea
samplecallasfollows:
POST https://123.123.123.123/vCenter-CB/api/vCenterServer.
TheAddvCenterServerAPItakesarequestXMLthatcapturesthefollowinginformation:
vCenterServerHostname/IP:FQDNorIPaddressofthevCenterServer.
vCenterServerName:AdisplaynameforthevCenterServer.
vCenterServerDescription:AdescriptionofthevCenterServer.Thisisoptional.