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

相关文章
|
API 数据库 虚拟化
Openstack Nova 源码分析 — Create instances (nova-conductor阶段)
目录 目录 前言 Instance Flavor Instance Status Virt Driver Resource Tracker nova-conductor Create Instancenova-conductor阶段 前言 Nova 控制着一个个虚拟机的状态变迁和生命周期,这种对虚拟机生命周期的管理是由 nova-compute service 来完成的。
1728 0
|
Python 数据安全/隐私保护 缓存
openstack中dashboard页面RuntimeError: Unable to create a new session key. It is likely that the cache is unavailable.
环境是centos7,直接跑在服务器上。 按照官网一步步安装openstack,到验证dashborad时出错。 登录http://192.168.1.73/dashboard ,输入域名,用户名,密码,出现错误,无法进入界面   tail -40 /etc/httpd/logs/error_log 查看打印 发现 [Sat Aug 12 19:42:16.
1538 0