cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
753
Views
1
Helpful
0
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
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

CategoryWorkflow
ComponentsvSphere 5.x
User Inputs


Instructions for Regular Workflow Use:

  1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
  2. Unzip the file on your computer. Should end up with a .WFD file.
  3. Log in to UCS Director as a user that has "system-admin" privileges.
  4. Navigate to "Policies-->Orchestration" and click on "Import".
  5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
  6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
  7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
  8. Click "Submit".
  9. 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.

The API call:

Screen Shot 2017-03-07 at 1.31.38 PM.png

Turns out it is not looking for the ID but the name of the policy

The Workflow:

Screen Shot 2017-03-07 at 1.52.55 PM.png

The domain tag that is looked for:

Screen Shot 2017-03-07 at 1.49.43 PM.png

Screen Shot 2017-03-07 at 1.52.49 PM.png

Workflow execution:

Screen Shot 2017-03-07 at 1.53.02 PM.png

The Task and global variable combined:

Screen Shot 2017-03-07 at 1.53.12 PM.png

The XML parse and the tag:

Screen Shot 2017-03-07 at 1.53.25 PM.png

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

Getting Started

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:

Quick Links