Using pyvmomi to set metadata on a VirtualMachine in vSphere

Do you need to set some kind of Key, Value info up on a VirtualMachine in vCenter that you can access from the API? I thought with 5.5 and the addition of this that there was going to be some kind of actual Matadata fields added to the vSphere API, but it seems that still hasnt happened, as this is incomplete and missing any way to actually use it. The good news is that since 4.0 there has been a way to add key value pairs to the vm.config.extraConfig. The key has to be a String, and the Value can be an object. I have used this to store all kinds of stuff from Strings to JSON and XML payloads and even base64 encoded files. I wrote a sample for the pyVmomi-community-samples project that uses the vm.config.extraConfig to store some key value pairs. You can get it here until it gets accepted by the project and merged into master.

2 thoughts on “Using pyvmomi to set metadata on a VirtualMachine in vSphere

  1. Hi Mike,

    Is it possible to inject a shell script using extraConfig ? What I wanna do is, I want to place a script in the run level. So that right after cloning when the VM will boot up the script will run automatically. Please provide some pointers.

    Thanks & Regards,
    Reuben

  2. You can store any kind of file there, but I dont know that you can access the file from inside the vm though. I feel like there is a way using vmware tools or GuestRPC but I am unable to find anything solid documentation wise on doing that.

    So you cant exactly “inject” it in there.

Leave a Reply

Your email address will not be published. Required fields are marked *