[libvirt-users] How to connect to a remote VM ESXi server with Python language?

Hi, Dear Mr/Mrs. I have trouble in connecting to a VM ESXi server with python. I am a developer using libvirt to control remote VM ESXi with python language. But I am not able to connect to a remote VM ESXi server. I make my try to solve this issue: 1: I use the function libvirt.Open() to open the remote VM ESXi Server, but I don't know how to input the password. It seems that there is no parameter for password input. 2: I use "virsh connect ---". It is succeed when it is executed on locale machine manual, but failed when I invoke this command in python environment. I use "subprocess.Popen" to execute the command "virsh", but this function would be hung on after command "communicate" executed. -bash-4.1# python Python 2.6.6 (r266:84292, May 20 2011, 16:42:11) [GCC 4.4.5 20110214 (Red Hat 4.4.5-6)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
from subprocess import Popen,PIPE,STDOUT
command=['virsh', '-c', 'esx://192.168.58.144/?no_verify=1','list', '--all']
p=Popen(command, stdin=PIPE,stdout=PIPE, stderr=STDOUT)
output = p.communicate()[0]
How to fix it? Thanks for help! Best regards!

2011/12/26 ice <ice_feng@usish.com>:
Hi, Dear Mr/Mrs.
I have trouble in connecting to a VM ESXi server with python.
I am a developer using libvirt to control remote VM ESXi with python language. But I am not able to connect to a remote VM ESXi server.
I make my try to solve this issue:
1: I use the function libvirt.Open() to open the remote VM ESXi Server, but I don’t know how to input the password. It seems that there is no parameter for password input.
Let's just ignore your second try with virsh. The problem with your first try is that you need to use libvirt.openAuth() instead of libvirt.open(). openAuth() allows to pass credentials via a callback mechanism. There is a Python example in the libvirt codebase that does this, see http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/python/esxlist.py -- Matthias Bolte http://photron.blogspot.com

Hi, Dear Mr/Mrs.
I have trouble in connecting to a VM ESXi server with python.
I am a developer using libvirt to control remote VM ESXi with python language. But I am not able to connect to a remote VM ESXi server.
I make my try to solve this issue:
1: I use the function libvirt.Open() to open the remote VM ESXi Server, but I don’t know how to input the password. It seems that there is no
Hi, Matthias, Thanks for your reply. I look into the example, and I am now having connected to the remote VM ESXi Server. Thanks a lot for your help. Best Regards. -----邮件原件----- 发件人: Matthias Bolte [mailto:matthias.bolte@googlemail.com] 发送时间: 2011年12月28日 23:09 收件人: ice 抄送: libvirt-users@redhat.com; libvir-list@redhat.com 主题: Re: [libvirt-users] How to connect to a remote VM ESXi server with Python language? 2011/12/26 ice <ice_feng@usish.com>: parameter
for password input.
Let's just ignore your second try with virsh. The problem with your first try is that you need to use libvirt.openAuth() instead of libvirt.open(). openAuth() allows to pass credentials via a callback mechanism. There is a Python example in the libvirt codebase that does this, see http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/python/esxlist.py -- Matthias Bolte http://photron.blogspot.com
participants (2)
-
ice
-
Matthias Bolte