def snapshot_delete(self, instance_name, snapshot_name, metadata=False): """delete the snapshot Todo: use virDomainXXX instead of virsh :param instance: instance of snapshot :param snapshot_name: Name of snapshot :param metadata: If True, delete the metadata only """ virsh_cmd = ['virsh', 'snapshot-delete', instance_name, snapshot_name] if metadata: virsh_cmd = virsh_cmd + ['--metadata'] utils.execute(*virsh_cmd, run_as_root=True)
def snapshot_delete(self, instance_name, snapshot_name, metadata = False): """delete the snapshot Todo: use virDomainXXX instead of virsh :param instance: instance of snapshot :param snapshot_name: Name of snapshot :param metadata: If True, delete the metadata only """ virsh_cmd = ['virsh', 'snapshot-delete', instance_name, snapshot_name] if metadata : virsh_cmd = virsh_cmd + ['--metadata'] utils.execute(*virsh_cmd, run_as_root=True)
def rebase(self, backing_file_base, backing_file_top): """rebase the backing_file_top to backing_file_base using unsafe mode :param backing_file_base: backing file to rebase to :param backing_file_top: top file to rebase """ utils.execute('qemu-img', 'rebase', '-u', '-b', backing_file_base, backing_file_top, run_as_root=True)
def blockcommit(self, instance, dev, backing_file_base, backing_file_top): """block commit the changes from top to base Todo: use virDomainXXX instead of virsh :param instance: instance to blockcommit :param dev: block device name :param backing_file_base: base to commit into :param backing_file_top: top file to commit from """ virsh_cmd = ['virsh', 'blockcommit', '--domain', instance, dev, '--wait', '--base', backing_file_base, '--top', backing_file_top] utils.execute(*virsh_cmd, run_as_root=True)
def blockcommit(self, instance, dev, backing_file_base, backing_file_top): """block commit the changes from top to base Todo: use virDomainXXX instead of virsh :param instance: instance to blockcommit :param dev: block device name :param backing_file_base: base to commit into :param backing_file_top: top file to commit from """ virsh_cmd = [ 'virsh', 'blockcommit', '--domain', instance, dev, '--wait', '--base', backing_file_base, '--top', backing_file_top ] utils.execute(*virsh_cmd, run_as_root=True)
def qemu_img_info(path): """Return an object containing the parsed output from qemu-img info.""" if not os.path.exists(path): return QemuImgInfo() out, err = utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path) return QemuImgInfo(out)
def snapshot_create_as(self, instance_name, snapshot_name, snapshot_description, dev_snapshot_disk_paths): """Atomic disk only external snapshots of an instance Todo: use virDomainSnapshotCreateXML instead of virsh :param instance: instance to snapshot :param snapshot_name: Name of snapshot :param snapshot_description: Description of snapshot :param snapshot_disk_paths: list of the new snapshot_disk_paths """ diskspecs = [] for dev, snapshot in dev_snapshot_disk_paths.iteritems(): diskspecs = diskspecs + ['--diskspec', dev + ',snapshot=external,file=' + snapshot] virsh_cmd = ['virsh', 'snapshot-create-as', instance_name, snapshot_name, snapshot_description, '--disk-only', '--atomic'] + diskspecs utils.execute(*virsh_cmd, run_as_root=True)
def snapshot_create_as(self, instance_name, snapshot_name, snapshot_description, dev_snapshot_disk_paths): """Atomic disk only external snapshots of an instance Todo: use virDomainSnapshotCreateXML instead of virsh :param instance: instance to snapshot :param snapshot_name: Name of snapshot :param snapshot_description: Description of snapshot :param snapshot_disk_paths: list of the new snapshot_disk_paths """ diskspecs = [] for dev, snapshot in dev_snapshot_disk_paths.iteritems(): diskspecs = diskspecs + [ '--diskspec', dev + ',snapshot=external,file=' + snapshot ] virsh_cmd = [ 'virsh', 'snapshot-create-as', instance_name, snapshot_name, snapshot_description, '--disk-only', '--atomic' ] + diskspecs utils.execute(*virsh_cmd, run_as_root=True)
def commit(self, backing_file_top): """rebase the backing_file_top to backing_file_base :param backing_file_top: top file to commit from to its base """ utils.execute('qemu-img', 'commit', backing_file_top, run_as_root=True)
def convert_image(source, dest, out_format, run_as_root=False): """Convert image to other format.""" cmd = ('qemu-img', 'convert', '-O', out_format, source, dest) utils.execute(*cmd, run_as_root=run_as_root)