[ $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(){
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}
__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
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'],
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
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()))
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
'''
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):