mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
f724cb6c1a
commit
4d4cb1e1dd
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue