VMware Cloud Community
BWinchell
Enthusiast
Enthusiast
Jump to solution

Declaring variables for host,pool,vmFolder

Hello,

I am working on a workflow to automate the deployment of VMs.  The idea is the end-user requesting the new VM can ask for X memory, X drives & size, and OS.  The thing I want to control is the VM (template to clone), HOST, POOL, DATASTORE, & vmFOLDER.  I want to know how to pass the ID or NAME to the variables of the:

System.getModule("com.vmware.library.vc.basic").cloneVM(vm,vmFolder,name,powerOn,template,datastore,host,pool)

I setup a debug that gave me values(names and ids) of these (when I run manually) but how to hard code them or pass is the real question?

Thanks

B

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

Heya B, rather than me writing an article here on how to do what you need, I've taken your code and what I grasp to be what you're trying to do and created a vCO Package file (see attached) of how I would approach this...

Import the package.

Notice that there is a Configuration Element with several attributes and empty values. You need to populate your values here in the configuration element. The workflow attributes will get their values from here.

Now take a look at the workflow - notice the attributes and how they point to the configuration element! Now look into the Scriptable task. The code there is far easier to read and it will be easier in the future to make a change to the East Coast and West Coast resources.

By defining these infrastructure specific resources as elements, you can reference them from many different workflows. And when you make a change for one of the resources that your workflow(s) use, it ONLY should need to be done in the configuration element, not the dozen or so workflows that all need to know what the West Coast Development Resource Pool is Smiley Wink

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

Reply
0 Kudos
12 Replies
ivand
VMware Employee
VMware Employee
Jump to solution

As far I understand, you want VM (template to clone), HOST, POOL, DATASTORE, & vmFOLDER to be choose by you.

You can have them as attributes in your workflow and you can select them from inventory.

About how to pass them to the action, you pass them as objects. Attributes should be input parameters of your scripting task and you can pass them to the action directly

Hope this help

Regards

Ivan

Reply
0 Kudos
BWinchell
Enthusiast
Enthusiast
Jump to solution

Hello Ivan,

Since I am trying to create an end-user self-servicing portal, they will not know what host, datastore, or resource pool to select.  I also do not want the VM techs to get involved, as it should be automatic.  The process is basically:

  1. End-user request
    1. Memory
    2. OS
    3. Drives
    4. Machine name
    5. Machine location (generic...East Coast, West Coast, etc...)
  2. Notification for approval
  3. VC spins up template
    1. Based on OS & location
  4. Modify the new machine with additional changes
    1. Drives, memory, Notes
  5. Notify Helpdesk of new machine
    1. Helpdesk process
  6. Notify end-user machine is available

So I am figuring I would need something like the following to declare my variable but I am unsure of the syntax:

var host = VcHostSystem.id(3025);

var host = VcHostSystem.name(machine1.domain.local);

var pool = VcResourcePool.id(3636);

**none of these work**

Any help?

Thanks

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Static environment variables like this should not be coded the way you are attempting.. you should setup attributes and define the values there. Whichever element(s) inside your workflow need those values would need to be bound to the attributes for their inputs. Take a look at our series of articles starting here to see exactly what I'm talking about: http://www.vcoteam.info/learn-vco/create-a-simple-vco-self-service-vm-provisioning-portal-part-1.htm... ... In a longer term, multi-environment variable, the attributes would be mapped to configuration elements that have the Infrastructure elements defined.

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
BWinchell
Enthusiast
Enthusiast
Jump to solution

Hi Burke,

Maybe I do not understand entirely (as I am a VCO newbie).  I have used your series & site (great by the way) to assist me to a degree.  I can understnad how this would work if I was dealing with one site or cluster but, what happens I am dealing with different sites?  Would I just have to create different workflows?

Maybe if i show some of my code, it might give more clarity into mind (probably not Smiley Happy).  This is not all of it but will give you the idea:

//Validate FQDN name structure

if (FQDN.match(new RegExp ("^([a-zA-Z0-9_-]+\.domain\.local)$"))) {
    System.log("FQDN: " + FQDN + " is valid");
    System.log("Return value: TRUE");
    return true;
    }
   
else {
    System.log("FQDN: " + FQDN + " is not valid");
    System.log("Return value: FALSE")
    return false;
    }

//Set var host based on location
if (vmDatacentreLocation == "WestCoast") {
    var host = VcHostSystem.id(3025);
    }
if (vmDatacentreLocation == "EastCoast") {
    var host = VcHostSystem.id(3026);
    }

