vcenter Chargeback API Programming Guide vcenter Chargeback 1.0.1

Similar documents
API Programming Guide vcenter Chargeback Manager 2.5.0

vcenter Chargeback User s Guide

VMware vcenter Configuration Manager and VMware vcenter Application Discovery Manager Integration Guide

vsphere PowerCLI Installation Guide VMware vsphere PowerCLI 4.1 Update 1 EN

Request Manager User's Guide

Lifecycle Manager User's Guide

VMware View Upgrade Guide

VMware vcenter Discovered Machines Import Tool User's Guide Version for vcenter Configuration Manager 5.6

vcenter Chargeback Manager Installation and Upgrade Guide

VMware vsphere Update Manager PowerCLI Installation and Administration Guide Update Manager PowerCLI 6.0 EN

vcenter CapacityIQ Installation Guide

vcenter Update Manager PowerCLI Installation and Administration Guide vcenter Update Manager PowerCLI 4.1 EN

vcenter CapacityIQ Installation Guide

Best Practices and Troubleshooting Guide

VMware Infrastructure 3 Primer Update 2 and later for ESX Server 3.5, ESX Server 3i version 3.5, VirtualCenter 2.5

Using the vcenter Orchestrator SOAP Plug-In 1.0.1

Using the vcenter Orchestrator Perspectives Plug-In

vsphere Guest Programming Guide VMware vsphere Guest SDK 4.0

VMware vcenter AppSpeed User s Guide AppSpeed 1.0 EN

Application Discovery Manager User s Guide vcenter Application Discovery Manager 6.2.2

VMware vcenter AppSpeed Installation and Upgrade Guide AppSpeed 1.2

VMware vrealize Configuration Manager Backup and Disaster Recovery Guide vrealize Configuration Manager 5.8

Customizing the vsphere Client VMware vsphere Web Services SDK 4.1

Developing and Deploying vsphere Solutions, vservices, and ESX Agents

Using the vrealize Orchestrator Operations Client. vrealize Orchestrator 7.5

Using vrealize Operations Tenant App as a Service Provider

VMware Skyline Collector Installation and Configuration Guide. VMware Skyline 1.4

Infrastructure Navigator User's Guide

Configuring Single Sign-on from the VMware Identity Manager Service to Marketo

VMware vrealize Configuration Manager SQL Migration Helper Tool User's Guide vrealize Configuration Manager 5.8

VMware Skyline Collector Installation and Configuration Guide. VMware Skyline Collector 2.0

Reconfiguring VMware vsphere Update Manager. Update 1 VMware vsphere 6.5 vsphere Update Manager 6.5

vrealize Operations Manager Customization and Administration Guide vrealize Operations Manager 6.4

vcenter Orchestrator Installation and Configuration Guide

vsphere Web Client Extensions Programming Guide vsphere 5.1

QuickStart Guide vcenter Server Heartbeat 5.5 Update 1 EN

VMware Skyline Collector User Guide. VMware Skyline 1.4

Using the vcenter Orchestrator Plug-In for vcloud Director 1.0

Getting Started with ESXi Embedded

VMware vfabric Data Director Installation Guide

Using VMware Identity Manager Apps Portal

Compatibility Matrixes for VMware vcenter Site Recovery Manager 4.0 and Later

vcloud SDK for.net Developer s Guide VMware vcloud SDK 1.0

Programming Guide Guest SDK 3.5

DCLI User's Guide. Data Center Command-Line Interface 2.9.1

VMware vfabric AppInsight Installation Guide

vcenter Server Heartbeat Administrator's Guide VMware vcenter Server Heartbeat 6.6 Update 2

DCLI User's Guide. Data Center Command-Line Interface 2.7.0

vcloud Director Administrator's Guide

Port Adapter Installation and Configuration Guide

Developing and Deploying vsphere Solutions, vservices, and ESX Agents

Reconfiguring VMware vsphere Update Manager. 17 APR 2018 VMware vsphere 6.7 vsphere Update Manager 6.7

VMware vcenter Configuration Manager Administration Guide vcenter Configuration Manager 5.7

Installing and Configuring vcenter Multi-Hypervisor Manager

Installing and Configuring vcloud Connector

VMware vfabric Data Director Installation Guide

vsphere Upgrade Guide

vsphere Basic System Administration

vshield API Programming Guide

Cloud Pod Architecture with VMware Horizon 6.1

