fmenabe/python-kvm

does this lib support creating a new VM/domain

ericfanye opened this issue · 2 comments

Hi there,

I'm trying to use this lib to manage the KVM server.
but I wonder if there is any feature to define a new domain? similar as:
virsh define ***.xml
or create a VM, similar as:
virt-install?

Thanks in advance!!

Eric

Hi

For your information, there is no real documentation but there is a page with examples: https://github.com/fmenabe/python-kvm/blob/master/doc/source/examples.rst

This module is essentially a wrapper to the virsh and almost all commands are implemented. You can look at the JSON file (https://github.com/fmenabe/python-kvm/blob/master/kvm/kvm.json)
that map functions (in properties) to virsh commands and indicate how outputs are parsed.

Defining a domain from an XML file is possible:

    import unix, kvm
    host = kvm.Hypervisor(unix.Local())
    host.domain.define('/path/to/the/file.xml')

There is nothing like virt-install in the module! But if you want to use virt-install the unix module (on which this module is based) allows to execute any command (even interactively):

    import unix, kvm
    host = kvm.Hypervisor(unix.Local())
    host.execute('virt-install', INTERACTIVE=True,
                 name='debian8', memory=2048, vcpu=1,
                 disk='path=/vm/disk/debian8.qcow2,size=5',
                 os_type='linux', os_variant='generic',
                 network='bridge=virbr0', graphics='none',
                 console='pty,target_type=serial',
                 location='http://ftp.nl.debian.org/debian/dists/jessie/main/installer-amd64/',
                 extra_args="'console=ttyS0,115200n8 serial'")

Where I work, we had (we are in the process of migrating to OpenNebula) another approach. We created models (basic installation of a system with partitionning), that were copied to the designated hypervisor and then the image was locally mounted (using qemu-nbd) and updated (there's functions in the unix module for chrooting and managing configuration of some OS).

François

Bonjour Monsieur!

Thank you for your great help! And we are taking the solution of sending commands to the host.

Merci beaucoup!

Eric