def _load_image(self, file_path): file_path = os.path.abspath(file_path) file_name = os.path.basename(file_path) om = re.match(r'(\w+)\.img', file_name) assert om is not None partition_name = om.group(1) if partition_name.find("data") < 0: partition_name += "_root" s = os.stat(file_path) size_g = s.st_size / 1024 / 1024 / 1024 mount_point = vps_common.get_mountpoint(file_path) if mount_point: self.logger.info("%s already mounted on %s" % (file_path, mount_point)) else: mount_point = vps_common.mount_loop_tmp( file_path, readonly=True, temp_dir=conf.MOUNT_POINT_DIR) self.logger.info("%s mounted on %s" % (file_path, mount_point)) return mount_point, size_g, partition_name
def pack_vps_fs_tarball(img_path, tarball_dir_or_path, is_image=False): """ if tarball_dir_or_path is a directory, will generate filename like XXX_fs_FSTYPE.tar.gz """ tarball_dir = None tarball_path = None if os.path.isdir(tarball_dir_or_path): tarball_dir = tarball_dir_or_path else: if os.path.exists(tarball_dir_or_path): raise Exception("file %s exists" % (tarball_dir_or_path)) tarball_path = tarball_dir_or_path tarball_dir = os.path.dirname(tarball_path) if not os.path.isdir(tarball_dir): raise Exception("directory %s not exists" % (tarball_dir)) if not tarball_path and tarball_dir: fs_type = vps_common.get_fs_type(img_path) tarball_name = "%s_fs_%s.tar.gz" % ( os.path.basename(img_path), fs_type) tarball_path = os.path.join(tarball_dir, tarball_name) if os.path.exists(tarball_path): raise Exception("file %s already exists" % (tarball_path)) if img_path.find("/dev") == 0: mount_point = vps_common.mount_partition_tmp( img_path, readonly=not is_image) else: mount_point = vps_common.mount_loop_tmp( img_path, readonly=not is_image) if is_image: clean_up_img(mount_point) cwd = os.getcwd() os.chdir(mount_point) try: call_cmd("tar zcf %s ." % (tarball_path)) finally: os.chdir(cwd) vps_common.umount_tmp(mount_point) return tarball_path
def mount_trash_temp (self, readonly=False): return vps_common.mount_loop_tmp (self.trash_path, readonly)
def mount_tmp (self, readonly=False): return vps_common.mount_loop_tmp (self.file_path, readonly)
def mount_trash_temp(self, readonly=False): return vps_common.mount_loop_tmp(self.trash_path, readonly, temp_dir=conf.MOUNT_POINT_DIR)
def mount_trash_temp(self, readonly=False): return vps_common.mount_loop_tmp(self.trash_path, readonly)
def mount_tmp(self, readonly=False): return vps_common.mount_loop_tmp(self.file_path, readonly)