Getting Started with ESX Server 3i Installable Update 2 and later for ESX Server 3i version 3.5 Installable and VirtualCenter 2.5

DCLI User's Guide. Modified on 20 SEP 2018 Data Center Command-Line Interface

Developing and Deploying vsphere Solutions, vservices, and ESX Agents. 17 APR 2018 vsphere Web Services SDK 6.7 vcenter Server 6.7 VMware ESXi 6.

DCLI User's Guide. Data Center Command-Line Interface

Using the VMware vcenter Orchestrator Client. vrealize Orchestrator 5.5.1

Installing vrealize Network Insight

vcenter Operations Manager for Horizon View Administration

Best Practices and Troubleshooting Guide

vrealize Production Test

VMware Identity Manager Connector Installation and Configuration (Legacy Mode)

vcenter Orchestrator Administration Guide

VMware Horizon Migration Tool User Guide

Developing and Deploying vsphere Solutions, vservices, and ESX Agents

VMware App Volumes Installation Guide. VMware App Volumes 2.13

vsphere Datacenter Administration Guide

vrealize Operations Service Discovery Management Pack 2.0

Workspace ONE UEM Certificate Authentication for Cisco IPSec VPN. VMware Workspace ONE UEM 1810

vsphere Basic System Administration

PostgreSQL Solution 1.1

Installing and Configuring vcloud Connector

Virtual Infrastructure Web Access Administrator s Guide Update 2 and later for ESX Server 3.5 and VirtualCenter 2.5

Using the VMware vrealize Orchestrator Client

Setup for Microsoft Cluster Service Update 1 Release for ESX Server 3.5, ESX Server 3i version 3.5, VirtualCenter 2.5

Getting Started with VMware View View 3.1

Using the vrealize Orchestrator Plug-In for vrealize Automation 7.0. vrealize Orchestrator 7.0

Deploying VMware Identity Manager in the DMZ. JULY 2018 VMware Identity Manager 3.2

vsphere SDK for Perl Installation Guide vsphere 4.0 EN

vcenter Server Installation and Setup Update 1 Modified on 30 OCT 2018 VMware vsphere 6.7 vcenter Server 6.7

vshield Administration Guide

vrealize Business for Cloud Troubleshooting Guide

vsphere Client Hardware Health Monitoring VMware vsphere 4.1

Using the Horizon vrealize Orchestrator Plug-In

IaaS Integration for Multi-Machine Services

Installing vrealize Network Insight. VMware vrealize Network Insight 3.3

Administration Guide vshield Zones 1.0 EN

vsphere SDK for.net Developer s Guide VMware vsphere SDK for.net 4.1 EN

VMware vrealize Operations for Horizon Installation

Deploying VMware Identity Manager in the DMZ. SEPT 2018 VMware Identity Manager 3.3

Developing Web Views for VMware vcenter Orchestrator

vsphere Upgrade Update 2 Modified on 4 OCT 2017 VMware vsphere 6.0 VMware ESXi 6.0 vcenter Server 6.0

