*Very Exprimental*
authorroot <root@xenapi.xen>
Mon, 29 Sep 2008 05:12:41 +0000 (29 07:12 +0200)
committerroot <root@xenapi.xen>
Mon, 29 Sep 2008 05:12:41 +0000 (29 07:12 +0200)
But, if you do feel lucky, there are a lot of interesting changes.

15 files changed:
Makefile
default.xsl
experiment10.c [new file with mode: 0644]
experiment8.c [new file with mode: 0644]
experiment9.c [new file with mode: 0644]
handler_avahi.c
handler_clusterstats.c
handler_clusterstats.h
handler_virt.c
handler_virt.h
node/Makefile [new file with mode: 0644]
node/avahi.c
node/node.h [new file with mode: 0644]
node/publish.c
node/tender.c

dissimilarity index 61%
index 74c7a69..4cc79c7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,13 @@
-all: handler_example.c
-       gcc -g -o create create.c
-       gcc -g -Wall -lrrd -lavahi-client -o rrdsaver rrdsaver.c
-       gcc -g -lavahi-client -L/opt/libvirt/lib -lvirt -o domumdns domumdns.c
-       gcc -g -lavahi-client -L/opt/libvirt/lib -lvirt -o offer offer.c
-       gcc -g -fPIC -shared -I/opt/cherokee/include -o libplugin_example.so handler_example.c
-       gcc -g -fPIC -shared -I/opt/cherokee/include -lavahi-client -o libplugin_avahi.so handler_avahi.c
-       gcc -DTRACE_ENABLED -D_GNU_SOURCE -I/usr/include/libxml2 -g -fPIC -shared -I/opt/cherokee/include -lrrd -lavahi-client -L/opt/domu/lib -lvirt -o libplugin_virt.so handler_avahi.c handler_virt.c experiment5.c handler_virt_domains.c
-       gcc -g -fPIC -shared -I/opt/cherokee/include -lavahi-client -o libplugin_clusterstats.so handler_clusterstats.c
-
-install:
-       cp *.so /opt/cherokee/lib/cherokee/.
-       cp Module*.py /opt/cherokee/share/cherokee/admin/.
+all: handler_example.c
+       gcc -g -o create create.c
+       gcc -g -Wall -lrrd -lavahi-client -o rrdsaver rrdsaver.c
+#      gcc -g -lavahi-client -L/opt/libvirt/lib -lvirt -o domumdns domumdns.c
+#      gcc -g -lavahi-client -L/opt/libvirt/lib -lvirt -o offer offer.c
+#      gcc -g -fPIC -shared -I/opt/cherokee/include -o libplugin_example.so handler_example.c
+#      gcc -g -fPIC -shared -I/opt/cherokee/include -lavahi-client -o libplugin_avahi.so handler_avahi.c
+       gcc -DTRACE_ENABLED -D_GNU_SOURCE -I/usr/include/libxml2 -g -fPIC -shared -I/opt/cherokee/include -lrrd -lavahi-client -L/opt/domu/lib -lvirt -o libplugin_virt.so handler_clusterstats.c handler_virt.c experiment5.c handler_virt_domains.c
+#      gcc -g -fPIC -shared -I/opt/cherokee/include -lavahi-client -o libplugin_clusterstats.so handler_clusterstats.c
+
+install:
+       cp *.so /opt/cherokee/lib/cherokee/.
+       cp Module*.py /opt/cherokee/share/cherokee/admin/.
index b6d17b3..84e6f0e 100644 (file)
@@ -4,13 +4,37 @@
 <xsl:template match="/domain">
   <br />
   <img src="/images/{./os/type}.png" alt="{./os/type}" style="float: left;"/>
+  <xsl:choose>
+  <xsl:when test="@id &gt; 0">
   <a href="/virt/{translate(./name,'_', '/')}/virDomainShutdown" style="background-image: url('/images/power.png'); background-repeat: no-repeat; display: block; width: 45px; height: 47px; font-size: 0; float: left;">Shutdown</a>
   <a href="/virt/{translate(./name,'_', '/')}/virDomainReboot" style="background-image: url('/images/reboot.png'); background-repeat: no-repeat; display: block; width: 45px; height: 47px; font-size: 0; float: left;">Reboot</a>
