You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/02/13 23:04:21 UTC

[41/50] [abbrv] CLOUDSTACK-684 support vm snapshot

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9a12756a/ui/scripts/vm_snapshots.js
----------------------------------------------------------------------
diff --git a/ui/scripts/vm_snapshots.js b/ui/scripts/vm_snapshots.js
new file mode 100644
index 0000000..0d6305b
--- /dev/null
+++ b/ui/scripts/vm_snapshots.js
@@ -0,0 +1,196 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+(function($, cloudStack) {
+  cloudStack.sections.vmsnapshots = {
+    title: 'label.vmsnapshot',
+    id: 'vmsnapshots',
+    listView: {
+      id: 'vmsnapshots',
+      isMaximized: true,
+      fields: {
+        displayname: {
+          label: 'label.name'
+        },
+        state: {
+          label: 'label.state',
+          indicator: {
+            'Ready': 'on',
+            'Error': 'off'
+          }
+        },
+        type:{
+          label: 'label.vmsnapshot.type'
+        },
+        current:{
+          label: 'label.vmsnapshot.current',
+          converter: cloudStack.converters.toBooleanText
+        },
+        parentName:{
+          label: 'label.vmsnapshot.parentname'
+        },
+        created: {
+          label: 'label.date',
+          converter: cloudStack.converters.toLocalDate
+        }
+      },
+
+      dataProvider: function(args) {
+        var apiCmd = "listVMSnapshot&listAll=true";
+        if (args.context != null) {
+          if ("instances" in args.context) {
+            apiCmd += "&virtualmachineid=" + args.context.instances[0].id;
+          }
+        }
+        $.ajax({
+          url: createURL(apiCmd),
+          dataType: "json",
+          async: true,
+          success: function(json) {
+            var jsonObj;
+            jsonObj = json.listvmsnapshotresponse.vmSnapshot;
+            args.response.success({
+              data: jsonObj
+            });
+          }
+        });
+      },
+      //dataProvider end
+      detailView: {
+        tabs: {
+          details: {
+            title: 'label.details',
+            fields: {
+              id: {
+                label: 'label.id'
+              },
+              name: {
+                label: 'label.name'
+              },
+              displayname: {
+                label: 'label.display.name',
+              },
+              type: {
+                label: 'label.vmsnapshot.type',
+              },
+              description: {
+                label: 'label.description',
+              },
+              state: {
+                label: 'label.state',
+                indicator: {
+                  'Ready': 'on',
+                  'Error': 'off'
+                }
+              },
+              current: {
+              	label: 'label.vmsnapshot.current',
+              	converter: cloudStack.converters.toBooleanText
+              },              
+              parentName: {
+              	label: 'label.vmsnapshot.parentname'
+              },
+              created: {
+                label: 'label.date',
+                converter: cloudStack.converters.toLocalDate
+              },
+
+            },
+            dataProvider: function(args) {
+              $.ajax({
+                url: createURL("listVMSnapshot&listAll=true&id=" + args.context.vmsnapshots[0].id),
+                dataType: "json",
+                async: true,
+                success: function(json) {
+                  var jsonObj;
+                  jsonObj = json.listvmsnapshotresponse.vmSnapshot[0];
+                  args.response.success({
+                    //actionFilter: vmActionfilter,
+                    data: jsonObj
+                  });
+                }
+              });
+            },
+            tags: cloudStack.api.tags({ resourceType: 'VMSnapshot', contextId: 'vmsnapshots' })
+          }
+        },
+        actions: {
+          //delete a snapshot
+          remove: {
+            label: 'label.action.vmsnapshot.delete',
+            messages: {
+              confirm: function(args) {
+                return 'message.action.vmsnapshot.delete';
+              },
+              notification: function(args) {
+                return 'label.action.vmsnapshot.delete';
+              }
+            },
+            action: function(args) {
+              $.ajax({
+                url: createURL("deleteVMSnapshot&vmsnapshotid=" + args.context.vmsnapshots[0].id),
+                dataType: "json",
+                async: true,
+                success: function(json) {
+                  var jid = json.deletevmsnapshotresponse.jobid;
+                  args.response.success(
+                    {_custom:
+                     {jobId: jid}
+                    }
+                  );
+                }
+              });
+            },
+            notification: {
+              poll: pollAsyncJobResult
+            }
+          },
+          restart: {
+            label: 'label.action.vmsnapshot.revert',
+            messages: {
+              confirm: function(args) {
+                return 'label.action.vmsnapshot.revert';
+              },
+              notification: function(args) {
+                return 'message.action.vmsnapshot.revert';
+              }
+            },
+            action: function(args) {
+              $.ajax({
+                url: createURL("revertToSnapshot&vmsnapshotid=" + args.context.vmsnapshots[0].id),
+                dataType: "json",
+                async: true,
+                success: function(json) {
+                  var jid = json.reverttosnapshotresponse.jobid;
+                  args.response.success({
+                    _custom: {
+                      jobId: jid
+                    }
+                  });
+                }
+              });
+
+            },
+            notification: {
+              poll: pollAsyncJobResult
+            }
+          }
+        }
+      }
+      //detailview end
+    }
+  }
+})(jQuery, cloudStack);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9a12756a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
index a765b42..40343b6 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
@@ -58,6 +58,8 @@ import com.vmware.vim25.PropertySpec;
 import com.vmware.vim25.SelectionSpec;
 import com.vmware.vim25.TraversalSpec;
 import com.vmware.vim25.VirtualMachineConfigSpec;
+import com.vmware.vim25.VirtualMachineSnapshotInfo;
+import com.vmware.vim25.VirtualMachineSnapshotTree;
 import com.vmware.vim25.VirtualNicManagerNetConfig;
 import com.vmware.vim25.NasDatastoreInfo;
 
@@ -949,4 +951,20 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
     	HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)_context.getServiceUtil().getDynamicProperty(_mor, "runtime");
     	return runtimeInfo.getConnectionState() == HostSystemConnectionState.connected;
 	}
+	
+    public boolean revertToSnapshot(ManagedObjectReference morSnapshot)
+            throws Exception {
+        ManagedObjectReference morTask = _context.getService()
+                .revertToSnapshot_Task(morSnapshot, _mor, false);
+        String result = _context.getServiceUtil().waitForTask(morTask);
+        if (result.equals("sucess")) {
+            _context.waitForTaskProgressDone(morTask);
+            return true;
+        } else {
+            s_logger.error("VMware revert to snapshot failed due to "
+                    + TaskMO.getTaskFailureInfo(_context, morTask));
+        }
+
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9a12756a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index cd54127..d36814d 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -405,6 +405,26 @@ public class VirtualMachineMO extends BaseMO {
 		return false;
 	}
 	
+    public boolean revertToSnapshot(String snapshotName) throws Exception {
+        ManagedObjectReference morSnapshot = getSnapshotMor(snapshotName);
+        if (morSnapshot == null) {
+            s_logger.warn("Unable to find snapshot: " + snapshotName);
+            return false;
+        }
+        ManagedObjectReference morTask = _context.getService()
+                .revertToSnapshot_Task(morSnapshot, _mor, null);
+        String result = _context.getServiceUtil().waitForTask(morTask);
+        if (result.equals("sucess")) {
+            _context.waitForTaskProgressDone(morTask);
+            return true;
+        } else {
+            s_logger.error("VMware revert to snapshot failed due to "
+                    + TaskMO.getTaskFailureInfo(_context, morTask));
+        }
+
+        return false;
+    }
+	
 	public boolean removeAllSnapshots() throws Exception {
 		VirtualMachineSnapshotInfo snapshotInfo = getSnapshotInfo();