Jayant Kaushal
ServiceNow Employee
ServiceNow Employee

In continuation to the last article where we talked about invoking CAPI operations through background scripts (Cloud Management : Invoking Cloud APIs through Scripts).

Once you are done testing you CAPI operations, you will want to hook them up in resources and test them out at the resource level,

Here, I will walk you through way to invoke resource operations through scripts. With this, you can test individual components of a resource.

1.How the expressions (Stack/CI/Script etc) are evaluated .

2.Host delegation: credentials/endpoints are getting resolved.

3.Response Mappings are populating CIs as expected.

 

Look at the way we are invoking a resource operation on a Virtual Server >> Stop operation.

var os = new sn_cmp_api.OrderServiceScript();
var data = 
{
  "entityType": "Resource", // tells us that its a resource operation
  "operationName": "Virtual Server Interface.Stop", // Interface Name.OperationName
  // order form data to execute the operation, this will vary based on the operatiomn you are trying to execute.
  "orderFormData": {
 "resourceId": "540ebd13778f3300761a54389a1061cf"
  },
  // Type of Resource on which you want to execute your operation
  "resource": "Virtual Server",
  // user which is making the order.
  "userId": "6816f79cc0a8016401c5a33be04be441"
}
var order = os.submitOrder(new global.JSON().encode(data));

2: Invoking AWS Datacenter Discovery :

 

var os = new sn_cmp_api.OrderServiceScript();
var data = 
{

  "entityType": "Resource", // tells us that its a resource operation
  "operationName": "Discovery Interface.ListDatacenters", // Interface Name.OperationName
  // order form data to execute the operation, this will vary based on the operatiomn you are trying to execute.
  "orderFormData": {
    "CloudServiceAccountId": "123456789876", // object_id of the ServiceAccount
    "Credential": "48f85dd377c233007d6054389a106141" // credential of the datacenter
  },
  // Type of Resource on which you want to execute your operation
  "resource": "AWS Datacenter",
  // user which is making the order.
  "userId": "6816f79cc0a8016401c5a33be04be441"
}

var order = os.submitOrder(new global.JSON().encode(data));
Version history
Last update:
‎08-09-2019 04:14 AM
Updated by: