VMware Cloud Community
FreddyFredFred
Hot Shot
Hot Shot

change drs settings for a specific vm

I’m having an intermittent problem when deploying vms from orchestrator and it appears it may be related to vmotion happening at a bad time in the process.

From a few posts on the forums and with the help of Onyx, I think I have some working code but I'm afraid to try it in case I mess up my cluster settings. Can someone take a look and let me know what they think?

The Onyx generated code has a lot more (shown at the end for referece) options. If I don't include those options, will all my cluster settings be reset when trying to adjust one vm?

thanks

set drs settings on vm to manual:

var myKey = System.getModule("com.mycompany.actions").getVmIdByName("VM123") //this returns the .id property, as a string, of a VcVirtualMachine when passed the name
var spec = new VcClusterConfigSpecEx();
spec.drsVmConfigSpec = new Array(VcClusterDrsVmConfigSpec, 1);
spec.drsVmConfigSpec[0] = new VcClusterDrsVmConfigSpec();
spec.drsVmConfigSpec[0].operation = VcArrayUpdateOperation.add;
spec.drsVmConfigSpec[0].info = new VcClusterDrsVmConfigInfo();
spec.drsVmConfigSpec[0].info.key = Server.findForType("VC:VirtualMachine", managedObject.vimHost.id + "/"+myKey+"\"");;
spec.drsVmConfigSpec[0].info.behavior = VcDrsBehavior.manual;

managedObject.reconfigureComputeResource_Task(spec, true);  // ClusterComputeResource


to remove the custom setting:

var myKey = System.getModule("com.mycompany.actions").getVmIdByName("VM123") //this returns the .id property, as a string, of a VcVirtualMachine when passed the name
var spec = new VcClusterConfigSpecEx();
spec.drsVmConfigSpec = new Array(VcClusterDrsVmConfigSpec, 1);
spec.drsVmConfigSpec[0] = new VcClusterDrsVmConfigSpec();
spec.drsVmConfigSpec[0].operation = VcArrayUpdateOperation.remove;
spec.drsVmConfigSpec[0].removeKey = myKey;

code generated by onyx
var spec = new VcClusterConfigSpecEx();
spec.vmSwapPlacement = "vmDirectory";
spec.dasConfig = new VcClusterDasConfigInfo();
spec.dasConfig.vmMonitoring = "vmMonitoringDisabled";
spec.dasConfig.defaultVmSettings = new VcClusterDasVmSettings();
spec.dasConfig.defaultVmSettings.restartPriority = "medium";
spec.dasConfig.defaultVmSettings.isolationResponse = "none";
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings = new VcClusterVmToolsMonitoringSettings();
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.enabled = true;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.vmMonitoring = "vmMonitoringDisabled";
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 30;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 120;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 3600;
spec.dasConfig.option = System.getModule("com.vmware.onyx").array(VcOptionValue, 1);
spec.dasConfig.option[0] = new VcOptionValue();
spec.dasConfig.option[0].key = "das.ignoreRedundantNetWarning";
spec.dasConfig.option[0].value = true;
spec.drsConfig = new VcClusterDrsConfigInfo();
spec.drsConfig.enabled = true;
spec.drsConfig.defaultVmBehavior = VcDrsBehavior.fullyAutomated;
spec.drsConfig.vmotionRate = 2;
spec.drsVmConfigSpec = System.getModule("com.vmware.onyx").array(VcClusterDrsVmConfigSpec, 1);
spec.drsVmConfigSpec[0] = new VcClusterDrsVmConfigSpec();
spec.drsVmConfigSpec[0].operation = VcArrayUpdateOperation.add;
spec.drsVmConfigSpec[0].info = new VcClusterDrsVmConfigInfo();
spec.drsVmConfigSpec[0].info.key = Server.findForType("VC:VirtualMachine", managedObject.vimHost.id + "/vm-1598");;
spec.drsVmConfigSpec[0].info.enabled = true;
spec.drsVmConfigSpec[0].info.behavior = VcDrsBehavior.manual;
spec.dpmConfig = new VcClusterDpmConfigInfo();
spec.dpmConfig.enabled = false;
spec.dpmConfig.hostPowerActionRate = 3;

managedObject.reconfigureComputeResource_Task(spec, true);  // ClusterComputeResource

10 Replies
ChristianWehner
VMware Employee
VMware Employee

Hi FreddyFredFred,

I tested you scripts on my test environment. The set DRS to manual should work without problems, I had to change something, cause I don't have your action "getVmIdByName" but here my working code:

var myVcClusterComputeResource = myVcVirtualMachine.runtime.host.parent; //myVcVirtualMachine as Workflow/Scriptable Task input

