开发者

How to deal with interactive API in python

I'm in a situation where I need to pass some texts to a prompt generate by a API (seems for API it's a pretty weird behavior, this is the first time I ran into this), like below:

kvm_cli = libvirt.open("qemu+ssh://han@10.0.10.8/system")

then a prompt shows up asking for the ssh password (password for 10.0.10.8 is:), I have to manually type it there in order to move on and yield the kvm_cli object I needed.

I tried to use the pexpect module to deal with this however it's for OS command line instead of API.

It's also开发者_JAVA百科 possible to work around this by using ssh certification files but it's not a favorable authentication approach in our scenario.

Since our wrapper to the 'open' method is not interactive, we cannot ask the user to input the password, do you guys have any thought how could I address it?


I am not a libvirt user, but I believe that the problem is not in the library, but in the connection method. You seem to be connecting via ssh, so you need to authenticate yourself.

I've been reading the libvirt page on ArchWiki, and I think that you could try:

  • setting up the simple (TCP/IP socket) connection method, or
  • setting up key-based, password-less SSH login for your virtual host.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