__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
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):
"""
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()
temp_dict['of_port'] = db_config['port']
temp_dict['of_dpid'] = db_config['dpid']
temp_dict['of_controller'] = db_config['type']
+ temp_dict['of_user'] = db_config['user']
+ temp_dict['of_password'] = db_config['password']
temp_dict['of_debug'] = self.config['log_level_of']
if result > 0:
try:
- self.net_update_ofc_thread(network_id)
+ if nbports:
+ self.net_update_ofc_thread(network_id)
except ovimException as e:
raise ovimException("Error while launching openflow rules in network '{}' {}"
.format(network_id, str(e)), HTTP_Internal_Server_Error)
port_data['switch_mac'] = port_mapping_data[0]['switch_mac']
# remove from compute_node, region and pci of_port_data to adapt to 'ports' structure
- del port_data['compute_node']
- del port_data['region']
- del port_data['pci']
+ if 'region' in port_data:
+ del port_data['region']
+ if 'pci' in port_data:
+ del port_data['pci']
+ if 'compute_node' in port_data:
+ del port_data['compute_node']
result, uuid = self.db.new_row('ports', port_data, True, True)
if result > 0:
else:
raise ovimException(str(uuid), -result)
- def net_update_ofc_thread(self, net_id, ofc_id=None):
+ def net_update_ofc_thread(self, net_id, ofc_id=None, switch_dpid=None):
"""
Insert a update net task by net id or ofc_id for each ofc thread
:param net_id: network id
:param ofc_id: openflow controller id
+ :param switch_dpid: switch dpid
:return:
"""
if not net_id:
raise ovimException("No net_id received", HTTP_Internal_Server_Error)
- switch_dpid = None
r = -1
c = 'No valid ofc_id or switch_dpid received'
ofc_id = port['ofc_id']
switch_dpid = port['switch_dpid']
break
+ #TODO if not ofc_id: look at database table ofcs
+
# If no ofc_id found it, default ofc_id is used.
if not ofc_id and not switch_dpid:
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)
# change of net.
try:
- self.net_update_ofc_thread(network)
+ self.net_update_ofc_thread(network, ofc_id=ports[0]["ofc_id"], switch_dpid=ports[0]["switch_dpid"])
except ovimException as e:
raise ovimException("Cannot insert a task for delete network '{}' {}".format(network, str(e)),
HTTP_Internal_Server_Error)
# insert in data base
if result >= 0:
result, content = self.db.update_rows('ports', port_data, WHERE={'uuid': port_id}, log=False)
+ port.update(port_data)
# Insert task to complete actions
if result > 0:
for net_id in nets:
try:
- self.net_update_ofc_thread(net_id)
+ self.net_update_ofc_thread(net_id, port["ofc_id"], switch_dpid=port["switch_dpid"])
except ovimException as e:
raise ovimException("Error updating network'{}' {}".format(net_id, str(e)),
HTTP_Internal_Server_Error)