Camberton
Enthusiast
Enthusiast

Init VC:VmwareDistributedVirtualSwitch in scriptable task

Jump to solution

Hi,

I have a little question : I want to modify default workflow to create vdPortGroup.

I want to remove input "dvSwitch" (VC:VmwareDistributedVirtualSwitch and replace it with "site" (String).

In the input, i want force user to select a site (Ex. Site A or Site B) and he cannot browse vCenter infrastructure.

Then, in a scriptable task i test the value selected and create dvportgroup on dvSwitch corresponding.

But i don't know how to initialize the dvSwitch object before to run :

dvPortgroupCreationTask = dvSwitch.addDVPortgroup_Task(specArray);

Regards

0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee

Oh, if it is that simple of an environment, then just do something along the lines of:

Setup to Configuration Attributes:

Name: site1Name -- Type: VC:VmwareDistributedVirtualSwitch -- Value: specify the CUSTOMER dvSwitch here

Name: site2Name -- similar as site 1

Then, for your custom workflow:

Create an Attribute named "config" of type "ConfigurationElement", specify the value as the config element you created as I instructed above.

inside your code, do something along these lines:

Assuming your site name input for the customer is "siteName" of type string:

dvSwitch = config.getAttributeWithKey(siteName).value

the above "configuration attribute names should be EXACTLY the value that the user would select for input in order for the above line to work.. if the user is presented with something different, then you'll need to do an if statement along these lines:

if(siteName == "My special Site 1") {

     dvSwitch = config.getAttributeWithKey("site1Name").value;

}else{

     dvSwitch = config.getAttributeWithKey("site2Name").value;

}

So, option 2 provides the most flexibility between what gets displayed to the user and which switch gets specified... if you move beyond 2 switches, then a "switch" statement could be used like this:

switch(siteName){

     case "My special Site 1":

          dvSwitch = config.getAttributeWithKey("site1Name").value;

          break;

     case "My special Site 2":

          dvSwitch = config.getAttributeWithKey("site2Name").value;

          break;

     // add cases as needed

     default:

          System.warn("invalid site specified");

}

NOTE - the snippets added here were by memory, should be close if not exact 🙂

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
6 Replies
Burke-
VMware Employee
VMware Employee

This request requires additional detail.. are your dvSwitch names based on the site names? This would be a requirement for what you are describing ... so for example, say the naming convention was "sitename-dvSwitch" for example (yes, very simple example), you would do something along the following in your scriptable task to get the dvSwitch object that could then be used to create the dvPortgroup:

var switches = Server.findAllForType("VC:VmwareDistributedVirtualSwitch","xpath:name='"+siteName+"-dvSwitch'");
System.log("Switches: "+switches.length);
var dvSwitch = switches[0];

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
Camberton
Enthusiast
Enthusiast

Hi Burke,

thank you for your reply.

I have 2 datacenters and 2 dvSwitchs for customers (1 per data center), but the name is DSwitch0 for both.

One datacenter has 2 clusters, but only one for customers and the other has only one cluster.

So with your code (if i understand correctly) i must add a parameter to scope on the datacenter corresponding to the site (input) parameter selected by user

But i don't know how to do that

Regards

0 Kudos
Burke-
VMware Employee
VMware Employee

Oh, if it is that simple of an environment, then just do something along the lines of:

Setup to Configuration Attributes:

Name: site1Name -- Type: VC:VmwareDistributedVirtualSwitch -- Value: specify the CUSTOMER dvSwitch here

Name: site2Name -- similar as site 1

Then, for your custom workflow:

Create an Attribute named "config" of type "ConfigurationElement", specify the value as the config element you created as I instructed above.

inside your code, do something along these lines:

Assuming your site name input for the customer is "siteName" of type string:

dvSwitch = config.getAttributeWithKey(siteName).value

the above "configuration attribute names should be EXACTLY the value that the user would select for input in order for the above line to work.. if the user is presented with something different, then you'll need to do an if statement along these lines:

if(siteName == "My special Site 1") {

     dvSwitch = config.getAttributeWithKey("site1Name").value;

}else{

     dvSwitch = config.getAttributeWithKey("site2Name").value;

}

So, option 2 provides the most flexibility between what gets displayed to the user and which switch gets specified... if you move beyond 2 switches, then a "switch" statement could be used like this:

switch(siteName){

     case "My special Site 1":

          dvSwitch = config.getAttributeWithKey("site1Name").value;

          break;

     case "My special Site 2":

          dvSwitch = config.getAttributeWithKey("site2Name").value;

          break;

     // add cases as needed

     default:

          System.warn("invalid site specified");

}

NOTE - the snippets added here were by memory, should be close if not exact 🙂

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
Camberton
Enthusiast
Enthusiast

Thank you very much! I do not know the Configuration Attributes.
I think my solution is.

2 questions and then I'll stop bothering you Smiley Happy


1. I create a Configuration Attributes (for Ex.) "site1Name" with different attributes : dvSwitch (with corresponding value), rootfolder and rootresourcePool.

in my workflow, I create an attribute witj configuration element type but when i want to select value, all is greyed out. I cannot select the value.


2. Can i get the value with code like this :  dvSwitch = config.getAttributeWithKey("site1Name").dvSwitch.value; or  rootfolder = dvSwitch = config.getAttributeWithKey("site1Name").rootFolder.value ?


Regards

0 Kudos
Camberton
Enthusiast
Enthusiast

ok, I understand, thank you again Smiley Happy

everything is in your replySmiley Happy

0 Kudos
Burke-
VMware Employee
VMware Employee

Here, let me save us both some time..

  1. import the attached package
  2. Go to Configurations -> Samples -> siteSwitches
  3. Change the array values in the "sites" attribute as desired (don't use spaces)
  4. Change the name of LAX to match one of your site names in the array
  5. Specify a valid switch for this first site by clicking the Value column and choosing the customer dvSwitch for that site
  6. Change the name of IAD to match one of your site names in the array
  7. Specify a valid switch for this first site by clicking the Value column and choosing the customer dvSwitch for that site
  8. Run the "dvSwitch by Site" workflow multiple times. Each time, choose a different siteName as the input and verify that the corresponding dvSwitch is chosen

Study this workflow/configuration - there are some great lessons here:

  • Reading from configuration elements
  • Predefined answers in workflow presentation
  • If/Else
If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos