UCSD - Case Sensitive / Insensitive VM Name Search Example

Version 1
    Task Name

    Example on how to serach with RedEx for VM name case insensitive.

    Description

     

    Prerequisites
    1. Tested on 6.0
    CategoryWorkflow
    ComponentsvSphere 5.x
    User Inputs
    Output

    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 .WFDX file resides. Choose the .WFDX 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

     

    A big thank you goes to Alejandro Madurga Ainoza for the inspiration.

     

    The workflow:

     

    Screen Shot 2016-09-20 at 11.57.14 AM.png

     

    Workflow run and input and output:

     

    Screen Shot 2016-09-20 at 11.57.08 AM.png

     

    Workflow task inputs:

     

    Screen Shot 2016-09-20 at 11.57.24 AM.png

     

     

    Custom task code:

     

     

     

    importPackage(java.lang);

    importPackage(com.cloupia.model.cIM);

    importPackage(com.cloupia.lib.util.managedreports);

    importPackage(com.cloupia.service.cIM.inframgr);

    importPackage(com.cloupia.model.cIM);

     

    var realvmname ='';

     

     

    function getReport(reportContext, reportName){

         var report = null;

                try{

                     report = ctxt.getAPI().getConfigTableReport(reportContext, reportName);

                    }catch(e)

                                {}

         if (report == null)

             {

             return ctxt.getAPI().getTabularReport(reportName, reportContext);

             }

                else {

                var source = report.getSourceReport();

                       return ctxt.getAPI().getTabularReport (source, reportContext);

                }

    }

     

    function getReportView(reportContext, reportName){

         var report = getReport(reportContext, reportName);

         if (report == null)

                     {

               logger.addError("No such report exists for the specified context "+reportName);

               return null;

                     }

         return new TableView(report);

    }

     

     

    function accessReports(filter){

     

     

              var reportName="TABULAR_REPORT_VMS_PAGINATED_CONFIG_REPORT";

              var repContext = util.createContextByType( "Global",null,null);

              var report = getReportView(repContext, reportName);

     

     

     

    logger.addInfo("RowCount Before filter : " + report.rowCount());

     

    logger.addInfo("Filtering VMs")

    //

    // true means reg ex filter

    // Example:  (?i)PRD-TU-01

    // will find the vmname PRD-tu-01

    //

    var filtered_report = report.filterRowsByColumn("VM Name", filter, true);

    logger.addInfo("Total VMs after filtering: "+ String(filtered_report.rowCount()));

     

     

    var ActualVMName =  filtered_report.getColumnValue(0, "VM Name");

    logger.addInfo("Actual VM Name: "+ ActualVMName);

     

     

    realvmname = ActualVMName;

     

     

    return  filtered_report.rowCount();

     

     

     

     

    }

    var filter = String(input.RegExFilter + input.VMName);

    //var filter = "(?i)PRD-tu-01";

    logger.addInfo("User Input:"+ filter)

    var out = accessReports(filter);

     

    output.VMsFound = out;

    output.ActualVMName = realvmname;