2.0
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
22 VMware, Inc.
Modify a Fixed Cost Value
UsingtheModifyFixedCostAPI,youcanupdatetheID,value,anddurationforafixedcost.
To modify a fixed cost value
1 CalltheAPIbyusingthefollowingsyntax.
<HTTP_request_method> <Base_URL>/fixedCost/{fixedCostId}/values
Forexample,youcandefineacalllikethis:
PUT https://123.123.123.123/vCenter-CB/api/fixedCost/{fixedCostId}/values
2IntherequestXML,specifyanameandadescriptionforthefixedcost.Thefollowingisanexample
requestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<FixedCosts>
<FixedCost id="1">
<Values>
<Value>
<Cost>3.1415</Cost>
<Duration id="1"/>
</Value>
</Values>
</FixedCost>
</FixedCosts>
</Request>
TheresponseXMLindicateswhetherthefixedcostvaluewassuccessfullymodified.
ThefollowingisanexampleprogramthatcallstheAPI.
/**
* This method is to modify the values of an existing fixedCost
*
* @param requestFilePath
* @param baseURL
* @param startTime
* @param endTime
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleModifyFixedCostValues(String requestFilePath, String baseURL,
int fixedCostId, long startTime, long endTime) throws IOException,
JDOMException, 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));
HttpClient client = new HttpClient();
String uri = "https://" + baseURL + "/vCenter-CB/api/fixedCost/" + fixedCostId +
"/values";
System.out.println(uri);
NameValuePair[] parameters = {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());