Creating a custom attribute using the perl sdk looks like this:
$customFieldMgr->AddCustomFieldDef(name => $cfkey, moType => 'VirtualMachine');
Doing the same in python using pyvmomi creates a traceback:
>>> customFieldMgr.AddCustomFieldDef(name = cfkey, moType = 'VirtualMachine')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyVmomi/VmomiSupport.py", line 553, in <lambda>
self.f(*(self.args + (obj,) + args), **kwargs)
File "pyVmomi/VmomiSupport.py", line 361, in _InvokeMethod
map(CheckField, info.params, args)
File "pyVmomi/VmomiSupport.py", line 936, in CheckField
% (info.name, info.type.__name__, valType.__name__))
TypeError: For "moType" expected type type, but got str
So whats wrong here?
BTW: does someone know a source of examples using pyvmomi?
I had written a simple sample before, but not the same as you expected:
Hi Matthias did you ever get an answer for this? Steve Jin I see your link's contents but it doesn't address the issue, could you be more specific if you know how to access the methods of the CustomFieldsManager object? I'm trying to use the SetField method myself and can't get it to work.
In PyVmomi you'll need to pass in the vim class type, not the string. I ran into this while doing some Ansible modules. I ended up needing something that worked from the entity type string ('VirtualMachine', 'HostSystem', etc); but generally the ManagedEntity types are hanging off the vim object
# Include this with your other pyVmomi imports
from pyVmomi import vim
customFieldMgr.AddCustomFieldDef(name = cfkey, moType = vim.VirtualMachine)
See if that does the trick.