2.0

API Programming Guide
28 VMware, Inc.
Add Cost Models
YoucanaddmultiplecostmodelsinvCenterChargebackManager.Definingmultiplecostmodelsenablesyou
tochargedifferentsetsofentitiesorhierarchiesdifferently.Italsoenablesyoutocomparethecostscalculated
usingdifferentcostmodelsforahierarchyorasetofentities.
To add a cost model
1 CalltheAddCostModel
APIbyspecifyingthefollowingURLinyourprogram.
POST https://<ipaddress>/vCenter-CB/api/costModel
2IntherequestXML,specifythefollowinginformation.
Name:SpecifyNetworkingasthenameofthecostmodel.
Description:ProvideabriefdescriptionfortheNetworkingcostmodel.
CurrencyID:(Optional)SpecifytheIDofthecurrencytobesetforthiscostmodel.Ifnotspecified,
thecurrencyIDwillautomaticallybesettoUSDollars(USD)ortheglobalcurrencyIDthatwasset
duringvCenterChargebackManagerupgrade.ForalistofcurrenciessupportedbyvCenter
ChargebackManager,seetheAppendixofthevCenterChargebackManagerAPIReference.
ThefollowingisanexamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<CostModels>
<CostModel>
<Name>Networking</Name>
<Description>Networking Cost Model</Description>
<Currency id="1"/>
</CostModel>
</CostModels>
</Request>
3Addthefollowingcostmodels.
AllocationPool
ReservationPool
Payasyougo
ThefollowingisanexampleprogramthatcallstheAddCostModelsAPI.Thisprogramassumesthatthe
requestXMLispopulatedwiththerequiredinformation.
/**
* This method is to add a cost model in vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleAddCostModel(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/costModel";