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

[Xen-devel] [PATCH] xend: check file exist for xm save


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Wei Kong <weikong.cn@xxxxxxxxx>
  • Date: Mon, 18 May 2009 17:42:05 +0800
  • Delivery-date: Mon, 18 May 2009 02:42:36 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=Czns+qLyv9v5bd5pcWzKoyGIHft9XBhBJGSByMuvG/KoBuKIdS7NnKA2Yn+8unBlQk Rx70daEFuu8flA364fmhvIXFHWvqdHIXcaXCsBp3pNgOKjnWLebh5zwNObpeLQN2L5rO hELUEMIh84R+/7VBeqE0oBZz6vKG3fB5/NUbc=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

Check file exist for xm save, allow force to overwrite.

Signed-off-by: Wei Kong <weikong.cn@gmail.com>

diff -uNrp xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py
--- xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py 2009-05-19 01:52:28.000000000 +0800
+++ xen-3.4.0-testing/tools/python/xen/xend/XendAPI.py 2009-05-19 01:52:44.000000000 +0800
@@ -1809,10 +1809,10 @@ class XendAPI(object):
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ bool(live), port, node, ssl)
ÂÂÂÂÂÂÂÂ return xen_api_success_void()

-ÂÂÂ def VM_save(self, _, vm_ref, dest, checkpoint):
+ÂÂÂ def VM_save(self, _, vm_ref, dest, checkpoint, force):
ÂÂÂÂÂÂÂÂ xendom = XendDomain.instance()
ÂÂÂÂÂÂÂÂ xeninfo = xendom.get_vm_by_uuid(vm_ref)
-ÂÂÂÂÂÂÂ xendom.domain_save(xeninfo.getDomid(), dest, checkpoint)
+ÂÂÂÂÂÂÂ xendom.domain_save(xeninfo.getDomid(), dest, checkpoint, force)
ÂÂÂÂÂÂÂÂ return xen_api_success_void()

ÂÂÂÂ def VM_restore(self, _, src, paused):
diff -uNrp xen-3.4.0-testing/tools/python/xen/xend/XendDomain.py xen-3.4.0-testing/tools/python/xen/xend/XendDomain.py
--- xen-3.4.0-testing/tools/python/xen/xend/XendDomain.pyÂÂÂÂÂÂ 2009-05-19 01:52:28.000000000 +0800
+++ xen-3.4.0-testing/tools/python/xen/xend/XendDomain.pyÂÂÂÂÂÂ 2009-05-19 01:52:44.000000000 +0800
@@ -1381,7 +1381,7 @@ class XendDomain:
ÂÂÂÂÂÂÂÂÂÂÂÂ finally:
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sock.close()

-ÂÂÂ def domain_save(self, domid, dst, checkpoint=False):
+ÂÂÂ def domain_save(self, domid, dst, checkpoint=False, force=False):
ÂÂÂÂÂÂÂÂ """Start saving a domain to file.

ÂÂÂÂÂÂÂÂ @param domid: Domain ID or Name
@@ -1397,6 +1397,9 @@ class XendDomain:
ÂÂÂÂÂÂÂÂÂÂÂÂ if not dominfo:
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ raise XendInvalidDomain(str(domid))

+ÂÂÂÂÂÂÂÂÂÂÂ if os.access(dst, os.F_OK) and not force:
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ raise XendError("Save file:%s exist!\n" % dst)
+
ÂÂÂÂÂÂÂÂÂÂÂÂ if dominfo.getDomid() == DOM0_ID:
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ raise XendError("Cannot save privileged domain %s" % str(domid))
ÂÂÂÂÂÂÂÂÂÂÂÂ if dominfo._stateGet() != DOM_STATE_RUNNING:
diff -uNrp xen-3.4.0-testing/tools/python/xen/xm/main.py xen-3.4.0-testing/tools/python/xen/xm/main.py
--- xen-3.4.0-testing/tools/python/xen/xm/main.pyÂÂÂÂÂÂ 2009-05-19 01:52:28.000000000 +0800
+++ xen-3.4.0-testing/tools/python/xen/xm/main.pyÂÂÂÂÂÂ 2009-05-19 01:57:31.000000000 +0800
@@ -118,7 +118,7 @@ SUBCOMMAND_HELP = {
ÂÂÂÂ 'reset'ÂÂÂÂÂÂ : ('<Domain>', 'Reset a domain.'),
ÂÂÂÂ 'restore'ÂÂÂÂ : ('<CheckpointFile> [-p]',
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 'Restore a domain from a saved state.'),
-ÂÂÂ 'save'ÂÂÂÂÂÂÂ : ('[-c] <Domain> <CheckpointFile>',
+ÂÂÂ 'save'ÂÂÂÂÂÂÂ : ('[-c|-f] <Domain> <CheckpointFile>',
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 'Save a domain state to restore later.'),
ÂÂÂÂ 'snapshot-create' : ('[-d] <Domain> <SnapshotName>',
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 'Snapshot a running domain.'),
@@ -283,6 +283,7 @@ SUBCOMMAND_OPTIONS = {
ÂÂÂÂ ),
ÂÂÂÂ 'save': (
ÂÂÂÂÂÂÂ ('-c', '--checkpoint', 'Leave domain running after creating snapshot'),
+ÂÂÂÂÂÂ ('-f', '--force', 'Force to overwrite exist file'),
ÂÂÂÂ ),
ÂÂÂÂ 'snapshot-create': (
ÂÂÂÂÂÂÂ ('-d', '--diskonly', 'Perform disk only snapshot of domain'),
@@ -801,18 +802,21 @@ def xm_snapshot_delete(args):

Âdef xm_save(args):

-ÂÂÂ arg_check(args, "save", 2, 3)
+ÂÂÂ arg_check(args, "save", 2, 4)

ÂÂÂÂ try:
-ÂÂÂÂÂÂÂ (options, params) = getopt.gnu_getopt(args, 'c', ['checkpoint'])
+ÂÂÂÂÂÂÂ (options, params) = getopt.gnu_getopt(args, 'cf', ['checkpoint', 'force'])
ÂÂÂÂ except getopt.GetoptError, opterr:
ÂÂÂÂÂÂÂÂ err(opterr)
ÂÂÂÂÂÂÂÂ usage('save')

ÂÂÂÂ checkpoint = False
+ÂÂÂ force = False
ÂÂÂÂ for (k, v) in options:
ÂÂÂÂÂÂÂÂ if k in ['-c', '--checkpoint']:
ÂÂÂÂÂÂÂÂÂÂÂÂ checkpoint = True
+ÂÂÂÂÂÂÂ if k in ['-f', '--force']:
+ÂÂÂÂÂÂÂÂÂÂÂ force = True

ÂÂÂÂ if len(params) != 2:
ÂÂÂÂÂÂÂÂ err("Wrong number of parameters")
@@ -826,9 +830,9 @@ def xm_save(args):
ÂÂÂÂÂÂÂÂ sys.exit(1)

ÂÂÂÂ if serverType == SERVER_XEN_API:
-ÂÂÂÂÂÂÂ server.xenapi.VM.save(get_single_vm(dom), savefile, checkpoint)
+ÂÂÂÂÂÂÂ server.xenapi.VM.save(get_single_vm(dom), savefile, checkpoint, force)
ÂÂÂÂ else:
-ÂÂÂÂÂÂÂ server.xend.domain.save(dom, savefile, checkpoint)
+ÂÂÂÂÂÂÂ server.xend.domain.save(dom, savefile, checkpoint, force)

Âdef xm_restore(args):
ÂÂÂÂ arg_check(args, "restore", 1, 2)

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.