-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to set custom attributes & tags when cloning VM from template #415
Comments
Hi, I'd love to see tags. Unfortunately it's not available in the SOAP API. VMWare does have an API but so far has not made the ruby gem available on rubygems, which means we can't distribute it, and haven't tried to do the code. Which custom attributes are you talking about? There's an |
Noted regarding tags. One example of a tool that leverages this is the vagrant-vsphere plugin, which also uses rbvmomi. When provisioning a VM with it, you can define which values to assign to one or more custom attribute keys. |
Aha, so this is setting |
in vagrant-vsphere, they call setCustomValue on the object returned by template.CloneVM_Task. |
We could definitely add that kind of stuff (or take PRs doing it ;) ), how were you thinking it would get used? |
Hint noted :) I see these use cases:
In all cases, any custom attribute key would need to already exist in vCenter, and be assigned to the object type (VM, datastore, etc) It should be possible to set the option value as a list of k/v pairs (or maybe call the option multiple times in the same command). I don't know how this is usually done in knife-vsphere. In my particular case, I'm wanting this to facilitate some asset management stuff. |
Typically we pass JSON, such as Since I don't use those features (yet? It sounds helpful) I'll have a look around the UI to see how and where I'd use them. |
I was taking a second look to the VMware link for ExtensibleManagedObject, and as the only method is setCustomValue, it limits this functionality to a (over)write operation, which is unfortunate. No idea if that information can be extracted with a different method. |
Would it be I also see in the docs there's a |
I digged a little bit further, and this is actually doable in a r/w fashion using the customFieldsManager interface. Came up with this snippet of code as proof of concept. This code finds the VM, gets all custom fields from vcenter and creates a simple hash map of field id > field name. Then iterates over the VM customValue property and outputs field Name and the Value assigned in that particular VM. Then actually changes the value of field with id 41. Seems to work fine, just tested against one vCenter 6.5. (disclaimer: Ruby newbie here) `vim = VIM.connect opts dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found" fields = vim.serviceInstance.content.customFieldsManager.field fields.each do |f| vm.customValue.each do |x| vim.serviceInstance.content.customFieldsManager.SetField(entity: vm, key: "41", value: "whatever")` |
Hello,
Did not find this capability in the documentation. Is this possible somehow?
I think it's very useful feature, to be able to classify the VM with either tags or custom attributes, either as part of the cloning process, and a separate get/set command for existing VM's.
Thanks.
The text was updated successfully, but these errors were encountered: