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
|