Skip to content

Instantly share code, notes, and snippets.

@avsm
Created December 3, 2009 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avsm/248294 to your computer and use it in GitHub Desktop.
Save avsm/248294 to your computer and use it in GitHub Desktop.
#!/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