More fun with snapshots.
authorroot <root@xenapi.xen>
Fri, 3 Oct 2008 14:21:39 +0000 (3 16:21 +0200)
committerroot <root@xenapi.xen>
Fri, 3 Oct 2008 14:21:39 +0000 (3 16:21 +0200)
default.xsl
handler_virt.c
handler_virt.h

index 84e6f0e..ce86891 100644 (file)
@@ -8,9 +8,17 @@
   <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>
+  <a href="/virt/{translate(./name,'_', '/')}/virDomainSave" style="background-image: url('/images/restore.png'); background-repeat: no-repeat; display: block; width: 45px; height: 47px; font-size: 0; float: left;">Snapshot</a>
   </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:variable name="snapshots" select="concat('/virt/', translate(./name,'_', '/'), '/virDomainGetXMLSnapshots')" />
+    <xsl:choose>
+        <xsl:when test= "count(document($snapshots)/snapshots/*) &gt; 0">
+            <a href="/virt/{translate(./name,'_', '/')}/virDomainRestore" style="background-image: url('/images/restore.png'); background-repeat: no-repeat; display: block; width: 45px; height: 47px; font-size: 0; float: left;">Snapshot</a>
+        </xsl:when>
+    </xsl:choose>
   </xsl:otherwise>
   </xsl:choose>
 
index 5a02560..ec3e2d4 100644 (file)
@@ -427,6 +427,7 @@ cherokee_handler_virt_init (cherokee_handler_virt_t *hdl)
                     else if (strcmp(this+12, "UUID") == 0) hdl->action = domainGetUUID;
                     else if (strcmp(this+12, "UUIDString") == 0) hdl->action = domainGetUUIDString;
                     else if (strcmp(this+12, "XMLDesc") == 0) hdl->action = domainGetXMLDesc;
+                    else if (strcmp(this+12, "XMLSnapshots") == 0) hdl->action = domainGetXMLSnapshots;
                 }
                 
                 else if (HDL_VIRT_PROPS(hdl)->read_only == FALSE) {
@@ -831,6 +832,27 @@ virt_virt_function(cherokee_handler_virt_t *hdl, virDomainPtr dom, virConnectPtr
                             break;
                         }
 
+                        case domainGetXMLSnapshots: {
+                            /* TODO: maybe in the future one would like to have all snapshots here */
+                            struct stat statbuf;
+                            cherokee_buffer_t path = CHEROKEE_BUF_INIT;
+                        
+                            cherokee_buffer_add_va (&path, "/mnt/netapp/users/%s/%s/memory", hdl->user.buf, hdl->vm.buf);
+
+                            if (stat(path.buf, &statbuf) != 0) {
+                                cherokee_buffer_add_str(buf, "<snapshots />");
+                            } else {
+                                char *date = ctime(&(statbuf.st_ctime));
+                                cherokee_buffer_add_str(buf, "<snapshots>\n");
+                                cherokee_buffer_add_va (buf, "  <snapshot at=\"");
+                                cherokee_buffer_add (buf, date, strlen(date)-1);
+                                cherokee_buffer_add_va (buf, "\" />\n");
+                                cherokee_buffer_add_str(buf, "</snapshots>");
+                            }
+
+                            cherokee_buffer_mrproper(&path);
+                            break;
+                        }
 
                         case domainDetachDevice: {
                             off_t postl;
index f27212f..f580883 100644 (file)
@@ -93,6 +93,7 @@ typedef struct {
         domainDefineXML_args,
         domainDefineXML,
         domainGetXMLDesc,
+        domainGetXMLSnapshots,
         storageVolGetXMLDesc_args,
         showall,
         showuservms