forked from rubrikinc/vRO-Workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubrikAssignVMToSLA.js
51 lines (46 loc) · 1.54 KB
/
rubrikAssignVMToSLA.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// vRO Action rubrikAssignVMToSLA from package com.rubrik.library.rest.package
//
// NAME - TYPE - DESCRIPTION
// ----------------------------------------------------
// <INPUT PARAMETERS>
// tokenBase64 - string - Rubrik authentication token
// rubrikHost - REST:REST Host - Rubrik REST host
// vmId - string - Rubrik ID for VM
// slaID - string - SLA Domain ID
// api_url - string - Versioned API URL
//
// <RETURN VALUE>
// N/A - void - N/A
//Construct REST call
var method = "PATCH";
var url = api_url + "vmware/vm/" + vmId;
var content = '{"configuredSlaDomainId":"' + slaID + '"}';
var request = rubrikHost.createRequest(method, url, content);
var token = ("Basic " + tokenBase64);
request.contentType = "application\/json";
request.setHeader("Accept", "application/json");
request.setHeader("Authorization", token);
//Log REST Call Info
System.log("token = " + token);
System.log("REST URL = " + request.fullUrl);
System.log("REST Content = " + content);
//Execute REST Call
try {
var response = request.execute();
}
catch (ex) {
System.error(ex);
throw "Stopping Execution";
}
//Evaluate REST Response
var statusCode = response.statusCode;
if (statusCode == 200) {
System.log("REST Execution Successful");
}
else {
System.log("ERROR Executing REST operation");
System.error("Status Code = " + statusCode);
throw "Stopping Execution";
}
//log response
System.log("Response: " + response.contentAsString);