-<xsl:value-of select="translate(./name,'_', ' ')"/>
+  </xsl:when>
+  <xsl:otherwise>
+    <a href="/virt/{translate(./name,'_', '/')}/virDomainCreate" style="background-image: url('/images/power.png'); background-repeat: no-repeat; display: block; width: 45px; height: 47px; font-size: 0; float: left;">Create</a>
+  </xsl:otherwise>
+  </xsl:choose>
+
+<h1 style="clear: both;" ><xsl:value-of select="translate(./name,'_', ' ')"/></h1>
+  <img src="/virt/{translate(./name,'_', '/')}/virGraphLoad" alt="Load of {substring-after(./name,'_')}" />
+  <img src="/virt/{translate(./name,'_', '/')}/virGraphInterface" alt="Traffic of {substring-after(./name,'_')}" />
+
 </xsl:template>
 
 <xsl:template match="domain">
-    <a href="/virt/{translate(./name,'_', '/')}" style="display: block; width: 4em; height: 4em; text-align: center; border: 1px black solid; vertical-align: middle; background-color: #fef; text-decoration: none;"><xsl:value-of select="translate(./name,'_', ' ')"/></a>
+    <xsl:choose>
+        <xsl:when test="@status = 'running'">
+            <xsl:variable name="color" select="'background-color: #0f0;'" />
+            <a href="/virt/{translate(./name,'_', '/')}" style="float: left; margin: 0.2em; font-size: 1em; display: block; width: 7em; height: 7em; text-align: center; border: 1px black solid; vertical-align: middle; {$color} text-decoration: none;"><xsl:value-of select="substring-before(./name,'_')"/><br /><xsl:value-of select="substring-after(./name,'_')"/></a>
+        </xsl:when>
+        <xsl:when test="@status = 'running'">
+            <xsl:variable name="color" select="'background-color: #000;'" /> 
+            <a href="/virt/{translate(./name,'_', '/')}" style="float: left; margin: 0.2em; font-size: 1em; display: block; width: 7em; height: 7em; text-align: center; border: 1px black solid; vertical-align: middle; {$color} text-decoration: none;"><xsl:value-of select="substring-before(./name,'_')"/><br /><xsl:value-of select="substring-after(./name,'_')"/></a>
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:variable name="color" select="'background-color: #fef;'" />
+            <a href="/virt/{translate(./name,'_', '/')}" style="float: left; margin: 0.2em; font-size: 1em; display: block; width: 7em; height: 7em; text-align: center; border: 1px black solid; vertical-align: middle; {$color} text-decoration: none;"><xsl:value-of select="substring-before(./name,'_')"/><br /><xsl:value-of select="substring-after(./name,'_')"/></a>
+        </xsl:otherwise>
+    </xsl:choose>
 </xsl:template>
 
 <xsl:template match="/">
