cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3972
Views
1
Helpful
7
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
Task NameLOV creation from CSV file
Description
  1. Change the user of a running workflow
Prerequisites
  1. Tested on 5.3.1
CategoryWorkflow
ComponentsvSphere 5.x
User Inputs
  1. userid to change to
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 .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.

Inspired by work from Tejeswar Sahu and Saranyasree Vadivel

This example will read from a CSV file located on UCSD and read in values and then register a new LOV variable in the system.

Every time this workflow is executed it will read the CSV file and update/change/create the LOV variable.

Examples of the CSV file being updated on UCSD:

Original List:

Screen Shot 2015-07-24 at 8.37.36 AM.png

The CSV file on UCSD was updated (new States were added):

Screen Shot 2015-07-24 at 8.39.20 AM.png

The the CSV file was partially deleted and updated:

Screen Shot 2015-07-24 at 8.41.07 AM.png

The workflow in 2 custom steps.

     Step 1 Read the file and assemble a variable

     Step 2 Create the LOV variable

Screen Shot 2015-07-24 at 8.41.24 AM.png

Global Workflow Input:

Screen Shot 2015-07-24 at 8.55.30 AM.png

Screen Shot 2016-10-10 at 7.38.06 AM.png

Currently coded with cdv file in /tmp and called States.csv

The LOV variable created is called LOVStates

The code / custom task behind Step 1:

     1 Input, the file name and path

     2 Output, the variable with the assembled string (format a=1,b=2,c=3)

importPackage(java.io);

importPackage(java.util);

importPackage(com.cloupia.model.cEvent.notify);

importPackage(com.cloupia.model.cIM);

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

importPackage(com.cloupia.fw.objstore);

var filenamewithpath = input.FileNameWithPath ;

var br = new BufferedReader(new FileReader(filenamewithpath));

var tokens;

var UCSDLoopCounter = new ArrayList();

while(true){

       var line = br.readLine();

       if(line == null)break;

       logger.addInfo("Line" + line);

       tokens = line.split(",");

       if(tokens != null && tokens.length > 0){

             UCSDLoopCounter.add(tokens);

       }

}

br.close();

logger.addInfo("UCSDLoopCounter");

var ListSize = UCSDLoopCounter.size();

var details = UCSDLoopCounter.iterator();

var sum = "";

while(details.hasNext()){

//dont want a comma at the end of the string

  if (sum != "") {

  sum = sum + "," ;

             }

  var arr = details.next();

  logger.addInfo("A0 : "+arr[0]);

  logger.addInfo("A1 : "+arr[1]);

  logger.addInfo("-------------------------------------");

  logger.addInfo("");

  var sum = sum + arr[0] + "=" + arr[1] ;

  logger.addInfo("Sum : " + sum);

}

output.LOVinputString = sum;

The code behind the registration of  the new LOV varaibel

     1 Input, the assembled string

     2 Inout, the name of the to be registered LOV varaible

importPackage(java.lang);

importPackage(java.util);

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

importPackage(com.cloupia.model.cIM);

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

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

var csvlist = input.CSV_List;

var lovvariablename = input.LOV_Variable_Name;

function createLOV(){

var dataProvider = getDataProvider();

registerLOV(dataProvider);

registerGlobalInputs(dataProvider)

}

function getDataProvider(){

var lovRegistry = LOVProviderRegistry.getInstance();

var lovProvider = new com.cloupia.service.cIM.inframgr.forms.wizard.LOVProviderIf({

getLOVs : function(session) {

//provide your own lovContent

//var lovContent = "Country1=1,Country2=2,Country3=3,Country4=4,Country5=5";

var lovContent = csvlist;

return getFormLovPair(lovContent);

//End of implementation for Lovprovider

}

});

return lovProvider;

}

function registerLOV(dataProvider){

var lovRegistry = LOVProviderRegistry.getInstance();

lovRegistry.registerProvider(lovvariablename, dataProvider);

}

function getWorkflowInputType(){

return lovvariablename;//provide here WorkflowInputType inside the Quotes

}

function getWorkflowInputLabel(){

return lovvariablename;//provide here WorkflowInputLabel inside the Quotes

}

function registerGlobalInputs(lovProvider){

var registry = CustomFeatureRegistry.getInstance();

registry.registerWorkflowInputFieldType(getWorkflowInputType(), getWorkflowInputLabel(), FormFieldDefinition.FIELD_TYPE_EMBEDDED_LOV, lovvariablename);

}

function getFormLovPair(lovContent) {

  var lovPairArr = lovContent.split(",");

  var lovPair;

  var lovLabel;

  var lovValue;

  var formlov;

  var formlovarr = [];

  for(var count = 0;count<lovPairArr.length;count++){

  lovPair = lovPairArr[count];

  lovLabel = lovPair.split("=")[0];

  lovValue = lovPair.split("=")[1];

  formlov = new FormLOVPair(lovLabel,lovValue);

  formlovarr[count] = formlov;

  }

  return formlovarr;

}

createLOV()

Adendum:

Inconsistent situation:

Suppose for the first time I created a lov taking the values from the csv file(say computer=1,phone=2).

Then I updated the lov from the GUI(say after updating ,lov contains computer=1,phone=2,Tv=3).

Again I updated the lov from the task taking the values from the csv file(say computer=1,phone=2,camera=3,watch=4).

As a result what we have updated the lov from the GUI will be lost(Tv=3).

So either we have to update the lov from the task always or from the GUI always.Updating the lov from both ways(task and GUI) might lead to data corruption.

Comments

hi,

I'm using this code to create LOV, and this is working fine. But LOV list that I create is not visible under Orchestration menu tab and is removed after UCSD services restart or appliance reboot.

Is that expected behaviour ?

Orf Gelbrich
Cisco Employee
Cisco Employee

Depending on your version of UCSD yes.

Check in the workflow that registers in UCSD the LOV the check box to run at system start up this workflow.

-

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site

tad.smith
Level 1
Level 1

Are these visible in the GUI (in 6.0x)? I am wondering how we would go about deleting an LOV that we created through this process.

Orf Gelbrich
Cisco Employee
Cisco Employee

Yes – the LOV is available in the GUI…

I have 3 pictures of the GUI.

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site (Twitter @UCSDGURU)

Orf Gelbrich
Cisco Employee
Cisco Employee

Deleting – go to custom workflow inputs and delete the LOV.

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site (Twitter @UCSDGURU)

fvaninet
Cisco Employee
Cisco Employee

Instructions say to download the .zip file on computer. However this post has multiple files attached, multiple zip files. Maybe you should explain what they are and which one is the correct file to download

Orf Gelbrich
Cisco Employee
Cisco Employee

Sorry to confuse with an older version. I deleted it.

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

Review Cisco Networking for a $25 gift card