Daniel Veillard wrote:
Looking at virDomainParseXMLDesc() in xml.c I see we are not accounting
for a <on_reboot> element (or on_crash, on_poweroff) in the XML. Are
I wasn't sure how much this was needed, clearly it is now.
you working on this Daniel or should I take a stab at it? I'm guessing
you just want elements like
<on_reboot>restart</on_reboot>
<on_poweroff>destroy</on_poweroff>
<on_crash>restart</on_crash>
Yes.
Please go ahead, I didn't yet applied your previous patch but it looks
sensible, just some bogus logic was left from the old code.
Same goes turning sxp to XML in xend_parse_sexp_desc() in xend_internal.c.
Yup. just provide information about the new elements added and their values
so I can extend the documentation page about the XML format (at some point
I will also provide a Relax-NG or XSD schemas to validate them).
Ok, here is a patch that accounts for various lifecycle events, e.g.
on_reboot, on_poweroff, on_crash. The new elements (children of domain
element) are
<on_reboot>action</on_reboot>
<on_poweroff>action</on_poweroff>
<on_crash>action</on_crash>
on_reboot: Action to be taken when domain is rebooted.
on_poweroff: Action to be taken when a power off or shutdown operation
is performed inside the domain.
on_crash: Action to be taken when domain crashes.
action values can be one of
destroy: The domain is cleaned up as normal.
restart: A new domain is started in place of the old one.
preserve: The domain will remain in memory until it is destroyed manually.
rename-restart: The domain will remain in memory until it is destroyed
manually, and a new, renamed domain is started.
Regards,
Jim
Index: xend_internal.c
===================================================================
RCS file: /data/cvs/libvir/src/xend_internal.c,v
retrieving revision 1.20
diff -u -r1.20 xend_internal.c
--- xend_internal.c 3 Apr 2006 13:46:43 -0000 1.20
+++ xend_internal.c 7 Apr 2006 19:40:56 -0000
@@ -1400,6 +1400,16 @@
(int) (sexpr_u64(root, "domain/maxmem") << 10));
virBufferVSprintf(&buf, " <vcpu>%d</vcpu>\n",
sexpr_int(root, "domain/vcpus"));
+ tmp = sexpr_node(root, "domain/on_poweroff");
+ if (tmp != NULL)
+ virBufferVSprintf(&buf, " <on_poweroff>%s</on_poweroff>\n", tmp);
+ tmp = sexpr_node(root, "domain/on_reboot");
+ if (tmp != NULL)
+ virBufferVSprintf(&buf, " <on_reboot>%s</on_reboot>\n", tmp);
+ tmp = sexpr_node(root, "domain/on_crash");
+ if (tmp != NULL)
+ virBufferVSprintf(&buf, " <on_crash>%s</on_crash>\n", tmp);
+
virBufferAdd(&buf, " <devices>\n", 12);
for (cur = root; cur->kind == SEXPR_CONS; cur = cur->cdr) {
node = cur->car;
Index: xml.c
===================================================================
RCS file: /data/cvs/libvir/src/xml.c,v
retrieving revision 1.14
diff -u -r1.14 xml.c
--- xml.c 30 Mar 2006 16:08:13 -0000 1.14
+++ xml.c 7 Apr 2006 19:40:56 -0000
@@ -877,6 +877,30 @@
}
xmlXPathFreeObject(obj);
+ obj = xmlXPathEval(BAD_CAST "string(/domain/on_poweroff[1])", ctxt);
+ if ((obj != NULL) && (obj->type == XPATH_STRING) &&
+ (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
+ virBufferVSprintf(&buf, "(on_poweroff '%s')", obj->stringval);
+ bootloader = 1;
+ }
+ xmlXPathFreeObject(obj);
+
+ obj = xmlXPathEval(BAD_CAST "string(/domain/on_reboot[1])", ctxt);
+ if ((obj != NULL) && (obj->type == XPATH_STRING) &&
+ (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
+ virBufferVSprintf(&buf, "(on_reboot '%s')", obj->stringval);
+ bootloader = 1;
+ }
+ xmlXPathFreeObject(obj);
+
+ obj = xmlXPathEval(BAD_CAST "string(/domain/on_crash[1])", ctxt);
+ if ((obj != NULL) && (obj->type == XPATH_STRING) &&
+ (obj->stringval != NULL) && (obj->stringval[0] != 0)) {
+ virBufferVSprintf(&buf, "(on_crash '%s')", obj->stringval);
+ bootloader = 1;
+ }
+ xmlXPathFreeObject(obj);
+
/* analyze of the os description */
virBufferAdd(&buf, "(image ", 7);
obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt);