Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for overriding automatically detected interface type #11

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 80 additions & 3 deletions manifests/l3/ifconfig.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
# [*bond_lacp_rate*]
# lacp MII rate
#
# [*bond_ifaces*]
# Array, or space-separated list of interfaces that should be on this
# bond interface. Only used if OVS enabled (global ::l23network::use_ovs
# or use_ovs_override are set to true.)
#
# [*ifname_order_prefix*]
# Sets the interface startup order
#
Expand Down Expand Up @@ -69,6 +74,30 @@
# [*check_by_ping_timeout*]
# Timeout for check_by_ping
#
# [*bridge*]
# Bridge interface that this interface should be attached to
# Only supported on EL-based distros
#
# [*routes]
# Static routes to be added for this interface. Format:
# [-net|-host] <host/net>/<mask> [gw <host/IP>]
#
# [*use_ovs_override*]
# Override the global ::l23network::use_ovs setting for this interface. (For
# Linux/OVS hybrid network setups, or situations where ::l23network::use_ovs
# is set by a higher level Puppet class.)
#
# [*ovs_extra*]
# Extra OVS configuration to be included in the interface file OVS_EXTRA.
#
# [*ovs_options*]
# Extra OVS configuration to be included in the interface file OVS_OPTIONS.
#
# [*type_override*]
# Override the automatically detected interface type value. For configuring
# interfaces like mgmt0, whose names to not necessarily conform to the
# regular interface naming conventions.
#
#
# If you configure 802.1q vlan interfaces then you must declare relationships
# between them in site.pp.
Expand All @@ -84,6 +113,7 @@
$bond_mode = undef,
$bond_miimon = 100,
$bond_lacp_rate = 1,
$bond_ifaces = undef,
$mtu = undef,
$dns_nameservers = undef,
$dns_search = undef,
Expand All @@ -93,6 +123,12 @@
$ifname_order_prefix = false,
$check_by_ping = 'gateway',
$check_by_ping_timeout = 120,
$bridge = false,
$routes = undef,
$use_ovs_override = undef,
$ovs_extra = undef,
$ovs_options = undef,
$type_override = undef,
#todo: label => "XXX", # -- "ip addr add..... label XXX"
){
include ::l23network::params
Expand All @@ -107,6 +143,15 @@
'balance-alb'
]

# Determine if we're using OVS for this interface
$real_use_ovs = $use_ovs_override ? { undef => $::l23network::use_ovs, default => $use_ovs_override }

# Ignore bond slave interfaces if not using OVS
$real_bond_ifaces = $interface ? {
/^bond/ => $real_use_ovs ? { true => $bond_ifaces, default => undef },
default => undef
}

