Skip to content

cloudify-incubator/cloudify-libvirt-plugin

Repository files navigation

cloudify-libvirt-plugin

Add direct support of libvirt to cloudify, use with restrictions.

Before use check that you have 64bit platform, if you want to start 64bit images.

Based on https://libvirt.org/docs/libvirt-appdev-guide-python/en-US/html/

Release history: CHANGELOG.txt

Plugin Requirements

  • Python versions:
    • 2.7.x
    • 3.6.x
  • Packages versions:
    • libvirt-python >= 3.7.0
    • libvirt >= 1.3.1
    • qemu >= 2.5.0

Before use on Ubuntu/Debian

sudo apt-get install -yq qemu-kvm qemu python-libvirt libvirt-dev libxml2-dev qemu-system-arm qemu-efi
sudo usermod -a -G libvirtd `whoami`

Before use on CentOS

sudo yum install -y epel-release
sudo yum install -y qemu-kvm libvirt-devel libvirt libvirt-python wget gcc python-devel qemu-system-x86 genisoimage
sudo service libvirtd restart
sudo groupadd libvirt
sudo usermod -a -G libvirt cfyuser
sudo usermod -a -G kvm cfyuser
sudo usermod -a -G qemu cfyuser

Types

cloudify.libvirt.domain

Description for VM

Supported properties:

  • libvirt_auth: connection url, by default: qemu:///system
  • backup_dir: directory for save backups, by default: ./
  • use_external_resource: (optional) Use external object. The default is false.
  • resource_id: (optional) Used to identify the object when use_external_resource is true.
  • params: params used for create object, useful for embeded template.
    • name: Domain name
    • vcpu: CPU count
    • memory_size: VM memory size in KiB
    • memory_maxsize: (optional) recomended VM memory size in KiB for downgrade. The default is value from memory_size * 2.
    • nvram: (optional) path to nvram (useful for arm)
    • disks: list connected disks
    • networks: list connected networks
    • full_dump: make full dump for backups with memory snapshot to dump file. On create/restore backup will be removed all snapshots in domain.
    • wait_for_ip: (optional) wait until we have some private ip on interfaces The default is true.
    • domain_type: (optional) type of virtualization. The default is qemu

Inputs for actions:

  • configure:
    • params: list of params for template, can be empty
    • template_resource: Template for domain. Defaults is domain.xml

Runtime properties:

  • resource_id: resource name.
  • params: params used for create object.

cloudify.libvirt.network

Description for Network

Supported properties:

  • libvirt_auth: connection url, by default: qemu:///system
  • backup_dir: directory for save backups, by default: ./
  • use_external_resource: (optional) Use external object. The default is false.
  • resource_id: (optional) Used to identify the object when use_external_resource is true.
  • params: params used for create object.
    • name: Network name
    • dev: Device name
    • forwards: settings for network forwards.
    • ips: settings for network ips.

Inputs for actions:

  • create:
    • params: list of params for template, can be empty
    • template_resource: Template for network. Defaults is network.xml

Runtime properties:

  • resource_id: resource name.
  • params: params used for create object.

Relationships

cloudify.libvirt.relationships.connected_to

Update ip runtime property in VM by data from network.

Examples

Without external connectivity

For documentation backup / restore workflows with noncluster blueprints look to Utilities Plugin.

With external connectivity

Notes for use:

  • Enable ssh login between manager and libvirt host without password, by call:

    cat examples/cluster/id_rsa.pub | ssh centos@<manager_host> "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >>  ~/.ssh/authorized_keys"
    cat examples/cluster/id_rsa.pub | ssh centos@<libvirt_host> "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >>  ~/.ssh/authorized_keys"
  • Provide private key '/etc/cloudify/kvm.key' to manager host:

    cat examples/cluster/id_rsa | ssh centos@<manager_host> "cat >> ~/kvm.key && sudo mv kvm.key /etc/cloudify/kvm.key && sudo chown cfyuser:cfyuser /etc/cloudify/kvm.key && sudo chmod 400 /etc/cloudify/kvm.key
  • Check that manager can connect to virthost by ssh, run on manager:

    sudo su cfyuser -
    ssh -i  /etc/cloudify/kvm.key centos@<libvirt_host>
  • You can use any user instead 'centos' with sudo rights without password ('ALL=(ALL) NOPASSWD:ALL' in sudoers).

  • Install libvirt client libraries on manager:

    sudo yum install -y libvirt-devel libvirt libvirt-python
    sudo service libvirtd restart
    sudo groupadd libvirt
    sudo usermod -a -G libvirt cfyuser
    sudo usermod -a -G kvm cfyuser
    sudo usermod -a -G qemu cfyuser
  • Fix routing on manager for see "external ips" from libvirt host, 192.168.202.0 will be fake network for exteranl ip's.

    sudo route add -net 192.168.202.0 netmask 255.255.255.0 gw <libvirt_host>
  • If you use openstack for host libvirt host (nested in nested virtualization) attach additional ip's to port:

    openstack port list | grep <libvirt_host> # search for <openstack_port_id>
    openstack port set --allowed-address ip-address=192.168.202.16 <openstack_port_id>
    openstack port set --allowed-address ip-address=192.168.202.17 <openstack_port_id>
    openstack port set --allowed-address ip-address=192.168.202.18 <openstack_port_id>
    openstack port set --allowed-address ip-address=192.168.202.19 <openstack_port_id>
    openstack port set --allowed-address ip-address=192.168.202.20 <openstack_port_id>
  • Set default secrets for blueprints:

    cfy profile use <manager_host> -u admin -p admin -t default_tenant
    cfy secret create agent_user -u -s "cfyagent"
    cfy secret create agent_use_public_ip -u -s "true"
    cfy secret create libvirt_cluster_user -u -s "centos"
    cfy secret create libvirt_cluster_key -u -s "/etc/cloudify/kvm.key"
    cfy secret create libvirt_cluster_host -u -s <libvirt_host>
    cfy secret create libvirt_cluster_external_ip -u -s "192.168.202.16,192.168.202.17,192.168.202.18,192.168.202.19,192.168.202.20"
    cfy secret create libvirt_cluster_external_dev -u -s "eth0"
    cfy secret create agent_key_public -u -f examples/cluster/id_rsa.pub
    cfy secret create agent_key_private -u -f examples/cluster/id_rsa
    cfy secret create libvirt_common_network -u -s "manager_network"

You should to install libvirt-devel before create wagon.

Examples

For official blueprint examples using this Cloudify plugin, please see Cloudify Community Blueprints Examples.

TODO:

  • Add more examples with different vm struct and archictures: mips, powerpc
  • Implement storage volume/pool
  • Implement firewall rules