Windspirit
Hot Shot
Hot Shot

Set restart priority for a VM

Jump to solution

Hi,

I try to set the restart priority for a VM in a cluster. I worked along the THIS DISCUSSION to create this script:

var myVcClusterDasConfigInfo = new VcClusterDasConfigInfo() ;

var myVcClusterDasVmConfigSpec = new VcClusterDasVmConfigSpec() ;

myVcClusterDasVmConfigSpec.operation = VcArrayUpdateOperation.add;

var myVcClusterDasVmConfigInfo = new VcClusterDasVmConfigInfo() ;

myVcClusterDasVmConfigInfo.key = VM;

myVcClusterDasVmConfigInfo.restartPriority =  VcDasVmPriority.high;

myVcClusterDasVmConfigSpec.info = myVcClusterDasVmConfigInfo;

var myVcClusterDasVmConfigSpecArray = new Array() ;

myVcClusterDasVmConfigSpecArray.push( myVcClusterDasVmConfigSpec );

var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;

myVcClusterConfigSpecEx.dasConfig = myVcClusterDasConfigInfo;

myVcClusterConfigSpecEx.dasVmConfigSpec = myVcClusterDasVmConfigSpecArray;

Cluster.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );

Where Cluster and VM are objects from the WF input.

The scripts runs thought, however in VC I get the error "The setting of {entry.@enum.InvalidDasConfigArgument.EntryForInvalidArgument} is invalid for cluster"

It is properly simple....but I just cant work it out.

Thanks guys

0 Kudos
1 Solution

Accepted Solutions
Windspirit
Hot Shot
Hot Shot

Also I just realized.....that the method I used is Deprecated...grrr

Here the correct one:

var myVcClusterDasVmSettings = new VcClusterDasVmSettings();

myVcClusterDasVmSettings.restartPriority=VcClusterDasVmSettingsRestartPriority.fromString(priority);

var myVcClusterDasVmConfigInfo = new VcClusterDasVmConfigInfo();

myVcClusterDasVmConfigInfo.key=VM;

myVcClusterDasVmConfigInfo.dasSettings=myVcClusterDasVmSettings;

var myVcClusterDasVmConfigSpec = new VcClusterDasVmConfigSpec() ;

myVcClusterDasVmConfigSpec.operation = VcArrayUpdateOperation.add;

myVcClusterDasVmConfigSpec.info = myVcClusterDasVmConfigInfo;

var myVcClusterDasVmConfigSpecArray = new Array() ;

myVcClusterDasVmConfigSpecArray.push( myVcClusterDasVmConfigSpec );

var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;

var myVcClusterDasConfigInfo = new VcClusterDasConfigInfo() ;

myVcClusterConfigSpecEx.dasConfig = myVcClusterDasConfigInfo;

myVcClusterConfigSpecEx.dasVmConfigSpec = myVcClusterDasVmConfigSpecArray;

task=ClusterName.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );

View solution in original post

0 Kudos
7 Replies
Thitho666
Contributor
Contributor

Hello !

You coult try this code :

var myoperation = "add" ;

var priority = "high" ;

var mydasVmConfigSpec = new Array();

var myVMconfig = new VcClusterDasVmConfigSpec();

myVMconfig.info = new VcClusterDasVmConfigInfo();

myVMconfig.info.key = vCloudVM;

myVMconfig.info.dasSettings = new VcClusterDasVmSettings();

myVMconfig.info.dasSettings.restartPriority = priority;

myVMconfig.operation = VcArrayUpdateOperation.fromString(myoperation);

mydasVmConfigSpec.push(myVMconfig);

var spec = new VcClusterConfigSpecEx();

spec.dasVmConfigSpec = mydasVmConfigSpec;

task = ClusterName.reconfigureComputeResource_Task(spec, true);

Hope this help...

Thitho

pabloramos
Enthusiast
Enthusiast

Thitho, I am trying to use your code to change the HA Restart priority for a specific VM. In the code below I am passing input variables for vm, cluster, and HARestartPri which I am setting to a value of Medium. The code runs and I don't get any errors in Vco, however the value for Restart priority does not change and I get the error below in Vcenter:

The setting of VmConfig is invalid for cluster <mycluster>

Can you assist?

var myoperation = "add";

var mydasVmConfigSpec = new Array();

var myVMconfig = new VcClusterDasVmConfigSpec();

myVMconfig.info = new VcClusterDasVmConfigInfo();

myVMconfig.info.key = vm;

myVMconfig.info.dasSettings = new VcClusterDasVmSettings();

myVMconfig.info.dasSettings.restartPriority = HARestartPri;

myVMconfig.operation = VcArrayUpdateOperation.fromString(myoperation);

mydasVmConfigSpec.push(myVMconfig);

var spec = new VcClusterConfigSpecEx();

spec.dasVmConfigSpec = mydasVmConfigSpec;

task = cluster.reconfigureComputeResource_Task(spec, true);

0 Kudos
Windspirit
Hot Shot
Hot Shot

OK...I figured it out:

var myVcClusterDasConfigInfo = new VcClusterDasConfigInfo() ;

var myVcClusterDasVmConfigSpec = new VcClusterDasVmConfigSpec() ;

myVcClusterDasVmConfigSpec.operation = VcArrayUpdateOperation.add;

var myVcClusterDasVmConfigInfo = new VcClusterDasVmConfigInfo() ;

myVcClusterDasVmConfigInfo.key = VM;

myVcClusterDasVmConfigInfo.restartPriority = VcDasVmPriority.fromString(priority) ;

myVcClusterDasVmConfigSpec.info = myVcClusterDasVmConfigInfo;

var myVcClusterDasVmConfigSpecArray = new Array() ;

myVcClusterDasVmConfigSpecArray.push( myVcClusterDasVmConfigSpec );

var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;

myVcClusterConfigSpecEx.dasConfig = myVcClusterDasConfigInfo;

myVcClusterConfigSpecEx.dasVmConfigSpec = myVcClusterDasVmConfigSpecArray;

task=ClusterName.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );

Where ClusterName,VM and priority are in variables

Please NOTE:if the priority IS allready set....this function will produce and error.

0 Kudos
pabloramos
Enthusiast
Enthusiast

When you say ":if the priority IS allready set....this function will produce and error." do you mean if I try to set priority to same value it's already at? For example priority set at Low and I try to set it at Low with his code. Since I am cloning from template, we have the priority set to "Use cluster setting." I would like to come in after vm is built and set it to Low, Medium, or High depending on customer needs.

0 Kudos
Windspirit
Hot Shot
Hot Shot

That should work. What I mean is that if the VM HAS already a Priority setting this script wont work.

0 Kudos
Windspirit
Hot Shot
Hot Shot

Also I just realized.....that the method I used is Deprecated...grrr

Here the correct one:

var myVcClusterDasVmSettings = new VcClusterDasVmSettings();

myVcClusterDasVmSettings.restartPriority=VcClusterDasVmSettingsRestartPriority.fromString(priority);

var myVcClusterDasVmConfigInfo = new VcClusterDasVmConfigInfo();

myVcClusterDasVmConfigInfo.key=VM;

myVcClusterDasVmConfigInfo.dasSettings=myVcClusterDasVmSettings;

var myVcClusterDasVmConfigSpec = new VcClusterDasVmConfigSpec() ;

myVcClusterDasVmConfigSpec.operation = VcArrayUpdateOperation.add;

myVcClusterDasVmConfigSpec.info = myVcClusterDasVmConfigInfo;

var myVcClusterDasVmConfigSpecArray = new Array() ;

myVcClusterDasVmConfigSpecArray.push( myVcClusterDasVmConfigSpec );

var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;

var myVcClusterDasConfigInfo = new VcClusterDasConfigInfo() ;

myVcClusterConfigSpecEx.dasConfig = myVcClusterDasConfigInfo;

myVcClusterConfigSpecEx.dasVmConfigSpec = myVcClusterDasVmConfigSpecArray;

task=ClusterName.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );

0 Kudos
pabloramos
Enthusiast
Enthusiast

That did the trick. Thanks.

0 Kudos