diff --git a/experiment10.c b/experiment10.c
new file mode 100644 (file)
index 0000000..df8399f
--- /dev/null
@@ -0,0 +1,14 @@
+#include <string.h>
+#include <stdio.h>
+
+int main() {
+                        /* TODO: terrible hack */
+                        char gateway[16];
+                        char *temp;
+                        strcpy(gateway, "192.168.1.1");
+                        temp = strchr(gateway, '.');
+                        temp = strchr(++temp, '.');
+                        temp = strchr(++temp, '.');
+                        strcpy(++temp, "254");
+                        printf("%s", gateway);
+}
diff --git a/experiment8.c b/experiment8.c
new file mode 100644 (file)
index 0000000..7a98af0
--- /dev/null
@@ -0,0 +1,82 @@
+#include <string.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+
+#include <libvirt/libvirt.h>
+
+virConnectPtr conn = NULL; /* the hypervisor connection */
+
+int main(int argc, char*argv[]) {
+//    xenUnifiedPrivatePtr priv;
+    char *xenbus_path, s[256], *params, *param_pool, *param_volume;
+    unsigned int len = 0;
+    virStoragePoolPtr pool;
+    virStorageVolPtr volume;
+
+
+    /* NULL means connect to local Xen hypervisor */
+    conn = virConnectOpenReadOnly(NULL);
+    if (conn == NULL) {
+        fprintf(stderr, "Failed to connect to hypervisor\n");
+        return -1;
+    }
+
+    xenbus_path = getenv ("XENBUS_PATH");
+
+    if (xenbus_path == NULL) {
+        fprintf(stderr, "No XENBUS_PATH so fail\n");
+        return -1;
+    }
+
+/*    priv = (xenUnifiedPrivatePtr) conn->privateData;
+
+    if (priv->xshandle == NULL) {
+        fprintf(stderr, "No Xen connection so fail\n");
+        return -1;
+    }
+
+    snprintf(s, 255, "%s/params", xenbus_path);
+    s[255] = '\0';
+
+    params = xs_read(priv->xshandle, 0, &s[0], &len);*/
+
+    param_pool   = &params[2];
+    param_volume = strchr(param_pool, '/');
+
+    if (param_volume == NULL) {
+        fprintf(stderr, "No Volume found\n");
+        return -1;
+    }
+
+    param_volume = '\0';
+    param_volume++;
+
+    printf("pool: %s, volume: %s\n", param_pool, param_volume);
+
+    pool = virStoragePoolLookupByName(conn, param_pool);
+
+    if (pool == NULL) {
+        fprintf(stderr, "Pool doesn't exist\n");
+        return -1;
+    }
+
+    volume = virStorageVolLookupByName(pool, param_volume);
+
+    if (volume == NULL) {
+        fprintf(stderr, "Volume doesn't exist\n");
+        return -1;
+    }
+
+    printf("%\n\n%s",  virStorageVolGetKey(volume), virStorageVolGetXMLDesc(volume, 0));
+
+    free(params);
+    virStoragePoolFree(pool);
+    virStorageVolFree(volume);
+    virConnectClose(conn);
+
+    return 0;
+}
diff --git a/experiment9.c b/experiment9.c
new file mode 100644 (file)
index 0000000..0342e4a
--- /dev/null
@@ -0,0 +1,23 @@
+#include <rrd.h>
+
+int main() {
+                char **calcpr  = NULL;
+                int xsize, ysize;
+                double ymin, ymax;
+                FILE *fd = tmpfile();
+                char *r_graph[] = { "rrdgraph",
+               //                       "/home/skinkie/development/htdocs/rrdtest.png",
+                                      "-a",
+                                       "PNG",
+                                       "-w",
+                                       "600",
+                                       "-h",
+                                       "200",
+                                    "DEF:cputime=/mnt/netapp/users/klant1/gentoo/cpuTime.rrd:cpuTime:AVERAGE:step=30", 
+                                    "CDEF:cpuload=cputime,1000000000,/", 
+                                    "LINE:cpuload#EE0000:cpuLoad" };
+
+                rrd_graph(10, r_graph, &calcpr, &xsize, &ysize, fd, &ymin, &ymax);
+
+                fclose(fd);
+}
index e7754f3..2e6ce1b 100644 (file)
@@ -124,7 +124,6 @@ cherokee_handler_avahi_configure (cherokee_config_node_t *conf, cherokee_server_
         return ret_error;
     }
 
-
        return ret_ok;
 }
 