Transcription:

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

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. 3401 Hillview Ave. Palo Alto, CA 94304 www.vmware.com 2 VMware, Inc.

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 Fixed Cost Value 19 Generate a Report 20 VMware, Inc. 3

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 Documentation The vcenter Chargeback documentation comprises the following guides: vcenter Chargeback User s Guide vcenter Chargeback API Programming Guide vcenter Chargeback API Reference Guide Technical Support and Education Resources The following sections describe the technical support resources available to you. To access the current version of this book and other books, go to http://www.vmware.com/support/pubs. Online and Telephone Support To use online support to submit technical support requests, view your product and contract information, and register your products, go to http://www.vmware.com/support. Customers with appropriate support contracts should use telephone support for the fastest response on priority 1 issues. Go to http://www.vmware.com/support/phone_support. Support Offerings To find out how VMware support offerings can help meet your business needs, go to http://www.vmware.com/support/services. VMware, Inc. 5

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. To access information about education classes, certification programs, and consulting services, go to http://www.vmware.com/services. 6 VMware, Inc.

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. This Web based application interacts with the vcenter Database to retrieve usage information, calculates the cost by using the defined Chargeback formulas, and generates reports. vcenter Chargeback runs on an Apache Tomcat server instance. The user interacts with the vcenter Chargeback application through a load balancer (Apache HTTP Server). vcenter Chargeback connects to a Chargeback database that stores information such as the defined hierarchies, cost model, users, roles, and so on. The application also interacts with the vcenter Server and vcenter Database through a Data Collector. The Data Collector uses VIM APIs to communicate with the vcenter Server and JDBC to communicate with the vcenter Database. vcenter Chargeback APIs provide an interface for application developers to programmatically use the functionality of vcenter Chargeback. For more information about Chargeback and its capabilities, see the vcenter Chargeback User s Guide. REST Architecture vcenter Chargeback APIs implement the Representational State Transfer (REST) architecture. REST based APIs typically help you send HTTP requests for resources over the network and receive responses. VMware, Inc. 7

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. Request Type Mapping Request Type POST GET PUT DELETE CRUD Operation CREATE READ UPDATE/CREATE DELETE Responses When an API task is successful, the value of the status field in the response XML is set to success as shown in the following example. <?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> 8 VMware, Inc.

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. <?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> Table 1-2. Components of Error Elements Element majorerrorcode minorerrorcode vendorspecificerrorcode (Optional) message ErrorStackTrace Description The class of the error. It represents the HTTP Status codes. The specific API error code. For example, it can indicate that hierarchy creation failed. A vendor/implementation specific error code that points to specific modules/parts of the code and can make problem diagnostics easier. For example, it can indicate if a code snippet is a vcenter error code or a Database error code. A one line, human readable message that describes the error that occurred. This element is present when the log level in Chargeback is set to Debug. Common Elements in the Request and Response XMLs The common XML elements used by the request and response XMLs are presented in the following table. Refer to the earlier sections for sample request and response XMLs. Table 1-3. Common Elements Element Request Response status Is Valid License Description An API request starts with this element. An API response starts with this element. Denotes whether API is successfully executed. Indicates the status of the license. Value can be true or false. Chargeback API Syntax Each vcenter Chargeback API has this syntax: <HTTP_request_method> <Base_Url>/<API_signature>?version=1.0.1 For example, GET https://123.123.123.123/vcenter-cb/api/hierarchies?version=1.0.1 Table 1-4. API Syntax Components Syntax Component HTTP_request_method Base_Url, API_signature Description PUT, POST, GET, or DELETE The URL of the Chargeback host. The base URL for vcenter Chargeback APIs is: https://<chargeback server IP>/vCenter-CB/api For example, https://123.123.123.123/vcenter-cb/api The URL path for a Chargeback API. For example, /hierarchies retrieves the hierarchies added to the Chargeback server running on 123.123.123.123. version API version. For Chargeback server 1.0.1, it needs to be passed as 1.0.1. VMware, Inc. 9

vcenter 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. <?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> The request states that, vcenter Chargeback API version 1.0.1 needs to be called. If the request is for vcenter Chargeback server version 1.0, this call fails. If the request is for vcenter Chargeback server 1.0.1, the call succeeds and gets a response as follows. <?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> This response indicates that vcenter Chargeback API 1.0.1 is called. All the APIs starting from version 1.0.1 will be backward compatible. That is, a request for vcenter Chargeback API 1.0.1 to vcenter Chargeback 1.2 server, will be valid. The API version, if being specified, should be present in both the request XML (wherever applicable) and in the URL. If it is specified only in the request XML or the URL and not both, then the API displays an error. If the API version is absent in both the URL and the request XML (wherever applicable), then the API returns the output corresponding to the latest version. URI Versioning In the URI of an API, you can pass an optional parameter to indicate the output version you expect as shown in the following example: HTTP_request_method> <Base_Url>/<API_signature>?[version=1.0.1] If you do not provide the version, the API returns the output corresponding to the latest version. 10 VMware, Inc.

