X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_openvim%2Fovim.py;h=dc21e2d0375f81d73ab786aeca54f86fb5993291;hb=refs%2Fchanges%2F32%2F1932%2F3;hp=c9990497ee241bf294ccd22000a85e6ce04d4509;hpb=e0c28c1feee0fac059bad64eb8601e9c6e47fefc;p=osm%2Fopenvim.git diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index c999049..dc21e2d 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -42,9 +42,9 @@ import openflow_conn __author__ = "Alfonso Tierno, Leonardo Mirabal" __date__ = "$06-Feb-2017 12:07:15$" -__version__ = "0.5.13-r529" -version_date = "May 2017" -database_version = 18 #needed database schema version +__version__ = "0.5.17-r533" +version_date = "Jun 2017" +database_version = 20 #needed database schema version HTTP_Bad_Request = 400 HTTP_Unauthorized = 401 @@ -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: @@ -191,6 +191,40 @@ class ovim(): self.config["db_lock"] = threading.Lock() self.of_test_mode = False if self.config['mode'] == 'normal' or self.config['mode'] == "OF only" else True + + # Create one thread for each host + host_test_mode = True if self.config['mode'] == 'test' or self.config['mode'] == "OF only" else False + host_develop_mode = True if self.config['mode'] == 'development' else False + host_develop_bridge_iface = self.config.get('development_bridge', None) + + # get host list from data base before starting threads + r, hosts = self.db.get_table(SELECT=('name', 'ip_name', 'user', 'uuid', 'password', 'keyfile'), + FROM='hosts', WHERE={'status': 'ok'}) + if r < 0: + raise ovimException("Cannot get hosts from database {}".format(hosts)) + + self.config['host_threads'] = {} + + for host in hosts: + thread = ht.host_thread(name=host['name'], user=host['user'], host=host['ip_name'], db=self.config["db"], + password=host['password'], + keyfile=host.get('keyfile', self.config["host_ssh_keyfile"]), + db_lock=self.config["db_lock"], test=host_test_mode, + image_path=self.config['host_image_path'], + version=self.config['version'], host_id=host['uuid'], + develop_mode=host_develop_mode, + develop_bridge_iface=host_develop_bridge_iface, + logger_name=self.logger_name + ".host." + host['name'], + debug=self.config.get('log_level_host')) + + try: + thread.check_connectivity() + except Exception as e: + self.logger.critical('Error detected for compute = {} with ip = {}' + .format(host['name'], host['ip_name'])) + + self.config['host_threads'][host['uuid']] = thread + # precreate interfaces; [bridge:, VLAN used at Host, uuid of network camping in this bridge, # speed in Gbit/s @@ -238,29 +272,7 @@ class ovim(): thread.start() self.config['dhcp_thread'] = thread - # Create one thread for each host - host_test_mode = True if self.config['mode'] == 'test' or self.config['mode'] == "OF only" else False - host_develop_mode = True if self.config['mode'] == 'development' else False - host_develop_bridge_iface = self.config.get('development_bridge', None) - # get host list from data base before starting threads - r, hosts = self.db.get_table(SELECT=('name', 'ip_name', 'user', 'uuid'), FROM='hosts', WHERE={'status': 'ok'}) - if r < 0: - raise ovimException("Cannot get hosts from database {}".format(hosts)) - - self.config['host_threads'] = {} - for host in hosts: - host['image_path'] = '/opt/VNF/images/openvim' - thread = ht.host_thread(name=host['name'], user=host['user'], host=host['ip_name'], db=self.config["db"], - db_lock=self.config["db_lock"], test=host_test_mode, - image_path=self.config['image_path'], - version=self.config['version'], host_id=host['uuid'], - develop_mode=host_develop_mode, - develop_bridge_iface=host_develop_bridge_iface, - logger_name=self.logger_name + ".host." + host['name'], - debug=self.config.get('log_level_host')) - thread.start() - self.config['host_threads'][host['uuid']] = thread # create ovs dhcp thread result, content = self.db.get_table(FROM='nets') @@ -270,13 +282,20 @@ class ovim(): for net in content: net_type = net['type'] - if (net_type == 'bridge_data' or net_type == 'bridge_man') \ - and net["provider"][:4] == 'OVS:' and net["enable_dhcp"] == "true": + if (net_type == 'bridge_data' or net_type == 'bridge_man') and \ + net["provider"][:4] == 'OVS:' and net["enable_dhcp"] == "true": + try: self.launch_dhcp_server(net['vlan'], net['dhcp_first_ip'], net['dhcp_last_ip'], net['cidr'], net['gateway_ip']) + except Exception as e: + self.logger.error("Fail at launching dhcp server for net_id='%s' net_name='%s': %s", + net["uuid"], net["name"], str(e)) + self.db.update_rows("nets", {"status": "ERROR", + "last_error": "Fail at launching dhcp server: " + str(e)}, + {"uuid": net["uuid"]}) def _start_of_db_tasks(self): """ @@ -378,19 +397,12 @@ class ovim(): module = temp_dict['of_controller'] if module not in ovim.of_module: - for base in ("", "osm_openvim.", "lib_osm_openvim."): - try: - pkg = __import__(base + module) - if base: - of_conn_module = getattr(pkg, module) - else: - of_conn_module = pkg - ovim.of_module[module] = of_conn_module - self.logger.debug("Module load from {}".format(base + module)) - break - except Exception as e: - self.logger.warning("Module {} not found {}".format(base + module, e)) - else: + try: + pkg = __import__("osm_openvim." + module) + of_conn_module = getattr(pkg, module) + ovim.of_module[module] = of_conn_module + self.logger.debug("Module load from {}".format("osm_openvim." + module)) + except Exception as e: self.logger.error("Cannot open openflow controller module of type '%s'", module) raise ovimException("Cannot open openflow controller of type module '{}'" "Revise it is installed".format(module), @@ -439,9 +451,13 @@ class ovim(): if 'dhcp_thread' in self.config: threads['dhcp'] = (self.config['dhcp_thread']) - for thread in threads.values(): + for thread_id, thread in threads.items(): + if thread_id == 'openvim_controller': + continue thread.insert_task("exit") - for thread in threads.values(): + for thread_id, thread in threads.items(): + if thread_id == 'openvim_controller': + continue thread.join() def get_networks(self, columns=None, db_filter={}, limit=None): @@ -571,7 +587,7 @@ class ovim(): bridge_net_name = net_provider[7:] for brnet in self.config['bridge_nets']: if brnet[0] == bridge_net_name: # free - if not brnet[3]: + if brnet[3]: raise ovimException("invalid 'provider:physical', " "bridge '%s' is already used" % bridge_net_name, HTTP_Conflict) bridge_net = brnet @@ -634,7 +650,7 @@ class ovim(): if network["name"] in self.config["dhcp_server"].get("nets", ()): self.config["dhcp_nets"].append(content) self.logger.debug("dhcp_server: add new net", content) - elif not bridge_net and bridge_net[0] in self.config["dhcp_server"].get("bridge_ifaces", ()): + elif bridge_net and bridge_net[0] in self.config["dhcp_server"].get("bridge_ifaces", ()): self.config["dhcp_nets"].append(content) self.logger.debug("dhcp_server: add new net", content, content) return content @@ -754,7 +770,7 @@ class ovim(): self.config["dhcp_nets"].remove(network_id) return content else: - raise ovimException("Error deleting network %s" % network_id, HTTP_Internal_Server_Error) + raise ovimException("Error deleting network '{}': {}".format(network_id, content), -result) def get_openflow_rules(self, network_id=None): """ @@ -843,7 +859,7 @@ class ovim(): else: raise ovimException("Default Openflow controller not not running", HTTP_Not_Found) - if ofc_id in self.config['ofcs_thread']: + elif ofc_id in self.config['ofcs_thread']: conn = self.config['ofcs_thread'][ofc_id].OF_connector else: raise ovimException("Openflow controller not found with ofc_id={}".format(ofc_id), HTTP_Not_Found) @@ -1353,22 +1369,27 @@ class ovim(): bridge_ifaces = [] controller_ip = self.config['ovs_controller_ip'] - ovs_controller_user = self.config['ovs_controller_user'] + ovs_controller_user = self.config.get('ovs_controller_user') host_test_mode = True if self.config['mode'] == 'test' or self.config['mode'] == "OF only" else False host_develop_mode = True if self.config['mode'] == 'development' else False dhcp_host = ht.host_thread(name='openvim_controller', user=ovs_controller_user, host=controller_ip, + password=self.config.get('ovs_controller_password'), + keyfile=self.config.get('ovs_controller_keyfile'), db=self.config["db"], db_lock=self.config["db_lock"], test=host_test_mode, - image_path=self.config['image_path'], version=self.config['version'], + image_path=self.config['host_image_path'], version=self.config['version'], host_id='openvim_controller', develop_mode=host_develop_mode, develop_bridge_iface=bridge_ifaces, logger_name=self.logger_name + ".host.controller", debug=self.config.get('log_level_host')) - dhcp_host.start() + # dhcp_host.start() self.config['host_threads']['openvim_controller'] = dhcp_host - if not host_test_mode: - dhcp_host.ssh_connect() + try: + dhcp_host.check_connectivity() + except Exception as e: + pass + return dhcp_host def launch_dhcp_server(self, vlan, first_ip, last_ip, cidr, gateway): @@ -1389,7 +1410,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__":