@@ -311,11 +310,12 @@ static void browse_callback(
     const char *domain,
     AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
     void* userdata) {
-    
+    cherokee_handler_avahi_props_t *props = userdata;
     assert(b);
 
     /* Called whenever a new services becomes available on the LAN or is removed from the LAN */
 
+
     switch (event) {
         case AVAHI_BROWSER_FAILURE:            
             TRACE("avahi", "(Browser) %s\n", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
@@ -329,7 +329,7 @@ static void browse_callback(
                function we free it. If the server is terminated before
                the callback function is called the server will free
                the resolver for us. */
-
+            
             if (!(avahi_service_resolver_new(avahi_service_browser_get_client(b), interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, userdata)))
                 TRACE("avahi", "Failed to resolve service '%s': %s\n", name, avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
             
@@ -339,7 +339,7 @@ static void browse_callback(
             void *val;
             cherokee_buffer_t buf = CHEROKEE_BUF_INIT;
             cherokee_buffer_add(&buf, name, strlen(name));
-            if (cherokee_avl_r_del(&PROP_AVAHI(userdata)->entries, &buf, &val) == ret_ok) {
+            if (cherokee_avl_r_del(&props->entries, &buf, &val) == ret_ok) {
                 cherokee_buffer_mrproper((cherokee_buffer_t *) val);
             }
             cherokee_buffer_mrproper(&buf);
index c478bd7..f18dfc2 100644 (file)
@@ -48,8 +48,8 @@ PLUGIN_INFO_HANDLER_EASIEST_INIT (clusterstats, http_get);
 /* Methods implementation
  */
 
-static ret_t 
-props_free (cherokee_handler_clusterstats_props_t *props)
+ret_t 
+cherokee_handler_clusterstats_props_free (cherokee_handler_clusterstats_props_t *props)
 {
     if (props->threaded_poll)
        avahi_threaded_poll_stop(props->threaded_poll);
@@ -81,7 +81,7 @@ cherokee_handler_clusterstats_configure (cherokee_config_node_t *conf, cherokee_
                CHEROKEE_NEW_STRUCT (n, handler_clusterstats_props);
 
                cherokee_module_props_init_base (MODULE_PROPS(n), 
-                                                MODULE_PROPS_FREE(props_free));                
+                                                MODULE_PROPS_FREE(cherokee_handler_clusterstats_props_free));
         
         /* Look at handler_clusterstats.h
          * This is an avahi of configuration.
@@ -97,8 +97,11 @@ cherokee_handler_clusterstats_configure (cherokee_config_node_t *conf, cherokee_
                *_props = MODULE_PROPS(n);
        }
 
+
        props = PROP_CLUSTERSTATS(*_props);
 
+    cherokee_avl_r_init(&props->entries);
+
        cherokee_config_node_foreach (i, conf) {
                cherokee_config_node_t *subconf = CONFIG_NODE(i);
 
@@ -169,14 +172,14 @@ cherokee_handler_clusterstats_free (cherokee_handler_clusterstats_t *hdl)
        return ret_ok;
 }
 
-static ret_t
-while_func_entries (cherokee_buffer_t *key, void *value, void *param) {
+ret_t
+cherokee_handler_clusterstats_while_func_entries (cherokee_buffer_t *key, void *value, void *param) {
     cherokee_buffer_t *buf = (cherokee_buffer_t *)param;
     AvahiStringList *list  = (AvahiStringList *)value;
     char *avahi_key, *avahi_value;
     unsigned int len;
     
-    cherokee_buffer_add_str (buf, "  <domain>\n");
+    cherokee_buffer_add_str (buf, "  <domain status=\"running\">\n");
     cherokee_buffer_add_va  (buf, "    <name>%s</name>\n", key->buf);
 
     if ((len = avahi_string_list_length (list)) > 0) {
@@ -220,7 +223,7 @@ clusterstats_build_page (cherokee_handler_clusterstats_t *hdl)
     /* Than, do your stuff */
     if (cherokee_avl_r_len(&HDL_CLUSTERSTATS_PROPS(hdl)->entries, &len) == ret_ok && len > 0) {
         cherokee_buffer_add_str (buf, "<domains>\n");
-        cherokee_avl_r_while (&HDL_CLUSTERSTATS_PROPS(hdl)->entries, (cherokee_avl_while_func_t) while_func_entries, (void *) buf, NULL, NULL);
+        cherokee_avl_r_while (&HDL_CLUSTERSTATS_PROPS(hdl)->entries, (cherokee_avl_while_func_t) cherokee_handler_clusterstats_while_func_entries, (void *) buf, NULL, NULL);
         cherokee_buffer_add_str (buf, "</domains>");
     } else {
         cherokee_buffer_add_str (buf, "<domains/>");
@@ -304,6 +307,7 @@ static void resolve_callback(
     AvahiStringList *txt,
     AvahiLookupResultFlags flags,
     void* userdata) {
+    cherokee_handler_clusterstats_props_t *props = userdata;
     assert(r);
 
     /* Called whenever a service has been resolved successfully or timed out */
@@ -325,13 +329,13 @@ static void resolve_callback(
             cherokee_buffer_t buf = CHEROKEE_BUF_INIT;
             cherokee_buffer_add(&buf, name, strlen(name));
             
-            if (cherokee_avl_r_del(&PROP_CLUSTERSTATS(userdata)->entries, &buf, (void *) &val) == ret_ok) {
+            if (cherokee_avl_r_del(&props->entries, &buf, (void *) &val) == ret_ok) {
                 avahi_string_list_free(val);
             }
 
             nonvol = avahi_string_list_add_pair(nonvol, "dom0", host_name);
 
-            cherokee_avl_r_add(&PROP_CLUSTERSTATS(userdata)->entries, &buf, (void* ) nonvol);
+            cherokee_avl_r_add(&props->entries, &buf, (void* ) nonvol);
             cherokee_buffer_mrproper(&buf);
 
             TRACE("avahi", "Service '%s' of type '%s' in domain '%s':\n", name, type, domain);
@@ -349,7 +353,7 @@ static void browse_callback(
     const char *domain,
     AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
     void* userdata) {
-    
+    cherokee_handler_clusterstats_props_t *props = userdata;
     assert(b);
 
     /* Called whenever a new services becomes available on the LAN or is removed from the LAN */
@@ -358,7 +362,6 @@ static void browse_callback(
         case AVAHI_BROWSER_FAILURE:            
             TRACE("avahi", "(Browser) %s\n", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
             avahi_service_browser_free(b);
-//            avahi_threaded_poll_stop(PROP_CLUSTERSTATS(userdata)->threaded_poll);
             return;
 
         case AVAHI_BROWSER_NEW:
@@ -378,7 +381,7 @@ static void browse_callback(
             void *val;
             cherokee_buffer_t buf = CHEROKEE_BUF_INIT;
             cherokee_buffer_add(&buf, name, strlen(name));
-            if (cherokee_avl_r_del(&PROP_CLUSTERSTATS(userdata)->entries, &buf, &val) == ret_ok) {
+            if (cherokee_avl_r_del(&props->entries, &buf, &val) == ret_ok) {
                 avahi_string_list_free((AvahiStringList*) val);
             }
             cherokee_buffer_mrproper(&buf);
@@ -393,13 +396,13 @@ static void browse_callback(
             TRACE("avahi", "(Browser) %s\n", event == AVAHI_BROWSER_CACHE_EXHAUSTED ? "CACHE_EXHAUSTED" : "ALL_FOR_NOW");
             break;
     }
-
 }
 
 static void client_callback(AvahiClient *c, AvahiClientState state, void * userdata) {
     cherokee_handler_clusterstats_props_t *props = userdata;
 
     /* Called whenever the client or server state changes */
+
     switch (state) {
         case AVAHI_CLIENT_S_RUNNING: {
             if (!(props->sb = avahi_service_browser_new(c, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, props->service_type.buf, NULL, 0, browse_callback, props))) {
index 899d07c..a7194ea 100644 (file)
@@ -85,5 +85,6 @@ ret_t cherokee_handler_clusterstats_add_headers (cherokee_handler_clusterstats_t
 static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata);
 static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* userdata);
 static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata);
+ret_t cherokee_handler_clusterstats_while_func_entries (cherokee_buffer_t *key, void *value, void *param);
 
 #endif /* CHEROKEE_HANDLER_CLUSTERSTATS_H */
index 5da1a23..9bdbbb8 100644 (file)
@@ -80,7 +80,7 @@
 
 
 #include "handler_virt.h"
-#include "handler_avahi.h"
+#include "handler_clusterstats.h"
 #include <cherokee/cherokee.h>
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
@@ -118,7 +118,7 @@ props_free (cherokee_handler_virt_props_t *props)
     cherokee_buffer_mrproper(&props->xsl);
     cherokee_buffer_mrproper(&props->virt);
 
-       return cherokee_handler_avahi_props_free (PROP_AVAHI(props));
+       return cherokee_handler_clusterstats_props_free (PROP_CLUSTERSTATS(props));
 }
 
 
@@ -134,7 +134,7 @@ cherokee_handler_virt_configure (cherokee_config_node_t *conf, cherokee_server_t
        if (*_props == NULL) {
                CHEROKEE_NEW_STRUCT (n, handler_virt_props);
 
-        cherokee_handler_avahi_props_init_base (PROP_AVAHI(n), MODULE_PROPS_FREE(props_free));
+        cherokee_handler_clusterstats_props_init_base (PROP_CLUSTERSTATS(n), MODULE_PROPS_FREE(props_free));
 
         /* Look at handler_virt.h
          * This is an virt of configuration.
@@ -170,7 +170,7 @@ cherokee_handler_virt_configure (cherokee_config_node_t *conf, cherokee_server_t
     /* Init base class
      */
 
-       return cherokee_handler_avahi_configure (conf, srv, _props);
+       return cherokee_handler_clusterstats_configure (conf, srv, _props);
 }
 
 static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata) {
@@ -288,15 +288,16 @@ static void tender_browse_callback(
     const char *domain,
     AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
     void* userdata) {
+        AvahiClient *c;
+        assert(b);
 
-    assert(b);
-    AvahiClient *c = avahi_service_browser_get_client(b);
+        c = avahi_service_browser_get_client(b);
 
     /* Called whenever a new services becomes available on the LAN or is removed from the LAN */
 
     switch (event) {
         case AVAHI_BROWSER_FAILURE:
-            fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b))));
+            fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_client_errno(c)));
             return;
 
         case AVAHI_BROWSER_NEW:
@@ -493,7 +494,6 @@ cherokee_handler_virt_init (cherokee_handler_virt_t *hdl)
         return ret_error;
     }
    
-
     return virt_build_page(hdl);
 }
 
@@ -633,7 +633,7 @@ static ret_t save_xml(cherokee_handler_virt_t *hdl, virDomainPtr result, cheroke
 static ret_t
 virt_virt_function(cherokee_handler_virt_t *hdl, virDomainPtr dom, virConnectPtr virConn) {
     cherokee_connection_t *conn = HANDLER_CONN(hdl);
-    cherokee_buffer_t *buf = &HDL_AVAHI(hdl)->buffer;
+    cherokee_buffer_t *buf = &HDL_VIRT(hdl)->buffer;
 
     switch (hdl->action) {
         /* Returns the status of a clone copy */
@@ -921,58 +921,57 @@ virt_virt_function(cherokee_handler_virt_t *hdl, virDomainPtr dom, virConnectPtr
                             best_tender.cost = FLT_MAX;
                             best_tender.dom  = NULL;
                             
-                            avahi_threaded_poll_lock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
-                            AvahiServiceBrowser *sb = avahi_service_browser_new(HDL_AVAHI_PROPS(hdl)->client, AVAHI_IF_UNSPEC, 
+                            avahi_threaded_poll_lock(HDL_CLUSTERSTATS_PROPS(hdl)->threaded_poll);
+                            AvahiServiceBrowser *sb = avahi_service_browser_new(HDL_CLUSTERSTATS_PROPS(hdl)->client, AVAHI_IF_UNSPEC, 
                                                                                  AVAHI_PROTO_UNSPEC, "_tender._tcp",
                                                                                  NULL, 0, tender_browse_callback, &best_tender);
 
                             if (sb == NULL) {
                                 TRACE("avahi", "For whatever reason the sb is NULL\n");
                             } else {
+                                AvahiEntryGroup *group = avahi_entry_group_new(HDL_CLUSTERSTATS_PROPS(hdl)->client, entry_group_callback, NULL);
 
-                            AvahiEntryGroup *group = avahi_entry_group_new(HDL_AVAHI_PROPS(hdl)->client, entry_group_callback, NULL);
-
-                            if (group == NULL) {
-                                TRACE("avahi", "For whatever reason the group is NULL\n");
-                            } else {
-                                avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0,
-                                                              best_tender.name, "_offer._tcp", NULL, NULL, 651, txt, NULL, NULL);
-                                avahi_entry_group_commit(group);
-                                avahi_threaded_poll_unlock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
+                                if (group == NULL) {
+                                    TRACE("avahi", "For whatever reason the group is NULL\n");
+                                } else {
+                                    avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0,
+                                                                  best_tender.name, "_offer._tcp", NULL, NULL, 651, txt, NULL, NULL);
+                                    avahi_entry_group_commit(group);
+                                    avahi_threaded_poll_unlock(HDL_CLUSTERSTATS_PROPS(hdl)->threaded_poll);
 
-                                sleep(3); /* we are for quick bidding ;) */
+                                    sleep(3); /* we are for quick bidding ;) */
 
-                                avahi_threaded_poll_lock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
-                                avahi_entry_group_free(group);
-                            }
+                                    avahi_threaded_poll_lock(HDL_CLUSTERSTATS_PROPS(hdl)->threaded_poll);
+                                    avahi_entry_group_free(group);
+                                }
                             
-                            avahi_service_browser_free(sb);
-                            avahi_threaded_poll_unlock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
+                                avahi_service_browser_free(sb);
+                                avahi_threaded_poll_unlock(HDL_CLUSTERSTATS_PROPS(hdl)->threaded_poll);
 
-                            if (best_tender.dom == NULL) {
-                                TRACE("virt", "Nobody wants %s, poor vm!\n", best_tender.name);
-                                cherokee_buffer_add_long10(buf, -1);
-                            } else {
-                                if (virDomainUndefine(dom) != 0) {
-                                    TRACE("virt", "Can't undefine %s, some idiot run it already?\n", best_tender.name);
+                                if (best_tender.dom == NULL) {
+                                    TRACE("virt", "Nobody wants %s, poor vm!\n", best_tender.name);
                                     cherokee_buffer_add_long10(buf, -1);
                                 } else {
-                                    cherokee_buffer_t uri = CHEROKEE_BUF_INIT;
-                                    virConnectClose(virConn);
-                                    cherokee_buffer_add_va (&uri, "xen://%s/", best_tender.dom);
-                                    virConn = virConnectOpen (uri.buf);
-                                    if (virConn == NULL) {
-                                        TRACE("virt", "Can't connect to %s\n", uri.buf);
+                                    if (virDomainUndefine(dom) != 0) {
+                                        TRACE("virt", "Can't undefine %s, some idiot run it already?\n", best_tender.name);
                                         cherokee_buffer_add_long10(buf, -1);
                                     } else {
-                                        cherokee_buffer_add_long10(buf,
-                                                                   (virDomainCreateLinux(virConn, xmlDesc.buf, 0) != NULL ?
-                                                                   0 : -1 ));
+                                        cherokee_buffer_t uri = CHEROKEE_BUF_INIT;
+                                        virConnectClose(virConn);
+                                        cherokee_buffer_add_va (&uri, "xen://%s/", best_tender.dom);
+                                        virConn = virConnectOpen (uri.buf);
+                                        if (virConn == NULL) {
+                                            TRACE("virt", "Can't connect to %s\n", uri.buf);
+                                            cherokee_buffer_add_long10(buf, -1);
+                                        } else {
+                                            cherokee_buffer_add_long10(buf,
+                                                                       (virDomainCreateLinux(virConn, xmlDesc.buf, 0) != NULL ?
+                                                                       0 : -1 ));
+                                        }
+                                        cherokee_buffer_mrproper(&uri);
                                     }
-                                    cherokee_buffer_mrproper(&uri);
-                                }
-                                TRACE("virt", "going to free\n");
-                                free(best_tender.dom);
+                                    TRACE("virt", "going to free\n");
+                                    free(best_tender.dom);
                             }
 
                             }
@@ -1090,7 +1089,7 @@ virt_get_vol_by_args(cherokee_handler_virt_t *hdl, virConnectPtr virConn, unsign
  * pool/volume combination */
 static ret_t
 virt_pool_vol(cherokee_handler_virt_t *hdl, virConnectPtr virConn) {
-    cherokee_buffer_t *buf = &HDL_AVAHI(hdl)->buffer;
+    cherokee_buffer_t *buf = &HDL_VIRT(hdl)->buffer;
     cherokee_connection_t *conn = HANDLER_CONN(hdl);
     virStorageVolPtr volume;
     ret_t ret = ret_ok;
@@ -1175,7 +1174,7 @@ virt_pool_vol_cleanup:
 
 static ret_t
 virt_virt_new(cherokee_handler_virt_t *hdl, virConnectPtr virConn) {
-    cherokee_buffer_t *buf = &HDL_AVAHI(hdl)->buffer;
+    cherokee_buffer_t *buf = &HDL_VIRT(hdl)->buffer;
     cherokee_connection_t *conn = HANDLER_CONN(hdl);
     cherokee_buffer_t xml = CHEROKEE_BUF_INIT;
     virStoragePoolPtr pool = NULL;
@@ -1605,38 +1604,39 @@ virt_build_page (cherokee_handler_virt_t *hdl)
 
 
     switch (hdl->action) {
-        case showall:
-            cherokee_buffer_add_str (&hdl->buffer, "<domains>\n");
-//            avahi_threaded_poll_lock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
-            cherokee_avl_r_while(&HDL_AVAHI_PROPS(hdl)->entries, virt_while, hdl, NULL, NULL);
-//            avahi_threaded_poll_unlock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
-            cherokee_buffer_add_str (&hdl->buffer, "</domains>");
+        case showall: {
+            size_t len;
+            if (cherokee_avl_r_len(&HDL_CLUSTERSTATS_PROPS(hdl)->entries, &len) == ret_ok && len > 0) {
+                cherokee_buffer_add_str (&hdl->buffer, "<domains>\n");
+                cherokee_avl_r_while (&HDL_CLUSTERSTATS_PROPS(hdl)->entries, (cherokee_avl_while_func_t) cherokee_handler_clusterstats_while_func_entries, (void *) &hdl->buffer, NULL, NULL);
+                cherokee_buffer_add_str (&hdl->buffer, "</domains>");
+            } else {
+                cherokee_buffer_add_str (&hdl->buffer, "<domains/>");
+            }
+        
             ret = ret_ok;
             break;
+        }
 
         case showuservms: {
             cherokee_buffer_add_str (&hdl->buffer, "<domains>\n");
-//            avahi_threaded_poll_lock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
-//            cherokee_avl_r_while(&HDL_AVAHI_PROPS(hdl)->entries, virt_while_user, hdl, NULL, NULL);
-//            avahi_threaded_poll_unlock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
-            get_all_configurations(&HDL_AVAHI_PROPS(hdl)->entries, &hdl->user, &hdl->buffer);
+            get_all_configurations(&HDL_CLUSTERSTATS_PROPS(hdl)->entries, &hdl->user, &hdl->buffer);
             cherokee_buffer_add_str (&hdl->buffer, "</domains>");
             ret = ret_ok;
             break;
         }
 
         default: {
-            cherokee_buffer_t *hostname = NULL;
+            AvahiStringList *list = NULL;
             cherokee_buffer_add_va (&domu, "%s_%s", hdl->user.buf, hdl->vm.buf);
 
-//            avahi_threaded_poll_lock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
-            ret = cherokee_avl_r_get(&HDL_AVAHI_PROPS(hdl)->entries, &domu, (void **) &hostname);
-//            avahi_threaded_poll_unlock(HDL_AVAHI_PROPS(hdl)->threaded_poll);
+            ret = cherokee_avl_r_get(&HDL_CLUSTERSTATS_PROPS(hdl)->entries, &domu, (void **) &list);
 
             if (ret == ret_not_found) {
                 virDomainPtr virDom;
                 virConnectPtr virConn;
-                cherokee_buffer_add_va (&uri, "xen://%s/", HDL_VIRT_PROPS(hdl)->virt); // TODO: change!
+                if (HDL_VIRT_PROPS(hdl)->virt.len > 0)
+                    cherokee_buffer_add_va (&uri, "xen://%s/", HDL_VIRT_PROPS(hdl)->virt); // TODO: change!
 
                 /* If we have the read only parameter, we will set up a connection to the
                  * Hypervisor here. */
@@ -1690,8 +1690,11 @@ virt_build_page (cherokee_handler_virt_t *hdl)
                 }
                 virConnectClose (virConn);
             } else if (ret == ret_ok) {
-                cherokee_buffer_add_va (&uri, "xen://%s/", hostname->buf);
+                char *hostname;
+                avahi_string_list_get_pair(avahi_string_list_find(list, "dom0"), NULL, &hostname, NULL); 
+                cherokee_buffer_add_va (&uri, "xen://%s/", hostname);
                 printf("%s\n", uri.buf);
+                avahi_free(hostname);
             } else {
                 hdl->action = http_internal_error;
                 hdl->action = nothing;
index 6ed8a0c..f27212f 100644 (file)
 
 #include <libvirt/libvirt.h>
 #include <cherokee/cherokee.h>
-#include "handler_avahi.h"
+#include "handler_clusterstats.h"
 
 /* Data types
  */
 typedef struct {
-       cherokee_handler_avahi_t  base;
+       cherokee_handler_clusterstats_t  base;
 
     /* Configuration parameters */
     cherokee_boolean_t   authenticate;
diff --git a/node/Makefile b/node/Makefile
new file mode 100644 (file)
index 0000000..035045d
--- /dev/null
@@ -0,0 +1,2 @@
+node:
+       gcc -I/usr/include/avahi -I/usr/include/libvirt -lvirt -lavahi-client -Wall avahi.c main.c publish.c tender.c -o $@
index 1896156..3b40ebc 100644 (file)
@@ -58,6 +58,8 @@ static void modify_callback(AvahiTimeout *e, void *userdata) {
         create_services(client);
 
         avahi_simple_poll_get(simple_poll)->timeout_update(e, avahi_elapse_time(&tv, 1000*POLL, 0));
+
+//        fprintf(stderr, "modify\n");
     }
 }
 
diff --git a/node/node.h b/node/node.h
new file mode 100644 (file)
index 0000000..5c10f1b
--- /dev/null
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <avahi-client/client.h>
+#include <avahi-client/publish.h>
+#include <avahi-client/lookup.h>
+
+#include <avahi-common/alternative.h>
+#include <avahi-common/simple-watch.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/error.h>
+
+AvahiSimplePoll *simple_poll;
+
+#define POLL 5
+
+void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata);
+void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata);
+void parse_tender(AvahiServiceResolver *r, const char *name, AvahiStringList *txt);
+void create_services(AvahiClient *c);
+int pull_tender(const char *name);
index 6dd0076..9a03961 100644 (file)
 
 #include "node.h"
 
+struct list_el {
+    unsigned int domainid;
+    AvahiEntryGroup *group;
+    unsigned short keep;
+};
+
+typedef struct list_el domu;
+
+domu * domus = NULL; /* list of domains */
+unsigned int domu_count = 0;
+
+
 static AvahiStringList * domainProperties(virDomainPtr thisDomain) {
-    AvahiStringList *new = avahi_string_list_new_from_array (NULL, 0);
+    AvahiStringList *new = NULL;
+    // avahi_string_list_new_from_array (NULL, 0);
     virDomainInfo info;
     virDomainInterfaceStatsStruct stats;
     virDomainGetInfo(thisDomain, &info);
index 262acd4..15a67a8 100644 (file)
 #include <avahi-common/error.h>
 #include <avahi-common/timeval.h>
 
-
 #include <libvirt/libvirt.h>
 
+typedef struct offer OFFER;
+struct offer {
+    char *name;
+    float cost;
+    unsigned long memory;
+    AvahiEntryGroup *group;
+    short int reservate;
+    OFFER *next;
+};
+
+OFFER *offers_head = NULL;
+OFFER *offers_tail = NULL;
+
+unsigned long reservate = 0;
+
 static int accept_tender(const char *name, unsigned long memory, AvahiClient *c) {
     OFFER * offer_new;
     char domain[254];