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
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 );
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
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);
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.
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.
That should work. What I mean is that if the VM HAS already a Priority setting this script wont work.
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 );
That did the trick. Thanks.