OLD | NEW |
(Empty) | |
| 1 import os, re, commands, sys |
| 2 """This script is used to setup bonding, macaddr of bond0 should be assigned by |
| 3 argv1""" |
| 4 |
| 5 if len(sys.argv) != 2: |
| 6 sys.exit(1) |
| 7 mac = sys.argv[1] |
| 8 eth_nums = 0 |
| 9 ifconfig_output = commands.getoutput("ifconfig") |
| 10 re_eth = "eth[0-9]*" |
| 11 for ename in re.findall(re_eth, ifconfig_output): |
| 12 eth_config_file = "/etc/sysconfig/network-scripts/ifcfg-%s" % ename |
| 13 eth_config = """DEVICE=%s |
| 14 USERCTL=no |
| 15 ONBOOT=yes |
| 16 MASTER=bond0 |
| 17 SLAVE=yes |
| 18 BOOTPROTO=none |
| 19 """ % ename |
| 20 f = file(eth_config_file,'w') |
| 21 f.write(eth_config) |
| 22 f.close() |
| 23 |
| 24 bonding_config_file = "/etc/sysconfig/network-scripts/ifcfg-bond0" |
| 25 bond_config = """DEVICE=bond0 |
| 26 BOOTPROTO=dhcp |
| 27 NETWORKING_IPV6=no |
| 28 ONBOOT=yes |
| 29 USERCTL=no |
| 30 MACADDR=%s |
| 31 """ % mac |
| 32 f = file(bonding_config_file, "w") |
| 33 f.write(bond_config) |
| 34 f.close() |
| 35 os.system("modprobe bonding") |
| 36 os.system("service NetworkManager stop") |
| 37 os.system("service network restart") |
OLD | NEW |