cisco ucs director cloupiascript cookbook
Post on 11-Feb-2017
263 views
Embed Size (px)
TRANSCRIPT
http://www.cisco.com/
Contents Organization....................................................................................................................................................................... 4
Conventions ....................................................................................................................................................................... 4
Obtaining Documentation and Submitting a Service Request .......................................................................................... 5
Overview ............................................................................................................................................................................ 6
About Cisco UCS Director, Custom Tasks, and CloupiaScript ........................................................................................ 6
Related Documentation ................................................................................................................................................. 6
Structure of the Examples ............................................................................................................................................. 6
How to Use the Examples .............................................................................................................................................. 7
Getting Inputs and Outputs of a Service Request ......................................................................................................... 7
Examples ............................................................................................................................................................................ 8
1. Logging in CloupiaScript ............................................................................................................................................. 8
2. Handling Numeric Input ............................................................................................................................................. 8
3. SSH to a Network Device ......................................................................................................................................... 10
4. Accessing a Network Element Account ................................................................................................................... 11
5. Accessing a Session or API for Virtual and Physical Accounts ................................................................................. 12
6. Accessing reports ..................................................................................................................................................... 16
7. Accessing a Delegate API ......................................................................................................................................... 17
8. Accessing and Operating on a Database Table ........................................................................................................ 18
9. Provisioning a Catalog Multiple Times ..................................................................................................................... 19
10. Calling or Executing a Workflow Task .................................................................................................................... 20
11. Setting a Task to Successful or Failed Status ......................................................................................................... 21
12. Invoking another Workflow ................................................................................................................................... 22
13. Calling an API on a Remote Cisco UCS Director ..................................................................................................... 23
14. Executing a Critical Section .................................................................................................................................... 24
15. Obtaining Complete List of VLANs across PODs .................................................................................................... 25
16. Obtaining Complete List of IPs Used per Pod ........................................................................................................ 26
17. Locking or Unlocking a VDC ................................................................................................................................... 27
18. Creating a Task to Obtain the List of Hosts from a VMware Cluster ..................................................................... 28
19. Moving Multiple VMs across VDCs ........................................................................................................................ 29
20. Rolling Back a Task in a Workflow ......................................................................................................................... 30
21. Integrating with ServiceNow Ticketing .................................................................................................................. 31
22. Sending Emails from the Cloupia Script ................................................................................................................. 33
23. Archiving Older Service Requests Automatically ................................................................................................... 34
24. Determining the Workflow Submitter Information ............................................................................................... 35
25. Resizing a Virtual Machine Disk ............................................................................................................................. 36
26. Uploading a JAR File ............................................................................................................................................... 37
27. Invoking a Library for a Custom Task ..................................................................................................................... 38
28. Using the Registered List of Values (LOV) in a Custom Task .................................................................................. 39
29. Using a Tabular Report in a Custom Workflow Task ............................................................................................. 40
Organization
Conventions
courier font courier
Obtaining Documentation and Submitting a Service Request
http://www.cisco.com/c/en/us/td/docs/general/whatsnew/whatsnew.html
Overview
About Cisco UCS Director, Custom Tasks, and CloupiaScript
Related Documentation
Structure of the Examples
http://www.cisco.com/c/en/us/support/servers-unified-computing/ucs-director/products-maintenance-guides-list.htmlhttp://www.cisco.com/c/en/us/support/servers-unified-computing/ucs-director/products-maintenance-guides-list.htmlhttp://www.cisco.com/c/en/us/support/servers-unified-computing/cloupia/products-installation-and-configuration-guides-list.htmlhttp://www.cisco.com/c/en/us/support/servers-unified-computing/ucs-director/products-programming-reference-guides-list.htmlhttp://www.cisco.com/c/en/us/support/servers-unified-computing/ucs-director/products-programming-reference-guides-list.html
How to Use the Examples
Getting Inputs and Outputs of a Service Request
Examples
1. Logging in CloupiaScript
Objective
Context
Prerequisites
Components
Code
logger.addDebug(About to process the user request); logger.addInfo(User +ctxt.getUserId()+ has requested to provision this); logger.addWarning(Resource has reached maximum capacity.); logger.addError(Failed to provision the resource.);
Results
2. Handling Numeric Input
Objective
Prerequisites
Components
Code
// Handle a number defined as a text input function handleNumbers() {
var strInput = input.stringInput; var convertedCustomTaskStringInput = null; if(strInput != null) {
// Use the Java Integer wrapper object convertedCustomTaskStringInput = new java.lang.Integer(strInput);
logger.addInfo("convertedCustomTaskStringInput = " + convertedCustomTaskStringInput);
} } handleNumbers(); // Handle a number defined as a numeric input function handleNumbers() {
var strInput = input.Input * 2; var convertedCustomTaskStringInput = null; if(strInput != null) {
// Use the java Integer wrapper object convertedCustomTaskStringInput = strInput; logger.addInfo("convertedCustomTaskStringInput = " +
convertedCustomTaskStringInput); }
} handleNumbers();
Results
Implementation
3. SSH to a Network Device
Objective
Context
Prerequisites
Components
Code
importPackage(com.cloupia.lib.util.ssh); importPackage(java.io); function testSSHClient() { var client = new SSHClient(input.ipAddress, 22, // 22 = SSH standard port
input.userName, input.password); client.connect(); var session = client.openShell(511,25); // (511, 25) = (columns, rows) var shellStream = new PrintStream(session.getOutputStream()); shellStream.println(input.command); shellStream.flush(); client.disconnect(); } testSSHClient();
Results
Implementation
4. Accessing a Network Element Account
Objective
Context
Prerequisites
Components
Code
importPackage(com.cloupia.feature.networkController); importPackage(com.cloupia.feature.networkController.
Recommended