Skip to content

Instantly share code, notes, and snippets.

View jreypo's full-sized avatar
🇪🇸
Living life my way

Juanma jreypo

🇪🇸
Living life my way
View GitHub Profile
@jreypo
jreypo / cbm_db_create.sql
Last active January 2, 2016 03:29
SQL script to create the vCenter Chargeback database in Microsoft SQL Server
use [master]
GO
CREATE DATABASE [CBDB] ON PRIMARY
(NAME = N'CBDB', FILENAME = N'E:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\CBDB.mdf' , SIZE = 200000KB , FILEGROWTH = 10% )
LOG ON
(NAME = N'CBDB_log', FILENAME = N'E:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\CBDB.ldf' , SIZE = 20000KB , FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO
use [CBDB]
@jreypo
jreypo / xml_auth_cbm.xml
Created April 20, 2014 12:42
XML payload for CBM REST API authentication
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="http://www.vmware.com/vcenter/chargeback/2.0">
<Users>
<User>
<LdapServerId></LdapServerId>
<Type>local</Type>
<Name>admin</Name>
<Password>vmware123</Password>
</User>
</Users>
@jreypo
jreypo / cbm_create_hierarchy.xml
Created April 20, 2014 13:49
XML payload for CBM REST API to create a new hierarchy
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Hierarchies>
<Hierarchy>
<Name>Test_Hierarchy</Name>
<Description>Test Hierarchy</Description>
</Hierarchy>
</Hierarchies>
</Request>
@jreypo
jreypo / list_hierarchies.js
Created April 20, 2014 13:56
Get CBM hierarchy list
var cbmHierarchyList = hierarchyList;
for each (var hierarchy in cbmHierarchyList){
System.log("Hierarchy: " + hierarchy.name);
}
var hierarchyName = "DevOrg";
var cbmHierarchy = cbmServer.getHierarchyByName(hierarchyName,cbmVersion);
var hierarchyId = cbmHierarchy.chargebackId;
System.log("Hierarchy ID: " + hierarchyId);
//API request payload in XML format
var payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Request xmlns=\"http://www.vmware.com/vcenter/chargeback/" + cbmVersion + "\">" +
" <Users>" +
" <User>" +
" <LdapServerId></LdapServerId>" +
" <Type>local</Type>" +
" <Name>" + cbmUser + "</Name>" +
" <Password>" + cbmPassword + "</Password>" +
" </User>" +
// Check operation status for success or failure
responseArray = (apiResponse.contentAsString).split("\n");
responseElement = responseArray[1];
System.log(responseElement);
var operationStatus = responseElement.indexOf("status\=\"success\"");
if (operationStatus != -1) {
var loginStatus = "OK";
System.log("Status OK");
} else {
var loginStatus = "NOK";
//API request payload in XML format
var payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Request xmlns=\"http://www.vmware.com/vcenter/chargeback/" + cbmVersion + "\">" +
" <Hierarchies>" +
" <Hierarchy>" +
" <Name>" + hierarchyName + "</Name>" +
" <Description>" + hierarchyDescription + "</Description>" +
" </Hierarchy>" +
" </Hierarchies>" +
"</Request>";
//API request payload in XML format
var payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Request xmlns=\"http://www.vmware.com/vcenter/chargeback/" + cbmVersion + "\">" +
" <FixedCosts>" +
" <FixedCost>" +
" <Name>" + fixedCostName + "</Name>" +
" <Description>" + fixedCostDescription + "</Description>" +
" <Currency id=\"" + fixedCostCurrency + "\"/>" +
" <IsProrated>" + isProrated + "</IsProrated>" +
" <IsPowerStateBased>" + isPowerStateBased + "</IsPowerStateBased>" +