WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [RFC][PATCH]: Give "xm start" a -c parameter for connecting

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [RFC][PATCH]: Give "xm start" a -c parameter for connecting to the console
From: Chris Lalancette <clalance@xxxxxxxxxx>
Date: Tue, 15 May 2007 13:15:16 -0400
Delivery-date: Tue, 15 May 2007 10:13:45 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.8-1.1.fc4 (X11/20060501)
All,
     Current 3.1.0 "xm start" doesn't allow you to connect to the console of an
already defined domain at domain creation time.  Because of this, you can't get
access to pygrub to select kernels, edit parameters, etc.  The attached patch
fixes this by adding a "-c" option to xm_start.  Most of the code is copied from
the equivalent option in "xm create".  I know this patch is ugly in that copies
the "do_console" code from create.py; I tried to put this function in
console.py, but it ended up spitting the error below when I did that.  Since
python is not my strong suit, does anyone have better ideas about this?

Thanks,
Chris Lalancette

XM ERROR:

[root@lore xm]# xm start -c f7pv
Unexpected error: <type 'exceptions.OSError'>

Please report to xen-devel@xxxxxxxxxxxxxxxxxxx
Traceback (most recent call last):
  File "/usr/sbin/xm", line 10, in <module>
    main.main(sys.argv)
  File "/usr/lib/python2.5/site-packages/xen/xm/main.py", line 2503, in main
    _, rc = _run_cmd(cmd, cmd_name, args)
  File "/usr/lib/python2.5/site-packages/xen/xm/main.py", line 2527, in _run_cmd
   return True, cmd(args)
  File "/usr/lib/python2.5/site-packages/xen/xm/main.py", line 1180, in xm_start
   console.do_console(dom)
  File "/usr/lib/python2.5/site-packages/xen/xm/console.py", line 34, in 
do_console
    (p, rv) = os.waitpid(cpid, os.WNOHANG)
OSError: [Errno 10] No child processes
--- xen-3.1.0-testing.hg-rc7/tools/python/xen/xm/main.py.orig
+++ xen-3.1.0-testing.hg-rc7/tools/python/xen/xm/main.py
@@ -231,6 +231,7 @@ SUBCOMMAND_OPTIONS = {
     ),
     'start': (
       ('-p', '--paused', 'Do not unpause domain after starting it'),
+      ('-c', '--console_autoconnect', 'Connect to the console after the domain 
is created'),
     ),
     'resume': (
       ('-p', '--paused', 'Do not unpause domain after resuming it'),
@@ -1125,29 +1126,67 @@ def xm_vcpu_list(args):
 
             print format % locals()
 
+def start_do_console(domain_name):
+    cpid = os.fork() 
+    if cpid != 0:
+        for i in range(10):
+            # Catch failure of the create process 
+            time.sleep(1)
+            (p, rv) = os.waitpid(cpid, os.WNOHANG)
+            if os.WIFEXITED(rv):
+                if os.WEXITSTATUS(rv) != 0:
+                    sys.exit(os.WEXITSTATUS(rv))
+            try:
+                # Acquire the console of the created dom
+                if serverType == SERVER_XEN_API:
+                    domid = server.xenapi.VM.get_domid(
+                               get_single_vm(domain_name))
+                else:
+                    dom = server.xend.domain(domain_name)
+                    domid = int(sxp.child_value(dom, 'domid', '-1'))
+                console.execConsole(domid)
+            except:
+                pass
+        print("Could not start console\n");
+        sys.exit(0)
+
 def xm_start(args):
-    arg_check(args, "start", 1, 2)
+
+    paused = False
+    console_autoconnect = False
 
     try:
-        (options, params) = getopt.gnu_getopt(args, 'p', ['paused'])
+        (options, params) = getopt.gnu_getopt(args, 'cp', 
['console_autoconnect','paused'])
+        for (k, v) in options:
+            if k in ('-p', '--paused'):
+                paused = True
+            if k in ('-c', '--console_autoconnect'):
+                console_autoconnect = True
+
+        if len(params) != 1:
+            raise OptionError("Expects 1 argument")
     except getopt.GetoptError, opterr:
         err(opterr)
         usage('start')
 
-    paused = False
-    for (k, v) in options:
-        if k in ['-p', '--paused']:
-            paused = True
+    dom = params[0]
 
-    if len(params) != 1:
-        err("Wrong number of parameters")
-        usage('start')
+    if console_autoconnect:
+        start_do_console(dom)
 
-    dom = params[0]
-    if serverType == SERVER_XEN_API:
-        server.xenapi.VM.start(get_single_vm(dom), paused)
-    else:
-        server.xend.domain.start(dom, paused)
+    try:
+        if serverType == SERVER_XEN_API:
+            server.xenapi.VM.start(get_single_vm(dom), paused)
+            domid = int(server.xenapi.VM.get_domid(get_single_vm(dom)))
+        else:
+            server.xend.domain.start(dom, paused)
+            info = server.xend.domain(dom)
+            domid = int(sxp.child_value(info, 'domid', '-1'))
+    except:
+        raise
+        
+    if domid == -1:
+        raise xmlrpclib.Fault(0, "Domain '%s' is not started" % dom)
 
 def xm_delete(args):
     arg_check(args, "delete", 1)
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [RFC][PATCH]: Give "xm start" a -c parameter for connecting to the console, Chris Lalancette <=