VMware Cloud Community
WJPConway
Contributor
Contributor
Jump to solution

vRO Workflow to Place vCD vAPP VM's in a DRS Affinity Rule

First of all apologies I am not a coder am an infrastructure guy so expect some stupidity below

I have a vro workflow that creates multiple vAPPs from a specified template.

All this is working fine for me

But now need to add a new step where it will create 2 DRS Affinity Rules an assign all the VMs to one of the rules based on a fairly simple pattern.

The rules will be

Rule-A and Rule-B

The VMs that will go into RuleA have Random names but the names will not contain 'VM-B-' - and the VMs that will go into RuleB will all have VM names that begin with 'VM-B-' then random characters.

So far I have

input is the vapp variable vapp

var vms = System.getModule("com.vmware.library.vCloud.vApp").getVmsFromVApp(vapp) ;

    for each (var vm in vms) {

if (vm.Name ='VM-B-'*){   //note sure is this the right syntax for like

System.log (vm.Name+' Should go into Rule-B')

//add vm.Name to array of VMs - B

}else{

System.log (vm.Name+' Should go into Rule-A')

//add vm.Name to array of VMs - A

}

//Create DRS Affinity Rule A with array of vms A

var rulea = System.getModule("com.vmware.library.vCloud.schema.objects").createVmAffinityRule(isEnabledArg,isMandatoryArg,'rulea',operationKeyArg,polarityArg,scopeArg,vmReferencesArg) ;

//Create DRS Affinity Rule B with array of vms B

var ruleb= System.getModule("com.vmware.library.vCloud.schema.objects").createVmAffinityRule(isEnabledArg,isMandatoryArg,'ruleb',operationKeyArg,polarityArg,scopeArg,vmReferencesArg) ;

1) When creating the rule - how do i plug in the standard values the only variables should be the names  - to create the syntax seems to be

System.getModule("com.vmware.library.vCloud.schema.objects").createVmAffinityRule(isEnabledArg,isMandatoryArg,'rulea',operationKeyArg,polarityArg,scopeArg,vmReferencesArg) ;

Can I just plug in boolen values directly like below (where can I get exactly what they are looking for here)

System.getModule("com.vmware.library.vCloud.schema.objects").createVmAffinityRule('1','1','rulea',operationKeyArg,'Affinity',scopeArg,vmReferencesArg) ;

2) Is vmReferenceArg an array of vms -

1 Solution

Accepted Solutions
qc4vmware
Virtuoso
Virtuoso
Jump to solution

I'm uploading some workflows and actions you can look through.  Hopefully they will connect the dots.  Most of these likely will not run without some tweaking (too much other custum content on our end I didn't include) but you'll get the gist.

View solution in original post

3 Replies
qc4vmware
Virtuoso
Virtuoso
Jump to solution

I'm uploading some workflows and actions you can look through.  Hopefully they will connect the dots.  Most of these likely will not run without some tweaking (too much other custum content on our end I didn't include) but you'll get the gist.

WJPConway
Contributor
Contributor
Jump to solution

Thanks qc4vmware,

Have decided to go a different route, I have this script and various others working through powercli - so rather than creating through vRO - just going to add an invoke an external script step.

I think the attached would of done what I needed with some tweaking so marking it as correct - but I have loads of other powercli stuff so think this might be a way to pull that stuff into vRO

Reply
0 Kudos
Windspirit
Hot Shot
Hot Shot
Jump to solution

Added DRS VM Host for VM to Host rules:

var addUpdateRule = new VcClusterVmHostRuleInfo();
addUpdateRule.name = ruleName;

if (type=="must"){
    addUpdateRule.mandatory = true;
    addUpdateRule.affineHostGroupName= hostGrpName;
    addUpdateRule.antiAffineHostGroupName =null;
}
if (type=="should"){
    addUpdateRule.mandatory = false;
    addUpdateRule.affineHostGroupName= hostGrpName;
    addUpdateRule.antiAffineHostGroupName =null;
}
if (type=="mustNot"){
    addUpdateRule.mandatory = true;
    addUpdateRule.affineHostGroupName= null;
    addUpdateRule.antiAffineHostGroupName =hostGrpName;
}
if (type=="shouldNot"){
    addUpdateRule.mandatory = false;
    addUpdateRule.affineHostGroupName= null;
    addUpdateRule.antiAffineHostGroupName =hostGrpName;
}

addUpdateRule.enabled = true;
addUpdateRule.userCreated = true;
addUpdateRule.vmGroupName = vmGrpName;
var MyVCClusterSpec = new VcClusterConfigSpecEx() ;
var MyVcClusterRulesSpec= new Array(); 
MyVcClusterRulesSpec[0] = new VcClusterRuleSpec();
MyVcClusterRulesSpec[0].operation =  VcArrayUpdateOperation.add;
MyVcClusterRulesSpec[0].info = addUpdateRule;
var MyVCClusterDRSConfigExSpec = new VcClusterConfigSpecEx() ;
MyVCClusterDRSConfigExSpec.drsConfig = new VcClusterDrsConfigInfo();
MyVCClusterDRSConfigExSpec.drsConfig.enabled = true;
MyVCClusterDRSConfigExSpec.rulesSpec = MyVcClusterRulesSpec;
MyVCClusterDRSConfigExSpec.rulesSpec[0].operation =  VcArrayUpdateOperation.add;

return cluster.reconfigureComputeResource_Task(MyVCClusterDRSConfigExSpec , true);
Reply
0 Kudos