2.5
Table Of Contents
- API Programming Guide
- Contents
- About This Book
- vCenter Chargeback Manager APIs
- Understanding the Workflow
- Using vCenter Chargeback Manager with a Billing System
- Index
API Programming Guide
16 VMware, Inc.
Log In to vCenter Chargeback Manager
TostartusingvCenterChargebackManagerAPIs,youmustlogintovCenterChargebackManager.
To log in to vCenter Chargeback Manager
1 CalltheLoginAPIbyusingthefollowingsyntax.
<HTTP_request_method> <Base_URL>/login
Forexample,youcandefineacallasfollows:
POST https://123.123.123.123/vCenter-CB/api/login?version=2.5
2 (Optional)UsetheURLparameterversiontospecifytheAPIversionthatyouwanttocall.
3IntherequestXMLforthisAPI,youcanspecifythefollowinglogindetails.
Usertype
Username
Password
LDAPserverIDorLDAPservername
ThefollowingisanexamplerequestXMLfile.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/2.0">
<Users>
<User>
<Type>userType</Type>
<Name>administrator</Name>
<Password>vmware</Password>
<!-- For LDap User you can either provide LdapServer id or ldap server name
-->
<LdapServer id=”1”/>
</User>
</Users>
<!-- For Ldap Users -->
<LdapServers>
<LdapServer>
<LdapServerName>vmw</LdapServerName>
</LdapServer>
</LdapServers>
</Request>
Iftheloginsucceeds,theAPIreturnsaresponseXMLthatindicateswhethertheuserisauthenticated.
ThefollowingisanexampleprogramthatcallstheAPI.
/**
* This method is for Login to vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @param version
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleLoginMethod(String requestFilePath, String baseURL, String
version) throws IOException, JDOMException,
NoSuchAlgorithmException, KeyManagementException, HttpException {
PostMethod post = null;
NameValuePair[] parameters = {new NameValuePair("version", version)};
Document requestDocument = CommonUtil.getXMLDocument(requestFilePath);
String bodyString = CommonUtil.xmlAsString(requestDocument);
HttpClient client = new HttpClient();