[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH v3 1/2] network: Introduce network hooks



On 11.02.2014 10:54, Daniel P. Berrange wrote:
On Mon, Feb 10, 2014 at 07:52:34PM +0100, Michal Privoznik wrote:

@@ -3583,6 +3639,48 @@ validate:
          }
      }

+    /* finally we can call the 'plugged' hook script if any */
+    if (virHookPresent(VIR_HOOK_DRIVER_NETWORK)) {
+        /* the XML construction is a bit complicated here,
+         * as we want to pass both domain XML and network XML */
+        virBuffer buf = VIR_BUFFER_INITIALIZER;
+        char *xml, *net_xml, *dom_xml;
+        int hookret;
+
+        net_xml = virNetworkDefFormat(netdef, 0);
+        dom_xml = virDomainDefFormat(dom, 0);
+
+        if (!net_xml || !dom_xml) {
+            VIR_FREE(net_xml);
+            VIR_FREE(dom_xml);
+            goto error;
+        }
+
+        virBufferAdd(&buf, net_xml, -1);
+        virBufferAdd(&buf, dom_xml, -1);

This isn't very easy for applications to consume. With all the
other things you can just pass stdin straight to your XML
parser and process it. When you concatenate 2 XML docs this
way it becomes much harder, since you have to split the two
docs which means parsing them without an XML parser. Usually
you'd want to place the 2 docs within a parent XML doc so the
overall result is still a single wellformed XML doc.

Okay, but how should the XML look then?
<hookData>
  <network/>
  <domain/>
</hookData>

I'm basically asking about the root element name. Then, if we do this for plug & unplug - should we follow the same scheme for network start & stop? Without the <domain/>. You know, once we require hook script to take network xml from /hookData/network we can do that for other cases too, so the XPath to select the network doesn't change. Or is that an overkill, because the hook script can easily do:

if [ "$2" == "plugged" -o "$2" == "unplugged" ]; then
  XPATH="/hookData/network"
else
  XPATH="/network"
fi


Michal


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]