Set mac address for vrouter dpdk
This commit introduce new fact that will handle mac address for dpdk interface Change-Id: Iec8e715f12d48618b026e89fedb5c2495b8aa2e5
This commit is contained in:
committed by
Illia Polliul
parent
583ccff1c8
commit
7bed0edf30
@@ -0,0 +1,82 @@
|
||||
require 'hiera'
|
||||
require 'ipaddress'
|
||||
|
||||
#This fact is designed to return sticky MAC address for use on dpdk computes.
|
||||
#The main idea that we generate hardware address from IP if bond is used for dpdk purposes.
|
||||
#If dpdk interface is pure NIC - trying to get real NIC MAC and in case of fail - generate new.
|
||||
Facter.add("dpdk_mac_address") do
|
||||
|
||||
#Generate static MAC address from IP
|
||||
#172.29.154.113 -> 00:11:AC:1D:9A:71
|
||||
def mac_from_ip(ip)
|
||||
prefix='00:11:'
|
||||
ip_arr=ip.split('.')
|
||||
out=sprintf('%.2x:%.2x:%.2x:%.2x',ip_arr[0], ip_arr[1], ip_arr[2], ip_arr[3])
|
||||
prefix+out
|
||||
end
|
||||
|
||||
def get_mac_for(iface)
|
||||
hmac=''
|
||||
#If NIC is still available in system read MAC from it
|
||||
if File.exist? "/sys/class/net/#{iface}/address"
|
||||
hmac=File.read("/sys/class/net/#{iface}/address")
|
||||
return hmac.chomp!
|
||||
end
|
||||
#If dpdk load interface, trying udev saved file
|
||||
if File.exist? "/etc/udev/rules.d/70-persistent-net.rules"
|
||||
File.foreach('/etc/udev/rules.d/70-persistent-net.rules') do |line, line_num|
|
||||
h=Hash.new
|
||||
if "#{line}".start_with?('SUBSYSTEM')
|
||||
line.gsub!(/\s/,'').gsub!(/==/, '=').split(',').each do |l|
|
||||
key, value = l.gsub('"','').split('=')
|
||||
h[key]=value
|
||||
end
|
||||
if h.has_key?('NAME') and h['NAME']==iface
|
||||
hmac=h.fetch('ATTR{address}', '')
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
hmac
|
||||
end
|
||||
|
||||
setcode do
|
||||
mac = ''
|
||||
hiera = Hiera.new(:config => '/etc/hiera.yaml')
|
||||
network_scheme = hiera.lookup('network_scheme', {}, {}, nil, :hash)
|
||||
roles = hiera.lookup('roles', [], {}, nil, :array)
|
||||
|
||||
#We need this fact only for dpdk computes
|
||||
if !roles.include? 'dpdk'
|
||||
break
|
||||
end
|
||||
|
||||
phys_dev = ''
|
||||
network_scheme['transformations'].each do |trans|
|
||||
if trans['bridge'] == network_scheme['roles']['neutron/mesh']
|
||||
phys_dev = trans['name'].split('.')[0]
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
priv_ip = network_scheme['endpoints']['br-mesh']['IP'][0].split('/')[0]
|
||||
if !IPAddress.valid? priv_ip
|
||||
break
|
||||
end
|
||||
generated_mac=mac_from_ip(priv_ip)
|
||||
|
||||
#For bonds we just generate static MAC
|
||||
if phys_dev.include? 'bond'
|
||||
mac=generated_mac
|
||||
#True hardware NIC
|
||||
else
|
||||
mac=get_mac_for(phys_dev)
|
||||
if mac.empty?
|
||||
mac=generated_mac
|
||||
end
|
||||
end
|
||||
mac
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
# Copyright 2016 Mirantis, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
require 'hiera'
|
||||
|
||||
Facter.add("mac_from_vrouter") do
|
||||
setcode do
|
||||
output=`vif --get 0`
|
||||
hiera = Hiera.new(:config => '/etc/hiera.yaml')
|
||||
network_scheme = hiera.lookup('network_scheme', {}, {}, nil, :hash)
|
||||
|
||||
phys_dev = vlan = ''
|
||||
network_scheme['transformations'].each do |trans|
|
||||
if trans['bridge'] == network_scheme['roles']['neutron/mesh']
|
||||
phys_dev, vlan = trans['name'].split('.')
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
mac = `cat /sys/class/net/#{phys_dev}/address`.chomp
|
||||
if $?.success?
|
||||
output.split('vif').each do |iface|
|
||||
if iface.start_with?( '0/0')
|
||||
mac = iface.split[8][7..-1]
|
||||
end
|
||||
end
|
||||
end
|
||||
mac
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# Copyright 2016 Mirantis, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:get_mac_from_vrouter, :type => :rvalue, :doc => <<-EOS
|
||||
Returns mac address of interface used by DPDK vrouter
|
||||
EOS
|
||||
) do |args|
|
||||
mac = "00:00:00:00:00:00"
|
||||
|
||||
begin
|
||||
output=`vif --list`
|
||||
result=$?.success?
|
||||
if result
|
||||
for int in output.split('vif')
|
||||
if int.start_with?( '0/0')
|
||||
mac = int.split[8][7..-1]
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception
|
||||
warning 'Could not retrieve correct mac address from vrouter. Probably vrouter is running incorrectly.'
|
||||
end
|
||||
return mac
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,9 +18,6 @@ class contrail::compute::network {
|
||||
$netmask = $contrail::netmask_short
|
||||
$default_gw = undef
|
||||
|
||||
$phys_dev_facter = regsubst($::contrail::phys_dev, '\.' , '_')
|
||||
$dev_mac = getvar("::macaddress_${phys_dev_facter}")
|
||||
|
||||
$br_file = $::operatingsystem ? {
|
||||
'Ubuntu' => '/etc/network/interfaces.d/ifcfg-br-mesh',
|
||||
'CentOS' => '/etc/sysconfig/network-scripts/ifcfg-br-mesh',
|
||||
@@ -31,6 +28,10 @@ class contrail::compute::network {
|
||||
path => '/usr/bin:/bin:/sbin',
|
||||
}
|
||||
|
||||
if $contrail::compute_dpdk_enabled {
|
||||
$dpdk_dev_mac = $::dpdk_mac_address
|
||||
}
|
||||
|
||||
file { $br_file: ensure => absent } ->
|
||||
|
||||
# Remove interface from the bridge
|
||||
@@ -44,15 +45,7 @@ class contrail::compute::network {
|
||||
onlyif => 'ip addr show dev br-mesh | grep -q inet',
|
||||
}
|
||||
|
||||
if $contrail::compute_dpdk_enabled {
|
||||
$dpdk_mac = $::mac_from_vrouter
|
||||
if $dpdk_mac {
|
||||
$dpdk_dev_mac = $dpdk_mac
|
||||
} else {
|
||||
$dpdk_dev_mac = $dev_mac
|
||||
}
|
||||
}
|
||||
|
||||
#ifcfg-vhost0 uses $dpdk_dev_mac
|
||||
case $::operatingsystem {
|
||||
'Ubuntu': {
|
||||
file {'/etc/network/interfaces.d/ifcfg-vhost0':
|
||||
|
||||
@@ -14,27 +14,18 @@
|
||||
|
||||
class contrail::compute::vrouter {
|
||||
|
||||
# facter uses underscore instead of dot as a separator for interface name with vlan
|
||||
$phys_dev_facter = regsubst($::contrail::phys_dev, '\.' , '_')
|
||||
$dev_mac = getvar("::macaddress_${phys_dev_facter}")
|
||||
$raw_phys_dev = $contrail::raw_phys_dev
|
||||
|
||||
if $contrail::compute_dpdk_enabled {
|
||||
$dpdk_mac = $::mac_from_vrouter
|
||||
if $dpdk_mac {
|
||||
$dpdk_dev_mac = $dpdk_mac
|
||||
} else {
|
||||
$dpdk_dev_mac = $dev_mac
|
||||
}
|
||||
|
||||
$raw_phys_dev = regsubst($::contrail::phys_dev, '\..*' , '')
|
||||
# in case of bonds, MAC address should be set permanently, because slave interfaces
|
||||
# may start in random order during the boot process
|
||||
if ( 'bond' in $raw_phys_dev) {
|
||||
file_line { 'permanent_mac':
|
||||
ensure => present,
|
||||
line => "hwaddress ${dpdk_dev_mac}",
|
||||
path => "/etc/network/interfaces.d/ifcfg-${raw_phys_dev}",
|
||||
after => "iface ${raw_phys_dev} inet manual",
|
||||
line => "hwaddress ${::dpdk_mac_address}",
|
||||
path => "/etc/network/interfaces.d/ifcfg-${raw_phys_dev}",
|
||||
after => "iface ${raw_phys_dev} inet manual",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +124,7 @@ class contrail::compute::vrouter {
|
||||
contrail_vrouter_agent_config {
|
||||
'DEFAULT/platform': value => 'dpdk';
|
||||
'DEFAULT/physical_interface_address' : value => $contrail::phys_dev_pci;
|
||||
'DEFAULT/physical_interface_mac': value => $dpdk_dev_mac;
|
||||
'DEFAULT/physical_interface_mac': value => $::dpdk_mac_address;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class contrail::contrail_vmware {
|
||||
$internal_vip = $contrail::mos_mgmt_vip
|
||||
$external_vip = $contrail::mos_public_vip
|
||||
$contrail_internal_vip = $contrail::contrail_private_vip
|
||||
$dev_mac = $contrail::dev_mac
|
||||
$mgmt_self_ip = $::ipaddress_br_mgmt
|
||||
|
||||
# Fetching the esxi data from hash
|
||||
@@ -43,9 +44,6 @@ class contrail::contrail_vmware {
|
||||
#$vmware = pick($esxi_data['ip'], '10.0.0.0')
|
||||
#$vmware_iface_name = pick($esxi_data['contrail_vm']['vmware_iface_name'], 'ens161')
|
||||
|
||||
$phys_dev_facter = regsubst($::contrail::phys_dev, '\.' , '_')
|
||||
$dev_mac = getvar("::macaddress_${phys_dev_facter}")
|
||||
|
||||
l23network::l3::ifconfig { $vmware_iface_name: ipaddr => 'none' }
|
||||
|
||||
$sysctl_settings = {
|
||||
|
||||
@@ -51,6 +51,8 @@ class contrail {
|
||||
$phys_dev = get_private_ifname($interface, $network_scheme)
|
||||
$phys_dev_pci = get_dev_pci_addr($phys_dev, $network_scheme)
|
||||
$phys_dev_mtu = get_physdev_mtu(regsubst($phys_dev, '\..*' , ''))
|
||||
$raw_phys_dev = regsubst($phys_dev, '\..*' , '')
|
||||
$dev_mac = getvar("::macaddress_${raw_phys_dev}")
|
||||
$vrouter_core_mask = pick($settings['vrouter_core_mask'], '0x3')
|
||||
$headless_mode = pick($settings['headless_mode'], true)
|
||||
$multi_tenancy = pick($settings['multi_tenancy'], true)
|
||||
|
||||
Reference in New Issue
Block a user