Skip to content

Instantly share code, notes, and snippets.

Avatar
🇪🇸
Living life my way

Juan Manuel Rey jreypo

🇪🇸
Living life my way
View GitHub Profile
@jreypo
jreypo / xml_auth_cbm.xml
Created Apr 20, 2014
XML payload for CBM REST API authentication
View xml_auth_cbm.xml
<?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>
View get_hierarchy_id.js
var hierarchyId = cbmHierarchy.chargebackId;
System.log("Hierarchy ID: " + hierarchyId);
View cbm_ssl.bat
:generatePublicKeyAndCopy
echo "Generating a Self-Signed Certificate"...
openssl.exe x509 -req -days 365 -in default.csr -signkey default.key -out default.cert
if not %ERRORLEVEL%==0 goto :error
View rest_api_login.js
//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>" +
View rest_api_task_status.js
// 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";
View cbm_rest_api_new_hierarchy.js
//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>";
@jreypo
jreypo / cbm_create_hierarchy.xml
Created Apr 20, 2014
XML payload for CBM REST API to create a new hierarchy
View cbm_create_hierarchy.xml
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Hierarchies>
<Hierarchy>
<Name>Test_Hierarchy</Name>
<Description>Test Hierarchy</Description>
</Hierarchy>
</Hierarchies>
</Request>
View cbm_rest_new_fixed_cost.js
//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>" +
@jreypo
jreypo / list_hierarchies.js
Created Apr 20, 2014
Get CBM hierarchy list
View list_hierarchies.js
var cbmHierarchyList = hierarchyList;
for each (var hierarchy in cbmHierarchyList){
System.log("Hierarchy: " + hierarchy.name);
}
View get_hierarchy_by_name.js
var hierarchyName = "DevOrg";
var cbmHierarchy = cbmServer.getHierarchyByName(hierarchyName,cbmVersion);