VMware vCenter vCenter Chargeback Manager 1.0.1 User guide

Category
Database software
Type
User guide
vCenter Chargeback API Programming
Guide
vCenter Chargeback 1.0.1
This document supports the version of each product listed and
supports all subsequent versions until the document is replaced
by a new edition. To check for more recent editions of this
document, see http://www.vmware.com/support/pubs.
EN-000296-00
VMware, Inc.
3401 Hillview Ave.
Palo Alto, CA 94304
www.vmware.com
2 VMware, Inc.
vCenter Chargeback API Programming Guide
You can find the most up-to-date technical documentation on the VMware Web site at:
http://www.vmware.com/support/
The VMware Web site also provides the latest product updates.
If you have comments about this documentation, submit your feedback to:
docfeedback@vmware.com
Copyright © 2009 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and
intellectual property laws. VMware products are covered by one or more patents listed at
http://www.vmware.com/go/patents.
VMware is a registered trademark or trademark of VMware, Inc. in the United States and/or other jurisdictions. All other marks
and names mentioned herein may be trademarks of their respective companies.
VMware, Inc. 3
Contents
AboutThisBook 5
1 vCenterChargebackAPIs 7
WhatIsvCenterChargeback? 7
RESTArchitecture 7
Requests 8
Responses 8
CommonElementsintheRequestandResponseXMLs 9
ChargebackAPISyntax 9
APIVersioning 10
URIVersioning 10
2 UnderstandingtheWorkflow 11
IntroductiontotheCaseStudy 11
LogintovCenterChargebackServer 12
AddvCenterServerInformation 13
CreateaCustomChargebackHierarchy 15
AddavCenterServerEntitytotheChargebackHierarchy 16
AddaFixedCost 18
ModifyaFixedCostValue 19
GenerateaReport 20
vCenter Chargeback API Programming Guide
4 VMware, Inc.
VMware, Inc. 5
ThevCenterChargebackAPIProgrammingGuideprovidesinformationonhowtousevCenterChargebackAPIs.
Intended Audience
ThisbookisintendedforanyonewhodevelopapplicationstoworkwithvCenterChargeback.
Document Feedback
VMwarewelcomesyoursuggestionsforimprovingourdocumentation.Ifyouhavecomments,sendyour
feedbacktodocfeedback@vmware.com.
vCenter Chargeback Documentation
ThevCenterChargebackdocumentationcomprisesthefollowingguides:
vCenterChargebackUsersGuide
vCenterChargebackAPIProgrammingGuide
vCenterChargebackAPIReferenceGuide
Technical Support and Education Resources
Thefollowingsectionsdescribethetechnicalsupportresourcesavailabletoyou.Toaccessthecurrentversion
ofthisbookandotherbooks,gotohttp://www.vmware.com/support/pubs.
Online and Telephone Support
Touseonlinesupporttosubmittechnicalsupportrequests,viewyourproductandcontractinformation,and
registeryourproducts,gotohttp://www.vmware.com/support.
Customerswithappropriatesupportcontractsshouldusetelephonesupportforthefastestresponseon
priority1issues.Gotohttp://www.vmware.com/support/phone_support.
Support Offerings
TofindouthowVMwaresupportofferingscanhelpmeetyourbusinessneeds,goto
http://www.vmware.com/support/services.
About This Book
vCenter Chargeback API Programming Guide
6 VMware, Inc.
VMware Professional Services
VMwareEducationServicescoursesofferextensivehandsonlabs,casestudyexamples,andcoursematerials
designedtobeusedasonthejobreferencetools.Coursesareavailableonsite,intheclassroom,andlive
online.Foronsitepilotprograms andimplementationbestpractices,VMwareConsultingServicesprovides
offeringsto helpyouassess,plan,
build,andmanageyourvirtualenvironment.Toaccessinformationabout
educationclasses,certificationprograms,andconsultingservices,gotohttp://www.vmware.com/services.
VMware, Inc. 7
1
Thischapterincludesthefollowingtopics:
“WhatIsvCenterChargeback?”onpage 7
“RESTArchitectureonpage 7
“ChargebackAPISyntax”onpage 9
“A P I Versioning”onpage 10
What Is vCenter Chargeback?
vCenterChargebackisanendtoendcostreportingsolutionforenvironmentsvirtualizedusingvSphere.
This WebbasedapplicationinteractswiththevCenterDatabasetoretrieveusageinformation,calculatesthe
costbyusingthedefinedChargebackformulas,andgeneratesreports.
vCenterChargebackrunsonanApacheTomcatserverinstance.Theuserinteracts
withthevCenter
Chargebackapplicationthroughaloadbalancer(ApacheHTTPServer).vCenterChargebackconnectstoa
Chargebackdatabasethatstoresinformationsuchasthedefinedhierarchies,costmodel,users,roles,andso
on.TheapplicationalsointeractswiththevCenterServerandvCenterDatabasethroughaDataCollector.
The Data
CollectorusesVIMAPIstocommunicatewiththevCenterServerandJDBCtocommunicatewith
thevCenterDatabase.
vCenterChargebackAPIsprovideaninterfaceforapplicationdeveloperstoprogrammaticallyusethe
functionalityofvCenterChargeback.
FormoreinformationaboutChargebackanditscapabilities,seethevCenterChargebackUser’sGuide.
REST Architecture
vCenterChargebackAPIsimplementtheRepresentationalStateTransfer(REST)architecture.RESTbased
APIstypicallyhelpyousendHTTPrequestsforresourcesoverthenetworkandreceiveresponses.
vCenter Chargeback APIs
1
vCenter Chargeback API Programming Guide
8 VMware, Inc.
Figure 1-1. REST in vCenter Chargeback Architecture
Requests
AnHTTPrequestsentbyaChargebackAPIcanbeoneofthefollowing:PUT,POST,GET,orDELETE.Each of
theserequesttypesmapstoastandardCRUDoperationasshowninthefollowingtable.
Responses
WhenanAPItaskissuccessful,thevalueofthestatusfieldintheresponseXMLissettosuccessasshown
inthefollowingexample.
<?xml version="1.0" encoding="UTF-8"?>
<Response status="success" isValidLicense="true"
xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Hierarchies>
<Hierarchy id="1">
<Name>Test_Hierarchy_Renamed</Name>
<Description>Test_Hierarchy_Renamed
</Description>
<InSync>true</InSync>
<LastUpdatedTime>1251893303708</LastUpdatedTime>
<LastUpdatedUser>CBM Server</LastUpdatedUser>
<Entities />
</Hierarchy>
</Hierarchies>
</Response>
Table 1-1. Request Type Mapping
Request Type CRUD Operation
POST CREATE
GET READ
PUT UPDATE/CREATE
DELETE DELETE
VMware, Inc. 9
Chapter 1 vCenter Chargeback APIs
IfanAPItaskisunsuccessful,thestatusfieldissettofailureandtheErrorelementcapturesallthedetails
asexplainedinthetableprovidedafterthiscodesample.
<?xml version="1.0" encoding="UTF-8"?>
<Response status="failure" isValidLicense="true"
xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Error majorErrorCode="500" minorErrorCode="2014"
message="Hierarchy with id '1' does not exist." />
</Response>
Common Elements in the Request and Response XMLs
ThecommonXMLelementsusedbytherequestandresponseXMLsarepresentedinthefollowingtable.
RefertotheearliersectionsforsamplerequestandresponseXMLs.
Chargeback API Syntax
EachvCenterChargebackAPIhasthissyntax:
<HTTP_request_method> <Base_Url>/<API_signature>?version=1.0.1
Forexample,GET https://123.123.123.123/vCenter-CB/api/hierarchies?version=1.0.1
Table 1-2. Components of Error Elements
Element Description
majorErrorCode Theclassoftheerror.ItrepresentstheHTTPStatuscodes.
minorErrorCode ThespecificAPIerrorcode.Forexample,itcanindicatethathierarchycreationfailed.
vendorSpecificErrorCode
(Optional)
Avendor/implementationspecificerrorcodethatpointstospecificmodules/partsofthe
codeandcanmakeproblemdiagnosticseasier.Forexample,itcanindicate
ifacode
snippetisavCentererrorcodeoraDatabaseerrorcode.
message Aoneline,humanreadablemessagethatdescribestheerrorthatoccurred.
ErrorStackTrace ThiselementispresentwhentheloglevelinChargebackissettoDebug.
Table 1-3. Common Elements
Element Description
Request AnAPIrequeststartswiththiselement.
Response AnAPIresponsestartswiththiselement.
status DenoteswhetherAPIissuccessfullyexecuted.
IsValidLicense Indicatesthestatusofthelicense.Valuecanbetrueorfalse.
Table 1-4. API Syntax Components
Syntax Component Description
HTTP_request_method PUT,POST,GET,orDELETE
Base_Url, TheURLoftheChargebackhost.ThebaseURLforvCenterChargebackAPIsis:
https://<Chargeback server IP>/vCenter-CB/api
Forexample,https://123.123.123.123/vCenter-CB/api
API_signature TheURLpathforaChargebackAPI.Forexample,/hierarchiesretrievesthe
hierarchiesaddedtotheChargebackserverrunningon123.123.123.123.
version APIversion.ForChargebackserver1.0.1,itneedsto
bepassedas1.0.1.
vCenter Chargeback API Programming Guide
10 VMware, Inc.
API Versioning
EveryvCenterChargeback1.0.1APIrequest/responseincludestargetnamespacetodenoteitsversion.
For example,thefollowingAPIrequestsendstheversionwithwhichitisworking.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<Hierarchies>
<Hierarchy>
<Name>Test_Hierarchy</Name>
<Description>Test Hierarchy</Description>
</Hierarchy>
</Hierarchies>
</Request>
Therequeststatesthat,vCenterChargebackAPIversion1.0.1needstobecalled.IftherequestisforvCenter
Chargebackserverversion1.0,thiscallfails.IftherequestisforvCenterChargebackserver1.0.1,thecall
succeedsandgetsaresponseasfollows.
<?xml version="1.0" encoding="UTF-8"?>
<Response status="success" isValidLicense="true"
xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Hierarchies>
<Hierarchy id="5">
<Name>Test_Hierarchy</Name>
<Description>Test Hierarchy</Description>
<InSync>true</InSync>
<LastUpdatedTime>1251892244029</LastUpdatedTime>
<LastUpdatedUser>local\admin</LastUpdatedUser>
<Entities>
<Entity id="119">
<Name>Test_Hierarchy</Name>
<Description>Root</Description>
<Type>100</Type>
<Shares>
<Share>
<Percentage>100</Percentage>
<Parent id="-1" />
</Share>
</Shares>
</Entity>
</Entities>
</Hierarchy>
</Hierarchies>
</Response>
ThisresponseindicatesthatvCenterChargebackAPI1.0.1iscalled.AlltheAPIsstartingfromversion1.0.1
willbebackwardcompatible.Thatis,arequestforvCenterChargebackAPI1.0.1tovCenterChargeback1.2
server,willbevalid.
TheAPIversion,ifbeingspecified,shouldbepresentinboththerequest
XML(whereverapplicable)andin
theURL.IfitisspecifiedonlyintherequestXMLortheURLandnotboth,thentheAPIdisplaysanerror.
If theAPIversionisabsentinboththeURLandtherequestXML(whereverapplicable),thentheAPIreturns
theoutputcorresponding
tothelatestversion.
URI Versioning
IntheURIofanAPI,youcanpassanoptionalparametertoindicatetheoutputversionyouexpectasshown
inthefollowingexample:
HTTP_request_method> <Base_Url>/<API_signature>?[version=1.0.1]
Ifyoudonotprovidetheversion,theAPIreturnstheoutputcorrespondingtothelatestversion.
VMware, Inc. 11
2
Thischapterpresentsacasestudyofafictitiouscompanytoexplainhowtoperformsomeofthebasic
vCenter ChargebacktasksusingtheAPIs.Thechapterincludesthefollowingtopics:
“IntroductiontotheCaseStudy”onpage 11
“LogintovCenterChargebackServeronpage 12
“A d d vCenterServerInformation”onpage 13
“CreateaCustomChargebackHierarchy”onpage 15
“A d d avCenterServerEntitytotheChargebackHierarchy”onpage 16
“A d d aFixedCost”onpage 18
“ModifyaFixedCostValueonpage 19
“GenerateaReport”onpage 20
Introduction to the Case Study
ABChasapresenceacrossgeographicregionssuchasAsiaPacific(APAC),Europe,theMiddleEastand
Africa(EMEA),andJapan.Ineachoftheseregions,theirofficesarelocatedinmultiplecities.Forexample,in
Japan,amongothercities,ABCalsohasanofficeinTokyo.Thisofficehasa
numberofESXhoststhatrunmany
virtualmachines.Thecompanywantstocreateahierarchyofresourcesandmeasurethecostofresourcesfor
eachofficeandforeachregionasrepresentedinFigure 21.
Figure 2-1. Sample Hierarchy for ABC
Understanding the Workflow
2
vCenter Chargeback API Programming Guide
12 VMware, Inc.
Toaccomplishtheobjectivestatedearlier,thevCenterChargebackAdministratorneedstodothefollowing
tasks.ThesectionsthatfollowthisdiagramexplainhowtoperformthesetasksusingthevCenterChargeback
APIs.
Figure 2-2. Task Flow
Login to vCenter Chargeback Server
UsetheLoginAPItologintovCenterChargebackserver.
ThesyntaxforthisAPIis<HTTP_request_method> <Base_URL>/login.Forexample,youcandefinea
callasfollows:
POST https://123.123.123.123/vCenter-CB/api/login.
UsetheURLparameterversiontospecifytheAPIversiontobecalled.
ThisAPItakesarequestXMLinwhichyoucanspecifythefollowinglogindetails:
LDAPserverID
Usertype
Username
Password
ThefollowingisasamplerequestXMLfile:
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<Users>
<User>
<!-- <LdapServerId>1</LdapServerId> -->
<Type>local</Type>
<Name>TestUser</Name>
<Password>SomePassword</Password>
</User>
</Users>
</Request>
Login
Generate Report
Add vCenter Server Information
Create Hierarchy
Add Fixed Cost
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.
vCenter Chargeback API Programming Guide
14 VMware, Inc.
vCenterServerUsername:UsernametoaccessthevCenterServer.
vCenterServerPassword:Passwordfortheusernameentered.
DatabaseURL:TheIPaddressofthesystemonwhichthevCenterChargebackdatabaseisinstalled
alongwitheithertheportatwhichthedatabaselistenerserviceisrunningorthevCenterChargeback
databaseinstancename.
ForOracledatabase,thedatabaseURLcanbeinoneofthefollowingformats:
<IP Address>:<TNS Listener Port>
<Host Name>:<TNS Listener Port>
ForSQLServer,thedatabaseURLcanbeinoneofthefollowingformats:
<IP Address>\<Database Instance Name>
<Host Name>\<Database Instance Name>
DatabaseName:ThenameofthevCenterServerdatabase.Forexample,vim_vcdb,whichisthe
defaultnamegivenbyvCenterServer.
DatabaseUsername:AdatabaseusernametoaccessthevCenterDatabase.
DatabasePassword:Apasswordforthedatabaseusernameentered.
DatabaseType:ThedatabasetypecanbeeitherSQLServer(default)orOracle.AnIDvalueof1
meansSQLserverand2meansOracle.
DataSourceAuthType:TheauthenticationtypeID,whichforSQLservercanbeWindows
authenticationordatabaseauthentication.TheID1meansCredentialbasedAuthenticationandthe
ID2indicatesWindowsauthentication.
vCenterServerViewType:ThetypeofviewtobeusedtodisplaytheentitiesinthevCenterServer
hierarchy.ThiscanbeeitherHostsandClustersorVirtualMachinesandTemplates.Anidvalueof1
indicatesHostsandClustersandavalueof2indicatesVirtualMachinesandTemplates.
Theseview
typesarethesameasthecorrespondingvCenterServerviewtypes,andtheentitiesinthevCenter
ServerhierarchywillbedisplayedinamannersimilartothevCenterServerviews.Onceset,this
optioncannotbeeditedforthevCenterServer.
RegisterAsVIClientPlugin:SelectthisoptionifyouwouldliketoregistervCenterChargebackasa
plugintoVIClient.Ifyouselectthisoption,eachtimeyoulogintothisvCenterServerusingthe
VI Client,thevCenterChargebackpluginisdisplayedontheVIClient.
YoucanaccessthevCenter
ChargebackapplicationfromtheVIClient.
EnableStatsReplication:SelectthisoptionifyouwanttheresourceusagestatisticsfromthevCenter
ServerDatabasetobereplicatedinthevCenterChargebackDatabase.
ThefollowingisasamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<VCenterServers>
<VCenterServer>
<Url>10.112.107.21:443</Url>
<Name>vc1</Name>
<Description>vc1</Description>
<UserName>administrator</UserName>
<Password>xxxx</Password>
<PluginRegistered>true</PluginRegistered>
<StatsSync>true</StatsSync>
<DataSourceUrl>
10.112.107.21\sqlexp_vim
</DataSourceUrl>
<DataSourceName>vim_vcdb</DataSourceName>
<DataSourceUserName>sa</DataSourceUserName>
<DataSourcePassword>xxxx</DataSourcePassword>
<DataSourceType id="1" />
<DataSourceAuthType id="1" />
<VCenterServerView id="1" />
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>
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>
VMware, Inc. 17
Chapter 2 Understanding the Workflow
<Hierarchy id="38">
<Entities>
<Entity id="171">
<VCenterServers>
<VCenterServer id="145">
<Entities>
<!-- Either id or MoId needs to be there. id takes
precedance over MoId-->
<Entity id="630">
<!-- <MoId>host-2460</MoId> -->
</Entity>
</Entities>
</VCenterServer>
</VCenterServers>
</Entity>
</Entities>
</Hierarchy>
</Hierarchies>
</Request>
ThefollowingisasampleprogramthatcallstheAddanEntityAPI.Makesurethatyou:
UpdatetherequestXMLforLoginAPIwithrequiredvaluesandrunthelogin.javasamplecode.
RunAddVCenterServer.javaandreadthevcIdfromtheresponse
ReadthevcEntityIdwhichyouneedtoaddundervCenterChargeBackhierarchyentity,fromthe
responseofsampleGetVcHierarchyMethod()
AddavCenterChargeBackHierarchyandfromtheresponse,readthehierarchyIdandtheCBEntity
IdunderwhichthevcEntityistobeadded
UpdatetheHierarchyid,cbEntityid,VCenterServeridandvcEntityidintherequestXMLfile.
/**
* This method is to add a new vCenter-Server entity under
* vCenter-Chargeback Hierarchy entity
*
* @param requestFilePath
* @param baseURL
* @param hierachyId
* @param CBEntityId
* @param clientVersion
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
@SuppressWarnings("deprecation")
public static void sampleAddNewVCenterServerEntity(String requestFilePath, String
baseURL, int hierachyId, int CBEntityId,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/" + hierachyId +
"/entity/" + CBEntityId;
try {
post = new PostMethod(uri);
post.setQueryString(parameters);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
vCenter Chargeback API Programming Guide
18 VMware, Inc.
}
finally {
if (post != null) {
post.releaseConnection();
}
}
}
}
Ifsuccessful,theAPIreturnsanXMLfilethatindicatesthestatus.
Add a Fixed Cost
Afixedcostisadefinitecostthatcanbechargedonanentity.UsingvCenterChargebackAPI,youcancreate
fixedcostsforentities.
TheURLforthisAPIis<HTTP_request_method> <Base_URL>/fixedCost.Youcandefineacalllike
this:
POST https://123.123.123.123/vCenter-CB/api/fixedCost
TheAPItakesarequestXMLfileinwhichyoucanspecifythefixedcostnameanditsdescription.
The followingisasamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<FixedCosts>
<FixedCost>
<Name>Fixed Cost 1</Name>
<Description>Fixed Cost 1 description</Description>
</FixedCost>
</FixedCosts>
</Request>
ThefollowingisasampleprogramthatcallstheAddanFixedCostAPI.Makesurethatyou:
UpdatetheLogin-request.xmlwithrequiredvaluesandrunthelogin.javasamplecode.
UpdatetheaddFixedCost-request.xmlwithfixedcostnameanditsdescription.
/**
* This method is to add a fixed cost in vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @param clientVersion
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
@SuppressWarnings("deprecation")
public static void sampleAddFixedCost(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/fixedCost";
VMware, Inc. 19
Chapter 2 Understanding the Workflow
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();
}
}
}
}
Ifthetaskissuccessful,theAPIreturnsanXMLfilethatreturnstheidentifierofthenewfixedcost.
Modify a Fixed Cost Value
UsingtheModifyFixedCostAPI,youcanupdatefixedcostid,valueanddurationforafixedcost.
TheURLforthisAPIis<HTTP_request_method> <Base_URL>/fixedCost/{fixedCostId}/values.
Youcandefineacalllikethis:
PUT https://123.123.123.123/vCenter-CB/api/fixedCost/{fixedCostId}/values
TheAPItakesarequestXMLfileinwhichyoucanspecifythefixedcostnameanditsdescription.
The followingisasamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<FixedCosts>
<FixedCost id="1">
<Values>
<Value>
<Cost>3.1415</Cost>
<Duration id="1"/>
</Value>
</Values>
</FixedCost>
</FixedCosts>
</Request>
ThefollowingisasampleprogramthatcallstheAddanFixedCostAPI.Makesurethatyou:
UpdatetheLogin-request.xmlwithrequiredvaluesandrunthelogin.javasamplecode.
RuntheAddFixedCostAPIandreadthefixedCostIdfromtheresponse.
UpdatethefixedCostId,thecostanddurationidinmodifyFixedCostValues-request.xmlfile.
/**
* This method is to modify the values of an existing fixedCost
*
* @param requestFilePath
* @param baseURL
* @param startTime
* @param endTime
* @param clientVersion
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
@SuppressWarnings("deprecation")
public static void sampleModifyFixedCostValues(String requestFilePath,
String baseURL, int fixedCostId, long startTime, long endTime,
String clientVersion) throws IOException, JDOMException,
vCenter Chargeback API Programming Guide
20 VMware, Inc.
NoSuchAlgorithmException, KeyManagementException, HttpException {
PutMethod put = null;
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/fixedCost/"
+ fixedCostId + "/values";
System.out.println(uri);
NameValuePair[] parameters = {
new NameValuePair("version", clientVersion),
new NameValuePair("startTime", String.valueOf(startTime)),
new NameValuePair("endTime", String.valueOf(endTime)) };
try {
put = new PutMethod(uri);
put.setRequestBody(bodyString);
put.setQueryString(parameters);
client.executeMethod(put);
System.out.println(put.getResponseBodyAsString());
}
finally {
if (put != null) {
put.releaseConnection();
}
}
}
}
Generate a Report
UsingtheGenerateaRawReportAPI,youcangenerateareportthatprovidesinformationoncostdetailsfor
thegivenentity.
TheURLforthisAPIis<HTTP_request_method> <Base_URL>/rawReport.Youcandefineacalllike
this:
POST https://123.123.123.123/vCenter-CB/api/rawReport
TheAPItakesarequestXMLfileinwhichyoucanspecifydetailsaboutthehierarchy,entity,resource
countersandthecostmodel.ThefollowingisasamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1">
<ReportTemplates>
<ReportTemplate>
<Name>Name</Name>
<Description>Description</Description>
<ReportType>COST_REPORT</ReportType>
<Hierarchies>
<Hierarchy id="1">
<Entities>
<Entity id="2" />
</Entities>
</Hierarchy>
</Hierarchies>
<CostModels>
<CostModel id="2" />
</CostModels>
<ComputingResources>
<ComputingResource id="2" />
</ComputingResources>
  • Page 1 1
  • Page 2 2
  • Page 3 3
  • Page 4 4
  • Page 5 5
  • Page 6 6
  • Page 7 7
  • Page 8 8
  • Page 9 9
  • Page 10 10
  • Page 11 11
  • Page 12 12
  • Page 13 13
  • Page 14 14
  • Page 15 15
  • Page 16 16
  • Page 17 17
  • Page 18 18
  • Page 19 19
  • Page 20 20
  • Page 21 21
  • Page 22 22

VMware vCenter vCenter Chargeback Manager 1.0.1 User guide

Category
Database software
Type
User guide

Ask a question and I''ll find the answer in the document

Finding information in a document is now easier with AI