From e3cf1f716be59fe0f3271a44589c1f31b10567ec Mon Sep 17 00:00:00 2001 From: mirabal Date: Thu, 25 May 2017 14:51:15 +0200 Subject: [PATCH] fix minor bugs related with dhcp - get_free_ip_from_range() was calculating wrong the free ip for if first and last ip is given and the range is lower than the CIDR - Namespace loopback up must be forced. - is_dhcp_port_free() mysql query fix Change-Id: I1bbf9ed2c23945accc16c75d4e75da4b62ce745c Signed-off-by: mirabal --- osm_openvim/host_thread.py | 7 ++++++- osm_openvim/vim_db.py | 12 ++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/osm_openvim/host_thread.py b/osm_openvim/host_thread.py index 80d9986..bf7a6da 100644 --- a/osm_openvim/host_thread.py +++ b/osm_openvim/host_thread.py @@ -813,7 +813,7 @@ class host_thread(threading.Thread): self.db_lock.acquire() result, content = self.db.get_table( FROM='ports', - WHERE={'p.type': 'instance:ovs', 'p.net_id': net_uuid} + WHERE={'type': 'instance:ovs', 'net_id': net_uuid} ) self.db_lock.release() @@ -1215,6 +1215,11 @@ class host_thread(threading.Thread): (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() + command = 'sudo ip netns exec ' + net_namespace + ' ip link set dev lo up' + self.logger.debug("command: " + command) + (_, stdout, _) = self.ssh_conn.exec_command(command) + content = stdout.read() + command = 'sudo ip netns exec ' + net_namespace + ' ' + ' ifconfig ' + namespace_interface \ + ' ' + ip_listen_address + ' netmask ' + netmask self.logger.debug("command: " + command) diff --git a/osm_openvim/vim_db.py b/osm_openvim/vim_db.py index b034342..5d7fb16 100644 --- a/osm_openvim/vim_db.py +++ b/osm_openvim/vim_db.py @@ -37,7 +37,7 @@ import uuid as myUuid import auxiliary_functions as af import json import logging -from netaddr import IPNetwork, IPSet, IPRange, all_matching_cidrs +from netaddr import IPNetwork, IPAddress HTTP_Bad_Request = 400 HTTP_Unauthorized = 401 @@ -1538,15 +1538,15 @@ class vim_db(): :param ip_used_list: contain all used ips to avoid ip collisions :return: """ - ip_tools = IPNetwork(cidr) cidr_len = ip_tools.prefixlen ips = IPNetwork(first_ip + '/' + str(cidr_len)) - ip_used_list.append(str(ips[0])) # first ip - ip_used_list.append(str(ips[1])) # gw ip - ip_used_list.append(str(ips[-1])) # broadcast ip + + ip_used_list.append(str(ips[1])) # gw ip + ip_used_list.append(str(ips[-1])) # broadcast ip + for vm_ip in ips: - if str(vm_ip) not in ip_used_list: + if str(vm_ip) not in ip_used_list and IPAddress(first_ip) <= IPAddress(vm_ip) <= IPAddress(last_ip): return vm_ip return None -- 2.17.1