diff options
| -rw-r--r-- | modules/libvirtd/files/storage_add.py | 28 | ||||
| -rw-r--r-- | modules/libvirtd/manifests/init.pp | 33 | 
2 files changed, 61 insertions, 0 deletions
| diff --git a/modules/libvirtd/files/storage_add.py b/modules/libvirtd/files/storage_add.py new file mode 100644 index 00000000..88475ec6 --- /dev/null +++ b/modules/libvirtd/files/storage_add.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +import libvirt +import sys + +name = sys.argv[1] +path = sys.argv[2] + +storage_xml = """ +<pool type='dir'> +  <name>%s</name> +  <capacity>0</capacity> +  <allocation>0</allocation> +  <available>0</available> +  <source> +  </source> +  <target> +    <path>%s</path> +    <permissions> +      <mode>0700</mode> +      <owner>-1</owner> +      <group>-1</group> +    </permissions> +  </target> +</pool>""" % ( name, path ) + +c=libvirt.open("qemu:///system") +c.storagePoolCreateXML(storage_xml,0) + diff --git a/modules/libvirtd/manifests/init.pp b/modules/libvirtd/manifests/init.pp index da04bbfa..193099c9 100644 --- a/modules/libvirtd/manifests/init.pp +++ b/modules/libvirtd/manifests/init.pp @@ -11,6 +11,23 @@ class libvirtd {              ensure => running,              path => "/etc/init.d/libvirtd",          } + +        #TODO remove once libvirt package is fixed to manage the directory +        file { "/etc/libvirt/storage": +            ensure => directory, +        } + +        file { "/etc/libvirt/storage/autostart": +            ensure => directory, +        } +         +        file { "/usr/local/bin/storage_add.py": +            ensure => present, +            owner => root, +            group => root, +            mode => 755, +            source => "puppet:///libvirtd/storage_add.py",  +        }      }      class kvm inherits base { @@ -33,4 +50,20 @@ class libvirtd {              content => template("libvirtd/50-template-libvirt-remote-access.pkla"),          }      } + +    define storage($path, $autostart = true) { +        include libvirtd::base + +        exec { "/usr/local/bin/storage_add.py $name $path": +            creates => "/etc/libvirt/storage/$name.xml", +            require => File['/usr/local/bin/storage_add.py'], +        } + +        file { "/etc/libvirt/storage/autostart/$name.xml": +            ensure => $autostart ? { +                            true => "/etc/libvirt/storage/$name.xml", +                            false => "absent" +                      } +        } +    }  } | 
