Backport to 4.0 following issues:
Closes-bug: #1279809 #1275132c82d4edd66
#1271274244acdaab1
#1277112078efe6720
#12751327776ffe6fd
#12771470ba23e1a6a
,5fd706f58a
#1274789b8105f58bc
#127871848e8c25aa4
* Update l3_if_downup to eval carrier state when starting * Allow more than two interfaces in the OVS bonds. * FIX: incorrect condition in l23network bond type * Fix un-changeable resource in l3_if_downup * FIX: L23network module can't get one-element array as bond parameter * FIX errors while print error massage. * L23network: allow setup MTU in the network_schema * Get Ordering of ifconfig operations from transformation order if it possible. Change-Id: I2fa29b72188dc7798eaf9c388cf46b831a5a38c9
This commit is contained in:
parent
4b5f30b8b7
commit
cda522650c
|
@ -22,6 +22,9 @@ module L23network
|
|||
action = trans[:action].downcase()
|
||||
# Setup defaults
|
||||
rv = case action
|
||||
when "noop" then {
|
||||
:name => nil,
|
||||
}
|
||||
when "add-br" then {
|
||||
:name => nil,
|
||||
#:stp_enable => true,
|
||||
|
@ -84,12 +87,9 @@ module L23network
|
|||
rv[:name] = name
|
||||
end
|
||||
if action == "add-bond"
|
||||
if not rv[:interfaces].is_a? Array or rv[:interfaces].size() != 2
|
||||
if not (rv[:interfaces].is_a?(Array) and rv[:interfaces].size() >= 2)
|
||||
raise(Puppet::ParseError, "Transformation bond '#{name}' have wrong 'interfaces' parameter.")
|
||||
end
|
||||
# rv[:interfaces].each do |i|
|
||||
# if
|
||||
# end
|
||||
end
|
||||
return rv
|
||||
end
|
||||
|
@ -144,11 +144,17 @@ Puppet::Parser::Functions::newfunction(:generate_network_config, :type => :rvalu
|
|||
|
||||
# collect interfaces and endpoints
|
||||
endpoints = {}
|
||||
ifconfig_order = []
|
||||
born_ports = []
|
||||
config_hash[:interfaces].each do |int_name, int_properties|
|
||||
int_name = int_name.to_sym()
|
||||
endpoints[int_name] = create_endpoint()
|
||||
born_ports.insert(-1, int_name)
|
||||
# add some of 1st level interface properties to it's config
|
||||
int_properties.each do |k,v|
|
||||
next if ! ['macaddr', 'mtu'].index(k.to_s)
|
||||
endpoints[int_name][:properties][k.to_sym] = v
|
||||
end
|
||||
end
|
||||
config_hash[:endpoints].each do |e_name, e_properties|
|
||||
e_name = e_name.to_sym()
|
||||
|
@ -189,7 +195,24 @@ Puppet::Parser::Functions::newfunction(:generate_network_config, :type => :rvalu
|
|||
action = t[:action].to_sym()
|
||||
end
|
||||
|
||||
# add newly-created interface to ifconfig order
|
||||
if [:noop, :port, :br].index(action)
|
||||
if ! ifconfig_order.index(t[:name].to_sym())
|
||||
ifconfig_order.insert(-1, t[:name].to_sym())
|
||||
end
|
||||
elsif action == :bond
|
||||
t[:interfaces].each do |physint|
|
||||
if ! ifconfig_order.index(physint.to_sym())
|
||||
ifconfig_order.insert(-1, physint.to_sym())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
next if action == :noop
|
||||
|
||||
trans = L23network.sanitize_transformation(t)
|
||||
|
||||
# create puppet resources
|
||||
resource = res_factory[action][:resource]
|
||||
p_resource = Puppet::Parser::Resource.new(
|
||||
res_factory[action][:name_of_resource],
|
||||
|
@ -258,43 +281,51 @@ Puppet::Parser::Functions::newfunction(:generate_network_config, :type => :rvalu
|
|||
raise(Puppet::ParseError, "generate_network_config(): Endpoint '#{e_name}' not found in interfaces or transformations result.")
|
||||
end
|
||||
end
|
||||
|
||||
# Calculate delta between all endpoints and ifconfig_order
|
||||
ifc_delta = endpoints.keys().sort() - ifconfig_order
|
||||
full_ifconfig_order = ifconfig_order + ifc_delta
|
||||
|
||||
# execute interfaces and endpoints
|
||||
# may be in future we will move interfaces before transformations
|
||||
endpoints.each do |endpoint_name, endpoint_body|
|
||||
# create resource
|
||||
resource = res_factory[:ifconfig][:resource]
|
||||
p_resource = Puppet::Parser::Resource.new(
|
||||
res_factory[:ifconfig][:name_of_resource],
|
||||
endpoint_name,
|
||||
:scope => self,
|
||||
:source => resource
|
||||
)
|
||||
p_resource.set_parameter(:interface, endpoint_name)
|
||||
# set ipaddresses
|
||||
if endpoint_body[:IP].empty?
|
||||
p_resource.set_parameter(:ipaddr, 'none')
|
||||
elsif ['none','dhcp'].index(endpoint_body[:IP][0])
|
||||
p_resource.set_parameter(:ipaddr, endpoint_body[:IP][0])
|
||||
else
|
||||
ipaddrs = []
|
||||
endpoint_body[:IP].each do |i|
|
||||
if i =~ /\/\d+$/
|
||||
ipaddrs.insert(-1, i)
|
||||
else
|
||||
ipaddrs.insert(-1, "#{i}#{default_netmask()}")
|
||||
# in order, defined by transformation
|
||||
full_ifconfig_order.each do |endpoint_name|
|
||||
if endpoints[endpoint_name]
|
||||
endpoint_body = endpoints[endpoint_name]
|
||||
# create resource
|
||||
resource = res_factory[:ifconfig][:resource]
|
||||
p_resource = Puppet::Parser::Resource.new(
|
||||
res_factory[:ifconfig][:name_of_resource],
|
||||
endpoint_name,
|
||||
:scope => self,
|
||||
:source => resource
|
||||
)
|
||||
p_resource.set_parameter(:interface, endpoint_name)
|
||||
# set ipaddresses
|
||||
if endpoint_body[:IP].empty?
|
||||
p_resource.set_parameter(:ipaddr, 'none')
|
||||
elsif ['none','dhcp'].index(endpoint_body[:IP][0])
|
||||
p_resource.set_parameter(:ipaddr, endpoint_body[:IP][0])
|
||||
else
|
||||
ipaddrs = []
|
||||
endpoint_body[:IP].each do |i|
|
||||
if i =~ /\/\d+$/
|
||||
ipaddrs.insert(-1, i)
|
||||
else
|
||||
ipaddrs.insert(-1, "#{i}#{default_netmask()}")
|
||||
end
|
||||
end
|
||||
p_resource.set_parameter(:ipaddr, ipaddrs)
|
||||
end
|
||||
p_resource.set_parameter(:ipaddr, ipaddrs)
|
||||
#set another (see L23network::l3::ifconfig DOC) parametres
|
||||
endpoint_body[:properties].each do |k,v|
|
||||
p_resource.set_parameter(k,v)
|
||||
end
|
||||
p_resource.set_parameter(:require, [previous]) if previous
|
||||
resource.instantiate_resource(self, p_resource)
|
||||
compiler.add_resource(self, p_resource)
|
||||
transformation_success.insert(-1, "endpoint(#{endpoint_name})")
|
||||
previous = p_resource.to_s
|
||||
end
|
||||
#set another (see L23network::l3::ifconfig DOC) parametres
|
||||
endpoint_body[:properties].each do |k,v|
|
||||
p_resource.set_parameter(k,v)
|
||||
end
|
||||
p_resource.set_parameter(:require, [previous]) if previous
|
||||
resource.instantiate_resource(self, p_resource)
|
||||
compiler.add_resource(self, p_resource)
|
||||
transformation_success.insert(-1, "endpoint(#{endpoint_name})")
|
||||
previous = p_resource.to_s
|
||||
end
|
||||
|
||||
return transformation_success.join(" -> ")
|
||||
|
|
|
@ -27,7 +27,7 @@ Puppet::Type.type(:l2_ovs_bond).provide(:ovs) do
|
|||
end
|
||||
end
|
||||
|
||||
bond_properties = @resource[:properties]
|
||||
bond_properties = Array(@resource[:properties])
|
||||
if @resource[:tag] > 0
|
||||
bond_properties.insert(-1, "tag=#{@resource[:tag]}")
|
||||
end
|
||||
|
@ -42,7 +42,6 @@ Puppet::Type.type(:l2_ovs_bond).provide(:ovs) do
|
|||
begin
|
||||
vsctl(bond_create_cmd)
|
||||
rescue Puppet::ExecutionFailure => error
|
||||
notice(">>>#{bond_create_cmd.join(',')}<<<")
|
||||
fail("Can't create bond '#{@resource[:bond]}' (interfaces: #{@resource[:interfaces].join(',')}) for bridge '#{@resource[:bridge]}'.\n#{error}")
|
||||
end
|
||||
end
|
||||
|
@ -50,8 +49,8 @@ Puppet::Type.type(:l2_ovs_bond).provide(:ovs) do
|
|||
def destroy
|
||||
begin
|
||||
vsctl("del-port", @resource[:bridge], @resource[:bond])
|
||||
rescue Puppet::ExecutionFailure
|
||||
fail("Can't remove bond '#{@resource[:bond]}' from bridge '#{@resource[:bridge]}'.")
|
||||
rescue Puppet::ExecutionFailure => error
|
||||
fail("Can't remove bond '#{@resource[:bond]}' from bridge '#{@resource[:bridge]}'.\n#{error}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -79,7 +79,23 @@ Puppet::Type.type(:l3_if_downup).provide(:ruby) do
|
|||
return rv
|
||||
end
|
||||
|
||||
def get_interface_carrier()
|
||||
begin
|
||||
return File.open("/sys/class/net/#{@resource[:interface]}/carrier", 'r'){ |file| file.read().to_i }
|
||||
rescue
|
||||
return -1
|
||||
end
|
||||
end
|
||||
|
||||
def restart()
|
||||
#Check the current state of the interface first
|
||||
if get_interface_carrier != 1
|
||||
notice("Carrier is DOWN, '#{@resource[:interface]}' skipping carrier test")
|
||||
poll_for_carrier = false
|
||||
else
|
||||
poll_for_carrier = true
|
||||
end
|
||||
|
||||
begin # downing inteface
|
||||
# add force for debian-based OS ([PRD-2132])
|
||||
if Facter.value(:osfamily) == 'Debian'
|
||||
|
@ -128,19 +144,15 @@ Puppet::Type.type(:l3_if_downup).provide(:ruby) do
|
|||
end
|
||||
notice("Interface '#{@resource[:interface]}' up.")
|
||||
# checking and waiting carrier for PHYS. interface
|
||||
if (@resource[:interface] =~ /^eth\d+$/) and @resource[:wait_carrier_after_ifup]
|
||||
if (@resource[:interface] =~ /^eth\d+$/) and @resource[:wait_carrier_after_ifup] and poll_for_carrier
|
||||
begin
|
||||
Timeout::timeout(@resource[:wait_carrier_after_ifup_timeout]) do
|
||||
_w = 10
|
||||
loop do
|
||||
begin
|
||||
_rc = File.open("/sys/class/net/#{@resource[:interface]}/carrier", 'r'){ |file| file.read() }
|
||||
rescue
|
||||
_rc = -1
|
||||
end
|
||||
if _rc.to_i() == 1
|
||||
carrier = get_interface_carrier
|
||||
if carrier == 1
|
||||
break
|
||||
elsif _rc.to_i() == -1
|
||||
elsif carrier == -1
|
||||
notice("Seems that the interface '#{@resource[:interface]}' was brought down administratively. Further deployment actions may fail!")
|
||||
sleep(10)
|
||||
else
|
||||
|
|
|
@ -9,7 +9,7 @@ Puppet::Type.newtype(:l2_ovs_bond) do
|
|||
desc "The bond name"
|
||||
#
|
||||
validate do |val|
|
||||
if not val =~ /^[a-z][0-9a-z\.\-\_]*[0-9a-z]$/
|
||||
if not (val =~ /^[a-zA-Z][0-9a-zA-Z\.\-\_]*[0-9a-zA-Z]$/)
|
||||
fail("Invalid bond name: '#{val}'")
|
||||
end
|
||||
end
|
||||
|
@ -19,11 +19,11 @@ Puppet::Type.newtype(:l2_ovs_bond) do
|
|||
desc "List of interfaces that will be added to the bond"
|
||||
#
|
||||
validate do |val|
|
||||
if not val.is_a?(Array)
|
||||
fail("Interfaces parameter must be an array (not #{val.class}).")
|
||||
if not (val.is_a?(Array) and val.size() >= 2)
|
||||
fail("Interfaces parameter must be an array of two or more interface names.")
|
||||
end
|
||||
for ii in val
|
||||
if not ii =~ /^[a-z][0-9a-z\.\-\_]*[0-9a-z]$/
|
||||
if not (ii =~ /^[a-zA-Z][0-9a-zA-Z\.\-\_]*[0-9a-zA-Z]$/)
|
||||
fail("Invalid port name: '#{ii}'")
|
||||
end
|
||||
end
|
||||
|
@ -38,13 +38,16 @@ Puppet::Type.newtype(:l2_ovs_bond) do
|
|||
newparam(:properties) do
|
||||
defaultto([])
|
||||
desc "Array of bond properties"
|
||||
munge do |val|
|
||||
Array(val)
|
||||
end
|
||||
end
|
||||
|
||||
newparam(:bridge) do
|
||||
desc "What bridge to use"
|
||||
#
|
||||
validate do |val|
|
||||
if not val =~ /^[a-z][0-9a-z\.\-\_]*[0-9a-z]$/
|
||||
if not (val =~ /^[a-zA-Z][0-9a-zA-Z\.\-\_]*[0-9a-zA-Z]$/)
|
||||
fail("Invalid bridge name: '#{val}'")
|
||||
end
|
||||
end
|
||||
|
@ -84,3 +87,4 @@ Puppet::Type.newtype(:l2_ovs_bond) do
|
|||
[self[:bridge]]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ define l23network::l3::ifconfig (
|
|||
$bond_mode = undef,
|
||||
$bond_miimon = 100,
|
||||
$bond_lacp_rate = 1,
|
||||
$macaddr = undef,
|
||||
$mtu = undef,
|
||||
$dns_nameservers = undef,
|
||||
$dns_search = undef,
|
||||
|
@ -107,6 +108,14 @@ define l23network::l3::ifconfig (
|
|||
'balance-alb'
|
||||
]
|
||||
|
||||
if $macaddr and $macaddr !~ /^([0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}$/ {
|
||||
fail("Invalid MAC address '${macaddr}' for interface '${interface}'")
|
||||
}
|
||||
|
||||
if $mtu and !is_integer("${mtu}") { # is_integer() fails if integer given :)
|
||||
fail("Invalid MTU '${mtu}' for interface '${interface}'")
|
||||
}
|
||||
|
||||
# setup configure method for inteface
|
||||
if $bond_master {
|
||||
$method = 'bondslave'
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
auto <%= interface %>
|
||||
iface <%= interface %> inet manual
|
||||
bond-master <%= @bond_master %>
|
||||
bond-master <%= @bond_master %>
|
||||
<% if @macaddr -%>
|
||||
hwaddress ether <%= @macaddr.downcase %>
|
||||
<% end -%>
|
||||
<% if @mtu -%>
|
||||
mtu <%= @mtu %>
|
||||
<% end -%>
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@ auto <%= interface %>
|
|||
iface <%= interface %> inet dhcp
|
||||
<% 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 %>
|
||||
<% if @mtu -%>
|
||||
mtu <%= @mtu %>
|
||||
<% end -%>
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
auto <%= interface %>
|
||||
iface <%= interface %> inet manual
|
||||
<% if @macaddr -%>
|
||||
hwaddress ether <%= @macaddr.downcase %>
|
||||
<% end -%>
|
||||
<% if @mtu -%>
|
||||
mtu <%= @mtu %>
|
||||
<% end -%>
|
||||
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
|
||||
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 %>
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
auto <%= interface %>
|
||||
iface <%= interface %> inet static
|
||||
<% if @macaddr -%>
|
||||
hwaddress ether <%= @macaddr.downcase %>
|
||||
<% end -%>
|
||||
<% if @mtu -%>
|
||||
mtu <%= @mtu %>
|
||||
<% end -%>
|
||||
<% if @vlan_mode %>vlan_raw_device <%= @vlan_dev %><% end %>
|
||||
address <%= effective_ipaddr %>
|
||||
netmask <%= effective_netmask %>
|
||||
|
@ -7,7 +13,6 @@ netmask <%= effective_netmask %>
|
|||
<% 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 %>
|
||||
<% if @dns_domain_string %>dns-domain <%= @dns_domain_string %><% 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 %>
|
||||
|
|
|
@ -4,3 +4,10 @@ ONBOOT=yes
|
|||
USERCTL=no
|
||||
MASTER=<%= @bond_master %>
|
||||
SLAVE=yes
|
||||
<% if @macaddr -%>
|
||||
MACADDR=<%= @macaddr.upcase %>
|
||||
<% end -%>
|
||||
<% if @mtu -%>
|
||||
MTU=<%= @mtu %>
|
||||
<% end -%>
|
||||
|
||||
|
|
|
@ -2,9 +2,25 @@ DEVICE=<%= interface %>
|
|||
BOOTPROTO=dhcp
|
||||
ONBOOT=yes
|
||||
USERCTL=no
|
||||
<% if @dhcp_hostname %>DHCP_HOSTNAME=<%= @dhcp_hostname %><% end %>
|
||||
<% if @vlan_mode %>VLAN=yes<% end %>
|
||||
<% if @vlan_mode == 'vlan' %>VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD
|
||||
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 @dhcp_hostname -%>
|
||||
DHCP_HOSTNAME=<%= @dhcp_hostname %>
|
||||
<% end -%>
|
||||
<% if @vlan_mode -%>
|
||||
VLAN=yes
|
||||
<% end -%>
|
||||
<% if @vlan_mode == 'vlan' -%>
|
||||
VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD
|
||||
PHYSDEV=<%= @vlan_dev %>
|
||||
<% end -%>
|
||||
<% if @mtu -%>
|
||||
MTU=<%= @mtu %>
|
||||
<% end -%>
|
||||
<% if @macaddr -%>
|
||||
MACADDR=<%= @macaddr.upcase %>
|
||||
<% 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 @mtu -%>
|
||||
MTU=<%= @mtu %>
|
||||
<% end -%>
|
||||
|
|
Loading…
Reference in New Issue