openstack G Version about snapshot , create ,delete
def create_snapshot(disk_path, snapshot_name): """Create a snapshot in a disk image :param disk_path: Path to disk image :param snapshot_name: Name of snapshot in disk image """ qemu_img_cmd = ('qemu-img', 'snapshot', '-c', snapshot_name, disk_path) # NOTE(vish): libvirt changes ownership of images execute(*qemu_img_cmd, run_as_root=True) def delete_snapshot(disk_path, snapshot_name): """Create a snapshot in a disk image :param disk_path: Path to disk image :param snapshot_name: Name of snapshot in disk image """ qemu_img_cmd = ('qemu-img', 'snapshot', '-d', snapshot_name, disk_path) # NOTE(vish): libvirt changes ownership of images execute(*qemu_img_cmd, run_as_root=True) def extract_snapshot(disk_path, source_fmt, snapshot_name, out_path, dest_fmt): """Extract a named snapshot from a disk image :param disk_path: Path to disk image :param snapshot_name: Name of snapshot in disk image :param out_path: Desired path of extracted snapshot """ # NOTE(markmc): ISO is just raw to qemu-img if dest_fmt == 'iso': dest_fmt = 'raw' qemu_img_cmd = ('qemu-img', 'convert', '-f', source_fmt, '-O', dest_fmt) # Conditionally enable compression of snapshots. if CONF.libvirt_snapshot_compression and dest_fmt == "qcow2": qemu_img_cmd += ('-c',) # When snapshot name is omitted we do a basic convert, which # is used by live snapshots. if snapshot_name is not None: qemu_img_cmd += ('-s', snapshot_name) qemu_img_cmd += (disk_path, out_path) execute(*qemu_img_cmd) waring: execute subprocess.Popen('',shell=True) 本文转自 swq499809608 51CTO博客,原文链接:http://blog.51cto.com/swq499809608/1214702