ia64/xen-unstable

changeset 15216:e046da853ffc

xend: Give "xm start" a -c parameter for connecting to the console
From: Chris Lalancette <clalance@redhat.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu May 24 15:36:13 2007 +0100 (2007-05-24)
parents 21f1a7a7ea30
children d1cce5bafe28
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Thu May 24 15:30:05 2007 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Thu May 24 15:36:13 2007 +0100
     1.3 @@ -231,6 +231,7 @@ SUBCOMMAND_OPTIONS = {
     1.4      ),
     1.5      'start': (
     1.6        ('-p', '--paused', 'Do not unpause domain after starting it'),
     1.7 +      ('-c', '--console_autoconnect', 'Connect to the console after the domain is created'),
     1.8      ),
     1.9      'resume': (
    1.10        ('-p', '--paused', 'Do not unpause domain after resuming it'),
    1.11 @@ -1125,29 +1126,67 @@ def xm_vcpu_list(args):
    1.12  
    1.13              print format % locals()
    1.14  
    1.15 +def start_do_console(domain_name):
    1.16 +    cpid = os.fork() 
    1.17 +    if cpid != 0:
    1.18 +        for i in range(10):
    1.19 +            # Catch failure of the create process 
    1.20 +            time.sleep(1)
    1.21 +            (p, rv) = os.waitpid(cpid, os.WNOHANG)
    1.22 +            if os.WIFEXITED(rv):
    1.23 +                if os.WEXITSTATUS(rv) != 0:
    1.24 +                    sys.exit(os.WEXITSTATUS(rv))
    1.25 +            try:
    1.26 +                # Acquire the console of the created dom
    1.27 +                if serverType == SERVER_XEN_API:
    1.28 +                    domid = server.xenapi.VM.get_domid(
    1.29 +                               get_single_vm(domain_name))
    1.30 +                else:
    1.31 +                    dom = server.xend.domain(domain_name)
    1.32 +                    domid = int(sxp.child_value(dom, 'domid', '-1'))
    1.33 +                console.execConsole(domid)
    1.34 +            except:
    1.35 +                pass
    1.36 +        print("Could not start console\n");
    1.37 +        sys.exit(0)
    1.38 +
    1.39  def xm_start(args):
    1.40 -    arg_check(args, "start", 1, 2)
    1.41 +
    1.42 +    paused = False
    1.43 +    console_autoconnect = False
    1.44  
    1.45      try:
    1.46 -        (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
    1.47 +        (options, params) = getopt.gnu_getopt(args, 'cp', ['console_autoconnect','paused'])
    1.48 +        for (k, v) in options:
    1.49 +            if k in ('-p', '--paused'):
    1.50 +                paused = True
    1.51 +            if k in ('-c', '--console_autoconnect'):
    1.52 +                console_autoconnect = True
    1.53 +
    1.54 +        if len(params) != 1:
    1.55 +            raise OptionError("Expects 1 argument")
    1.56      except getopt.GetoptError, opterr:
    1.57          err(opterr)
    1.58          usage('start')
    1.59  
    1.60 -    paused = False
    1.61 -    for (k, v) in options:
    1.62 -        if k in ['-p', '--paused']:
    1.63 -            paused = True
    1.64 +    dom = params[0]
    1.65 +
    1.66 +    if console_autoconnect:
    1.67 +        start_do_console(dom)
    1.68  
    1.69 -    if len(params) != 1:
    1.70 -        err("Wrong number of parameters")
    1.71 -        usage('start')
    1.72 -
    1.73 -    dom = params[0]
    1.74 -    if serverType == SERVER_XEN_API:
    1.75 -        server.xenapi.VM.start(get_single_vm(dom), paused)
    1.76 -    else:
    1.77 -        server.xend.domain.start(dom, paused)
    1.78 +    try:
    1.79 +        if serverType == SERVER_XEN_API:
    1.80 +            server.xenapi.VM.start(get_single_vm(dom), paused)
    1.81 +            domid = int(server.xenapi.VM.get_domid(get_single_vm(dom)))
    1.82 +        else:
    1.83 +            server.xend.domain.start(dom, paused)
    1.84 +            info = server.xend.domain(dom)
    1.85 +            domid = int(sxp.child_value(info, 'domid', '-1'))
    1.86 +    except:
    1.87 +        raise
    1.88 +        
    1.89 +    if domid == -1:
    1.90 +        raise xmlrpclib.Fault(0, "Domain '%s' is not started" % dom)
    1.91  
    1.92  def xm_delete(args):
    1.93      arg_check(args, "delete", 1)