kvm metadata, map fix, doc fix
diff --git a/README.rst b/README.rst
index 3263129..dd8609e 100644
--- a/README.rst
+++ b/README.rst
@@ -14,6 +14,11 @@
libvirt:
server:
enabled: true
+ virtualization:
+ - kvm
+ network:
+ default:
+ ensure: absent
.. code-block:: yaml
diff --git a/libvirt/map.jinja b/libvirt/map.jinja
index e6fddbc..40b4b6e 100644
--- a/libvirt/map.jinja
+++ b/libvirt/map.jinja
@@ -1,12 +1,14 @@
{% set server = salt['grains.filter_by']({
'Debian': {
- 'pkgs': ['libvirt-bin','pm-utils','libvirt0','qemu-kvm','qemu-utils','bridge-utils','python-libvirt'],
+ 'pkgs': ['libvirt-bin','libvirt-dev','pm-utils','libvirt0','python-libvirt'],
+ 'kvm_pkgs': ['qemu-kvm','qemu-utils'],
'service': 'libvirt-bin',
'config': '/etc/libvirt/libvirtd.conf',
'config_sys': '/etc/default/libvirt-bin'
},
'RedHat': {
- 'pkgs': ['libvirt','qemu-kvm'],
+ 'pkgs': ['libvirt'],
+ 'kvm_pkgs': ['qemu-kvm'],
'service': 'libvirtd',
'config': '/etc/libvirt/libvirtd.conf',
'config_sys': '/etc/sysconfig/libvirtd'
diff --git a/libvirt/server/network.sls b/libvirt/server/network.sls
index 900a836..4d83223 100644
--- a/libvirt/server/network.sls
+++ b/libvirt/server/network.sls
@@ -1,12 +1,67 @@
-{% from "libvirt/map.jinja" import server with context %}
+{%- from "libvirt/map.jinja" import server with context %}
{%- if server.enabled %}
+include:
+- libvirt.server.service
-if pillar.libvirt.server.netcfg
+{%- for name, network server:networks.iteritems() %}
-{%- if server.netcfg is defined %}
+{%- set network_config_file = '/etc/libvirt/qemu/networks' ~ '/' ~ name ~ '.xml' %}
-/etc/libvirt/qemu/networks/default.xml:
- file.managed.absent:
+{%- if network.ensure|default('running') in ['present', 'running'] %}
+
+{{ network_config_file }}:
+ file.managed:
+ - mode: 600
+ - user: root
+ - group: root
+ - contents_pillar: libvirt:networks:{{ name }}:xml
+ - watch_in:
+ - service: libvirt_service
+
+net-{{ name }}:
+ cmd.run:
+ - name: virsh net-define {{ network_config_file }}
+ - unless: virsh -q net-list --all | grep -q '^{{ name }}'
+
+{%- if network.autostart|default(True) %}
+
+net-autostart-{{ name }}:
+ cmd.run:
+ - name: virsh net-autostart {{ name }}
+ - unless: virsh net-info {{ name }} | grep -Eq '^Autostart:\s+yes'
+
+{%- endif %}
+
+net-startstop-{{ name }}:
+ cmd.run:
+ - name: virsh net-start {{ name }}
+ - unless: virsh -q net-list --all | grep -Eq '^{{ name }}\s+active'
+
+{%- elif network.ensure|default('running') == 'absent' %}
+
+{{ network_config_file }}:
+ file.absent:
+ - watch_in:
+ - service: libvirt_service
+
+net-{{ name }}:
+ cmd.run:
+ - name: virsh net-destroy {{ name }} 2>&1 1>/dev/null; virsh net-undefine {{ name }}
+ - onlyif: virsh -q net-list --all | grep -q '^{{ name }}'
+
+net-autostart-{{ name }}:
+ cmd.run:
+ - name: virsh net-autostart {{ name }} --disable
+ - onlyif: virsh net-info {{ name }} | grep -Eq '^Autostart:\s+yes'
+
+net-startstop-{{ name }}:
+ cmd.run:
+ - name: virsh net-destroy {{ name }}
+ - onlyif: virsh -q net-list --all | grep -Eq '^{{ name }}\s+active'
+
+{%- endif %}
+
+{%- endfor %}
{%- endif %}
diff --git a/libvirt/server/service.sls b/libvirt/server/service.sls
index fc4f3c8..3e19947 100644
--- a/libvirt/server/service.sls
+++ b/libvirt/server/service.sls
@@ -5,6 +5,18 @@
pkg.installed:
- names: {{ server.pkgs }}
+{%- for virtualization in server.virtualizations %}
+
+{%- if virtualization == 'kvm' %}
+
+libvirt_kvm_packages:
+ pkg.installed:
+ - names: {{ server.kvm_pkgs }}
+
+{%- endif %}
+
+{%- endfor %}
+
libvirt_config:
file.managed:
- name: {{ server.config }}
diff --git a/metadata/service/server/kvm.yml b/metadata/service/server/kvm.yml
new file mode 100644
index 0000000..a4e7bcb
--- /dev/null
+++ b/metadata/service/server/kvm.yml
@@ -0,0 +1,11 @@
+applications:
+- libvirt
+parameters:
+ libvirt:
+ server:
+ enabled: true
+ virtualization:
+ - kvm
+ network:
+ default:
+ ensure: absent