From 4d4cb1e1dda0abf9c2b31be4ffee14bb86fcbb99 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Fri, 2 Sep 2016 10:38:36 +0530 Subject: [PATCH] handle case where 'nic_device_id' is not present in address present ip_association.json dbag this happens when IP is to be deleted and its the last ip associated with the interface retrieve original nic_device_id from current ips.json for merge --- systemvm/patches/debian/config/opt/cloud/bin/cs_ip.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs_ip.py b/systemvm/patches/debian/config/opt/cloud/bin/cs_ip.py index efcf311296f..c34fc01d9e3 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs_ip.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs_ip.py @@ -21,15 +21,20 @@ from netaddr import * def merge(dbag, ip): added = False + nic_dev_id = None for dev in dbag: if dev == "id": continue for address in dbag[dev]: if address['public_ip'] == ip['public_ip']: + if 'nic_dev_id' in address: + nic_dev_id = address['nic_dev_id'] dbag[dev].remove(address) ipo = IPNetwork(ip['public_ip'] + '/' + ip['netmask']) - ip['device'] = 'eth' + str(ip['nic_dev_id']) + if 'nic_dev_id' in ip: + nic_dev_id = ip['nic_dev_id'] + ip['device'] = 'eth' + str(nic_dev_id) ip['broadcast'] = str(ipo.broadcast) ip['cidr'] = str(ipo.ip) + '/' + str(ipo.prefixlen) ip['size'] = str(ipo.prefixlen) @@ -37,8 +42,8 @@ def merge(dbag, ip): if 'nw_type' not in ip.keys(): ip['nw_type'] = 'public' if ip['nw_type'] == 'control': - dbag['eth' + str(ip['nic_dev_id'])] = [ip] + dbag['eth' + str(nic_dev_id)] = [ip] else: - dbag.setdefault('eth' + str(ip['nic_dev_id']), []).append(ip) + dbag.setdefault('eth' + str(nic_dev_id), []).append(ip) return dbag