L23network::l2::port -- OVS options for port and port's interfaces

Example:
    l23network::l2::bridge {'pvt': }
    l23network::l2::port{'pvt-eth2':
      bridge  => 'pvt',
      port    => 'eth2',
      port_options => ['tag=10'],
      interface_options => ['type=internal']
    }

+ some small fixes
This commit is contained in:
Sergey Vasilenko 2013-03-26 19:57:37 +04:00
parent 8a07ac087e
commit 14a39e1eca
8 changed files with 71 additions and 9 deletions

View File

@ -4,18 +4,17 @@
module Puppet::Parser::Functions
newfunction(:array_or_string_to_array, :type => :rvalue, :doc => <<-EOS
This function get array or string with seperator (comma, colon or space).
This function get array or string with separator (comma, colon or space).
and return array without empty or false elements.
*Examples:*
array_or_string_to_array(['a','b','c','d'])
array_or_string_to_array('a,b:c d'])
array_or_string_to_array('a,b:c d')
Would result in: ['a','b','c','d']
EOS
) do |arguments|
# Technically we support two arguments but only first is mandatory ...
raise(Puppet::ParseError, "array_or_string_to_array(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

View File

@ -14,7 +14,6 @@ This function get arrays, merge it and return.
Would result in: ['a','b','c','d']
EOS
) do |arguments|
# Technically we support two arguments but only first is mandatory ...
raise(Puppet::ParseError, "merge_arrays(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

View File

@ -15,7 +15,7 @@ Puppet::Type.type(:l2_ovs_bridge).provide(:ovs) do
#external_ids = @resource[:external_ids] if @resource[:external_ids]
return true
else
raise ExecutionFailure, "Bridge '#{@resource[:bridge]}' already exists."
raise Puppet::ExecutionFailure, "Bridge '#{@resource[:bridge]}' already exists."
end
rescue Puppet::ExecutionFailure
# pass

View File

@ -11,18 +11,42 @@ Puppet::Type.type(:l2_ovs_port).provide(:ovs) do
if @resource[:skip_existing]
return true
else
raise ExecutionFailure, "Port '#{@resource[:interface]}' already exists."
raise Puppet::ExecutionFailure, "Port '#{@resource[:interface]}' already exists."
end
rescue Puppet::ExecutionFailure
# pass
end
# Port create begins from definition brodge and port
cmd = [@resource[:bridge], @resource[:interface]]
# add port options (k/w) to command line
if @resource[:port_options]
for option in @resource[:port_options]
cmd += [option]
end
end
# set interface type
#TODO: implement type=>patch sintax as type=>'patch:peer-name'
if @resource[:type] and @resource[:type].to_s != ''
tt = "type=" + @resource[:type].to_s
cmd += ['--', "set", "Interface", @resource[:interface], tt]
end
# executing OVS add-port command
cmd = ["add-port"] + cmd
vsctl(cmd)
begin
vsctl(cmd)
rescue Puppet::ExecutionFailure => error
raise Puppet::ExecutionFailure, "Can't add port '#{@resource[:interface]}'\n#{error}"
end
# set interface options
if @resource[:interface_options]
for option in @resource[:interface_options]
begin
vsctl('--', "set", "Interface", @resource[:interface], option.to_s)
rescue Puppet::ExecutionFailure => error
raise Puppet::ExecutionFailure, "Interface '#{@resource[:interface]}' can't set option '#{option}':\n#{error}"
end
end
end
end
def destroy

View File

@ -19,7 +19,10 @@ Puppet::Type.newtype(:l2_ovs_bond) do
desc "List of ports, that will be added to the bond"
#
validate do |val|
val.each do |port|
if not val.is_a?(Array)
fail("Ports option must be array (not be #{val.class}).")
end
for port in val
if not port =~ /^[a-z][0-9a-z\.\-\_]*[0-9a-z]$/
fail("Invalid port name: '#{port}'")
end

View File

@ -36,6 +36,26 @@ Puppet::Type.newtype(:l2_ovs_port) do
end
end
newparam(:port_options) do
defaultto([])
desc "Array of port options"
validate do |val|
if not (val.is_a?(Array) or val.is_a?(String)) # String need for array with one element. it's a puppet's feature
fail("port_options must be array (not be #{val.class}).")
end
end
end
newparam(:interface_options) do
defaultto([])
desc "Array of port interface options"
validate do |val|
if not (val.is_a?(Array) or val.is_a?(String)) # String need for array with one element. it's a puppet's feature
fail("interface_options must be array (not be #{val.class}).")
end
end
end
autorequire(:l2_ovs_bridge) do
[self[:bridge]]
end

View File

@ -26,6 +26,8 @@ define l23network::l2::port (
$bridge,
$port = $name,
$type = '',
$port_options = [],
$interface_options = [],
$ensure = present,
$skip_existing = false,
) {
@ -34,6 +36,8 @@ define l23network::l2::port (
ensure => $ensure,
bridge => $bridge,
type => $type,
port_options => $port_options,
interface_options => $interface_options,
skip_existing => $skip_existing,
}
Service<| title == 'openvswitch-service' |> -> L2_ovs_port[$port]

View File

@ -24,8 +24,17 @@
# If current network configuration contains a default gateway
# this option allow try to save it.
#
# [*dns_nameservers*]
# Dns nameservers to use
#
# [*dns_domain*]
# describe DNS domain
#
# [*dns_search*]
# DNS domain to search for
#
define l23network::l3::create_br_iface (
$interface,
$interface, #TODO: if interface is array -- create bond, using bond_options.
$bridge,
$ipaddr,
$netmask = '255.255.255.0',
@ -33,6 +42,8 @@ define l23network::l3::create_br_iface (
$se = true,
$external_ids = '',
$dns_nameservers = undef,
$dns_domain = undef,
$dns_search = undef,
$save_default_gateway = false,
$interface_vlandev = undef,
$interface_bond_mode = undef,
@ -74,6 +85,8 @@ define l23network::l3::create_br_iface (
netmask => $netmask,
gateway => $gateway_ip_address_for_newly_created_interface,
dns_nameservers => $dns_nameservers,
dns_domain => $dns_domain,
dns_search => $dns_search,
ifname_order_prefix => 'ovs',
require => L23network::L3::Ifconfig[$interface],
}