0

This is the code generated by the code capture feature.

from pyVmomi import vim

spec = vim.cluster.ConfigSpecEx()
spec.drsConfig = vim.cluster.DrsConfigInfo()
spec.drsConfig.defaultVmBehavior = "fullyAutomated"
spec.drsConfig.scaleDescendantsShares = 'disabled'
spec.drsConfig.vmotionRate = 1
spec.drsConfig.enabled = True
spec.drsConfig.enableVmBehaviorOverrides = True
spec_drsConfig_option_0 = vim.option.OptionValue()
spec_drsConfig_option_0.value = '1'
spec_drsConfig_option_0.key = 'TryBalanceVmsPerHost'
spec_drsConfig_option_1 = vim.option.OptionValue()
spec_drsConfig_option_1.key = 'MaxVcpusPerCore'
spec.drsConfig.option = [spec_drsConfig_option_0,
spec_drsConfig_option_1]
spec.proactiveDrsConfig = vim.cluster.ProactiveDrsConfigInfo()
spec.proactiveDrsConfig.enabled = True
spec.dpmConfig = vim.cluster.DpmConfigInfo()
spec.dpmConfig.hostPowerActionRate = 3
spec.dpmConfig.enabled = False
modify = True
managedObject.ReconfigureComputeResource_Task(spec, modify)   # ClusterComputeResource-domain-c8


Error: C:\python>python drsTestThing.py
Traceback (most recent call last):
  File "C:\python\drsTestThing.py", line 38, in <module>
    managedObject.ReconfigureComputeResource_Task(spec, modify)   # ClusterComputeResource-domain-c8
NameError: name 'managedObject' is not defined

So far I gave determined that the return of the ReconfigureComputeResource_Task function is a Task object according to this https://vdc-download.vmware.com/vmwb-repository/dcr-public/da47f910-60ac-438b-8b9b-6122f4d14524/16b7274a-bf8b-4b4c-a05e-746f2aa93c8c/doc/vim.ComputeResource.html and it must be called by a cluster object.

My issue is I don't understand how to make to make a cluster object and how that connects to vSphere and changes the configuration of the cluster.

Currently I am connecting to the host using SmartConnect from the pyVim library. I also have this working with powerCLI but the connect-vi server method hangs so I would like to accomplish this task with python.

jasont41
  • 49
  • 1
  • 6

1 Answers1

0

It looks like you never established the cluster (or ClusterComputeResource) as the managedObject variable. That should have been done prior to creating the spec variable and may have been missed from the Code Capture output.

Kyle Ruddy
  • 1,886
  • 1
  • 7
  • 5
  • I noticed that, there wasn't anything on the code capture that defined that variable. I noticed this in [regards to the cluster](https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.Folder.html#createClusterEx) but I'm not sure how to go about properly creating that variable. I just found [this](https://www.programcreek.com/python/?code=vmware%2Fpyvmomi-community-samples%2Fpyvmomi-community-samples-master%2Fsamples%2Flist_dc_datastore_info.py), would using retrieve_content() get my the reference to the MO? – jasont41 Jul 20 '21 at 15:38
  • FWIW, here's how it looks in my Code Capture output: ``` $spec = New-Object VMware.Vim.ClusterConfigSpecEx $spec.DrsConfig = New-Object VMware.Vim.ClusterDrsConfigInfo ... $_this = Get-View -Id 'ClusterComputeResource-domain-c7' $_this.ReconfigureComputeResource_Task($spec, $modify) ``` – Kyle Ruddy Jul 21 '21 at 16:10
  • That looks like the powerCLI output. That works for the most part but the connect-vi server cmdlet can hang and I want to avoid that. This is the python output I get: # managedObject.RetrieveDasAdvancedRuntimeInfo() # spec = vim.cluster.ConfigSpecEx() # modify = True # managedObject.ReconfigureComputeResource_Task(spec, modify) # ClusterComputeResource-domain-c8 I had to click around a little bit when capturing the code to get the managed object reference but it still errors out and I'm not sure why. It appears I need to instantiate the ClusterResource variable but I'm not sure how – jasont41 Jul 21 '21 at 16:20
  • ah, sorry about that, the dropdown changed between recordings. You might be able to update it with the following: managedObject = get_obj(content, [vim.ClusterComputeResource], inputs['cluster_name']) – Kyle Ruddy Jul 22 '21 at 17:20
  • I'll give that a spin and let you know how it goes. It seems like this side of VMware isn't well documented. Thanks for all the help! – jasont41 Jul 23 '21 at 07:51