From 72fcda7e20f984e0d6fd57322e13c9013f74cebd Mon Sep 17 00:00:00 2001 From: mirabal Date: Tue, 9 May 2017 11:01:06 +0200 Subject: [PATCH] Fix minor bugs in dhcp service during vm deployment Change-Id: Iaa0fdc083836242c8b713b09d4875fd05450061a Signed-off-by: mirabal --- openflow | 6 ++--- osm_openvim/host_thread.py | 52 +++++++++++++++++++------------------- osm_openvim/ovim.py | 6 ++--- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/openflow b/openflow index 07261df..316ac0f 100755 --- a/openflow +++ b/openflow @@ -375,10 +375,10 @@ if __name__=="__main__": module = of_controller_module else: module = of_controller_type - module_info = imp.find_module(module) - - of_conn = imp.load_module("of_conn", *module_info) + try: + pkg = __import__("osm_openvim." + module) + of_conn = getattr(pkg, module) ofconnector = of_conn.OF_conn(params) except Exception as e: print "Cannot open the Openflow controller '%s': %s" % (type(e).__name__, str(e)) diff --git a/osm_openvim/host_thread.py b/osm_openvim/host_thread.py index 0cf2691..1f8fdb4 100644 --- a/osm_openvim/host_thread.py +++ b/osm_openvim/host_thread.py @@ -628,7 +628,7 @@ class host_thread(threading.Thread): elif content[0]['provider'][0:3] == "OVS": vlan = content[0]['provider'].replace('OVS:', '') text += self.tab() + "" + \ - self.inc_tab() + "" + self.inc_tab() + "" else: return -1, 'Unknown Bridge net provider ' + content[0]['provider'] if model!=None: @@ -751,7 +751,7 @@ class host_thread(threading.Thread): if self.test: return True try: - port_name = 'ovim-' + vlan + port_name = 'ovim-' + str(vlan) command = 'sudo ovs-vsctl del-port br-int ' + port_name self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) @@ -779,7 +779,7 @@ class host_thread(threading.Thread): if not self.is_dhcp_port_free(vlan, net_uuid): return True try: - net_namespace = 'ovim-' + vlan + net_namespace = 'ovim-' + str(vlan) dhcp_path = os.path.join(dhcp_path, net_namespace) pid_file = os.path.join(dhcp_path, 'dnsmasq.pid') @@ -852,8 +852,8 @@ class host_thread(threading.Thread): if self.test: return True try: - port_name = 'ovim-' + vlan - command = 'sudo ovs-vsctl add-port br-int ' + port_name + ' tag=' + vlan + port_name = 'ovim-' + str(vlan) + command = 'sudo ovs-vsctl add-port br-int ' + port_name + ' tag=' + str(vlan) self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() @@ -909,8 +909,8 @@ class host_thread(threading.Thread): if self.test: return True try: - port_name = 'ovim-' + vlan - command = 'sudo ip link set dev veth0-' + vlan + ' down' + port_name = 'ovim-' + str(vlan) + command = 'sudo ip link set dev veth0-' + str(vlan) + ' down' self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) # content = stdout.read() @@ -952,7 +952,7 @@ class host_thread(threading.Thread): if self.test: return True try: - port_name = 'ovim-' + vlan + port_name = 'ovim-' + str(vlan) command = 'sudo brctl show | grep ' + port_name self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) @@ -1010,7 +1010,7 @@ class host_thread(threading.Thread): if self.test: return True - net_namespace = 'ovim-' + vlan + net_namespace = 'ovim-' + str(vlan) dhcp_path = os.path.join(dhcp_path, net_namespace) dhcp_hostsdir = os.path.join(dhcp_path, net_namespace) @@ -1054,7 +1054,7 @@ class host_thread(threading.Thread): if self.test: return False try: - net_namespace = 'ovim-' + vlan + net_namespace = 'ovim-' + str(vlan) dhcp_path = os.path.join(dhcp_path, net_namespace) dhcp_hostsdir = os.path.join(dhcp_path, net_namespace) @@ -1094,8 +1094,8 @@ class host_thread(threading.Thread): if self.test: return True try: - interface = 'tap-' + vlan - net_namespace = 'ovim-' + vlan + interface = 'tap-' + str(vlan) + net_namespace = 'ovim-' + str(vlan) dhcp_path = os.path.join(dhcp_path, net_namespace) leases_path = os.path.join(dhcp_path, "dnsmasq.leases") pid_file = os.path.join(dhcp_path, 'dnsmasq.pid') @@ -1149,18 +1149,18 @@ class host_thread(threading.Thread): if self.test: return True try: - net_namespace = 'ovim-' + vlan - command = 'sudo ovs-vsctl del-port br-int ovs-tap-' + vlan + net_namespace = 'ovim-' + str(vlan) + command = 'sudo ovs-vsctl del-port br-int ovs-tap-' + str(vlan) self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() - command = 'sudo ip netns exec ' + net_namespace + ' ip link set dev tap-' + vlan + ' down' + command = 'sudo ip netns exec ' + net_namespace + ' ip link set dev tap-' + str(vlan) + ' down' self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() - command = 'sudo ip link set dev ovs-tap-' + vlan + ' down' + command = 'sudo ip link set dev ovs-tap-' + str(vlan) + ' down' self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() @@ -1170,11 +1170,11 @@ class host_thread(threading.Thread): self.ssh_connect() return False - def create_dhcp_interfaces(self, vlan, ip, netmask): + def create_dhcp_interfaces(self, vlan, ip_listen_address, netmask): """ Create a linux bridge with STP active :param vlan: segmentation id - :param ip: Ip included in the dhcp range for the tap interface living in namesapce side + :param ip_listen_address: Listen Ip address for the dhcp service, the tap interface living in namesapce side :param netmask: dhcp net CIDR :return: True if success """ @@ -1182,41 +1182,41 @@ class host_thread(threading.Thread): if self.test: return True try: - net_namespace = 'ovim-' + vlan - namespace_interface = 'tap-' + vlan + net_namespace = 'ovim-' + str(vlan) + namespace_interface = 'tap-' + str(vlan) command = 'sudo ip netns add ' + net_namespace self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() - command = 'sudo ip link add tap-' + vlan + ' type veth peer name ovs-tap-' + vlan + command = 'sudo ip link add tap-' + str(vlan) + ' type veth peer name ovs-tap-' + str(vlan) self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() - command = 'sudo ovs-vsctl add-port br-int ovs-tap-' + vlan + ' tag=' + vlan + command = 'sudo ovs-vsctl add-port br-int ovs-tap-' + str(vlan) + ' tag=' + str(vlan) self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() - command = 'sudo ip link set tap-' + vlan + ' netns ' + net_namespace + command = 'sudo ip link set tap-' + str(vlan) + ' netns ' + net_namespace self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() - command = 'sudo ip netns exec ' + net_namespace + ' ip link set dev tap-' + vlan + ' up' + command = 'sudo ip netns exec ' + net_namespace + ' ip link set dev tap-' + str(vlan) + ' up' self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() - command = 'sudo ip link set dev ovs-tap-' + vlan + ' up' + command = 'sudo ip link set dev ovs-tap-' + str(vlan) + ' 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 + ' netmask ' + netmask + + ' ' + ip_listen_address + ' netmask ' + netmask self.logger.debug("command: " + command) (_, stdout, _) = self.ssh_conn.exec_command(command) content = stdout.read() diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index fb34552..b0fa78f 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -142,11 +142,11 @@ class ovim(): ips = IPNetwork(cidr) if "dhcp_first_ip" not in network: - network["dhcp_first_ip"] = str(ips[2]) + network["dhcp_first_ip"] = str(ips[3]) if "dhcp_last_ip" not in network: network["dhcp_last_ip"] = str(ips[-2]) if "gateway_ip" not in network: - network["gateway_ip"] = str(ips[1]) + network["gateway_ip"] = str(ips[2]) return True else: @@ -1382,7 +1382,7 @@ class ovim(): controller_host = self.get_dhcp_controller() controller_host.create_linux_bridge(vlan) - controller_host.create_dhcp_interfaces(vlan, first_ip, dhcp_netmask) + controller_host.create_dhcp_interfaces(vlan, gateway, dhcp_netmask) controller_host.launch_dhcp_server(vlan, ip_range, dhcp_netmask, dhcp_path, gateway) if __name__ == "__main__": -- 2.25.1