* (#11) Add a new fact to get a valid netmask for OpenVZ's virtual

interfaces (venet).
* (#11) Use the new fact vznetmask_venet0_0 to add the route in
 interfaces.tail file.
This commit is contained in:
gardouille 2015-03-02 19:06:14 +01:00
parent 8bf0ff4c81
commit 5946af1bda
3 changed files with 35 additions and 2 deletions

View File

@ -10,6 +10,10 @@
* Update README.md.
* Upgrade pve-kernel-3.10.0-7-pve and pve-kernel-2.6.32-37 to the last version.
##### Bugfixes
* (#11) Add a new fact to get a valid netmask for OpenVZ's virtual interfaces (venet).
* (#11) Use the new fact vznetmask_venet0_0 to add the route in interfaces.tail file.
---------------------------------------
### 0.2.1 - 2015/02/03

29
lib/facter/vznetmask.rb Normal file
View File

@ -0,0 +1,29 @@
# Fact: vznetmask
#
# Purpose:
# Get netmasks for Virtual Network aka venet in OpenVZ CT, for available
# network networks
#
# Resolution:
# Uses `facter/util/ip` to enumerate interfaces and return their information.
#
require 'facter/util/ip'
require 'ipaddr'
Facter::Util::IP.get_interfaces.each do |interface|
Facter.add("vznetmask_" + Facter::Util::IP.alphafy(interface)) do
setcode do
if interface =~ /^venet*/
netmask = Facter::Util::IP.get_interface_value(interface, "netmask")
if netmask == "255.255.255.255"
# It's not possible to modify the netmask from WebGUI, so it's mainly set to /32
# http://openvz.org/Venet#Adding_IP_address_to_a_container
netmask = "255.255.255.0"
end
end
netmask
end
end
end

View File

@ -10,6 +10,6 @@ iface eth0 inet dhcp
# <%= scope.lookupvar('::ipaddress_eth0') %>
up ip route add default dev eth0
up ip route add <%= scope.lookupvar('::network_eth0') %>/<%= scope.lookupvar('::netmask_eth0') %> dev eth0 protocol kernel src <%= scope.lookupvar('::ipaddress_eth0') %>
up ip route add <%= scope.lookupvar('::vznetwork_venet0_0') %>/<%= scope.lookupvar('::netmask_venet0_0') %> dev venet0
up ip route add <%= scope.lookupvar('::vznetwork_venet0_0') %>/<%= scope.lookupvar('::vznetmask_venet0_0') %> dev venet0
down ip route del default dev eth0
down ip route del <%= scope.lookupvar('::vznetwork_venet0_0') %>/<%= scope.lookupvar('::netmask_venet0_0') %> dev venet0
down ip route del <%= scope.lookupvar('::vznetwork_venet0_0') %>/<%= scope.lookupvar('::vznetmask_venet0_0') %> dev venet0