EZ Cloud Integrating Calling Python from UCSD Custom Task

Version 2

    Python comes to UCS Director!

     

    UCS Director has, as of this post, over 2,000 out of the box tasks for building workflows.  With that library, you can create some very robust infrastructure automation workflows without a single line of scripting or coding.  However, it is inevitable that you will find yourself needing to do something where Cisco hasn't provided an OOB task yet.  The main language used for creating custom scripting in UCSD is CloupiaScript, or a combination of JavaScript and several UCSD libraries for accessing the UCSD Infrastructure Management system.  JavaScript isn't a bad language, but it is also not always the best tool for the job.  Particularly in infrastructure engineering circles, it is rarely the language of choice... a position held by Python for many engineers.

     

    The UCS Director product management team knows of the desire for native python support, however it hasn't made it into the product yet, but that doesn't mean you can't work around that restriction with a little bit of creative integration.  I have several projects underway where I need to integrate with third party systems through APIs that would be much easier to do so with Python than JavaScript.  To make this easier, I pulled together a template for a UCS Director Custom Task written in CloupiaScript that can be used to reach out to another host and run Python Scripts, and make retrieval of script outputs as simple as possible back in UCS Director.

     

    Attached to this post is a UCSDirector Export that contains a the Custom Task Sample and an Example Workflow using it, and the related Python Script file that is being called by the Task.  The Python file doesn't do anything terribly interesting, but the framework is there to enable you to run whatever you need in Python and send relevant details back to UCS Director.  I'm also attaching the sample CloupiaScript text for reference as well.

     

    Though I'll be using this primarily with Python, there is nothing that would prevent this same framework from working with any other scripting language.  All that is needed is a script that can be called leveraging command line parameters that can print out JSON text.  So feel free to leverage this with bash, perl, python, go, or any other language you might want to work in.

     

    Also, you could use the UCS Director appliance itself to run the script files from, rather than need a separate host.  I opted to not do this for now because the python versions shipping on the UCSD appliance are a bit older and I like to stick with at least 2.7.x.

     

    Walkthrough of the example!

     

    Executing the UCS Director Workflow

    execute.png

     

    The Workflow Task User Inputs Screen

    user_intputs.png

     

    The Workflow Task Admin Inputs Screen

    admin_inputs.png

     

    The Credential Policy for the Python Host

    credential policy .png

     

    The Service Request Log showing the script running and returned data

    log.png

     

    The CloupiaScript for the Sample Task

    cloupiascript.png

     

    The Python Script being Executed

    python.png

     

    Basic Info

    NameEZ Cloud New vDC Utilities
    Description
    1. Set of Custom Tasks to create new vDC, Policies, and Manipulate Categories
    Prerequisites
    1. Built and Tested with UCSD 5.3.2.0
    CategoryWorkflow and Tasks
    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".