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.
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.
Contents About This Book 5 1 vCenter Chargeback APIs 7 What Is vCenter Chargeback? 7 REST Architecture 7 Requests 8 Responses 8 Common Elements in the Request and Response XMLs 9 Chargeback API Syntax 9 API Versioning 10 URI Versioning 10 2 Understanding the Workflow 11 Introduction to the Case Study 11 Login to vCenter Chargeback Server 12 Add vCenter Server Information 13 Create a Custom Chargeback Hierarchy 15 Add a vCenter Server Entity to the Chargeback Hierarchy 16 Add a Fixed Cost 18 Modify a Fi
vCenter Chargeback API Programming Guide 4 VMware, Inc.
About This Book The vCenter Chargeback API Programming Guide provides information on how to use vCenter Chargeback APIs. Intended Audience This book is intended for anyone who develop applications to work with vCenter Chargeback. Document Feedback VMware welcomes your suggestions for improving our documentation. If you have comments, send your feedback to docfeedback@vmware.com.
vCenter Chargeback API Programming Guide VMware Professional Services VMware Education Services courses offer extensive hands‐on labs, case study examples, and course materials designed to be used as on‐the‐job reference tools. Courses are available onsite, in the classroom, and live online. For onsite pilot programs and implementation best practices, VMware Consulting Services provides offerings to help you assess, plan, build, and manage your virtual environment.
1 vCenter Chargeback APIs 1 This chapter includes the following topics: “What Is vCenter Chargeback?” on page 7 “REST Architecture” on page 7 “Chargeback API Syntax” on page 9 “API Versioning” on page 10 What Is vCenter Chargeback? vCenter Chargeback is an end‐to‐end cost reporting solution for environments virtualized using vSphere.
vCenter Chargeback API Programming Guide Figure 1-1. REST in vCenter Chargeback Architecture Requests An HTTP request sent by a Chargeback API can be one of the following: PUT, POST, GET, or DELETE. Each of these request types maps to a standard CRUD operation as shown in the following table. Table 1-1.
Chapter 1 vCenter Chargeback APIs If an API task is unsuccessful, the status field is set to failure and the Error element captures all the details as explained in the table provided after this code sample. PAGE 10vCenter Chargeback API Programming Guide API Versioning Every vCenter Chargeback 1.0.1 API request/response includes targetnamespace to denote its version. For example, the following API request sends the version with which it is working. PAGE 112 Understanding the Workflow 2 This chapter presents a case study of a fictitious company to explain how to perform some of the basic vCenter Chargeback tasks using the APIs.
vCenter Chargeback API Programming Guide To accomplish the objective stated earlier, the vCenter Chargeback Administrator needs to do the following tasks. The sections that follow this diagram explain how to perform these tasks using the vCenter Chargeback APIs. Figure 2-2. Task Flow Login Add vCenter Server Information Create Hierarchy Add Fixed Cost Generate Report Login to vCenter Chargeback Server Use the Login API to login to vCenter Chargeback server.
Chapter 2 Understanding the Workflow The following is a sample program that calls the Login API. This program assumes that the request XML is populated with the required information.
vCenter Chargeback API Programming Guide vCenter Server Username: User name to access the vCenter Server. vCenter Server Password: Password for the user name entered. Database URL: The IP address of the system on which the vCenter Chargeback database is installed along with either the port at which the database listener service is running or the vCenter Chargeback database instance name.
Chapter 2 Understanding the Workflow false The following is a sample program that calls the Add vCenter Server Information API. This program assumes that the request XML is populated with the required information.
vCenter Chargeback API Programming Guide Test_Hierarchy Test Hierarchy The following is a sample program that calls the Add a Chargeback Hierarchy API. This program assumes that the request XML is populated with the required information.
Chapter 2 Understanding the Workflow The following is a sample program that calls the Add an Entity API.
vCenter Chargeback API Programming Guide } finally { if (post != null) { post.releaseConnection(); } } } } If successful, the API returns an XML file that indicates the status. Add a Fixed Cost A fixed cost is a definite cost that can be charged on an entity. Using vCenter Chargeback API, you can create fixed costs for entities. The URL for this API is /fixedCost. You can define a call like this: POST https://123.123.123.
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(); } } } } If the task is successful, the API returns an XML file that returns the identifier of the new fixed cost.
vCenter Chargeback API Programming Guide 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.
Chapter 2 Understanding the Workflow NOW 1211871400000 1232399800000 1 The following is a sample program that call
vCenter Chargeback API Programming Guide 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(); } } } } } 22 VMware, Inc.