//Set var vm based on OS
if (operatingSystem == "Win2K8R2x64STD") {
    var vm = vm.id(4001);
    }
if (operatingSystem = "CentOS6") {
    var vm = vm.id(4002);
    }
   
//Set var pool based on devEnvironment
if (devEnvironment == true & vmDatacentreLocation == "WestCoast") {
    var pool = VcResourcePool.id(5001);
    }
if (devEnvironment == true & vmDatacentreLocation == "EastCoast") {
    var pool = VcResourcePool.id(5002);
    }
if (devEnvironment != true & vmDatacentreLocation == "WestCoast") {
    var pool = VcResourcePool.id(6001);
    }
if (devEnvironment != true & vmDatacentreLocation == "EastCoast") {
    var pool = VcResourcePool.id(6002);
    }
   
//Set var datastore based on location and environment
//I do not have the code for this yet

//Launch task to deploy VM from template
actionResult = System.getModule("com.vmware.library.vc.basic").cloneVM(vm,vmFolder,name,powerOn,template,datastore,host,pool);

Thanks

B

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Heya B, rather than me writing an article here on how to do what you need, I've taken your code and what I grasp to be what you're trying to do and created a vCO Package file (see attached) of how I would approach this...

Import the package.

Notice that there is a Configuration Element with several attributes and empty values. You need to populate your values here in the configuration element. The workflow attributes will get their values from here.

Now take a look at the workflow - notice the attributes and how they point to the configuration element! Now look into the Scriptable task. The code there is far easier to read and it will be easier in the future to make a change to the East Coast and West Coast resources.

By defining these infrastructure specific resources as elements, you can reference them from many different workflows. And when you make a change for one of the resources that your workflow(s) use, it ONLY should need to be done in the configuration element, not the dozen or so workflows that all need to know what the West Coast Development Resource Pool is Smiley Wink

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
Reply
0 Kudos
BWinchell
Enthusiast
Enthusiast
Jump to solution

Hello Burke,

Thanks for that.  Now that explains clearly how Configuration elements fit into the whole picture.  I can use that to continue on this workflow.  I will upload the results when I am finished.

Thanks

B

Reply
0 Kudos
BWinchell
Enthusiast
Enthusiast
Jump to solution

Hello Burke,

I am at the point of putting all the workflows together to achieve this flow.  One problem I have run into is when I run "TNG_deployVmFromTemplateWthCustomizations", it completes fine and does exactly what it is suppossed to.  When I run "TNG_deployVmWithCustomizationToDatastore", it fails on the 2nd workflow "TNG_deployVmFromTemplateWthCustomizations" with an error "Unable to create CloneSpec: template must be defined (type: boolean) (Dynamic Script Module name : getCloneSpec#7)".

It looks like the workflow, once called inside another workflow, seems to be missing general attributes inside itself.  Am I missing something or misunderstanding?  The only way I have found around this is to insert a scriptable task and declare the general attributes at outputs.  Is this the correct way? *(I removed the config file from the package because of network information)*

Thanks

B

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

I could not check your workflows but this may help:

The attribute must be passed to the sub workflow in its input parameters. To do so they must have a finder type (be available as a workflow input). CloneSpecs, Customization specs do not have a finder so they must be defined again in the sub workflow.

Christophe.

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
BWinchell
Enthusiast
Enthusiast
Jump to solution

Hi Cdecanini,

If those attributes are already declared as general attributes inside the individual workflow (which runs to completion, no errors), do i have to set/declare them again in the encompassing workflow?

The problem comes in with the getCloneSpec action seems to be missing the general attributes, but they are in the individual workflow cause it works (hard to explain with pics).

Individual workflow: 'pic1' => works Smiley Happy

encompassing workflow: 'pic2' => error Smiley Sad

Thanks

B

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

OK, I have misunderstood.

If each individual workflow work individually then they should work the same way when you start them from a parent workflow (as long as you pass them the input parameters right). Check that the inputs have the same values.

Christophe.

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
robrtb12
Enthusiast
Enthusiast
Jump to solution

Based on the error "Unable to create CloneSpec: template must be defined (type: boolean) (Dynamic Script Module name : getCloneSpec#7)"."  You are not passing a valid "boolean" as input for the getCloneSpec action.

The "template" input for the getCloneSpec action is a Yes/No answer to the question:  Specifies whether or not the new virtual machine should be marked as a template.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Good catch.

If the boolean is an attribute of the parent workflow, make sure you set / unset it once. With recent versions of vCO there is a third boolean state (no joke) to recognize if it was not set by the end user of if it was set to false.

Christophe.

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos