Hi guys Is anybody can help me how to use openAuth to connect a remote URI without input the boring password? we assume the password of root for remote machine is "123456". Even I running the example in libvirt library esxlist.py(change uri to a qemu type and assign the username and password). Bellow is my simple test code, unfortunately it still need me to input the password. import libvirt def authcb(ncred, cbdata): for cred in ncred: if cred[0] == libvirt.VIR_CRED_AUTHNAME: cred[4] = "root" elif cred == libvirt.VIR_CRED_PASSPHRASE: cred[4] = "123456" return 0 class connection: def __init__(self, uri): self.uri = uri def open(self): auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], authcb, None] vm_conn = libvirt.openAuth(self.uri, auth, 0); print self.uri if vm_conn == None: print 'Failed to open connection to %s' % self.uri for name in vm_conn.listDefinedDomains(): print name vm = vm_conn.lookupByName(name) if __name__ == '__main__': conn = connection('qemu+ssh://root at 192.168.1.203/system') conn.open() Thanks fan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20120826/5fd7e7da/attachment.htm>
Martin Kletzander
2012-Aug-27 13:48 UTC
[libvirt-users] question about using openAuth with Python
On 08/26/2012 03:39 PM, lulin Fan wrote:> Hi guys > > Is anybody can help me how to use openAuth to connect a remote URI > without input the boring password? we assume the password of root for > remote machine is "123456". > > Even I running the example in libvirt library esxlist.py(change uri to a > qemu type and assign the username and password). > > Bellow is my simple test code, unfortunately it still need me to input > the password. > > import libvirt > > def authcb(ncred, cbdata): > for cred in ncred: > if cred[0] == libvirt.VIR_CRED_AUTHNAME: > cred[4] = "root" > elif cred == libvirt.VIR_CRED_PASSPHRASE: > cred[4] = "123456" > return 0 > class connection: > def __init__(self, uri): > self.uri = uri > def open(self): > auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], > authcb, None] > vm_conn = libvirt.openAuth(self.uri, auth, 0); > print self.uri > if vm_conn == None: > print 'Failed to open connection to %s' % self.uri > > for name in vm_conn.listDefinedDomains(): > print name > vm = vm_conn.lookupByName(name) > > if __name__ == '__main__': > conn = connection('qemu+ssh://root at 192.168.1.203/system > <http://root at 192.168.1.203/system>') > conn.open() > Thanks >Hi, the formatting has gone wrong, but that doesn't matter. The auth you are supplying is for libvirt authentication (might not be required as you use ssh to root) and the password you are being asked for is needed for the ssh connection. You can either create ssh keys for password-less connection or use other type of transport (uri qemu://192.168.1.203/system which defaults to qemu+tls or qemu+tcp://192.168.1.203/system). For setting up the other transports you can have a look at docs or web pages. Martin