# setup configure method for inteface
if $bond_master {
$method = 'bondslave'
Expand Down Expand Up @@ -211,11 +256,12 @@
$vlan_id = $2
$vlan_dev = $1
}
/^(bond\d+)$/: {
if ! $bond_mode {

/^(bond\d+)/: {
if ! $real_use_ovs and ! $bond_mode {
fail("To configure the interface bonding you must the bond_mode parameter is required and must be between 0..6.")
}
if $bond_mode <0 or $bond_mode>6 {
if ! $real_use_ovs and ($bond_mode <0 or $bond_mode>6) {
fail("For interface bonding the bond_mode must be between 0..6, not '${bond_mode}'.")
}
$vlan_mode = undef
Expand All @@ -225,6 +271,26 @@
}
}

# Interface type (taking into account $type_override setting):
$iftype = $type_override ? {
default => $type_override,
undef => $interface ? {
/^br[-\d]+/ => $real_use_ovs ? { true => 'OVSBridge', default => 'Bridge' },
/^bond\d+/ => $real_use_ovs ? { true => 'OVSBond', default => 'Bonding' },
default => $real_use_ovs ? { true => 'OVSPort', default => false }
}
}

# Device type:
$devtype = $real_use_ovs ? {
true => 'ovs',
default => false
}

if $iftype == 'Bridge' and $::osfamily !~ /(?i)redhat/ {
fail("bridge parameter unsupported on ${::osfamily}/${::operatingsystem}")
}

# Specify interface file name prefix
if $ifname_order_prefix {
$interface_file= "${if_files_dir}/ifcfg-${ifname_order_prefix}-${interface}"
Expand Down Expand Up @@ -287,6 +353,17 @@
File <| title == $interface_file |>
}

if $routes and $::osfamily =~ /(?i)redhat/ {
file { "/etc/sysconfig/network-scripts/route-${interface}":
ensure => present,
content => template("l23network/route_RedHat.erb"),
owner => "root",
group => "root",
mode => "0644",
notify => L3_if_downup["${interface}"],
}
}

notify {"ifconfig_${interface}": message=>"Interface:${interface} IP:${effective_ipaddr}/${effective_netmask}", withpath=>false} ->
l3_if_downup {"$interface":
check_by_ping => $check_by_ping,
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
/(?i)redhat/: {
$ovs_service_name = 'openvswitch' #'ovs-vswitchd'
$ovs_status_cmd = '/etc/init.d/openvswitch status'
$ovs_packages = ['kmod-openvswitch', 'openvswitch']
$ovs_status_cmd = '/etc/init.d/openvswitch status | grep -q "is running"'
$ovs_packages = ['openvswitch-kmod', 'openvswitch']
$lnx_vlan_tools = 'vconfig'
$lnx_bond_tools = undef
$lnx_ethernet_tools = 'ethtool'
Expand Down
11 changes: 8 additions & 3 deletions templates/ipconfig_Debian_bondslave.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
auto <%= interface %>
iface <%= interface %> inet manual
bond-master <%= @bond_master %>
auto <%= @interface %>
iface <%= @interface %> inet manual
bond-master <%= @bond_master %>
<% @routes.each do |route| -%>
up route add <%= route %> dev <%= @interface %>
<% end -%>
<% if @ovs_extra %>ovs_extra <%= @ovs_extra %><% end %>
<% if @ovs_options %>ovs_options <%= @ovs_options %><% end %>
14 changes: 11 additions & 3 deletions templates/ipconfig_Debian_dhcp.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
auto <%= interface %>
iface <%= interface %> inet dhcp
auto <%= @interface %>
iface <%= @interface %> inet dhcp
<% if @devtype %>ovs_type <%= @devtype %><% end %>
<% if @dhcp_hostname %>hostname <%= @dhcp_hostname %><% end %>
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
<% if @mtu %>mtu <%= @mtu %><% end %>
<% if @bond_mode %>slaves none
bond-mode <%= @bond_mode %><% if @bond_miimon %>
bond-miimon <%= @bond_miimon %><% end %><% if @bond_lacp_rate %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>
<% end %>
<% @routes.each do |route| -%>
up route add <%= route %> dev <%= @interface %>
<% end -%>
<% if @real_bond_ifaces %>ovs_bonds <%= @real_bond_ifaces %><% end %>
<% if @ovs_extra %>ovs_extra <%= @ovs_extra %><% end %>
<% if @ovs_options %>ovs_options <%= @ovs_options %><% end %>
<% if @real_use_ovs %>ovs_bridge <%= @bridge %><% end %>
18 changes: 13 additions & 5 deletions templates/ipconfig_Debian_manual.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
auto <%= interface %>
iface <%= interface %> inet manual
auto <%= @interface %>
iface <%= @interface %> inet manual
<% if @devtype %>ovs_type <%= @devtype %><% end %>
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
up ip l set <%= interface %> up
down ip l set <%= interface %> down
up ip l set <%= @interface %> up
down ip l set <%= @interface %> down
<% if @mtu %>mtu <%= @mtu %><% end %>
<% if @bond_mode %>slaves none
bond-mode <%= @bond_mode %><% if @bond_miimon %>
bond-miimon <%= @bond_miimon %><% end %><% if @bond_lacp_rate %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>
<% end %>
<% @routes.each do |route| -%>
up route add <%= route %> dev <%= @interface %>
<% end -%>
<% if @real_bond_ifaces %>ovs_bonds <%= @real_bond_ifaces %><% end %>
<% if @ovs_extra %>ovs_extra <%= @ovs_extra %><% end %>
<% if @ovs_options %>ovs_options <%= @ovs_options %><% end %>
<% if @real_use_ovs %>ovs_bridge <%= @bridge %><% end %>
20 changes: 14 additions & 6 deletions templates/ipconfig_Debian_static.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
auto <%= interface %>
iface <%= interface %> inet static
auto <%= @interface %>
iface <%= @interface %> inet static
<% if @devtype %>ovs_type <%= @devtype %><% end %>
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
address <%= effective_ipaddr %>
netmask <%= effective_netmask %>
address <%= @effective_ipaddr %>
netmask <%= @effective_netmask %>
<% if @def_gateway %>gateway <%= @def_gateway %><% end %>
<% if @dns_nameservers_1 or @dns_nameservers_2 %>dns-nameservers <% if @dns_nameservers_1 %><%= @dns_nameservers_1 %><% end %> <% if @dns_nameservers_2 %><%= @dns_nameservers_2 %><% end %><% end %>
<% if @dns_search_string %>dns-search <%= @dns_search_string %><% end %>
Expand All @@ -13,7 +14,14 @@ bond-mode <%= @bond_mode %><% if @bond_miimon %>
bond-miimon <%= @bond_miimon %><% end %><% if @bond_lacp_rate %>
bond-lacp-rate <%= @bond_lacp_rate %><% end %>
<% end %>
<% if @real_bond_ifaces %>ovs_bonds <%= @real_bond_ifaces %><% end %>
<%- if @ipaddr_aliases -%><%- @ipaddr_aliases.each do |addr| -%>
post-up ip addr add <%= addr %> dev <%= interface %>
pre-down ip addr del <%= addr %> dev <%= interface %>
post-up ip addr add <%= addr %> dev <%= @interface %>
pre-down ip addr del <%= addr %> dev <%= @interface %>
<%- end -%><%- end -%>
<% @routes.each do |route| -%>
up route add <%= route %> dev <%= @interface %>
<% end -%>
<% if @ovs_extra %>ovs_extra <%= @ovs_extra %><% end %>
<% if @ovs_options %>ovs_options <%= @ovs_options %><% end %>
<% if @real_use_ovs %>ovs_bridge <%= @bridge %><% end %>
5 changes: 4 additions & 1 deletion templates/ipconfig_RedHat_bondslave.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
DEVICE=<%= interface %>
DEVICE=<%= @interface %>
<% if @devtype %>DEVICETYPE="<%= @devtype %>"<% end %>
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=<%= @bond_master %>
SLAVE=yes
<% if @ovs_extra %>OVS_EXTRA="<%= @ovs_extra %>"<% end %>
<% if @ovs_options %>OVS_OPTIONS="<%= @ovs_options %>"<% end %>
8 changes: 7 additions & 1 deletion templates/ipconfig_RedHat_dhcp.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
DEVICE=<%= interface %>
DEVICE=<%= @interface %>
<% if @iftype %>TYPE=<%= @iftype %><% end %>
<% if @devtype %>DEVICETYPE="<%= @devtype %>"<% end %>
BOOTPROTO=dhcp
ONBOOT=yes
USERCTL=no
Expand All @@ -8,3 +10,7 @@ USERCTL=no
PHYSDEV=<%= @vlan_dev %><% end %>
<% if @mtu %>MTU=<%= @mtu %><% end %>
<% if @bond_mode %>BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_miimon %> miimon=<%= @bond_miimon %><% end %><% if @bond_lacp_rate %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"<% end %>
<% if @bridge %><% if @real_use_ovs %>OVS_BRIDGE=<%= @bridge %><% else %>BRIDGE=<%= @bridge %><% end %><% end %>
<% if @real_bond_ifaces %>BOND_IFACES="<%= @real_bond_ifaces %>"<% end %>
<% if @ovs_extra %>OVS_EXTRA="<%= @ovs_extra %>"<% end %>
<% if @ovs_options %>OVS_OPTIONS="<%= @ovs_options %>"<% end %>
8 changes: 7 additions & 1 deletion templates/ipconfig_RedHat_manual.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
DEVICE=<%= interface %>
DEVICE=<%= @interface %>
<% if @iftype %>TYPE=<%= @iftype %><% end %>
<% if @devtype %>DEVICETYPE="<%= @devtype %>"<% end %>
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
Expand All @@ -7,3 +9,7 @@ USERCTL=no
PHYSDEV=<%= @vlan_dev %><% end %>
<% if @mtu %>MTU=<%= @mtu %><% end %>
<% if @bond_mode %>BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_miimon %> miimon=<%= @bond_miimon %><% end %><% if @bond_lacp_rate %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"<% end %>
<% if @bridge %><% if @real_use_ovs %>OVS_BRIDGE=<%= @bridge %><% else %>BRIDGE=<%= @bridge %><% end %><% end %>
<% if @real_bond_ifaces %>BOND_IFACES="<%= @real_bond_ifaces %>"<% end %>
<% if @ovs_extra %>OVS_EXTRA="<%= @ovs_extra %>"<% end %>
<% if @ovs_options %>OVS_OPTIONS="<%= @ovs_options %>"<% end %>
12 changes: 9 additions & 3 deletions templates/ipconfig_RedHat_static.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
DEVICE=<%= interface %>
IPADDR=<%= effective_ipaddr %>
NETMASK=<%= effective_netmask %>
DEVICE=<%= @interface %>
IPADDR=<%= @effective_ipaddr %>
NETMASK=<%= @effective_netmask %>
<% if @iftype %>TYPE=<%= @iftype %><% end %>
<% if @devtype %>DEVICETYPE="<%= @devtype %>"<% end %>
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
Expand All @@ -13,3 +15,7 @@ PHYSDEV=<%= @vlan_dev %><% end %>
<% if @dns_search_string %>SEARCH=<%= @dns_search_string %><% end %>
<% if @mtu %>MTU=<%= @mtu %><% end %>
<% if @bond_mode %>BONDING_OPTS="mode=<%= @bond_mode %><% if @bond_miimon %> miimon=<%= @bond_miimon %><% end %><% if @bond_lacp_rate %> bond-lacp-rate=<%= @bond_lacp_rate %><% end %>"<% end %>
<% if @bridge %><% if @real_use_ovs %>OVS_BRIDGE=<%= @bridge %><% else %>BRIDGE=<%= @bridge %><% end %><% end %>
<% if @real_bond_ifaces %>BOND_IFACES="<%= @real_bond_ifaces %>"<% end %>
<% if @ovs_extra %>OVS_EXTRA="<%= @ovs_extra %>"<% end %>
<% if @ovs_options %>OVS_OPTIONS="<%= @ovs_options %>"<% end %>
4 changes: 2 additions & 2 deletions templates/ipconfig_RedHat_static_down-script.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
<%- if @ipaddr_aliases -%>
<%- @ipaddr_aliases.each do |addr| -%>
ip addr del <%= addr %> dev <%= interface %>
ip addr del <%= addr %> dev <%= @interface %>
<%- end -%>
<%- end -%>
true
true
4 changes: 2 additions & 2 deletions templates/ipconfig_RedHat_static_up-script.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
<%- if @ipaddr_aliases -%>
<%- @ipaddr_aliases.each do |addr| -%>
ip addr add <%= addr %> dev <%= interface %>
ip addr add <%= addr %> dev <%= @interface %>
<%- end -%>
<%- end -%>
true
true
3 changes: 3 additions & 0 deletions templates/route_RedHat.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @routes.each do |route| -%>
<%= route %>
<% end -%>