Skip to content

Commit

Permalink
Bug#1421564 On Ubuntu14.04 provision of multi-interface fails as inte…
Browse files Browse the repository at this point in the history
…rface name is renamed after reimage

Multi interface creation on the target system are based on the names,
and various falvors of ubuntu is having different names.
Then json files are not usable and user needs to keep changing it, which is not ideal situation.
With this fix, interface can be created based on mac-address identifer or interface name.

Change-Id: I880384092d9ffe3f7df8f95e229b11b2994ac3ae
  • Loading branch information
miriyalar committed Feb 13, 2015
1 parent 9839780 commit 7e3ef24
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
29 changes: 27 additions & 2 deletions src/kickstarts/interface_setup.py
Expand Up @@ -63,6 +63,31 @@ def __init__(self, **kwargs):
self.bond_opts_str = ''
self.mac_list = {}
self.tempfile = NamedTemporaryFile(delete=False)
self.intf_mac_mapping = self.gen_intf_mac_mapping()
self.populate_device()

def gen_intf_mac_mapping(self):
sys_dir = '/sys/class/net/'
mac_map = {}
for device in os.listdir(sys_dir):
mac = os.popen('cat %s/%s/address'%(sys_dir, device)).read()
mac_map[mac.strip()] = device
return mac_map

def populate_device(self):
if self.is_valid_mac(self.device):
log.info("mac address is %s", self.device)
self.device = self.intf_mac_mapping.get(self.device, '')
if not self.device:
log.warn("mac address is not present in the system")
return
members = []
for i in xrange(len(self.members)):
if self.is_valid_mac(self.members[i]):
log.info("mac address is %s", self.members[i])
self.members[i] = self.intf_mac_mapping.get(self.members[i], '')
if not self.members[i]:
log.warn("mac address is not present in the system")

def validate_bond_opts(self):
for key in list(self.bond_opts):
Expand Down Expand Up @@ -401,12 +426,12 @@ def parse_cli(args):
parser.add_argument('--device',
action='store',
required=True,
help='Interface Name')
help='Interface Name or Mac address')
parser.add_argument('--members',
action='store',
default=[],
nargs='+',
help='Name of Member interfaces')
help='Name of Member interfaces or Mac addresses')
parser.add_argument('--ip',
action='store',
required=True,
Expand Down
31 changes: 26 additions & 5 deletions src/server_mgr_main.py
Expand Up @@ -2481,6 +2481,22 @@ def reimage_server(self):
return reimage_status
# end reimage_server

def get_member_interfaces(self, network_dict, member_intfs):
new_member_list = []
if not member_intfs:
return new_member_list
interface_list = network_dict["interfaces"]
for intf in interface_list:
name = intf.get('name', '')
if name and name in member_intfs:
mac_address = intf.get('mac_address', '')
if mac_address:
new_member_list.append(mac_address)
else:
new_member_list.append(name)
return new_member_list

# end get_member_interfaces

def build_server_cfg(self, server):
#Fetch network realted data and push to reimage
Expand All @@ -2494,22 +2510,27 @@ def build_server_cfg(self, server):
device_str = "#!/bin/bash\n"
for intf in interface_list:
i += 1
name = intf['name']
if 'mac_address' in intf:
name = intf['mac_address']
else:
name = intf['name']
ip_addr = intf.get('ip_address', None)
if ip_addr is None:
continue
if name.lower() == mgmt_intf.lower():
if intf['name'].lower() == mgmt_intf.lower():
continue

ip = IPNetwork(ip_addr)
d_gw = intf.get('default_gateway', None)
dhcp = intf.get('dhcp', None)
type = intf.get('type', None)
bond_opts = intf.get('bond_options', None)
mem_intfs = intf.get('member_interfaces', None)

#form string
if type and type.lower() == 'bond':
bond_opts = intf.get('bond_options', {})
member_intfs = intf.get('member_interfaces', [])
if member_intfs:
mem_intfs = self.get_member_interfaces(network_dict,
member_intfs)
device_str+= ("python interface_setup.py \
--device %s --members %s --bond-opts \"%s\" --ip %s\n") % \
(name,
Expand Down

0 comments on commit 7e3ef24

Please sign in to comment.