Created
December 3, 2009 16:24
-
-
Save avsm/248294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, os, subprocess | |
import XenAPI, inventory, xmlrpclib | |
xenconsole = "/usr/lib/xen/bin/xenconsole" | |
def attach_console(session, uuid): | |
vmref = session.xenapi.VM.get_by_uuid(uuid) | |
try: | |
session.xenapi.VM.start(vmref, True, True) | |
except: | |
print "Unable to start VM, is it already running?" | |
return 1 | |
domid="-1" | |
while domid=="-1": | |
domid=session.xenapi.VM.get_domid(vmref) | |
args = [ xenconsole, domid ] | |
proc = subprocess.Popen(args,close_fds=False) | |
try: | |
session.xenapi.VM.unpause(vmref) | |
except: | |
print "Unable to unpause VM" | |
return 1 | |
proc.wait () | |
sys.stdout.flush () | |
sys.stderr.flush () | |
if __name__ == "__main__": | |
session = XenAPI.xapi_local() | |
try: | |
session.xenapi.login_with_password("root", "") | |
except: | |
print "Unable to connect to xapi" | |
sys.exit(1) | |
uuid="6720667c-5666-d425-9600-3ab6db6bd7a4" | |
try: | |
attach_console(session, uuid) | |
finally: | |
session.xenapi.logout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment