From 46ca3a99010165035dc55e41887f86d55c6dff6f Mon Sep 17 00:00:00 2001 From: tierno Date: Wed, 5 Apr 2017 19:49:24 +0200 Subject: [PATCH] Allow several pci for of_port_mapping. Log enhancement Change-Id: Ifbf474da57abf269fd87cb237a05e427d4981d43 Signed-off-by: tierno --- database_utils/migrate_vim_db.sh | 26 ++++++++++++++++++++++++++ ovim.py | 21 +++++++++++++-------- vim_db.py | 11 ++++++++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/database_utils/migrate_vim_db.sh b/database_utils/migrate_vim_db.sh index 6a08a44..599938d 100755 --- a/database_utils/migrate_vim_db.sh +++ b/database_utils/migrate_vim_db.sh @@ -184,6 +184,7 @@ DATABASE_TARGET_VER_NUM=0 [ $OPENVIM_VER_NUM -ge 5007 ] && DATABASE_TARGET_VER_NUM=14 #0.5.7 => 14 [ $OPENVIM_VER_NUM -ge 5008 ] && DATABASE_TARGET_VER_NUM=15 #0.5.8 => 15 [ $OPENVIM_VER_NUM -ge 5009 ] && DATABASE_TARGET_VER_NUM=16 #0.5.9 => 16 +[ $OPENVIM_VER_NUM -ge 5010 ] && DATABASE_TARGET_VER_NUM=17 #0.5.10 => 17 #TODO ... put next versions here function upgrade_to_1(){ @@ -620,6 +621,31 @@ function downgrade_from_16(){ echo "ALTER TABLE ofcs DROP COLUMN last_error, DROP COLUMN status; " | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 echo "DELETE FROM schema_version WHERE version_int = '16';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 } + +function upgrade_to_17(){ + echo " upgrade database from version 0.16 to version 0.17" + echo " Add pci to the unique indexes switch_dpid_switch_port switch_dpid_switch_mac at of_port_mappings" + echo "ALTER TABLE of_port_mappings DROP INDEX switch_dpid_switch_port, "\ + "ADD UNIQUE INDEX switch_dpid_switch_port (switch_dpid, switch_port, pci);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE of_port_mappings DROP INDEX switch_dpid_switch_mac, "\ + "ADD UNIQUE INDEX switch_dpid_switch_mac (switch_dpid, switch_mac, pci);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo " Add nets_with_same_vlan to table ofcs" + echo "ALTER TABLE ofcs ADD COLUMN nets_with_same_vlan ENUM('true','false') NOT NULL DEFAULT 'false' AFTER status;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "INSERT INTO schema_version (version_int, version, openvim_ver, comments, date) VALUES (17, '0.17', '0.5.10', 'Add pci to unique index dpid port/mac at of_port_mappings', '2017-04-05');"| $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} + +function downgrade_from_17(){ + echo " downgrade database from version 0.17 to version 0.16" + echo " Delete pci fromthe unique indexes switch_dpid_switch_port switch_dpid_switch_mac at of_port_mappings" + echo "ALTER TABLE of_port_mappings DROP INDEX switch_dpid_switch_port, "\ + "ADD UNIQUE INDEX switch_dpid_switch_port (switch_dpid, switch_port);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "ALTER TABLE of_port_mappings DROP INDEX switch_dpid_switch_mac, "\ + "ADD UNIQUE INDEX switch_dpid_switch_mac (switch_dpid, switch_mac);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo " Remove nets_with_same_vlan from table ofcs" + echo "ALTER TABLE ofcs DROP COLUMN nets_with_same_vlan;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "DELETE FROM schema_version WHERE version_int = '17';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} + #TODO ... put funtions here echo "db version = "${DATABASE_VER_NUM} diff --git a/ovim.py b/ovim.py index bf1f311..efdb58b 100755 --- a/ovim.py +++ b/ovim.py @@ -29,9 +29,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 +__version__ = "0.5.10-r526" +version_date = "Apr 2017" +database_version = "0.17" #expected database schema version import threading import vim_db @@ -95,16 +95,17 @@ class ovim(): def __init__(self, configuration): self.config = configuration - self.logger = logging.getLogger(configuration["logger_name"]) + self.logger_name = configuration.get("logger_name", "openvim") + self.logger = logging.getLogger(self.logger_name) self.db = None - self.db = self._create_database_connection() + self.db = self._create_database_connection() self.db_lock = None self.db_of = None self.of_test_mode = False def _create_database_connection(self): db = vim_db.vim_db((self.config["network_vlan_range_start"], self.config["network_vlan_range_end"]), - self.config['log_level_db']); + self.logger_name + ".db", self.config.get('log_level_db')) if db.connect(self.config['db_host'], self.config['db_user'], self.config['db_passwd'], self.config['db_name']) == -1: # self.logger.error("Cannot connect to database %s at %s@%s", self.config['db_name'], self.config['db_user'], @@ -176,7 +177,8 @@ class ovim(): 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], database_version) ) - + self.logger.critical("Starting ovim server version: '{} {}' database version '{}'".format( + self.get_version(), self.get_version_date(), self.get_database_version())) # create database connection for openflow threads self.db_of = self._create_database_connection() self.config["db"] = self.db_of @@ -1369,9 +1371,12 @@ class ovim(): if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("-v","--version", help="increase output verbosity", action="store_true") + parser.add_argument("-v","--version", help="show ovim library version", action="store_true") + parser.add_argument("--database-version", help="show required database version", action="store_true") args = parser.parse_args() if args.version: print ('openvimd version {} {}'.format(ovim.get_version(), ovim.get_version_date())) print ('(c) Copyright Telefonica') + elif args.database_version: + print ('required database version: {}'.format(ovim.get_database_version())) diff --git a/vim_db.py b/vim_db.py index ce19cf6..c34160d 100644 --- a/vim_db.py +++ b/vim_db.py @@ -50,7 +50,7 @@ HTTP_Internal_Server_Error = 500 class vim_db(): - def __init__(self, vlan_range, debug="ERROR"): + def __init__(self, vlan_range, logger_name= None, debug=None): '''vlan_range must be a tuple (vlan_ini, vlan_end) with available vlan values for networks every dataplane network contain a unique value, regardless of it is used or not ''' @@ -59,8 +59,13 @@ class vim_db(): self.net_vlan_usedlist = None self.net_vlan_lastused = self.net_vlan_range[0] -1 self.debug=debug - self.logger = logging.getLogger('vim.db') - self.logger.setLevel( getattr(logging, debug) ) + if logger_name: + self.logger_name = logger_name + else: + self.logger_name = 'openvim.db' + self.logger = logging.getLogger(self.logger_name) + if debug: + self.logger.setLevel( getattr(logging, debug) ) def connect(self, host=None, user=None, passwd=None, database=None): -- 2.25.1