logo

NJP

Cloud Management : Invoking Cloud APIs through Scripts

Import · Aug 08, 2019 · article

As you build new APIs/Operations, You would want to test just individual operations so that you can focus on your cloud/mid specific logic not how its invoked. In this article , I will share an example of Starting a vmware node through background scripts.

The script is self explanatory and gives enough info about each field.

For reference you can have a look at vSphere Compute API under Cloud APIs, which comes OOB.

// CAPI Interface
var interfaceName = "Compute Interface";
// Interface method
var methodName = "StartNode";
// version of API
var version = "1.0";
// CAPI Provider for API
var providerName = "vmware-compute";
// Endpoint -  optional, only valid for private clouds/apis.
var endpoint = "https://ip_addr/sdk";
// sys_id of credential associated with Service Account
var datacenterCredential = 'sys_id_of_vmware_credential';
//Datacenter Name
var datacenter = 'object_id_of_datacenter';
// object_id of the service account
var serviceAccount = 'service_account_object_id';
var apiParameters=new Object();
apiParameters['NodeID']='vm_inst_id';
apiParameters['Location']=datacenter;


// Create CAPI API Executor Object
var capi = new sn_cloud_api.CAPIOrchestratorServiceScript();

// execute the api call
capi.executeApi(providerName, version, datacenterCredential, interfaceName,methodName, endpoint, new JSON().encode(apiParameters),"",serviceAccount,datacenter); 

View original source

https://www.servicenow.com/community/itom-articles/cloud-management-invoking-cloud-apis-through-scripts/ta-p/2296268