add net config
Change-Id: Ia995b3efaff6179db68c88bb7bac473a7b2fd7d9 Signed-off-by: Yao Lu <lu.yao135@zte.com.cn>
This commit is contained in:
parent
98b0119538
commit
cf3097b214
314
backend/kolla/daisy.py
Executable file
314
backend/kolla/daisy.py
Executable file
@ -0,0 +1,314 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import datetime
|
||||
import time
|
||||
|
||||
json_path = '/home/os_install/os.json'
|
||||
shell_path = '/usr/bin/bash /home/linux_action.sh'
|
||||
update_network_mode = False
|
||||
|
||||
def analyze_json():
|
||||
f = file(json_path)
|
||||
data = json.load(f)
|
||||
f.close()
|
||||
interface_info = data['interfaces']
|
||||
if len(interface_info) == 0:
|
||||
print "%s interface information is Null" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f")
|
||||
sys.exit()
|
||||
else:
|
||||
print "%s interface_info : %s " % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f"), interface_info)
|
||||
return interface_info
|
||||
|
||||
|
||||
def key_vlaue_check(key, dic):
|
||||
if key in dic and dic[key]:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_netmask_num(number):
|
||||
if number == 255:
|
||||
return 8
|
||||
if number == 254:
|
||||
return 7
|
||||
if number == 252:
|
||||
return 6
|
||||
if number == 248:
|
||||
return 5
|
||||
if number == 240:
|
||||
return 4
|
||||
if number == 224:
|
||||
return 3
|
||||
if number == 192:
|
||||
return 2
|
||||
if number == 128:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
def get_ip_net_str(ip, netmask):
|
||||
num = 0
|
||||
for i in netmask.split('.'):
|
||||
num += get_netmask_num(int(i))
|
||||
return ip + '/' + str(num)
|
||||
|
||||
|
||||
def ip_gateway_check(interface, plane):
|
||||
if key_vlaue_check('ip', interface):
|
||||
if key_vlaue_check('gateway', interface):
|
||||
return 'only', interface['ip'], interface['netmask'], interface['gateway']
|
||||
else:
|
||||
return 'only', interface['ip'], interface['netmask'], None
|
||||
else:
|
||||
if key_vlaue_check('ip', plane):
|
||||
if key_vlaue_check('gateway', plane):
|
||||
return 'multi', plane['ip'], plane['netmask'], plane['gateway']
|
||||
else:
|
||||
return 'multi', plane['ip'], plane['netmask'], None
|
||||
return None, None, None, None
|
||||
|
||||
|
||||
def ip_config(operation, interface, management_location):
|
||||
i = 0
|
||||
for plane in interface['assigned_networks']:
|
||||
mark, ip, netmask, gateway = ip_gateway_check(interface, plane)
|
||||
print "%s IP_CONNFIG mark:%s ip:%s netmask:%s gateway:%s" % \
|
||||
(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f"), mark, ip, netmask, gateway)
|
||||
if mark == 'only':
|
||||
if operation == '2':
|
||||
if gateway is not None:
|
||||
os.system(shell_path+" 2 %s %s %s %s %s" %
|
||||
('br-'+interface['name'], 'v_'+interface['name'], ip, netmask, gateway))
|
||||
else:
|
||||
os.system(shell_path+" 2 %s %s %s %s" %
|
||||
('br-'+interface['name'], 'v_'+interface['name'], ip, netmask))
|
||||
elif operation == '4':
|
||||
if gateway is not None:
|
||||
os.system(shell_path+" 4 %s %s %s %s" %
|
||||
(interface['name'], ip, netmask, gateway))
|
||||
else:
|
||||
os.system(shell_path+" 4 %s %s %s" %
|
||||
(interface['name'], ip, netmask))
|
||||
break
|
||||
elif mark == 'multi':
|
||||
if operation == '2':
|
||||
if key_vlaue_check('vlan_id', plane):
|
||||
if gateway is not None:
|
||||
os.system(shell_path+" 7 %s %s %s %s %s %s" %
|
||||
('br-'+interface['name'], plane['network_type'].lower()[0:3] + '_' + interface['name'], plane['vlan_id'], ip, netmask, gateway))
|
||||
else:
|
||||
os.system(shell_path+" 7 %s %s %s %s %s" %
|
||||
('br-'+interface['name'], plane['network_type'].lower()[0:3] + '_' + interface['name'], plane['vlan_id'], ip, netmask))
|
||||
else:
|
||||
if gateway is not None:
|
||||
os.system(shell_path+" 2 %s %s %s %s %s" %
|
||||
('br-'+interface['name'], plane['network_type'].lower()[0:3] + '_' + interface['name'], ip, netmask, gateway))
|
||||
else:
|
||||
os.system(shell_path+" 2 %s %s %s %s" %
|
||||
('br-'+interface['name'], plane['network_type'].lower()[0:3] + '_' + interface['name'], ip, netmask))
|
||||
elif operation == '4':
|
||||
if key_vlaue_check('vlan_id', plane):
|
||||
if gateway is not None:
|
||||
os.system(shell_path+" 8 %s %s %s %s %s %s" %
|
||||
(interface['name'], plane['vlan_id'], get_ip_net_str(ip, netmask), ip, netmask, gateway))
|
||||
elif plane.has_key('old_ip') and plane['ip'] == plane['old_ip'] and plane['network_type'] == 'MANAGEMENT':
|
||||
os.system(shell_path+" 10 %s %s %s" %
|
||||
(interface['name'], plane['old_vlan_id'], plane['vlan_id']))
|
||||
else:
|
||||
os.system(shell_path+" 8 %s %s %s %s %s" %
|
||||
(interface['name'], plane['vlan_id'], get_ip_net_str(ip, netmask), ip, netmask))
|
||||
else:
|
||||
if i == 0 and management_location == -1:
|
||||
if gateway is not None:
|
||||
os.system(shell_path+" 4 %s %s %s %s" %
|
||||
(interface['name'], ip, netmask, gateway))
|
||||
else:
|
||||
os.system(shell_path+" 4 %s %s %s" %
|
||||
(interface['name'], ip, netmask))
|
||||
else:
|
||||
if gateway is not None:
|
||||
os.system(shell_path+" 4 %s %s %s %s" %
|
||||
(interface['name']+':'+str(i), ip, netmask, gateway))
|
||||
else:
|
||||
os.system(shell_path+" 4 %s %s %s" %
|
||||
(interface['name']+':'+str(i), ip, netmask))
|
||||
i += 1
|
||||
|
||||
def update_interface(interface):
|
||||
if key_vlaue_check('ip', interface):
|
||||
os.system(shell_path + " 4 %s %s %s" %
|
||||
(interface['name'], interface['ip'], interface['netmask']))
|
||||
|
||||
without_vlan_plane_list = []
|
||||
i = 0
|
||||
for plane in interface['assigned_networks']:
|
||||
if 'old_vlan_id' not in plane.keys():
|
||||
continue
|
||||
if plane['old_vlan_id'] != plane['vlan_id'] and \
|
||||
plane['network_type'] == 'MANAGEMENT':
|
||||
continue
|
||||
if plane['old_vlan_id'] != plane['vlan_id']:
|
||||
update_interface_with_vlan(plane, interface)
|
||||
elif plane['old_ip'] != plane['ip'] or \
|
||||
plane['old_netmask'] != plane['netmask']:
|
||||
update_interface_without_vlan(plane, interface)
|
||||
without_vlan_plane_list.insert(0, i)
|
||||
i += 1
|
||||
print "without_vlan_plane_list is %s" % without_vlan_plane_list
|
||||
for plane_index in without_vlan_plane_list:
|
||||
del interface['assigned_networks'][plane_index]
|
||||
print interface
|
||||
|
||||
def update_interface_with_vlan(plane, interface):
|
||||
print "old_vlan is %s" % plane['old_vlan_id']
|
||||
if plane['old_vlan_id'] != None:
|
||||
os.system(shell_path + " 9 %s %s" %
|
||||
(interface['name'], plane['old_vlan_id']))
|
||||
|
||||
|
||||
def update_interface_without_vlan(plane, interface):
|
||||
interface_list = os.popen('ls /etc/sysconfig/network-scripts |grep %s'
|
||||
% interface['name']).read().split("\n")
|
||||
print "interface_list is %s" % interface_list
|
||||
for interface_name in interface_list:
|
||||
if not interface_name:
|
||||
continue
|
||||
print interface_name
|
||||
print os.popen('cat /etc/sysconfig/network-scripts/%s |grep %s'
|
||||
% (interface_name, plane['old_ip'])).read()
|
||||
if os.popen('cat /etc/sysconfig/network-scripts/%s |grep %s'
|
||||
% (interface_name, plane['old_ip'])).read():
|
||||
os.system(shell_path + " 4 %s %s %s %s" %
|
||||
(interface_name[6:], plane['ip'], plane['netmask'], plane['gateway']))
|
||||
return
|
||||
|
||||
def multi_plane(interface):
|
||||
private_physnet = 0
|
||||
ovs_physnet = 0
|
||||
management_location = -1
|
||||
location = 0
|
||||
capability = []
|
||||
for plane in interface['assigned_networks']:
|
||||
if plane['network_type'] == 'DATAPLANE':
|
||||
private_physnet += 1
|
||||
#if 'ovs' in plane['ml2_type']:
|
||||
# ovs_physnet += 1
|
||||
if private_physnet > 1:
|
||||
print "%s can not multi private plane overlapping" % \
|
||||
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f")
|
||||
sys.exit()
|
||||
if plane['network_type'] == 'MANAGEMENT':
|
||||
management_location = location
|
||||
if plane['capability']:
|
||||
capability.append(plane['capability'])
|
||||
location += 1
|
||||
print " %s name:%s type:%s private_physnet:%s ovs_physnet:%s management_location:%s capability:%s" % \
|
||||
(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f"),
|
||||
interface['name'],
|
||||
interface['type'],
|
||||
private_physnet,
|
||||
ovs_physnet,
|
||||
management_location,
|
||||
capability)
|
||||
if interface['type'] == 'bond':
|
||||
if management_location != -1:
|
||||
if private_physnet == 0 and len(set(capability)) == 1 and 'high' in capability:
|
||||
del interface['assigned_networks'][management_location]
|
||||
ip_config('4', interface, management_location)
|
||||
#else:
|
||||
# os.system(shell_path+" 5 %s %s %s %s" %
|
||||
# (interface['name'], interface['slave1'], interface['slave2'], interface['mode']))
|
||||
# ip_config('2', interface)
|
||||
else:
|
||||
if private_physnet == 0 and len(set(capability)) == 1 and 'high' in capability:
|
||||
os.system(shell_path+" 3 %s %s %s %s" %
|
||||
(interface['name'], interface['slave1'], interface['slave2'], interface['mode']))
|
||||
ip_config('4', interface, management_location)
|
||||
#else:
|
||||
# os.system(shell_path+" 6 %s %s %s %s" %
|
||||
# (interface['name'], interface['slave1'], interface['slave2'], interface['mode']))
|
||||
# ip_config('2', interface)
|
||||
else:
|
||||
if management_location != -1:
|
||||
if ovs_physnet == 0 and len(set(capability)) < 2 and 'low' not in capability:
|
||||
if not update_network_mode:
|
||||
del interface['assigned_networks'][management_location]
|
||||
ip_config('4', interface, management_location)
|
||||
#else:
|
||||
# os.system(shell_path+" 1 %s" % interface['name'])
|
||||
# ip_config('2', interface)
|
||||
else:
|
||||
if ovs_physnet == 0 and len(set(capability)) < 2 and 'low' not in capability:
|
||||
ip_config('4', interface, management_location)
|
||||
#else:
|
||||
# os.system(shell_path+" 1 %s" % interface['name'])
|
||||
# ip_config('2', interface)
|
||||
|
||||
|
||||
def plane_overlapping_check(interface):
|
||||
plane_num = len(interface['assigned_networks'])
|
||||
if interface.get('vswitch_type', None) == 'dvs':
|
||||
return
|
||||
if plane_num == 0 and not update_network_mode:
|
||||
print "%s %s is not belong to any physnet planes" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f"),
|
||||
interface['name'])
|
||||
#elif plane_num == 1:
|
||||
# single_plane(interface)
|
||||
else:
|
||||
if update_network_mode:
|
||||
update_interface(interface)
|
||||
multi_plane(interface)
|
||||
|
||||
def update_private_networks():
|
||||
f = file(json_path)
|
||||
data = json.load(f)
|
||||
vlan_ranges = ''
|
||||
vxlan_ranges = ''
|
||||
for plane_data in data['private_networks']:
|
||||
if plane_data['segmentation_type'] == 'vlan':
|
||||
vlan_ranges += plane_data['network_name']
|
||||
vlan_ranges += ':'
|
||||
vlan_ranges += plane_data['vlan_start']
|
||||
vlan_ranges += ':'
|
||||
vlan_ranges += plane_data['vlan_end']
|
||||
vlan_ranges += ','
|
||||
elif plane_data['segmentation_type'] == 'vxlan':
|
||||
vxlan_ranges += plane_data['vlan_start']
|
||||
vxlan_ranges += ':'
|
||||
vxlan_ranges += plane_data['vlan_end']
|
||||
vlan_ranges = vlan_ranges[:-1]
|
||||
|
||||
os.system("openstack-config --set /etc/neutron/plugin.ini ml2_type_vlan network_vlan_ranges %s"
|
||||
% vlan_ranges)
|
||||
os.system("openstack-config --set /etc/neutron/plugin.ini ml2_type_vxlan vni_ranges %s"
|
||||
% vxlan_ranges)
|
||||
os.system("systemctl restart neutron-server.service")
|
||||
|
||||
def main(argv):
|
||||
if len(argv) > 1:
|
||||
global json_path
|
||||
global update_network_mode
|
||||
json_path = argv[1]
|
||||
update_network_mode = True
|
||||
|
||||
if json_path == "/home/config_dir/config_update/private_network/private_ctrl.json":
|
||||
update_private_networks()
|
||||
return
|
||||
|
||||
interface_info = analyze_json()
|
||||
for interface in interface_info:
|
||||
print "%s config: %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:%f"), interface)
|
||||
plane_overlapping_check(interface)
|
||||
#if not update_network_mode:
|
||||
# os.system("systemctl restart network.service")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv)
|
||||
|
||||
|
||||
|
270
backend/kolla/linux_action.sh
Executable file
270
backend/kolla/linux_action.sh
Executable file
@ -0,0 +1,270 @@
|
||||
#!/bin/bash
|
||||
|
||||
log_file='/home/os_install/shell_action.log'
|
||||
|
||||
function make_linux_bond
|
||||
{
|
||||
bond_name=$1
|
||||
bond_eth1=$2
|
||||
bond_eth2=$3
|
||||
bond_mode=$4
|
||||
if [ -f "/etc/sysconfig/network-scripts/ifcfg-$bond_name" ];then
|
||||
rm -rf /etc/sysconfig/network-scripts/ifcfg-$bond_name
|
||||
sed '/MASTER/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '/SLAVE/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '/MASTER/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
sed '/SLAVE/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
fi
|
||||
touch /etc/sysconfig/network-scripts/ifcfg-$bond_name
|
||||
echo "DEVICE=$bond_name" >>/etc/sysconfig/network-scripts/ifcfg-$bond_name
|
||||
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-$bond_name
|
||||
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-$bond_name
|
||||
echo "BONDING_OPTS=\"mode=$bond_mode miimon=100\"" >>/etc/sysconfig/network-scripts/ifcfg-$bond_name
|
||||
sed '$a\MASTER='$bond_name'' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '$a\SLAVE=yes' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '/IPADDR/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '/NETMASK/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '/GATEWAY/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '$a\MASTER='$bond_name'' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
sed '$a\SLAVE=yes' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
sed '/IPADDR/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
sed '/NETMASK/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
sed '/GATEWAY/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
if [ -f "/etc/modprobe.d/bonding.conf" ];then
|
||||
touch /etc/modprobe.d/bonding.conf
|
||||
fi
|
||||
echo "alias $bond_name bonding" >>/etc/modprobe.d/bonding.conf
|
||||
echo "options $bond_name miimon=100 mode=$bond_mode" >> /etc/modprobe.d/bonding.conf
|
||||
#modprobe bonding
|
||||
#systemctl restart network
|
||||
}
|
||||
|
||||
function add_ip
|
||||
{
|
||||
eth_name=$1
|
||||
ipaddr=$2
|
||||
netmask=$3
|
||||
gateway=$4
|
||||
if [ -f /etc/sysconfig/network-scripts/ifcfg-$eth_name ];then
|
||||
sed '/IPADDR/d' -i /etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
sed '/NETMASK/d' -i /etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
sed '/GATEWAY/d' -i /etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
else
|
||||
touch /etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
echo "DEVICE=$eth_name" >>/etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
fi
|
||||
echo "IPADDR=$ipaddr" >>/etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
echo "NETMASK=$netmask" >>/etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
if [ "$gateway" ];then
|
||||
echo "GATEWAY=$gateway" >>/etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
fi
|
||||
}
|
||||
|
||||
function vlan_eth_create
|
||||
{
|
||||
eth_name=$1
|
||||
vlan_id=$2
|
||||
ipstr=$3
|
||||
ipaddr=$4
|
||||
netmask=$5
|
||||
gateway=$6
|
||||
vlan_eth_name="$eth_name.$vlan_id"
|
||||
ip link add link $eth_name name $vlan_eth_name type vlan id $vlan_id
|
||||
ifconfig $vlan_eth_name $ipstr
|
||||
if [ -f "/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name" ];then
|
||||
rm -rf /etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
fi
|
||||
touch /etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
echo "DEVICE=$vlan_eth_name" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
echo "IPADDR=$ipaddr" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
echo "NETMASK=$netmask" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
echo "VLAN=yes" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
if [ "$gateway" ];then
|
||||
echo "GATEWAY=$gateway" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
fi
|
||||
}
|
||||
|
||||
function change_mgt_eth_vlan_id
|
||||
{
|
||||
eth_name=$1
|
||||
old_vlan_id=$2
|
||||
vlan_id=$3
|
||||
old_vlan_eth_name="$eth_name.$old_vlan_id"
|
||||
vlan_eth_name="$eth_name.$vlan_id"
|
||||
ip link del $old_vlan_eth_name
|
||||
if [ -f "/etc/sysconfig/network-scripts/ifcfg-$old_vlan_eth_name" ];then
|
||||
mv /etc/sysconfig/network-scripts/ifcfg-$old_vlan_eth_name /etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
fi
|
||||
sed -i '/DEVICE/'d /etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
echo "DEVICE=$vlan_eth_name" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
ip link add link $eth_name name $vlan_eth_name type vlan id $vlan_id
|
||||
service network restart
|
||||
}
|
||||
|
||||
function vlan_eth_delete
|
||||
{
|
||||
eth_name=$1
|
||||
vlan_id=$2
|
||||
vlan_eth_name="$eth_name.$vlan_id"
|
||||
if [ -f "/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name" ];then
|
||||
rm -rf /etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
|
||||
ip link del $vlan_eth_name
|
||||
fi
|
||||
}
|
||||
|
||||
function bond_change
|
||||
{
|
||||
bond_name=$1
|
||||
bond_eth1=$2
|
||||
bond_eth2=$3
|
||||
bond_mode=$4
|
||||
rm -rf /etc/sysconfig/network-scripts/ifcfg-$bond_name
|
||||
sed '/MASTER/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '/SLAVE/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
|
||||
sed '/MASTER/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
sed '/SLAVE/d' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
|
||||
sed '/'$bond_name'/d' -i /etc/modprobe.d/bonding.conf
|
||||
echo -$bond_name >/sys/class/net/bonding_masters
|
||||
#systemctl restart network.service
|
||||
ovs-vsctl add-br br-$bond_name
|
||||
if [ $bond_mode = "0" ];then
|
||||
ovs-vsctl add-bond br-$bond_name $bond_name $bond_eth1 $bond_eth2 -- set port $bond_name bond_mode=active-backup
|
||||
elif [ $bond_mode = "1" ];then
|
||||
ovs-vsctl add-bond br-$bond_name $bond_name $bond_eth1 $bond_eth2 -- set port $bond_name bond_mode=balance-slb lacp=off
|
||||
elif [ $bond_mode = "2" ];then
|
||||
ovs-vsctl add-bond br-$bond_name $bond_name $bond_eth1 $bond_eth2 -- set port $bond_name bond_mode=balance-tcp lacp=active
|
||||
fi
|
||||
ovs-vsctl set interface $bond_eth1 other-config:enable-vlan-splinters=true
|
||||
ovs-vsctl set interface $bond_eth2 other-config:enable-vlan-splinters=true
|
||||
}
|
||||
|
||||
function make_ovs_bond
|
||||
{
|
||||
bond_name=$1
|
||||
bond_eth1=$2
|
||||
bond_eth2=$3
|
||||
bond_mode=$4
|
||||
ovs-vsctl add-br br-$bond_name
|
||||
if [ $bond_mode = "0" ];then
|
||||
ovs-vsctl add-bond br-$bond_name $bond_name $bond_eth1 $bond_eth2 -- set port $bond_name bond_mode=active-backup
|
||||
elif [ $bond_mode = "1" ];then
|
||||
ovs-vsctl add-bond br-$bond_name $bond_name $bond_eth1 $bond_eth2 -- set port $bond_name bond_mode=balance-slb lacp=off
|
||||
elif [ $bond_mode = "2" ];then
|
||||
ovs-vsctl add-bond br-$bond_name $bond_name $bond_eth1 $bond_eth2 -- set port $bond_name bond_mode=balance-tcp lacp=active
|
||||
fi
|
||||
ovs-vsctl set interface $bond_eth1 other-config:enable-vlan-splinters=true
|
||||
ovs-vsctl set interface $bond_eth2 other-config:enable-vlan-splinters=true
|
||||
}
|
||||
|
||||
function single_eth_ovs
|
||||
{
|
||||
eth_name=$1
|
||||
if [ -f /etc/sysconfig/network-scripts/ifcfg-$eth_name ];then
|
||||
sed '/IPADDR/d' -i /etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
sed '/NETMASK/d' -i /etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
sed '/GATEWAY/d' -i /etc/sysconfig/network-scripts/ifcfg-$eth_name
|
||||
fi
|
||||
ovs-vsctl add-br br-$eth_name
|
||||
ovs-vsctl add-port br-$eth_name $eth_name
|
||||
ovs-vsctl set interface $eth_name other-config:enable-vlan-splinters=true
|
||||
}
|
||||
|
||||
function add_ovs_port
|
||||
{
|
||||
bridge=$1
|
||||
name=$2
|
||||
ipaddr=$3
|
||||
netmask=$4
|
||||
gateway=$5
|
||||
ovs-vsctl add-port $bridge $name -- set interface $name type=internal
|
||||
touch /etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "DEVICE=$name" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "DEVICETYPE=ovs" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "TYPE=OVSIntPort" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "OVS_BRIDGE=$bridge" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "IPADDR=$ipaddr" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "NETMASK=$netmask" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
if [ "$gateway" ];then
|
||||
echo "GATEWAY=$gateway" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
fi
|
||||
}
|
||||
|
||||
function ovs_tag_port_create
|
||||
{
|
||||
bridge=$1
|
||||
name=$2
|
||||
tag=$3
|
||||
ipaddr=$4
|
||||
netmask=$5
|
||||
gateway=$6
|
||||
ovs-vsctl add-port $bridge $name tag=$tag -- set interface $name type=internal
|
||||
touch /etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "DEVICE=$name" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "DEVICETYPE=ovs" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "TYPE=OVSIntPort" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "OVS_BRIDGE=$bridge" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "OVS_OPTIONS=\"tag=$tag\"" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "IPADDR=$ipaddr" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
echo "NETMASK=$netmask" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
if [ "$gateway" ];then
|
||||
echo "GATEWAY=$gateway" >>/etc/sysconfig/network-scripts/ifcfg-$name
|
||||
fi
|
||||
}
|
||||
|
||||
function operation
|
||||
{
|
||||
local options=$1
|
||||
case $options in
|
||||
"1")
|
||||
single_eth_ovs $2
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) single_eth_ovs $2" >>$log_file
|
||||
;;
|
||||
"2")
|
||||
add_ovs_port $2 $3 $4 $5 $6
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) add_ovs_port $2 $3 $4 $5 $6" >>$log_file
|
||||
;;
|
||||
"3")
|
||||
make_linux_bond $2 $3 $4 $5
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) make_linux_bond $2 $3 $4 $5" >>$log_file
|
||||
;;
|
||||
"4")
|
||||
add_ip $2 $3 $4 $5
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) add_ip $2 $3 $4 $5" >>$log_file
|
||||
;;
|
||||
"5")
|
||||
bond_change $2 $3 $4 $5
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) bond_change $2 $3 $4" >>$log_file
|
||||
;;
|
||||
"6")
|
||||
make_ovs_bond $2 $3 $4 $5
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) make_ovs_bond $2 $3 $4 $5" >>$log_file
|
||||
;;
|
||||
"7")
|
||||
ovs_tag_port_create $2 $3 $4 $5 $6 $7
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) ovs_tag_port_create $2 $3 $4 $5 $6 $7" >>$log_file
|
||||
;;
|
||||
"8")
|
||||
vlan_eth_create $2 $3 $4 $5 $6 $7
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) vlan_eth_create $2 $3 $4 $5 $6 $7" >>$log_file
|
||||
;;
|
||||
"9")
|
||||
vlan_eth_delete $2 $3
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) vlan_eth_delete $2 $3" >>$log_file
|
||||
;;
|
||||
"10")
|
||||
change_mgt_eth_vlan_id $2 $3 $4
|
||||
echo "$(date +%Y-%m-%d' '%k:%M:%S:%N) change_mgt_eth_vlan_id $2 $3 $4" >>$log_file
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
operation $1 $2 $3 $4 $5 $6 $7
|
@ -29,6 +29,7 @@ from daisy.api.backends.kolla import config
|
||||
import daisy.api.backends.common as daisy_cmn
|
||||
import daisy.api.backends.kolla.common as kolla_cmn
|
||||
import ConfigParser
|
||||
import daisy.api.common as api_cmn
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
_ = i18n._
|
||||
@ -294,6 +295,24 @@ def _calc_progress(log_file):
|
||||
return progress
|
||||
|
||||
|
||||
def _get_hosts_id_by_mgnt_ips(self, ips):
|
||||
params = {'cluster_id': self.cluster_id}
|
||||
hosts = registry.get_hosts_detail(self.req.context, **params)
|
||||
hosts_needed = []
|
||||
for host in hosts:
|
||||
host_info = registry.get_host_metadata(self.req.context,
|
||||
host['id'])
|
||||
for interface in host_info['interfaces']:
|
||||
if interface.get('assigned_networks', None):
|
||||
assigned_networks = interface['assigned_networks']
|
||||
for assigned_network in assigned_networks:
|
||||
if assigned_network['type'] == 'MANAGEMENT' and\
|
||||
assigned_network['ip'] in ips:
|
||||
hosts_needed.append(host)
|
||||
hosts_id_needed = [host_needed['id'] for host_needed in hosts_needed]
|
||||
return hosts_id_needed
|
||||
|
||||
|
||||
class KOLLAInstallTask(Thread):
|
||||
"""
|
||||
Class for kolla install openstack.
|
||||
@ -350,6 +369,17 @@ class KOLLAInstallTask(Thread):
|
||||
self.state = kolla_state['INSTALL_FAILED']
|
||||
self.message = "hosts %s ping failed" % unreached_hosts
|
||||
raise exception.NotFound(message=self.message)
|
||||
root_passwd = 'ossdbg1'
|
||||
for mgnt_ip in self.mgnt_ip_list:
|
||||
check_hosts_id = self._get_hosts_id_by_mgnt_ips(mgnt_ip.split(","))
|
||||
is_ssh_host = daisy_cmn._judge_ssh_host(self.req,
|
||||
check_hosts_id[0])
|
||||
if not is_ssh_host:
|
||||
LOG.info(_("Begin to config network\
|
||||
on %s" % mgnt_ip))
|
||||
ssh_host_info = {'ip': mgnt_ip, 'root_pwd': root_passwd}
|
||||
api_cmn.config_network_new(ssh_host_info, 'kolla')
|
||||
time.sleep(20)
|
||||
generate_kolla_config_file(self.cluster_id, kolla_config)
|
||||
(role_id_list, host_id_list, hosts_list) = \
|
||||
kolla_cmn.get_roles_and_hosts_list(self.req, self.cluster_id)
|
||||
@ -361,10 +391,11 @@ class KOLLAInstallTask(Thread):
|
||||
with open(self.log_file, "w+") as fp:
|
||||
for host in hosts_list:
|
||||
host_ip = host['mgtip']
|
||||
cmd = '/var/lib/daisy/kolla/trustme.sh %s ossdbg1' % host_ip
|
||||
cmd = '/var/lib/daisy/kolla/trustme.sh %s %s' % \
|
||||
(host_ip, root_passwd)
|
||||
daisy_cmn.subprocess_call(cmd, fp)
|
||||
config_nodes_hosts(host_name_ip_list, host_ip)
|
||||
cmd = 'sshpass -p ossdbg1 ssh -o StrictHostKeyChecking=no %s \
|
||||
cmd = 'ssh -o StrictHostKeyChecking=no %s \
|
||||
"if [ ! -d %s ];then mkdir %s;fi" ' % \
|
||||
(host_ip, self.host_prepare_file, self.host_prepare_file)
|
||||
daisy_cmn.subprocess_call(cmd, fp)
|
||||
@ -372,13 +403,13 @@ class KOLLAInstallTask(Thread):
|
||||
/var/lib/daisy/kolla/prepare.sh \
|
||||
root@%s:%s" % (host_ip, self.host_prepare_file)
|
||||
daisy_cmn.subprocess_call(cmd, fp)
|
||||
cmd = 'sshpass -p ossdbg1 ssh -o StrictHostKeyChecking=no %s \
|
||||
cmd = 'ssh -o StrictHostKeyChecking=no %s \
|
||||
chmod u+x %s/prepare.sh' % \
|
||||
(host_ip, self.host_prepare_file)
|
||||
daisy_cmn.subprocess_call(cmd, fp)
|
||||
try:
|
||||
exc_result = subprocess.check_output(
|
||||
'sshpass -p ossdbg1 ssh -o StrictHostKeyChecking='
|
||||
'ssh -o StrictHostKeyChecking='
|
||||
'no %s %s/prepare.sh %s' %
|
||||
(host_ip, self.host_prepare_file, docker_registry_ip),
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
|
@ -241,11 +241,11 @@ def remote_execute_script(ssh_host_info,
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
|
||||
def config_network(ssh_host_info, json_file=None):
|
||||
def config_network_new(ssh_host_info, backend, json_file=None):
|
||||
remote_dir = '/home/'
|
||||
daisy_script_name = 'daisy.py'
|
||||
linux_action_name = 'linux_action.sh'
|
||||
daisy_path = '/var/lib/daisy/'
|
||||
daisy_path = '/var/lib/daisy/%s/' % backend
|
||||
scp_files = [{'file': daisy_path + daisy_script_name,
|
||||
'remote_dir': remote_dir},
|
||||
{'file': daisy_path + linux_action_name,
|
||||
@ -267,3 +267,7 @@ def config_network(ssh_host_info, json_file=None):
|
||||
except Exception:
|
||||
msg = "Wait network restart..."
|
||||
LOG.info(msg)
|
||||
|
||||
|
||||
def config_network(ssh_host_info, json_file=None):
|
||||
config_network_new(ssh_host_info, 'tecs', json_file)
|
||||
|
@ -224,6 +224,8 @@ fi
|
||||
/var/lib/daisy/kolla/trustme.sh
|
||||
/var/lib/daisy/kolla/prepare.sh
|
||||
/var/lib/daisy/kolla/getnodeinfo.sh
|
||||
/var/lib/daisy/kolla/daisy.py
|
||||
/var/lib/daisy/kolla/linux_action.sh
|
||||
/etc/daisy/daisy-api-paste.ini
|
||||
/etc/daisy/daisy-registry-paste.ini
|
||||
%doc README.rst
|
||||
|
Loading…
x
Reference in New Issue
Block a user