var myVcClusterDrsVmConfigInfo = new VcClusterDrsVmConfigInfo() ;

myVcClusterDrsVmConfigInfo.key = myVcVirtualMachine; //myVcVirtualMachine as Workflow/Scriptable Task input

myVcClusterDrsVmConfigInfo.behavior = VcDrsBehavior.manual;

var myVcClusterDrsVmConfigSpec = new VcClusterDrsVmConfigSpec() ;

myVcClusterDrsVmConfigSpec.operation = VcArrayUpdateOperation.add;

myVcClusterDrsVmConfigSpec.info = myVcClusterDrsVmConfigInfo;

var myVcClusterDrsVmConfigSpecArray = new Array() ;

myVcClusterDrsVmConfigSpecArray.push( myVcClusterDrsVmConfigSpec );

var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;

myVcClusterConfigSpecEx.drsVmConfigSpec = myVcClusterDrsVmConfigSpecArray;

myVcClusterComputeResource.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );

Interesting fact: DRS is set to disabled and not to manual, but I think this works fine for you too.

The set DRS to default again wont work for me. I tried it with this code:

var myVcClusterComputeResource = myVcVirtualMachine.runtime.host.parent; //myVcVirtualMachine as Workflow/Scriptable Task input

var myVcClusterDrsVmConfigSpec = new VcClusterDrsVmConfigSpec() ;

myVcClusterDrsVmConfigSpec.operation = VcArrayUpdateOperation.remove;

myVcClusterDrsVmConfigSpec.removeKey = myVcVirtualMachine.id; //myVcVirtualMachine as Workflow/Scriptable Task input

var myVcClusterDrsVmConfigSpecArray = new Array() ;

myVcClusterDrsVmConfigSpecArray.push( myVcClusterDrsVmConfigSpec );

var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;

myVcClusterConfigSpecEx.drsVmConfigSpec = myVcClusterDrsVmConfigSpecArray;

myVcClusterComputeResource.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, false );

This works in vCO but in vCenter there is an error which says: A specified parameter was not correct. Maybe your try it with a new onyx session, post the code and I will test it again.

Regards,

Chris

FreddyFredFred
Hot Shot
Hot Shot

Hi Chris,

First, how do I get that pretty numbered line code in my post? Smiley Happy


I'm having trouble getting your code to work

I added this line at the top

var myVcVirtualMachine = System.getModule("org.mycompany.actions").getVmIdByName(in1);

my getVmIdByName (modified to work with your code) is basically just

return System.getModule("com.vmware.library.vc.vm").getAllVMsMatchingRegexp(vmname);

when I run it, i get he following error:

TypeError: Cannot read property "parent" from undefined (Workflow:testing 2 / Scriptable task (item0)#4)

and I can't figure it why.

Below is the Onyx code to remove the custom option

// ------- ReconfigureComputeResource_Task -------

var spec = new VcClusterConfigSpecEx();
spec.vmSwapPlacement = "vmDirectory";
spec.dasConfig = new VcClusterDasConfigInfo();
spec.dasConfig.vmMonitoring = "vmMonitoringDisabled";
spec.dasConfig.defaultVmSettings = new VcClusterDasVmSettings();
spec.dasConfig.defaultVmSettings.restartPriority = "medium";
spec.dasConfig.defaultVmSettings.isolationResponse = "none";
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings = new VcClusterVmToolsMonitoringSettings();
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.enabled = true;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.vmMonitoring = "vmMonitoringDisabled";
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.failureInterval = 30;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.minUpTime = 120;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailures = 3;
spec.dasConfig.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow = 3600;
spec.dasConfig.option = System.getModule("com.vmware.onyx").array(VcOptionValue, 1);
spec.dasConfig.option[0] = new VcOptionValue();
spec.dasConfig.option[0].key = "das.ignoreRedundantNetWarning";
spec.dasConfig.option[0].value = true;
spec.drsConfig = new VcClusterDrsConfigInfo();
spec.drsConfig.enabled = true;
spec.drsConfig.defaultVmBehavior = VcDrsBehavior.fullyAutomated;
spec.drsConfig.vmotionRate = 2;
spec.drsVmConfigSpec = System.getModule("com.vmware.onyx").array(VcClusterDrsVmConfigSpec, 1);
spec.drsVmConfigSpec[0] = new VcClusterDrsVmConfigSpec();
spec.drsVmConfigSpec[0].operation = VcArrayUpdateOperation.remove;
spec.drsVmConfigSpec[0].removeKey = vm-1598;
spec.dpmConfig = new VcClusterDpmConfigInfo();
spec.dpmConfig.enabled = false;
spec.dpmConfig.hostPowerActionRate = 3;

managedObject.reconfigureComputeResource_Task(spec, true);  // ClusterComputeResource

ChristianWehner
VMware Employee
VMware Employee

Hi,

parent is only working on a VcVirtualMachine and not on a VcVirtualMachine.key thats your problem. If you give a VcVirtualMachine as Input its working.

The code to set it default again will I test later this day.

Regards,

Chris

0 Kudos
FreddyFredFred
Hot Shot
Hot Shot

That's what I figured based on the comment in your code. Below is the exact code I'm running and I still get the error about parent being undefined. I even changed it so I select the virtual machine (VC:VirtualMachine) for input but I still get the same error: cannot read property "parent" from undefinied.

When I run the workflow, in1 is a string and I type in the name of the VM I want to adjust.

var myVcVirtualMachineArray = System.getModule("com.vmware.library.vc.vm").getAllVMsMatchingRegexp(in1);

var myVcVirtualMachine=myVcVirtualMachineArray[0];


var myVcClusterComputeResource = myVcVirtualMachine.runtime.host.parent; //myVcVirtualMachine as Workflow/Scriptable Task input 

var myVcClusterDrsVmConfigInfo = new VcClusterDrsVmConfigInfo() ; 
myVcClusterDrsVmConfigInfo.key = myVcVirtualMachine; //myVcVirtualMachine as Workflow/Scriptable Task input 
myVcClusterDrsVmConfigInfo.behavior = VcDrsBehavior.manual; 
var myVcClusterDrsVmConfigSpec = new VcClusterDrsVmConfigSpec() ; 
myVcClusterDrsVmConfigSpec.operation = VcArrayUpdateOperation.add; 
myVcClusterDrsVmConfigSpec.info = myVcClusterDrsVmConfigInfo; 
var myVcClusterDrsVmConfigSpecArray = new Array() ; 
myVcClusterDrsVmConfigSpecArray.push( myVcClusterDrsVmConfigSpec ); 
var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ; 
myVcClusterConfigSpecEx.drsVmConfigSpec = myVcClusterDrsVmConfigSpecArray; 
myVcClusterComputeResource.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true ); 

I added the following to see what vCO was getting:

System.log(myVcVirtualMachine.runtime);

System.log(myVcVirtualMachine.runtime.host);

and this is what is says

[I] DynamicWrapper (Instance

) : [VcVirtualMachineRuntimeInfo]-[class com.vmware.vim.vi4.VirtualMachineRuntimeInfo] -- VALUE : com.vmware.vim.vi4.VirtualMachineRuntimeInfo@b2eded3f

[I] undefined

[I] TypeError: Cannot read property "parent" from undefined (Workflow:testing 2 / Scriptable task (item0)#8)

so it can't even figure out the host in this case

ChristianWehner
VMware Employee
VMware Employee

Can you take a look to https://yourvcenter.domain.com/mob navigate to the VM you want to reconfigure and take a look to the runtime information?! I see there the host system the VM is registered on.

0 Kudos
ChristianWehner
VMware Employee
VMware Employee

The set DRS to fully automated part is still not running. It seems like I've been missing something. Here the code I test, maybe it is running on your environment:

var myVcClusterComputeResource = myVcVirtualMachine.runtime.host.parent; //myVcVirtualMachine as Workflow/Scriptable Task input

var myVcClusterDrsConfigInfo = new VcClusterDrsConfigInfo() ;

myVcClusterDrsConfigInfo.enabled = true;

myVcClusterDrsConfigInfo.defaultVmBehavior = VcDrsBehavior.fullyAutomated;

myVcClusterDrsConfigInfo.vmotionRate = 2;

var myVcClusterDrsVmConfigSpec = new VcClusterDrsVmConfigSpec() ;

myVcClusterDrsVmConfigSpec.operation = VcArrayUpdateOperation.remove;

myVcClusterDrsVmConfigSpec.removeKey = myVcVirtualMachine.id; //myVcVirtualMachine as Workflow/Scriptable Task input

var myVcClusterDrsVmConfigSpecArray = new Array() ;

myVcClusterDrsVmConfigSpecArray.push( myVcClusterDrsVmConfigSpec );

var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;

myVcClusterConfigSpecEx.drsConfig = myVcClusterDrsConfigInfo;

myVcClusterConfigSpecEx.drsVmConfigSpec = myVcClusterDrsVmConfigSpecArray;

myVcClusterComputeResource.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );

If you get the problem with the parent running 🙂 Please let me know the result.

Regards

FreddyFredFred
Hot Shot
Hot Shot

Good news, bad news.

