10-29-2015 03:59 AM - edited 03-01-2019 06:38 AM
Task Name | UCSD and UCSM HTTP integration Example |
Description |
|
Prerequisites |
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs |
Instructions for Regular Workflow Use:
Custom Workflow Task : GetUCSM_ServiceProfileBootOrder
This task has 4 inputs : uri, username, passwd, serviceprofilename
This task has 4 outputs : vHBA0_P, vHBA0_S, vHBA1_P, vHBA1_S
This task has a Cloupia Script .
The Script does the following
—>Login to UCS-XML-API using xml over http
—>get session cookie
—>Use the cookie to fetch other details
—>Parse Xml response , get the required output data(wwn)
TEST using Sample Workflow : Get UCSM boot Order
This w/f has 4 inputs associated with admin input ( done for ease of testing … However these inputs can be mapped to the output from prior tasks in any other workflow)
Code Example:
importPackage(java.io);
importPackage(javax.xml.xpath);
importPackage(org.apache.commons.httpclient);
importPackage(org.apache.commons.httpclient.methods);
importPackage(org.xml.sax);
importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.service.cIM.inframgr);
var UCSM_URI = "UCSM_URI";
var UCSM_Username = "UCSM_Username";
var UCSM_Password = "UCSM_Password";
var UCSM_ServiceProfile = "UCSM_ServiceProfile";
// var url = "http://" + ctxt.getInput(UCSM_URI) + ":80/nuova";
// var username = ctxt.getInput(UCSM_Username);
// var password = ctxt.getInput(UCSM_Password);
// var serviceProfile = ctxt.getInput(UCSM_ServiceProfile);
var url = "http://" + input.UCSM_URI + ":80/nuova";
var username = input.UCSM_Username;
var password = input.UCSM_Password;
var serviceProfile = input.UCSM_ServiceProfile;
// =====================================================
var cookie;
var quesryResp;
logger.addInfo("=================BEGIN=================");
logger.addInfo("========LOGIN to UCS XML API========");
doLogin();
logger.addInfo("========UCS Query set context========");
doQueryDN("org-root/ls-" + serviceProfile, false);
logger.addInfo("========UCS Query Fetch Data========");
var responseXML = doQueryDN("org-root/boot-policy-SAN_Boot/storage", true);
logger.addInfo("========LOGOUT frm UCS XML API========");
doLogout();
logger.addInfo("========Parse Response and get data========");
getStorageBootOrder(responseXML);
logger.addInfo("=================END=================");
// =====================================================
function doLogin() {
var loginxml = "<aaaLogin inName='" + username + "' inPassword= '" + password + "'></aaaLogin>";
logger.addInfo("loginXML:" + loginxml);
var xml = doPostXML(loginxml);
logger.addInfo("tokenXML:" + xml);
cookie = getXpathData("//aaaLogin/@outCookie", xml);
logger.addInfo("token:" + cookie);
}
function doLogout() {
var logoutxml = "<aaaLogout inCookie='" + cookie + "'></aaaLogout>";
logger.addInfo("logoutxml:" + logoutxml);
var xml = doPostXML(logoutxml);
logger.addInfo("logoutRespxml:" + xml);
}
function doQueryDN(queryPath, inHierarchical) {
var queryxml = "<configResolveDn dn='" + queryPath + "' cookie='" + cookie + "' inHierarchical='" + inHierarchical + "'/>";
var xml = doPostXML(queryxml);
logger.addInfo("Result:" + queryPath + ": " + xml);
return xml;
}
function doQueryChildren(queryPath) {
var queryxml = "<configResolveChildren inDn='" + queryPath + "' cookie='" + cookie + "' inHierarchical='" + inHierarchical + "'/>";
var xml = doPostXML(queryxml);
logger.addInfo("Result:" + xml);
}
function getStorageBootOrder(xml) {
var vHBA0_P = getXpathData("/configResolveDn/outConfig/lsbootStorage[@dn='org-root/boot-policy-SAN_Boot/storage']/lsbootSanImage[@type='primary']/lsbootSanImagePath[@type='primary']/@wwn", xml);
var vHBA0_S = getXpathData("/configResolveDn/outConfig/lsbootStorage[@dn='org-root/boot-policy-SAN_Boot/storage']/lsbootSanImage[@type='primary']/lsbootSanImagePath[@type='secondary']/@wwn", xml);
var vHBA1_P = getXpathData("/configResolveDn/outConfig/lsbootStorage[@dn='org-root/boot-policy-SAN_Boot/storage']/lsbootSanImage[@type='secondary']/lsbootSanImagePath[@type='primary']/@wwn", xml);
var vHBA1_S = getXpathData("/configResolveDn/outConfig/lsbootStorage[@dn='org-root/boot-policy-SAN_Boot/storage']/lsbootSanImage[@type='secondary']/lsbootSanImagePath[@type='secondary']/@wwn", xml);
logger.addInfo("vHBA0_P:" + vHBA0_P);
logger.addInfo("vHBA0_S:" + vHBA0_S);
logger.addInfo("vHBA1_P:" + vHBA1_P);
logger.addInfo("vHBA1_S:" + vHBA1_S);
output.vHBA0_P = vHBA0_P;
output.vHBA0_S = vHBA0_S;
output.vHBA1_P = vHBA1_P;
output.vHBA1_S = vHBA1_S;
// ctxt.setOutputValue("vHBA0_P",vHBA0_P)
}
function getXpathData(xpathString, xml) {
var xpathFactory = XPathFactory.newInstance();
var xpath = xpathFactory.newXPath();
var source = new InputSource(new StringReader(xml));
try {
var msg = xpath.evaluate(xpathString, source);
return msg;
} catch (e) {
logger.addInfo("ERROR :" + e);
}
return "";
}
function doPostXML(data) {
var br = null;
var xml = "";
var httpClient = new HttpClient();
httpClient.getParams().setParameter("http.useragent", "UCSD Script Client");
var httpMethod = new PostMethod(url);
httpMethod.setRequestEntity(new StringRequestEntity(data));
httpMethod.addRequestHeader("Content-Type", "application/xml");
try {
var statuscode = httpClient.executeMethod(httpMethod);
if (statuscode != 200) {
// logger.addError("Error in invocation "+statuscode);
} else {
br = new BufferedReader(new InputStreamReader(httpMethod.getResponseBodyAsStream()));
var readLine = "";
var response = "";
while (((readLine = br.readLine()) != null)) {
response = response + readLine;
}
xml = response.toString();
}
} catch (e) {
logger.addInfo("ERROR :" + e);
} finally {
httpMethod.releaseConnection();
if (br != null)
try {
br.close();
} catch (fe) {}
}
return xml;
}
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: