On 02/13/2012 05:03 PM, Wayne Sun wrote:
* new APIs
get_parent(self, domname, snapname, flag = 0)
children_num(self, domname, snapname, flag)
children_names_list(self, domname, snapname, flag)
the flag in children_num and children_names_list could be in 0-7,
which is the OR operation result of
(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
VIR_DOMAIN_SNAPSHOT_LIST_METADATA |
VIR_DOMAIN_SNAPSHOT_LIST_LEAVES)
* deleted redundancy spaces and fixed a typo in function domain()
* getConnect(), getDomain() and getName() API are not added in,
current snapshotAPI requires user to offer connection obj, domain
name and snapshot name.
---
lib/snapshotAPI.py | 59 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/lib/snapshotAPI.py b/lib/snapshotAPI.py
index 43ccb89..d866b60 100644
--- a/lib/snapshotAPI.py
+++ b/lib/snapshotAPI.py
@@ -24,14 +24,14 @@ import libvirt
import re
import os
-def append_path(path):
+def append_path(path):
"""Append root path of package"""
if path in sys.path:
pass
else:
sys.path.append(path)
-
-pwd = os.getcwd()
+
+pwd = os.getcwd()
result = re.search('(.*)libvirt-test-API', pwd)
append_path(result.group(0))
@@ -39,7 +39,7 @@ import exception
class SnapshotAPI(object):
def __init__(self, connection):
- self.conn = connection
+ self.conn = connection
def create(self, domname, xml_desc, flag = 0):
try:
@@ -57,7 +57,7 @@ class SnapshotAPI(object):
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
- raise exception.LibvirtAPI(message, code)
+ raise exception.LibvirtAPI(message, code)
def snapshot_name_list(self, domname, flag = 0):
try:
@@ -66,7 +66,7 @@ class SnapshotAPI(object):
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
- raise exception.LibvirtAPI(message, code)
+ raise exception.LibvirtAPI(message, code)
def snapshot_nums(self, domname, flag = 0):
try:
@@ -95,31 +95,64 @@ class SnapshotAPI(object):
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
-
+
def delete(self, domname, snapname, flag = 0):
try:
- snap = self.snapshot_lookup_by_name(domname, snapname, flag = 0)
+ snap = self.snapshot_lookup_by_name(domname, snapname)
return snap.delete(flag)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
- raise exception.LibvirtAPI(message, code)
+ raise exception.LibvirtAPI(message, code)
def get_xml_desc(self, domname, snapname, flag = 0):
try:
- snap = self.snapshot_lookup_by_name(domname, snapname, flag = 0)
+ snap = self.snapshot_lookup_by_name(domname, snapname)
return snap.getXMLDesc(flag)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def domain(self, domname):
+ def domain(self, domname, snapname):
try:
- snap = self.snapshot_lookup_by_name(domname, snapname, flag = 0)
+ snap = self.snapshot_lookup_by_name(domname, snapname)
return snap.domain()
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
-
+
+ def get_parent(self, domname, snapname, flag = 0):
+ try:
+ snap = self.snapshot_lookup_by_name(domname, snapname)
+ return snap.getParent(flag)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def children_num(self, domname, snapname, flag):
+ try:
+ snap = self.snapshot_lookup_by_name(domname, snapname)
+ return snap.numChildren(flag)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def children_names_list(self, domname, snapname, flag):
+ try:
+ snap = self.snapshot_lookup_by_name(domname, snapname)
+ return snap.listChildrenNames(flag)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+# virDomainSnapshotListFlags
+VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS = 1
+VIR_DOMAIN_SNAPSHOT_LIST_ROOTS = 1
+VIR_DOMAIN_SNAPSHOT_LIST_METADATA = 2
+VIR_DOMAIN_SNAPSHOT_LIST_LEAVES = 4
+
ACK