hpcsa.js
hpcsa.js is a nodejs library for automating Hewlett Packard's Cloud Service Automation product. You can use it to build testing tools and alternative front end interfaces to your cloud services.
This library uses promises. When you invoke any of the provided methods, a promise will be returned. If you're new to promises, read this and then come back.
Install
In a new, empty folder, run
> npm install hpcsa
and in your script, require the module:
var hpcsa = ;
Usage
First you need to log in to your CSA instance.
var hpcsa = ; var login = hpcsa login
Once you've verified this works, you can move onto actually doing stuff.
Order a subscription
Here's how to order a basic subscription (add this to the bottom of the above code):
login
I've left the subscriber options empty for the moment; if your service offering has default values for all the options, then you can go ahead and run the above to create a new subscription.
If you want to specify options, then just provide an object to the order method, like so:
login
In the subscriber options object you can specify either an option set display name. or a property name. The below screenshot shows both types. In the design shown, Compute Class is an option set, and PROJECTCODE is the real name of the Project Code property.
you can grab the option models (including default values) by running the following:
login // -> //- // offeringName: CSATesterOffering// offeringId: 2c9030e44f3fd64b014f4173135727e5// category: SIMPLE_SYSTEM// catalogId: 90d9650a36988e5d0136988f03ab000f// optionModel: // - // Small: true// - // Medium: false// - // Gargantuan: false// - // PROJECTCODE: P012345// - // SUPPORTTEAM: OPS//- // offeringName: CSATestercles// offeringId: 2c9030e44fdfb913014ff442cbd90006// category: SIMPLE_SYSTEM// catalogId: 90d9650a36988e5d0136988f03ab000f// optionModel: // - // Small: true// - // Medium: false// - // Gargantuan: false// - // PROJECTCODE: P012345// - // SUPPORTTEAM: OPS
Modify a subscription
login
Run a control action
login
Cancel a subscription
login
Putting it all together
Using promises allows us to easily chain and recombine asynchronous actions. Here's how you would order a new subscription, immediately modify it, and then finally cancel it:
login
Here's how you would create three subscriptions simultaneously!
var newSubs = [
[
"Global Shared Catalog",
"SIMPLE_SYSTEM",
"Windows 2008 R2 SQL server",
{"COLLATION":"Latin"}
"My SQL server",
],
[
"Global Shared Catalog",
"SIMPLE_SYSTEM",
"RHEL7 Virtual Server",
{}
"My app server",
],
[
"Global Shared Catalog",
"SIMPLE_SYSTEM",
"RHEL7 Virtual Server",
{"Install Apache": true}
"My web server",
]
]
login.then(function(){
//convert each array element to a promise
var promises = newSubs.map(function(sub){
return hpcsa.order.apply(this, sub)
})
// return when they're all done!
return Promise.all(promises)
})