2 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. The chapter includes the following topics: Introduction to the Case Study on page 11 Login to vcenter Chargeback Server on page 12 Add vcenter Server Information on page 13 Create a Custom Chargeback Hierarchy on page 15 Add a vcenter Server Entity to the Chargeback Hierarchy on page 16 Add a Fixed Cost on page 18 Modify a Fixed Cost Value on page 19 Generate a Report on page 20 Introduction to the Case Study ABC has a presence across geographic regions such as Asia Pacific (APAC), Europe, the Middle East and Africa (EMEA), and Japan. In each of these regions, their offices are located in multiple cities. For example, in Japan, among other cities, ABC also has an office in Tokyo. This office has a number of ESX hosts that run many virtual machines. The company wants to create a hierarchy of resources and measure the cost of resources for each office and for each region as represented in Figure 2 1. Figure 2-1. Sample Hierarchy for ABC VMware, Inc. 11

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. The syntax for this API is <HTTP_request_method> <Base_URL>/login. For example, you can define a call as follows: POST https://123.123.123.123/vcenter-cb/api/login. Use the URL parameter version to specify the API version to be called. This API takes a request XML in which you can specify the following login details: LDAP server ID User type User name Password The following is a sample request XML file: <?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> 12 VMware, Inc.

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. /** * 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(); If the login succeeds, the API returns a response XML that indicates the status of the operation. Add vcenter Server Information Use the Add vcenter Server API to add vcenter servers instances in your virtualized environment to vcenter Chargeback. This helps determine the computing resources utilization for the virtual machines and calculate the total costs. The URL for this API is <HTTP_request_method> <Base_URL>/vCenterServer. You can define a sample call as follows: POST https://123.123.123.123/vcenter-cb/api/vcenterserver. The Add vcenter Server API takes a request XML that captures the following information: vcenter Server Hostname/IP: FQDN or IP address of the vcenter Server. vcenter Server Name: A display name for the vcenter Server. vcenter Server Description: A description of the vcenter Server. This is optional. VMware, Inc. 13

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. For Oracle database, the database URL can be in one of the following formats: <IP Address>:<TNS Listener Port> <Host Name>:<TNS Listener Port> For SQL Server, the database URL can be in one of the following formats: <IP Address>\<Database Instance Name> <Host Name>\<Database Instance Name> Database Name: The name of the vcenter Server database. For example, vim_vcdb, which is the default name given by vcenter Server. Database Username: A database user name to access the vcenter Database. Database Password: A password for the database user name entered. Database Type: The database type can be either SQL Server (default) or Oracle. An ID value of 1 means SQL server and 2 means Oracle. DataSourceAuthType: The authentication type ID, which for SQL server can be Windows authentication or database authentication. The ID 1 means Credential based Authentication and the ID 2 indicates Windows authentication. vcenter Server View Type: The type of view to be used to display the entities in the vcenter Server hierarchy. This can be either Hosts and Clusters or Virtual Machines and Templates. An id value of 1 indicates Hosts and Clusters and a value of 2 indicates Virtual Machines and Templates. These view types are the same as the corresponding vcenter Server view types, and the entities in the vcenter Server hierarchy will be displayed in a manner similar to the vcenter Server views. Once set, this option cannot be edited for the vcenter Server. Register As VI Client Plugin: Select this option if you would like to register vcenter Chargeback as a plug in to VI Client. If you select this option, each time you log in to this vcenter Server using the VI Client, the vcenter Chargeback plug in is displayed on the VI Client. You can access the vcenter Chargeback application from the VI Client. Enable Stats Replication: Select this option if you want the resource usage statistics from the vcenter Server Database to be replicated in the vcenter Chargeback Database. The following is a sample request XML. <?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" /> 14 VMware, Inc.

Chapter 2 Understanding the Workflow <ForceUpdate>false</ForceUpdate> </VCenterServer> </VCenterServers> </Request> 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. /** * 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(); If the vcenter Server is successfully added, the API returns an XML that provides the vcenter Server identifier. Create a Custom Chargeback Hierarchy Use the Add a Chargeback Hierarchy API to create a hierarchy with the given name and description. The URL for this API is <HTTP_request_method> <Base_URL>/hierarchy. You can define a sample call like this: POST https://123.123.123.123/vcenter-cb/api/hierarchy The API takes a request XML in which you can specify the name and description for the hierarchy. A sample input XML is provided below. <?xml version="1.0" encoding="utf-8"?> <Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1"> <Hierarchies> <Hierarchy> VMware, Inc. 15

vcenter Chargeback API Programming Guide <Name>Test_Hierarchy</Name> <Description>Test Hierarchy</Description> </Hierarchy> </Hierarchies> </Request> 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. /** * 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(); If successful, the API returns the new hierarchy. Add a vcenter Server Entity to the Chargeback Hierarchy This API helps you create a vcenter Server entity under a specified parent entity in a Chargeback hierarchy. The URL for this API is <HTTP_request_method> <Base_URL>/hierarchy/{hierarchyId/entity/{parentEntityId. You can define a call like this: POST https://123.123.123.123/vcenter-cb/api/hierarchy/11/entity/101. The API takes a request XML file in which you can specify the hierarchy identifier, entity name and description for the hierarchy. A sample request XML is provided below. <?xml version="1.0" encoding="utf-8"?> <Request xmlns="http://www.vmware.com/vcenter/chargeback/1.0.1"> <Hierarchies> 16 VMware, Inc.

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> The following is a sample program that calls the Add an Entity API. Make sure that you: Update the request XML for Login API with required values and run the login.java sample code. Run AddVCenterServer.java and read the vcid from the response Read the vcentity Id which you need to add under vcenter ChargeBack hierarchy entity, from the response of samplegetvchierarchymethod() Add a vcenter ChargeBack Hierarchy and from the response, read the hierarchy Id and the CBEntity Id under which the vcentity is to be added Update the Hierarchy id, cbentity id, VCenterServer id and vcentity id in the request XML file. /** * 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()); VMware, Inc. 17

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 <HTTP_request_method> <Base_URL>/fixedCost. You can define a call like this: POST https://123.123.123.123/vcenter-cb/api/fixedcost The API takes a request XML file in which you can specify the fixed cost name and its description. The following is a sample request XML. <?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> The following is a sample program that calls the Add an Fixed Cost API. Make sure that you: Update the Login-request.xml with required values and run the login.java sample code. Update the addfixedcost-request.xml with fixed cost name and its description. /** * 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"; 18 VMware, Inc.

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. Modify a Fixed Cost Value Using the Modify Fixed Cost API, you can update fixed cost id, value and duration for a fixed cost. The URL for this API is <HTTP_request_method> <Base_URL>/fixedCost/{fixedCostId/values. You can define a call like this: PUT https://123.123.123.123/vcenter-cb/api/fixedcost/{fixedcostid/values The API takes a request XML file in which you can specify the fixed cost name and its description. The following is a sample request XML. <?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> The following is a sample program that calls the Add an Fixed Cost API. Make sure that you: Update the Login-request.xml with required values and run the login.java sample code. Run the Add Fixed Cost API and read the fixedcostid from the response. Update the fixed Cost Id, the cost and duration id in modifyfixedcostvalues-request.xml file. /** * 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, VMware, Inc. 19

vcenter Chargeback API Programming Guide Generate a Report 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(); Using the Generate a Raw Report API, you can generate a report that provides information on cost details for the given entity. The URL for this API is <HTTP_request_method> <Base_URL>/rawReport. You can define a call like this: POST https://123.123.123.123/vcenter-cb/api/rawreport The API takes a request XML file in which you can specify details about the hierarchy, entity, resource counters and the cost model. The following is a sample request XML. <?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> 20 VMware, Inc.

Chapter 2 Understanding the Workflow <BillingScheduleType>NOW</BillingScheduleType> <BillingPeriod> <Now> <StartDate>1211871400000</StartDate> <EndDate>1232399800000</EndDate> </Now> </BillingPeriod> <DataFilter> <DataDepth>1</DataDepth> <ExcludeFilters> <Filter id="categorizedcosts" /> <Filter id="categorizedusage" /> <Filter id="informationmessages" /> <Filter id="costdetails" /> </ExcludeFilters> </DataFilter> </ReportTemplate> </ReportTemplates> </Request> The following is a sample program that calls the Generate Raw Report API. Make sure that you: Update the request XML for Login API with required values and run the login.java sample code. Run AddVCenterServer.java and read the vcid from the response. Read the vcentity Id, which you need to add under vcenter ChargeBack hierarchy entity, from the response of samplegetvchierarchymethod() Add a vcenter ChargeBack Hierarchy and from the response, read the hierarchy Id and CBEntity Id under which the vcentity is to be added. Update the Hierarchy id, cbentity id, VCenterServer id and vcentity id in AddVCenterEntity-request.xml file. Add the vcentity under vcenter ChargeBack hierarchy entity by calling method addnewvcenterserverentity() Update the Hierarchy id, Entity id (on which you want to generate report), StartDate and EndDate in GenerateRawReport-request.xml. /** * This method is to generate report for a vcenter-chargeback hierarchy * entity in vcenter-chargeback * * @param requestfilepath * @param baseurl * @throws IOException * @throws JDOMException * @throws NoSuchAlgorithmException * @throws KeyManagementException * @throws HttpException */ @SuppressWarnings("deprecation") public static void samplegeneratereportmethod(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/rawreport"; System.out.println(uri); System.out.println(bodyString); VMware, Inc. 21

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.