07-24-2015 06:55 AM - edited 03-01-2019 06:36 AM
Task Name | LOV creation from CSV file |
Description |
|
Prerequisites |
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs |
|
Output |
Instructions for Regular Workflow Use:
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:
The CSV file on UCSD was updated (new States were added):
The the CSV file was partially deleted and updated:
The workflow in 2 custom steps.
Step 1 Read the file and assemble a variable
Step 2 Create the LOV variable
Global Workflow Input:
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.
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 ?
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
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.
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)
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)
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
Sorry to confuse with an older version. I deleted it.
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: