The Now Platform® Washington DC release is live. Watch now!
on ‎08-08-2019 12:06 AM
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);
Thanks for the useful tools you have been providing Jayant.
thanks, will keep them coming.
This will help in the dev and debugging of operations.
Having a ready made script to test SSH script execution can always come handy.
// CAPI Interface
var interfaceName = "Node Access Interface";
// Interface method
var methodName = "ExecuteSSHScript";
// version of API
var version = "1.0";
// CAPI Provider for API
var providerName = "node-access";
// Datacenter Endpoint - Blank as its not a datacenter call.
var endpoint = "";
// Datacenter Endpoint - Blank as its not a datacenter call.
var datacenterCredential = '';
//Datacenter ObjectId - if known,provide, will help you in reaching right Mid
var datacenter = 'us-east-1';
//ServiceAccount Object Id - if known , provide, will help you in reaching right Mid
var serviceAccount = '';
// Credential sys_id of the node.
var nodeCredentialId = '523a7bebdb27f700590e9258db9619fe';
// ip address of the node.
var nodeAddress = "10.33.115.57";
// script to be executed.
var script = 'sudo mkdir -p /tmp/snow_tmp_dir';
var apiParameters=new Object();
apiParameters['NodeCredential']='$(capiResolver.NodeCredentialResolver#nodeCredentialId='+nodeCredentialId+')';
apiParameters['NodeAddress']=nodeAddress;
apiParameters['Script']=script;
// 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);
How can we invoke Cloud APIs through Scripts for AWS (we are on Orlando)
For apiParameters['NodeID']='vm_inst_id';
What is the NodeID? We have no data populated in 'vm_inst_id' when running Discovery? Is it the same as 'object_id'? Any help would be appreciated.
Thanks!
Great solution Jayant,
Also thought worth adding this point, we might have to add new global.JSON().encode(apiParameters) in place of
new JSON().encode(apiParameters) to resolve Error: o,Detail: Unexpected token: o.
Also getting could not resolve this error Error: Could not resolve mid server for API request.
Also where can we check the processing of this script before it hits mid server?
Hi - in a related question - the patterns that i'm using for reference have a REST call in the format below - can someone point me to the API documentation for this and or tell me what the parameters are ? this works for GETs but i need to know how to do a POST
thanks
restApiQuery = cloudCall.cloudApiExecute(${service_account}, null, topicUrl, new Packages.java.util.HashMap(), 'GET', null, 'true', CTX);