From cde133eadd7845db08cdaa84aa4c8dd0b5cb8de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= Date: Thu, 20 Nov 2014 15:59:29 +0100 Subject: [PATCH] str2bool is not only useful in backup_xva, make it avail. elsewhere. --- libtisbackup/backup_xva.py | 14 +++++--------- libtisbackup/common.py | 5 +++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libtisbackup/backup_xva.py b/libtisbackup/backup_xva.py index a7a00b8..b074194 100755 --- a/libtisbackup/backup_xva.py +++ b/libtisbackup/backup_xva.py @@ -48,10 +48,6 @@ class backup_xva(backup_generic): verify_export = "no" reuse_snapshot = "no" - def str2bool(self,v): - if type(v) != bool: - return v.lower() in ("yes", "true", "t", "1") - def verify_export_xva(self,filename): self.logger.debug("[%s] Verify xva export integrity",self.server_name) tar = tarfile.open(filename) @@ -93,12 +89,12 @@ class backup_xva(backup_generic): #add snapshot option - if self.str2bool(halt_vm) == False: + if str2bool(halt_vm) == False: self.logger.debug("[%s] Check if previous tisbackups snapshots exist",vdi_name) old_snapshots = session.xenapi.VM.get_by_name_label("tisbackup-%s"%(vdi_name)) self.logger.debug("[%s] Old snaps count %s", vdi_name, len(old_snapshots)) - if len(old_snapshots) == 1 and self.str2bool(reuse_snapshot) == True: + if len(old_snapshots) == 1 and str2bool(reuse_snapshot) == True: snapshot = old_snapshots[0] self.logger.debug("[%s] Reusing snap \"%s\"", vdi_name, session.xenapi.VM.get_name_description(snapshot)) vm = snapshot # vm = session.xenapi.VM.get_by_name_label("tisbackup-%s"%(vdi_name))[0] @@ -143,7 +139,7 @@ class backup_xva(backup_generic): socket.setdefaulttimeout(120) scheme = "http://" - if self.str2bool(enable_https) == True: + if str2bool(enable_https) == True: scheme = "https://" url = scheme+user_xen+":"+password_xen+"@"+self.xcphost+"/export?uuid="+session.xenapi.VM.get_uuid(vm) @@ -157,7 +153,7 @@ class backup_xva(backup_generic): raise finally: - if self.str2bool(halt_vm) == False: + if str2bool(halt_vm) == False: self.logger.debug("[%s] Destroy snapshot",'tisbackup-%s'%(vdi_name)) try: for vbd in session.xenapi.VM.get_VBDs(snapshot): @@ -186,7 +182,7 @@ class backup_xva(backup_generic): unlink(filename_temp) return("Tar error") tar.close() - if self.str2bool(self.verify_export): + if str2bool(self.verify_export): self.verify_export_xva(filename_temp) os.rename(filename_temp,filename) diff --git a/libtisbackup/common.py b/libtisbackup/common.py index 7e07cff..0be472e 100644 --- a/libtisbackup/common.py +++ b/libtisbackup/common.py @@ -280,6 +280,11 @@ def monitor_stdout(aprocess, onoutputdata,context): return "\n".join(stdout) +def str2bool(val): + if type(val) != bool: + return val.lower() in ("yes", "true", "t", "1") + + class BackupStat: dbpath = '' db = None