2.5

API Programming Guide
28 VMware, Inc.
Add Pricing Models
YoucanaddmultiplepricingmodelsinvCenterChargebackManager.Definingmultiplepricingmodels
enablesyoutochargedifferentsetsofentitiesorhierarchiesdifferently.Italsoenablesyoutocomparethe
costscalculatedusingdifferentpricingmodelsforahierarchyorasetofentities.
To add a pricing model
1 CalltheAddPricingModel
APIbyspecifyingthefollowingURLinyourprogram.
POST https://<ipaddress>/vCenter-CB/api/costModel
2IntherequestXML,specifythefollowinginformation.
Name:SpecifyNetworkingasthenameofthepricingmodel.
Description:ProvideabriefdescriptionfortheNetworkingpricingmodel.
CurrencyID:(Optional)SpecifytheIDofthecurrencytobesetforthispricingmodel.Ifnotspecified,
thecurrencyIDwillautomaticallybesettoUSDollars(USD)ortheglobalcurrencyIDthatwasset
duringvCenterChargebackManagerupgrade.ForalistofcurrenciessupportedbyvCenter
ChargebackManager,seetheAppendixofthevCenterChargebackManagerAPIReference.
ThefollowingisanexamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<CostModels>
<CostModel>
<Name>Networking</Name>
<Description>Networking Pricing Model</Description>
<Currency id="1"/>
</CostModel>
</CostModels>
</Request>
3Addthefollowingpricingmodels.
AllocationPool
ReservationPool
Payasyougo
ThefollowingisanexampleprogramthatcallstheAddPricingModelsAPI.Thisprogramassumesthat
therequestXMLispopulatedwiththerequiredinformation.
/**
* This method is to add a pricing 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";