Skip to content

Commit

Permalink
Closes-Bug: #1378991 set MTU for control/data interface
Browse files Browse the repository at this point in the history
Change-Id: Ie5068a4d6e59c55f394395a6cc26130bd004e695
  • Loading branch information
miriyalar committed Sep 13, 2016
1 parent 5909991 commit 0fb5394
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/kickstarts/interface_setup.py
Expand Up @@ -55,6 +55,7 @@ def __init__(self, **kwargs):
self.vlan = kwargs.get('vlan', None)
self.dhcp = kwargs.get('dhcp', None)
self.no_restart_network = kwargs.get('no_restart_network', False)
self.mtu = kwargs.get('mtu', None)
self.bond_opts = {'miimon': '100', 'mode': '802.3ad',
'xmit_hash_policy': 'layer3+4'}
try:
Expand Down Expand Up @@ -174,6 +175,8 @@ def create_vlan_interface(self):
}
if self.gw:
cfg['GATEWAY'] = self.gw
if self.mtu:
cfg['MTU'] = self.mtu
self.write_network_script(vlanif, cfg)

def create_bond_members(self):
Expand Down Expand Up @@ -225,6 +228,8 @@ def create_bonding_interface(self):
})
if self.gw:
cfg['GATEWAY'] = self.gw
if self.mtu:
cfg['MTU'] = self.mtu
else:
self.create_vlan_interface()
self.write_network_script(self.device, cfg)
Expand All @@ -238,6 +243,8 @@ def create_interface(self):
'BOOTPROTO' : 'none',
'NM_CONTROLLED' : 'no',
'HWADDR' : mac}
if self.mtu:
cfg['MTU'] = self.mtu
if not self.vlan:
if self.dhcp:
cfg.update({'BOOTPROTO': 'dhcp'})
Expand Down Expand Up @@ -370,16 +377,22 @@ def create_interface(self):
cfg = ['auto %s' %self.device,
'iface %s inet manual' %self.device,
'down ip addr flush dev %s' %self.device]
if self.mtu:
cfg.append('mtu %s' %self.mtu)
elif self.dhcp:
cfg = ['auto %s' %self.device,
'iface %s inet dhcp' %self.device]
if self.mtu:
cfg.append('pre-up /sbin/ip link set %s mtu %s' % (self.device, self.mtu))
else:
cfg = ['auto %s' %self.device,
'iface %s inet static' %self.device,
'address %s' %self.ipaddr,
'netmask %s' %self.netmask]
if self.gw:
cfg.append('gateway %s' %self.gw)
if self.mtu:
cfg.append('mtu %s' %self.mtu)
self.write_network_script(cfg)
if self.vlan:
self.create_vlan_interface()
Expand All @@ -404,6 +417,8 @@ def create_vlan_interface(self):
'vlan-raw-device %s' %self.device]
if self.gw:
cfg.append('gateway %s' %self.gw)
if self.mtu:
cfg.append('mtu %s' %self.mtu)
self.write_network_script(cfg)

def create_bonding_interface(self):
Expand All @@ -429,6 +444,8 @@ def create_bonding_interface(self):
'hwaddress %s' % bond_mac]
if self.gw:
cfg.append('gateway %s' %self.gw)
if self.mtu:
cfg.append('mtu %s' %self.mtu)
cfg += self.bond_opts_str.split("\n")
self.write_network_script(cfg)
if self.vlan:
Expand Down Expand Up @@ -471,6 +488,9 @@ def parse_cli(args):
action='store_true',
default=False,
help='Disable network restart after configuring interfaces')
parser.add_argument('--mtu',
action='store',
help='MTU size of interface')
pargs = parser.parse_args(args)
if len(args) == 0:
parser.print_help()
Expand Down
17 changes: 10 additions & 7 deletions src/server_mgr_main.py
Expand Up @@ -3051,6 +3051,9 @@ def build_server_cfg(self, server):
ip = IPNetwork(ip_addr)
d_gw = intf.get('default_gateway', None)
dhcp = intf.get('dhcp', None)
mtu = intf.get('mtu', '')
if mtu:
mtu = '--mtu %s' %mtu
if name.lower() == mgmt_intf.lower():
dhcp = True
type = intf.get('type', None)
Expand All @@ -3060,20 +3063,20 @@ def build_server_cfg(self, server):
member_intfs = self.get_member_interfaces(network_dict,
intf.get('member_interfaces', []))
device_str+= ("python /root/interface_setup.py \
--device %s --members %s --bond-opts \"%s\" --ip %s\n") % \
--device %s --members %s --bond-opts \"%s\" --ip %s %s\n") % \
(name,
" ".join(member_intfs),
json.dumps(bond_opts), ip_addr)
" ".join(member_intfs),
json.dumps(bond_opts), ip_addr, mtu)
execute_script = True
else:
if 'mac_address' in intf:
name = intf['mac_address'].lower()
if dhcp:
device_str+= ("python /root/interface_setup.py --device %s --dhcp\n") % \
(name)
device_str+= ("python /root/interface_setup.py --device %s --dhcp %s\n") % \
(name, mtu)
else:
device_str+= ("python /root/interface_setup.py --device %s --ip %s\n") % \
(name, ip_addr)
device_str+= ("python /root/interface_setup.py --device %s --ip %s %s\n") % \
(name, ip_addr, mtu)
execute_script = True
# Build route configuration and add it
route_str = self.build_route_cfg(server)
Expand Down

0 comments on commit 0fb5394

Please sign in to comment.