def _load_lvm(self, dev): # return partition_name, size_g, mount_point arr = dev.split("/") partition_name = arr[-1] size_g = vps_common.lv_getsize(dev) mount_point = vps_common.lv_get_mountpoint(dev) if mount_point: self.logger.info("%s already mounted on %s" % (dev, mount_point)) else: mount_point = vps_common.mount_partition_tmp( dev, readonly=True, temp_dir=conf.MOUNT_POINT_DIR) self.logger.info("%s mounted on %s" % (dev, 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_partition_tmp (self.trash_dev, readonly)
def mount_trash_temp(self, readonly=False): return vps_common.mount_partition_tmp(self.trash_dev, readonly, temp_dir=conf.MOUNT_POINT_DIR)
def mount_trash_temp(self, readonly=False): return vps_common.mount_partition_tmp(self.trash_dev, readonly)