How to rename a virtual machine in ESX using python scripts?

502 views
Skip to first unread message

sasikiran v

unread,
Oct 8, 2012, 12:35:35 AM10/8/12
to pysp...@googlegroups.com
Is there any API that can be used to rename a VM in ESX?
or
If anyone has the python scripts readily please send me the link

Esteban Mendoza

unread,
Oct 9, 2012, 2:59:38 PM10/9/12
to pysp...@googlegroups.com
Try this:

>>> from pysphere.vi_task import VITask
>>> import pysphere.resources.VimService_services as VI
>>> from pysphere import VIServer
>>> server = VIServer()
>>> server.connect("1.1.1.1", "your_user", "your_password")
>>> vm = server.get_vm_by_name("Win 2008 R2") # get VM
>>> request = VI.Rename_TaskRequestMsg()
>>> _this = request.new__this(vm._mor)
>>> _this.set_attribute_type(vm._mor.get_attribute_type())
>>> request.set_element__this(_this)
>>> request.set_element_newName("Windows 2008 R2")
>>> task = server._proxy.Rename_Task(request)._returnval
>>> task = VITask(task, server)

Hope this helps

sasikiran v

unread,
Oct 9, 2012, 11:55:14 PM10/9/12
to pysp...@googlegroups.com
Thank you very much Esteban Mendoza
It helped me a lot..

Seba

unread,
Oct 10, 2012, 8:58:01 AM10/10/12
to pysp...@googlegroups.com, Esteban Mendoza, sasiki...@gmail.com
Hi,
  I've just committed revision r84, now you can just do:

vm.rename("New vm name")

or 

task = vm.rename("New vm name", sync_run=False)

Regards,

Seba.
Reply all
Reply to author
Forward
0 new messages