mcescalante
Contributor
Contributor

Add VM to DRS Rule

I am working on a script and a PowerCLI commandlet seems to already be written for it. The script adds an existing vm to an existing DRS Rule.

Here is the code for the commandlet I would like to replicate:

$spec = New-Object VMware.Vim.ClusterConfigSpecEx
$spec.groupSpec = New-Object VMware.Vim.ClusterGroupSpec[] (1)
$spec.groupSpec[0] = New-Object VMware.Vim.ClusterGroupSpec
$spec.groupSpec[0].operation = "edit"
$spec.groupSpec[0].info = $DrsGroup
$spec.groupSpec[0].info.vm += $VM.ExtensionData.MoRef

$Cluster.ExtensionData.ReconfigureComputeResource_Task($spec, $true)


To my understanding, something along the following lines can be done to translate this to Perl:

1. Create a ClusterGroupSpec object with the correct information. I fail here, and am unsure of how to add "info.vm" into ClusterGroupSpec in Perl.

     my $cluster_group_spec = ClusterGroupSpec->new(operation => "edit", info => $drs_rule_name...


2. Pass this as a ClusterConfigSpecEx object into rulesSpec

     my $cluster_config_spec = ClusterConfigSpecEx->new(rulesSpec => [$cluster_group_spec]);


3. Reconfigure with spec as $cluster_config_spec.


What I am confused about is how to pass in info.vm from the PowerCLI. There is no member of info or ClusterConfigInfo called "vm". How would I tell the Group Spec what VM to use?



Updated the title to be more informative (it is no longer solely a "translation", the thread contains the answer to the title now).

Tags (3)