I am trying to find a code support in python
for moving a machine between Datacenter's folders without success, I saw in pysphere
that you can define the folder just in the clone stage and not after machine already cloned.
This seems as a solution for my problem but it is in powershell, do anybody know a wrapping support for it in python
You can do this with pyVmomi. I would avoid pysphere because pyVmomi is maintained by VMWare and pysphere hasnt been updated in 4 years or more.
That said here is some sample code that uses pyVmomi
In this example I create a
ServiceInstance
by connecting to a vCenter, next I grab an instance of theSearchIndex
. TheSearchIndex
has several methods that can be used to locate your managed objects. In this example I decided to use theFindByInventoryPath
method, but you could use any that will work for you. First I find the instance of theFolder
namednew_folder
that I want to move myVirtualMachine
into. Next I find theVirtualMachine
I want to move. Finally I execute theTask
that will move the vm for me. That task takes a param of the list of objects to be moved into the folder, and in this case its a single item list containing only the one vm I want to move. From here you can monitor the task if you want.Keep in mind that if you use the
FindByInventoryPath
there are many hidden folders that are not visible from the GUI. I find that using the ManagedObjectBrowser is very helpful at times.Helpful doc links: