X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=ovim.py;h=f896adc6a725e5e778fc5d86991cd47211cb05ee;hb=2db743baaa4e14e758fbdfdb7a2db0f8d0e91853;hp=16b3f03e1b0a0dfe20afb97a93a6e387f4c5fdbc;hpb=7bbf50e0ee85e14bca8db01694fbfb3322619ee7;p=osm%2Fopenvim.git diff --git a/ovim.py b/ovim.py index 16b3f03..f896adc 100644 --- a/ovim.py +++ b/ovim.py @@ -28,6 +28,9 @@ Two thread will be launched, with normal and administrative permissions. __author__ = "Alfonso Tierno, Leonardo Mirabal" __date__ = "$06-Feb-2017 12:07:15$" +__version__ = "0.5.8-r524" +version_date = "March 2017" +database_version = "0.15" #expected database schema version import threading import vim_db @@ -109,6 +112,18 @@ class ovim(): self.config['db_host']) ) return db + @staticmethod + def get_version(): + return __version__ + + @staticmethod + def get_version_date(): + return version_date + + @staticmethod + def get_database_version(): + return database_version + @staticmethod def _check_dhcp_data_integrity(network): """ @@ -149,15 +164,16 @@ class ovim(): Start ovim services :return: """ + global database_version # if self.running_info: # return #TODO service can be checked and rebuild broken threads r = self.db.get_db_version() if r[0] < 0: raise ovimException("DATABASE is not a VIM one or it is a '0.0' version. Try to upgrade to version '{}' with "\ - "'./database_utils/migrate_vim_db.sh'".format(self.config["database_version"]) ) - elif r[1] != self.config["database_version"]: + "'./database_utils/migrate_vim_db.sh'".format(database_version) ) + elif r[1] != database_version: raise ovimException("DATABASE wrong version '{}'. Try to upgrade/downgrade to version '{}' with "\ - "'./database_utils/migrate_vim_db.sh'".format(r[1], self.config["database_version"]) ) + "'./database_utils/migrate_vim_db.sh'".format(r[1], database_version) ) # create database connection for openflow threads self.db_of = self._create_database_connection() @@ -316,7 +332,7 @@ class ovim(): def _load_of_module(self, db_config): """ import python module for each SDN controller supported - :param default: SDN dn information + :param db_config: SDN dn information :return: Module """ if not db_config: @@ -326,8 +342,8 @@ class ovim(): try: if self.of_test_mode: - return oft.of_test_connector({"name": db_config['type'], "dpid": db_config['dpid'], - "of_debug": self.config['log_level_of']}) + return oft.of_test_connector({"name": db_config['type'], "dpid": db_config['dpid'], + "of_debug": self.config['log_level_of']}) temp_dict = {} if db_config: @@ -719,9 +735,8 @@ class ovim(): where_ = {} else: where_ = {"net_id": network_id} - result, content = self.db.get_table( - SELECT=("name", "net_id", "priority", "vlan_id", "ingress_port", "src_mac", "dst_mac", "actions"), + SELECT=("name", "net_id", "ofc_id", "priority", "vlan_id", "ingress_port", "src_mac", "dst_mac", "actions"), WHERE=where_, FROM='of_flows') if result < 0: @@ -763,24 +778,44 @@ class ovim(): return result - def delete_openflow_rules(self): + def delete_openflow_rules(self, ofc_id=None): """ To make actions over the net. The action is to delete ALL openflow rules :return: return operation result """ - # ignore input data - r, c = self.config['of_thread'].insert_task("clear-all") - if r < 0: - raise ovimException(str(c), -r) + + if not ofc_id: + if 'Default' in self.config['ofcs_thread']: + r, c = self.config['ofcs_thread']['Default'].insert_task("clear-all") + else: + raise ovimException("Default Openflow controller not not running", HTTP_Not_Found) + + elif ofc_id in self.config['ofcs_thread']: + r, c = self.config['ofcs_thread'][ofc_id].insert_task("clear-all") + + # ignore input data + if r < 0: + raise ovimException(str(c), -r) + else: + raise ovimException("Openflow controller not found with ofc_id={}".format(ofc_id), HTTP_Not_Found) return r - def get_openflow_ports(self): + def get_openflow_ports(self, ofc_id=None): """ Obtain switch ports names of openflow controller :return: Return flow ports in DB """ - data = {'ports': self.config['of_thread'].OF_connector.pp2ofi} - return data + if not ofc_id: + if 'Default' in self.config['ofcs_thread']: + conn = self.config['ofcs_thread']['Default'].OF_connector + else: + raise ovimException("Default Openflow controller not not running", HTTP_Not_Found) + + if 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) + return conn.pp2ofi def get_ports(self, columns=None, filter={}, limit=None): # result, content = my.db.get_ports(where_) @@ -853,8 +888,7 @@ class ovim(): port_mapping_data = self.get_of_port_mappings(columns, db_filter) if not len(port_mapping_data): - raise ovimException("No port mapping founded for region='{}', compute id='{}' and pci='{}'". - format(db_filter['region'], db_filter['compute_node'], db_filter['pci']), + raise ovimException("No port mapping founded for '{}'".format(str(db_filter)), HTTP_Not_Found) elif len(port_mapping_data) > 1: raise ovimException("Wrong port data was given, please check pci, region & compute id data", @@ -921,7 +955,7 @@ class ovim(): r, c = ofc_t[switch_dpid].insert_task("update-net", net_id) if r < 0: - message = "Cannot insert a task for updating network '$s', %s", net_id, c + message = "Cannot insert a task for updating network '{}', {}".format(net_id, c) self.logger.error(message) raise ovimException(message, HTTP_Internal_Server_Error)