diff options
author | Michael Scherer <misc@mageia.org> | 2011-03-31 01:49:33 +0000 |
---|---|---|
committer | Michael Scherer <misc@mageia.org> | 2011-03-31 01:49:33 +0000 |
commit | d3f25373513266e1101687234c56116890e6a1e8 (patch) | |
tree | d642f9275c8f29632099256759b6b00ce331967a /modules/libvirtd | |
parent | 08f091b55a22a4023a1f7fc66725110189d1101a (diff) | |
download | puppet-d3f25373513266e1101687234c56116890e6a1e8.tar puppet-d3f25373513266e1101687234c56116890e6a1e8.tar.gz puppet-d3f25373513266e1101687234c56116890e6a1e8.tar.bz2 puppet-d3f25373513266e1101687234c56116890e6a1e8.tar.xz puppet-d3f25373513266e1101687234c56116890e6a1e8.zip |
add helper script to create network in libvirt
Diffstat (limited to 'modules/libvirtd')
-rw-r--r-- | modules/libvirtd/files/network_add.py | 62 | ||||
-rw-r--r-- | modules/libvirtd/manifests/init.pp | 9 |
2 files changed, 71 insertions, 0 deletions
diff --git a/modules/libvirtd/files/network_add.py b/modules/libvirtd/files/network_add.py new file mode 100644 index 00000000..ab40bf0e --- /dev/null +++ b/modules/libvirtd/files/network_add.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +import libvirt +import os +import IPy + +# bridge_name + +# forward -> nat/ route +# forward-dev + +# network +# => deduire la gateway , et le range +# en dhcp automatiquement + +# tftp_root + +# enable_pxelinux + + +bridge_name = os.environ.get('BRIDGE_NAME', 'virbr0') +forward = os.environ.get('FORWARD', 'nat') +forward_dev = os.environ.get('FORWARD_DEV', 'eth0') + +network = os.environ.get('NETWORK', '192.168.122.0/24') + +tftp_root = os.environ.get('TFTP_ROOT', '') +disable_pxelinux = os.environ.get('DISABLE_PXE', False) + +name = os.environ.get('NAME', 'default') + + +ip = IPy.IP(network) +gateway = ip[1] +dhcp_start = ip[2] +dhcp_end = ip[-2] + +netmask = ip.netmask() +tftp_xml = '' +pxe_xml = '' + +if tftp_root: + tftp_xml = "<tftp root='" + tftp_root + "' />" + if not disable_pxelinux: + pxe_xml = "<bootp file='pxelinux.0' />" + +network_xml = """ +<network> + <name>%(name)s</name> + <bridge name="%(bridge_name)s" /> + <forward mode="%(forward)s" dev="%(forward_dev)s"/> + <ip address="%(gateway)s" netmask="%(netmask)s"> + %(tftp_xml)s + <dhcp> + <range start="%(dhcp_start)s" end="%(dhcp_end)s" /> + %(pxe_xml)s + </dhcp> + </ip> +</network>""" % globals() + +c=libvirt.open("qemu:///system") +c.networkDefineXML(network_xml) + diff --git a/modules/libvirtd/manifests/init.pp b/modules/libvirtd/manifests/init.pp index 63359016..f93bc26e 100644 --- a/modules/libvirtd/manifests/init.pp +++ b/modules/libvirtd/manifests/init.pp @@ -29,6 +29,15 @@ class libvirtd { mode => 755, source => "puppet:///modules/libvirtd/storage_add.py", } + + file { "/usr/local/bin/network_add.py": + ensure => present, + owner => root, + group => root, + mode => 755, + source => "puppet:///modules/libvirtd/network_add.py", + } + } class kvm inherits base { |