03-07-2017 12:02 PM - edited 03-01-2019 06:45 AM
Task Name | UCSD internal API call example /cloupia/api-v2/hyperVDeploymentPolicy/HyperVPolicy1 and subsequent XML parsing |
Description | |
Prerequisites | Tested on UCSD 6.0.1.1 |
Category | Workflow |
Components | vSphere 5.x |
User Inputs |
Instructions for Regular Workflow Use:
The API call:
Turns out it is not looking for the ID but the name of the policy
The Workflow:
The domain tag that is looked for:
Workflow execution:
The Task and global variable combined:
The XML parse and the tag:
Custom Task Get API Info:
importPackage(com.cloupia.model.cIM);
importPackage(java.util);
importPackage(java.lang);
importPackage(java.io);
importPackage(com.cloupia.lib.util);
importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.service.cIM.inframgr);
importPackage(org.apache.commons.httpclient);
importPackage(org.apache.commons.httpclient.cookie);
importPackage(org.apache.commons.httpclient.methods);
importPackage(org.apache.commons.httpclient.auth);
importPackage(com.cloupia.model.cEvent.notify);
importPackage(com.cloupia.lib.util.mail);
importPackage(com.cloupia.fw.objstore);
importPackage(com.cloupia.lib.util.managedreports);
var url = input.URL;
// ctxt.getAPI().getMoResourceAsJson() available only in GB release.
//var resp = ctxt.getAPI().userAPIMoQuery("hyperVDeploymentPolicy",null,null);
var resp = ctxt.getAPI().userAPIMoQuery(url,null,null);
logger.addInfo("Response: "+resp);
output.out1 = resp;
Custom task XML parser:
importPackage(org.w3c.dom);
importPackage(javax.xml.parsers);
importPackage(java.io);
importPackage(java.lang);
importPackage(java.util);
var factory = DocumentBuilderFactory.newInstance();
var builder = factory.newDocumentBuilder();
var xmlStringBuilder = new StringBuilder();
xmlStringBuilder.append(input.XML);
var a1 = input.TAG;
logger.addInfo("a1 : " + a1);
var input = new ByteArrayInputStream( xmlStringBuilder.toString().getBytes('UTF-8') );
var doc = builder.parse(input);
doc.getDocumentElement().normalize();
var nList = doc.getElementsByTagName(a1);
logger.addInfo("Root element :" + doc.getDocumentElement().getNodeName());
logger.addInfo("nList length: " +nList.getLength() );
for (var i = 0; i < nList.getLength(); i++) {
var nNode = nList.item(i);
logger.addInfo("\nCurrent Element : " + nNode.getNodeName());
logger.addInfo("\nNodeType : " + nNode.getNodeType());
logger.addInfo("typeof nNode: "+typeof nNode);
var value = nNode.getTextContent();
logger.addInfo("Object: " + value );
output.object = value;
}
The run Log:
Service Request ID: 320
Workflow Inputs:
- HyperVSystemPolicyName
Mar 07, 2017 19:45:10 UTC Request submitted
Mar 07, 2017 19:45:10 UTC Executing workflow item number 1
Mar 07, 2017 19:45:10 UTC Completed workflow item number 1, with status Completed
Mar 07, 2017 19:45:16 UTC Executing workflow item number 2
Mar 07, 2017 19:45:16 UTC Trigger context executeWorkFlowStep called
Mar 07, 2017 19:45:16 UTC Executing custom action Get_API (custom_Get_API_INFO_v1)
Mar 07, 2017 19:45:16 UTC Executing custom action Get_API (custom_Get_API_INFO_v1)
Mar 07, 2017 19:45:16 UTC Executing custom script for Get_API_INFO_v1
Mar 07, 2017 19:45:16 UTC Response: <cuicOperationResponse><cuicOperationStatus>0</cuicOperationStatus><response><hyperVDeploymentPolicy><allowEndUserHostNameSuffix>false</allowEndUserHostNameSuffix><allowEndUserSuffix>false</allowEndUserSuffix><autoLogon>true</autoLogon><autoLogonCount>0</autoLogonCount><domain>TheDomainIAMlookingfor.com</domain><domainAdmin>user</domainAdmin><domainPassword>a2pmZGt3amVm</domainPassword><fullName></fullName><guiRunOnceCommands></guiRunOnceCommands><hostNameTemplate>host-${GROUP_NAME}-SR${SR_ID}</hostNameTemplate><joinTypeDomain>true</joinTypeDomain><licenseMode>Per-Seat</licenseMode><licenseUsers>5</licenseUsers><linuxDnsDomain></linuxDnsDomain><orgName></orgName><password>cGFzc3dvcmRAMTIz</password><policyDescription></policyDescription><policyId>1</policyId><policyName>Hypervsyspol1</policyName><powerOn>true</powerOn><productId></productId><recycleHostName>true</recycleHostName><recycleVMName>true</recycleVMName><rootPassword></rootPassword><SIDUnique>false</SIDUnique><timezone>4</timezone><username></username><vmImageType>Windows and Linux</vmImageType><vmNameTemplate>vm-${GROUP_NAME}-SR${SR_ID}</vmNameTemplate><workGroupName></workGroupName></hyperVDeploymentPolicy></response></cuicOperationResponse>
Mar 07, 2017 19:45:16 UTC Processing output: out1
Mar 07, 2017 19:45:16 UTC Task #2 (Get_API (custom_Get_API_INFO_v1)) completed successfully in 0 seconds
Mar 07, 2017 19:45:16 UTC Input/Output values for Task #2 (Get_API (custom_Get_API_INFO_v1)):
Mar 07, 2017 19:45:16 UTC [Template Input:URL = hyperVDeploymentPolicy/${HyperVSystemPolicyName}]
Mar 07, 2017 19:45:16 UTC [Resolved Template Input: URL = hyperVDeploymentPolicy/Hypervsyspol1]
Mar 07, 2017 19:45:16 UTC [Local Input: URL = hyperVDeploymentPolicy/Hypervsyspol1]
Mar 07, 2017 19:45:16 UTC [Output: out1 = <cuicOperationResponse><cuicOperationStatus>0</cuicOperationStatus><response><hyperVDeploymentPolicy><allowEndUserHostNameSuffix>false</allowEndUserHostNameSuffix><allowEndUserSuffix>false</allowEndUserSuffix><autoLogon>true</autoLogon><autoLogonCount>0</autoLogonCount><domain>TheDomainIAMlookingfor.com</domain><domainAdmin>user</domainAdmin><domainPassword>a2pmZGt3amVm</domainPassword><fullName></fullName><guiRunOnceCommands></guiRunOnceCommands><hostNameTemplate>host-${GROUP_NAME}-SR${SR_ID}</hostNameTemplate><joinTypeDomain>true</joinTypeDomain><licenseMode>Per-Seat</licenseMode><licenseUsers>5</licenseUsers><linuxDnsDomain></linuxDnsDomain><orgName></orgName><password>cGFzc3dvcmRAMTIz</password><policyDescription></policyDescription><policyId>1</policyId><policyName>Hypervsyspol1</policyName><powerOn>true</powerOn><productId></productId><recycleHostName>true</recycleHostName><recycleVMName>true</recycleVMName><rootPassword></rootPassword><SIDUnique>false</SIDUnique><timezone>4</timezone><username></username><vmImageType>Windows and Linux</vmImageType><vmNameTemplate>vm-${GROUP_NAME}-SR${SR_ID}</vmNameTemplate><workGroupName></workGroupName></hyperVDeploymentPolicy></response></cuicOperationResponse>]
Mar 07, 2017 19:45:16 UTC Completed workflow item number 2, with status Completed
Mar 07, 2017 19:45:22 UTC Executing workflow item number 3
Mar 07, 2017 19:45:22 UTC Trigger context executeWorkFlowStep called
Mar 07, 2017 19:45:22 UTC Executing custom action Get_API (custom_XMLParser)
Mar 07, 2017 19:45:22 UTC Executing custom action Get_API (custom_XMLParser)
Mar 07, 2017 19:45:22 UTC Executing custom script for XMLParser
Mar 07, 2017 19:45:22 UTC a1 : domain
Mar 07, 2017 19:45:22 UTC Root element :cuicOperationResponse
Mar 07, 2017 19:45:22 UTC nList length: 1
Mar 07, 2017 19:45:22 UTC Current Element : domain
Mar 07, 2017 19:45:22 UTC NodeType : 1
Mar 07, 2017 19:45:22 UTC typeof nNode: object
Mar 07, 2017 19:45:22 UTC Object: TheDomainIAMlookingfor.com
Mar 07, 2017 19:45:22 UTC Processing output: object
Mar 07, 2017 19:45:22 UTC Task #3 (Get_API (custom_XMLParser)) completed successfully in 0 seconds
Mar 07, 2017 19:45:22 UTC Input/Output values for Task #3 (Get_API (custom_XMLParser)):
Mar 07, 2017 19:45:22 UTC [Template Input:XML = <cuicOperationResponse><cuicOperationStatus>0</cuicOperationStatus><response><hyperVDeploymentPolicy><allowEndUserHostNameSuffix>false</allowEndUserHostNameSuffix><allowEndUserSuffix>false</allowEndUserSuffix><autoLogon>true</autoLogon><autoLogonCount>0</autoLogonCount><domain>TheDomainIAMlookingfor.com</domain><domainAdmin>user</domainAdmin><domainPassword>a2pmZGt3amVm</domainPassword><fullName></fullName><guiRunOnceCommands></guiRunOnceCommands><hostNameTemplate>host-${GROUP_NAME}-SR${SR_ID}</hostNameTemplate><joinTypeDomain>true</joinTypeDomain><licenseMode>Per-Seat</licenseMode><licenseUsers>5</licenseUsers><linuxDnsDomain></linuxDnsDomain><orgName></orgName><password>cGFzc3dvcmRAMTIz</password><policyDescription></policyDescription><policyId>1</policyId><policyName>Hypervsyspol1</policyName><powerOn>true</powerOn><productId></productId><recycleHostName>true</recycleHostName><recycleVMName>true</recycleVMName><rootPassword></rootPassword><SIDUnique>false</SIDUnique><timezone>4</timezone><username></username><vmImageType>Windows and Linux</vmImageType><vmNameTemplate>vm-${GROUP_NAME}-SR${SR_ID}</vmNameTemplate><workGroupName></workGroupName></hyperVDeploymentPolicy></response></cuicOperationResponse>]
Mar 07, 2017 19:45:22 UTC [Resolved Template Input: XML = <cuicOperationResponse><cuicOperationStatus>0</cuicOperationStatus><response><hyperVDeploymentPolicy><allowEndUserHostNameSuffix>false</allowEndUserHostNameSuffix><allowEndUserSuffix>false</allowEndUserSuffix><autoLogon>true</autoLogon><autoLogonCount>0</autoLogonCount><domain>TheDomainIAMlookingfor.com</domain><domainAdmin>user</domainAdmin><domainPassword>a2pmZGt3amVm</domainPassword><fullName></fullName><guiRunOnceCommands></guiRunOnceCommands><hostNameTemplate>host-${GROUP_NAME}-SR320</hostNameTemplate><joinTypeDomain>true</joinTypeDomain><licenseMode>Per-Seat</licenseMode><licenseUsers>5</licenseUsers><linuxDnsDomain></linuxDnsDomain><orgName></orgName><password>cGFzc3dvcmRAMTIz</password><policyDescription></policyDescription><policyId>1</policyId><policyName>Hypervsyspol1</policyName><powerOn>true</powerOn><productId></productId><recycleHostName>true</recycleHostName><recycleVMName>true</recycleVMName><rootPassword></rootPassword><SIDUnique>false</SIDUnique><timezone>4</timezone><username></username><vmImageType>Windows and Linux</vmImageType><vmNameTemplate>vm-${GROUP_NAME}-SR320</vmNameTemplate><workGroupName></workGroupName></hyperVDeploymentPolicy></response></cuicOperationResponse>]
Mar 07, 2017 19:45:22 UTC [Mapped Input: XML = <cuicOperationResponse><cuicOperationStatus>0</cuicOperationStatus><response><hyperVDeploymentPolicy><allowEndUserHostNameSuffix>false</allowEndUserHostNameSuffix><allowEndUserSuffix>false</allowEndUserSuffix><autoLogon>true</autoLogon><autoLogonCount>0</autoLogonCount><domain>TheDomainIAMlookingfor.com</domain><domainAdmin>user</domainAdmin><domainPassword>a2pmZGt3amVm</domainPassword><fullName></fullName><guiRunOnceCommands></guiRunOnceCommands><hostNameTemplate>host-${GROUP_NAME}-SR320</hostNameTemplate><joinTypeDomain>true</joinTypeDomain><licenseMode>Per-Seat</licenseMode><licenseUsers>5</licenseUsers><linuxDnsDomain></linuxDnsDomain><orgName></orgName><password>cGFzc3dvcmRAMTIz</password><policyDescription></policyDescription><policyId>1</policyId><policyName>Hypervsyspol1</policyName><powerOn>true</powerOn><productId></productId><recycleHostName>true</recycleHostName><recycleVMName>true</recycleVMName><rootPassword></rootPassword><SIDUnique>false</SIDUnique><timezone>4</timezone><username></username><vmImageType>Windows and Linux</vmImageType><vmNameTemplate>vm-${GROUP_NAME}-SR320</vmNameTemplate><workGroupName></workGroupName></hyperVDeploymentPolicy></response></cuicOperationResponse>]
Mar 07, 2017 19:45:22 UTC [Local Input: TAG = domain]
Mar 07, 2017 19:45:22 UTC [Output: object = TheDomainIAMlookingfor.com]
Mar 07, 2017 19:45:22 UTC Completed workflow item number 3, with status Completed
Mar 07, 2017 19:45:25 UTC Executing workflow item number 4
Mar 07, 2017 19:45:25 UTC Completed workflow item number 4, with status Completed
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: