def disk_compress(disk_name): spexe = "virt-sparsify" if not hf.test_exe(spexe): logger.warn("No virt-sparsify executable found.") logger.warn("Consider installing libguestfs-tools.") return disk_path = get_disk_path(disk_name) pool_dir = os.path.dirname(disk_path) logger.info("Compressing disk image, input file:\n\t%s", disk_path) stat = os.stat(disk_path) mode = stat.st_mode logger.debug("mode\t%s", oct(mode)) uid = stat.st_uid logger.debug("uid\t%s", uid) gid = stat.st_gid logger.debug("gid\t%s", gid) size = stat.st_size logger.debug("size\t%s", size) tmp_file = os.path.join(pool_dir, ".{}".format(disk_name)) # virt-sparsify uses about 10 GB additional, temporary work space. # The default (/tmp) is often too small (especially if it is a RAM # disk). We use the pool_dir instead. subprocess.call( ["sudo", spexe, "--tmp", pool_dir, "--compress", disk_path, tmp_file]) logger.info("Restoring owner.") # No root wrapper, so use sudo with shell commands subprocess.call( ["sudo", "chown", "-v", "--reference={}".format(disk_path), tmp_file]) logger.info("Restoring permissions.") subprocess.call( ["sudo", "chmod", "-v", "--reference={}".format(disk_path), tmp_file]) logger.info("Moving temporary file into final location.") subprocess.call(["sudo", "mv", "-v", "-f", tmp_file, disk_path]) # os.chown(tmp_file, uid, gid) # os.chmod(tmp_file, mode) # import shutil # shutil.move(tmp_file, disk_path) stat = os.stat(disk_path) mode = stat.st_mode logger.debug("mode\t%s", oct(mode)) uid = stat.st_uid logger.debug("uid\t%s", uid) gid = stat.st_gid logger.debug("gid\t%s", gid) new_size = stat.st_size logger.debug("size\t%s", new_size) compression = "%0.0f" % round((1 - new_size / size) * 100) + "%" # logger.info("size\t%s (compressed by %s%)", new_size, compression) logger.info("size\t%s (compressed by %s)", new_size, compression)
def disk_compress(disk_name): spexe = "virt-sparsify" if not hf.test_exe(spexe): logger.warn("No virt-sparsify executable found.") logger.warn("Consider installing libguestfs-tools.") return disk_path = get_disk_path(disk_name) pool_dir = os.path.dirname(disk_path) logger.info("Compressing disk image, input file:\n\t%s", disk_path) stat = os.stat(disk_path) mode = stat.st_mode logger.debug("mode\t%s", oct(mode)) uid = stat.st_uid logger.debug("uid\t%s", uid) gid = stat.st_gid logger.debug("gid\t%s", gid) size = stat.st_size logger.debug("size\t%s", size) tmp_file = os.path.join(pool_dir, ".{}".format(disk_name)) subprocess.call(["sudo", spexe, "--compress", disk_path, tmp_file]) logger.info("Restoring owner.") # No root wrapper, so use sudo with shell commands subprocess.call(["sudo", "chown", "-v", "--reference={}".format(disk_path), tmp_file]) logger.info("Restoring permissions.") subprocess.call(["sudo", "chmod", "-v", "--reference={}".format(disk_path), tmp_file]) logger.info("Moving temporary file into final location.") subprocess.call(["sudo", "mv", "-v", "-f", tmp_file, disk_path]) # os.chown(tmp_file, uid, gid) # os.chmod(tmp_file, mode) # import shutil # shutil.move(tmp_file, disk_path) stat = os.stat(disk_path) mode = stat.st_mode logger.debug("mode\t%s", oct(mode)) uid = stat.st_uid logger.debug("uid\t%s", uid) gid = stat.st_gid logger.debug("gid\t%s", gid) new_size = stat.st_size logger.debug("size\t%s", new_size) compression = "%0.0f" % round((1-new_size/size)*100) + "%" # logger.info("size\t%s (compressed by %s%)", new_size, compression) logger.info("size\t%s (compressed by %s)", new_size, compression)
def check_provider(): if provider == "virtualbox": if do_build and not hf.test_exe("VBoxManage", "-v"): logger.error("VBoxManage not found. Is VirtualBox installed?") logger.error("Aborting.") sys.exit(1) elif provider == "kvm": if platform.uname()[0] != "Linux": logger.error("Provider kvm only supported on Linux. Aborting.") sys.exit(1) if not hf.test_exe("virsh", "-v"): logger.error("virsh not found. Aborting.") sys.exit(1) if wbatch: logger.error("Cannot build Windows batch files with provider kvm." "Aborting.") sys.exit(1) else: logger.error("Unknown provider: %s", provider) logger.error("Aborting.") sys.exit(1)
def get_git_info(): git_exe = "git" if not hf.test_exe("git"): logger.debug("No git executable found. Unable to log git status.") return None summary_args = ["git", "describe", "--all", "--long", "--dirty"] diff_args = ["git", "--no-pager", "diff", "HEAD", "-p", "--stat"] try: result = "git status: " result += subprocess.check_output(summary_args) result += subprocess.check_output(diff_args).rstrip() except subprocess.CalledProcessError: result = None return result