Add Old fashioned to new CentOs7 interface name conversion function

Change-Id: I9326dbad4d05521913c2a3769679a93ec56db6e4
This commit is contained in:
Alex Ruiz Estradera 2016-07-26 18:22:05 +02:00
parent 27a96320b4
commit 8e2c562cb7
2 changed files with 224 additions and 0 deletions

View File

@ -0,0 +1,53 @@
require 'facter'
# Function to figure out old school to new school mappings
# Uses the biosdevname info to generate a mapping
module Puppet::Parser::Functions
newfunction(:c7_int_name, :type => :rvalue) do |args|
if args.length != 1
raise(Puppet::ParseError, "No interface name passed to convert")
end
int_name = args[0]
if Facter.value('osfamily') == 'Debian'
#nothing to do here..
return int_name
end
# Don't need any of this logic for 6
Facter.loadfacts()
os_majrelease = Facter.value('operatingsystemmajrelease')
if os_majrelease != '7'
return int_name
end
# Get the kernel names
interfaces = {}
kernel_devs=`/usr/sbin/biosdevname -d`
kernel_devs.split("\n").each do |dev_info|
# Split the values
name, value = dev_info.split(':', 2)
# Stip the whitespace out
name = name.sub(/^[\s\n\r]*/, '').sub(/[\s\n\r]*$/, '')
value = value.sub(/^[\s\n\r]*/, '').sub(/[\s\n\r]*$/, '')
# Grab the kernel names
if name == 'Kernel name'
# Figure out the old school mapping
old_school=`/usr/sbin/biosdevname --policy=all_ethN -i '#{value}'`
interfaces[old_school.chomp] = value
end
end
# Lookup
if interfaces.has_key?(int_name)
return interfaces[int_name]
end
# Default to what was passed
return int_name
end
end

View File

@ -0,0 +1,171 @@
# == Resource: midonet::resources::network_creation
#
# Creates external and tenant networks and creates their ports
#
# === Parameters
#
# [*api_endpoint*]
# Midonet API endpoint
# [*keystone_username*]
# Keystone username
# [*keystone_password*]
# KKeystone Password
# [*tenant_name*]
# Tenant Name
# [*controller_ip*]
# Controller node ip
# [*controller_neutron_port*]
# Controller neutron port
# [*network external*]
# Name of the external network
# [*allocation_pools*]
# Allocation Pools for the external subnets
# [*gateway_ip*]
# Gateway ip
# [*subnet_cidr*]
# Subnet cidr ( ex. 172.17.0.0/24 )
# [*subnet_name*]
# Subnet name ( ex. ext-subnet)
# [*edge_router_name*]
# Edge Router Name
# [*edge_network_name*]
# Edge Network Name
# [*edge_subnet_name*]
# Edge subnet name
# [*edge_cidr*]
# Edge cidr ( ex. 172.17.0.0/24)
# [*port_name*]
# Port name
# [*port_fixed_ip*]
# Port fixed ip
# [*port_interface_name*]
# Port interface name ( in the old-fashioned form , like eth0, eth1...)
#
#
# === Examples
#
# network_creation(
# api_endpoint => 'http://127.0.0.1:8181/midonet-api',
# keystone_username => 'midogod',
# keystone_password => 'testmido',
# tenant_name => 'admin',
# controller_ip => '127.0.0.1',
# controller_neutron_port => '9696',
# network_external => 'ext-net',
# allocation_pools => ['start=172.17.0.10,end=172.17.0.200'],
# gateway_ip => '172.17.0.3',
# subnet_cidr => '172.17.0.0/24',
# subnet_name => 'ext-subnet',
# edge_router_name => 'edge-router',
# edge_network_name => 'net-edge1-gw1',
# edge_subnet_name => 'subnet-edge1-gw1',
# edge_cidr => '172.17.0.0/24',
# port_name => 'testport',
# port_fixed_ip => '172.17.0.3',
# port_interface_name => 'eth1'
#
# )
#
# === Authors
#
# Midonet (http://midonet.org)
#
# === Copyright
#
# Copyright (c) 2015 Midokura SARL, All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
define midonet::resources::network_creation(
$api_endpoint = 'http://127.0.0.1:8181/midonet-api',
$keystone_username = 'midogod',
$keystone_password = 'testmido',
$tenant_name = 'admin',
$controller_ip = '127.0.0.1',
$controller_neutron_port = '9696',
$network_external = 'ext-net',
$allocation_pools = ['start=172.17.0.10,end=172.17.0.200'],
$gateway_ip = '172.17.0.3',
$subnet_cidr = '172.17.0.0/24',
$subnet_name = 'ext-subnet',
$edge_router_name = 'edge-router',
$edge_network_name = 'net-edge1-gw1',
$edge_subnet_name = 'subnet-edge1-gw1',
$edge_cidr = '172.17.0.0/24',
$port_name = 'testport',
$port_fixed_ip = '172.17.0.3',
$port_interface_name = 'eth1'
) {
$neutron_auth_creds = {
'neutron_auth_uri' => "http://${controller_ip}:${controller_neutron_port}",
'admin_username' => $keystone_username,
'admin_password' => $keystone_password,
'admin_tenant_name' => $tenant_name,
}
neutron_network { $network_external:
external => true,
shared => true,
neutron_credentials => $neutron_auth_creds
} ->
neutron_subnet { $subnet_name:
allocation_pools => $allocation_pools,
enable_dhcp => false,
gateway_ip => $gateway_ip,
cidr => $subnet_cidr,
network_name => $network_external,
neutron_credentials => $neutron_auth_creds
} ->
neutron_router { $edge_router_name:
neutron_credentials => $neutron_auth_creds
} ->
neutron_router_interface { "${edge_router_name}:${subnet_name}":
neutron_credentials => $neutron_auth_creds
} ->
neutron_network { $edge_network_name:
tenant_id => $tenant_name,
provider_network_type => 'uplink',
neutron_credentials => $neutron_auth_creds
} ->
neutron_subnet { $edge_subnet_name:
enable_dhcp => false,
cidr => $edge_cidr,
tenant_id => $tenant_name,
network_name => $edge_network_name,
neutron_credentials => $neutron_auth_creds
} ->
neutron_port { $port_name:
network_name => $edge_network_name,
binding_host_id => $::hostname,
binding_profile => {
'interface_name' => c7_int_name($port_interface_name)
},
fixed_ip => $port_fixed_ip,
neutron_credentials => $neutron_auth_creds
} ->
neutron_router_interface { "${edge_router_name}:null":
port => $port_name,
neutron_credentials => $neutron_auth_creds
}
}