Bad news is I still can't get the .parent to work and I'm not sure where to look with that /mob url you have me.

The good news is it's working Smiley Happy Even the disable part.

To work around the problem of finding the cluster, I used the following code. I use it elsewhere in my deploy workflow so I already have the cluster. I just need to make a small adjustment to get access to the variable (You may have been the one to give me the code below in one of my earlier posts actually)

var vCenters=VcPlugin.allSdkConnections;

//System.log (vCenters[0].name);

for each (vCenter in vCenters){

var clusters = vCenter.getAllClusterComputeResources();

for each (mycluster in clusters)

{

  System.log(mycluster.name);

  if (mycluster.name=="Cluster02") //check included for future use

   cluster=mycluster;

}

}

As for removing the key, I found the answer in this thread:

https://communities.vmware.com/thread/439832

Below is the code which seems to work (I commented out your DRSConfigInfo and it seems to work without that. I just don't want to set any DRS stuff in the workflow and forget about it one day if I reconfigure my cluster options)

var mo = new VcManagedObjectReference();
mo.type="VirtualMachine";
mo.value=myVcVirtualMachine.id;

var myVcClusterComputeResource = cluster; //myVcVirtualMachine as Workflow/Scriptable Task input 
var myVcClusterDrsConfigInfo = new VcClusterDrsConfigInfo() ; 
//myVcClusterDrsConfigInfo.enabled = true; 
//myVcClusterDrsConfigInfo.defaultVmBehavior = VcDrsBehavior.fullyAutomated; 
//myVcClusterDrsConfigInfo.vmotionRate = 2; 
var myVcClusterDrsVmConfigSpec = new VcClusterDrsVmConfigSpec() ; 
myVcClusterDrsVmConfigSpec.operation = VcArrayUpdateOperation.remove; 
myVcClusterDrsVmConfigSpec.removeKey = mo;
//myVcClusterDrsVmConfigSpec.removeKey = myVcVirtualMachine.id; //myVcVirtualMachine as Workflow/Scriptable Task input 
var myVcClusterDrsVmConfigSpecArray = new Array() ; 
myVcClusterDrsVmConfigSpecArray.push( myVcClusterDrsVmConfigSpec ); 
var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ; 
myVcClusterConfigSpecEx.drsConfig = myVcClusterDrsConfigInfo; 
myVcClusterConfigSpecEx.drsVmConfigSpec = myVcClusterDrsVmConfigSpecArray; 
myVcClusterComputeResource.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );

Thanks again for all your help Christian. Now to clean everything, integrate it and hope it still works. I will need to run two workflows in parallel to get this to work with my current setup due to using the built-in clone workflow. I'll be sure to post again if I have trouble Smiley Wink

FreddyFredFred
Hot Shot
Hot Shot

and a little followup.... my cluster workaround turned into a problem for my workflow. Turns out there's an action under com.vmware.library.vc.cluster called getComputeResourceOfVm which seems to be returning the cluster after I pass the VCVirtualMachine

0 Kudos
ChristianWehner
VMware Employee
VMware Employee

Nice you got it running! *like* Smiley Happy

0 Kudos
Windspirit
Hot Shot
Hot Shot

Hi,

I'm actually NOT getting your script to work...

  1. var myVcClusterComputeResource = myVcVirtualMachine.runtime.host.parent; //myVcVirtualMachine as Workflow/Scriptable Task input 
  2. var myVcClusterDrsVmConfigInfo = new VcClusterDrsVmConfigInfo() ; 
  3. myVcClusterDrsVmConfigInfo.key = myVcVirtualMachine; //myVcVirtualMachine as Workflow/Scriptable Task input 
  4. myVcClusterDrsVmConfigInfo.behavior = VcDrsBehavior.manual; 
  5. var myVcClusterDrsVmConfigSpec = new VcClusterDrsVmConfigSpec() ; 
  6. myVcClusterDrsVmConfigSpec.operation = VcArrayUpdateOperation.add; 
  7. myVcClusterDrsVmConfigSpec.info = myVcClusterDrsVmConfigInfo; 
  8. var myVcClusterDrsVmConfigSpecArray = new Array() ; 
  9. myVcClusterDrsVmConfigSpecArray.push( myVcClusterDrsVmConfigSpec ); 
  10. var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ; 
  11. myVcClusterConfigSpecEx.drsVmConfigSpec = myVcClusterDrsVmConfigSpecArray; 
  12. myVcClusterComputeResource.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true ); 

I input the Cluster directly as well as the VM but what I get is :"Property or method 'key' not found on object VcClusterDrsVmConfigInfo"

which is BS as "key" is an Property of VcClusterDrsVmConfigInfo....

Any Idea?