Task Name | Container cloning |
Description |
|
Prerequisites | - Tested on 5.3
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs | |
Instructions for Regular Workflow Use:
- Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
- Unzip the file on your computer. Should end up with a .WFD file.
- Log in to UCS Director as a user that has "system-admin" privileges.
- Navigate to "Policies-->Orchestration" and click on "Import".
- Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
- Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
- Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
- Click "Submit".
- A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.
Credits go to Wei Zixi
The workflow after import:
The workflow inputs:
Workflow Execution:
Simple workflow to call custom task:
Custom Task Java Script:
mportPackage(java.io);
importPackage(java.lang);
importPackage(java.util);
importPackage(org.json);
importPackage(org.apache.commons.httpclient);
importPackage(org.apache.commons.httpclient.methods);
importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.service.cIM.inframgr);
importPackage(com.cloupia.lib.util);
// Handle Task Input, the API key is now manually obtained from GUI
// var APIkey = "6D9933046E054EE5816102343B8BLAEE";
// Handle User Input
var orgContainer = input.orgContainer;
var dstContainer = input.dstContainer;
var APIkey = input.APIkey;
logger.addInfo('Original Container ID is: '+orgContainer);
logger.addInfo('Destination Container is: '+dstContainer);
// Craft API Request to retrieve Container Name
var RCNURL = '/app/api/rest?formatType=json&opName=fenced:userAPIGetServiceContainerDetails&opData={param0:'+orgContainer+'}';
var APIcall = encodeURI(RCNURL);
logger.addInfo('Request URL is: '+APIcall);
// Retrieve Container Name via API
var httpClient = new HttpClient();
httpClient.getHostConfiguration().setHost("127.0.0.1", 80, "http");
var httpMethod = new PostMethod(APIcall);
httpMethod.addRequestHeader("X-Cloupia-Request-Key", APIkey);
httpClient.executeMethod(httpMethod);
var statuscode = httpMethod.getStatusCode();
if (statuscode != 200)
{
logger.addError("Request failed. HTTP response code: "+statuscode);
logger.addError("Response = "+httpMethod.getResponseBodyAsString());
httpMethod.releaseConnection();
// Set this task as failed.
ctxt.setFailed("Request failed.");
} else {
logger.addInfo("Request was Succcessful.");
logger.addInfo("Response = "+httpMethod.getResponseBodyAsString());
var SCname = new InputStreamReader(httpMethod.getResponseBodyAsStream());
SCname = JSON.getJsonElement(SCname, null);
SCname = JSON.getJsonElement(SCname, 'serviceResult');
SCname = JSON.getJsonElement(SCname, 'rows');
SCname = SCname.get(0);
SCname = JSON.getJsonElement(SCname,"Overview_containerName");
SCname = String(SCname);
SCname = SCname.replace(/"/g, "");
logger.addInfo('Original Service Container name is: '+SCname);
}
httpMethod.releaseConnection();
// Craft API Request to clone Container
var URL = '/app/api/rest?formatType=json&opName=fenced:userAPICloneServiceContainer&opData={param0:"'+SCname+'",param1:"'+dstContainer+'"}';
logger.addInfo('Request URL is: '+URL);
var CreateAPIcall = encodeURI(URL);
// Clone Service Container via API
var httpClient = new HttpClient();
httpClient.getHostConfiguration().setHost("10.11.11.11", 80, "http");
var httpMethod = new PostMethod(CreateAPIcall);
httpMethod.addRequestHeader("X-Cloupia-Request-Key", APIkey);
httpClient.executeMethod(httpMethod);
var statuscode = httpMethod.getStatusCode();
var childSrId = httpMethod.getResponseBodyAsString();
if (statuscode != 200)
{
logger.addError("Request failed. HTTP response code: "+statuscode);
logger.addError("Response = "+httpMethod.getResponseBodyAsString());
httpMethod.releaseConnection();
// Set this task as failed.
ctxt.setFailed("Request failed.");
} else {
logger.addInfo("Request was Succcessful.");
logger.addInfo("Response = "+httpMethod.getResponseBodyAsString());
}
httpMethod.releaseConnection();
childSrId = JSON.getJsonElement(childSrId, 'serviceResult');
childSrId = parseInt(childSrId);
logger.addInfo('childSrId is: '+childSrId);
var status = ctxt.waitForCompletion(childSrId, 1800000);
//provide waiting time
if (status == 0){
logger.addInfo("Child SR ID ="+ childSrId+ " completed successfully.");
} else {
logger.addError("Child SR ID ="+ childSrId+ " failed");
}