X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=ovim.py;h=bf1f311c9ffc832299beda68e0066067e3496f52;hb=15f23870227476d8611b0e0fc63c313aadccc940;hp=965cf30919047bc196186d4250eb7431c2a4329c;hpb=a8776d1e6fd339cb9bcd0bfe16267bea45467f22;p=osm%2Fopenvim.git diff --git a/ovim.py b/ovim.py old mode 100644 new mode 100755 index 965cf30..bf1f311 --- a/ovim.py +++ b/ovim.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # -*- coding: utf-8 -*- ## @@ -35,13 +36,14 @@ database_version = "0.15" #expected database schema version import threading import vim_db import logging -import threading import imp import host_thread as ht import dhcp_thread as dt import openflow_thread as oft from netaddr import IPNetwork from jsonschema import validate as js_v, exceptions as js_e +import openflow_conn +import argparse HTTP_Bad_Request = 400 HTTP_Unauthorized = 401 @@ -342,8 +344,9 @@ 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 openflow_conn.OfTestConnector({"name": db_config['type'], + "dpid": db_config['dpid'], + "of_debug": self.config['log_level_of']}) temp_dict = {} if db_config: @@ -392,10 +395,11 @@ class ovim(): """ # create openflow thread - if 'of_controller_nets_with_same_vlan' in self.config: - ofc_net_same_vlan = self.config['of_controller_nets_with_same_vlan'] - else: - ofc_net_same_vlan = False + #if 'of_controller_nets_with_same_vlan' in self.config: + # ofc_net_same_vlan = self.config['of_controller_nets_with_same_vlan'] + #else: + # ofc_net_same_vlan = False + ofc_net_same_vlan = False thread = oft.openflow_thread(ofc_uuid, of_conn, of_test=self.of_test_mode, db=self.db_of, db_lock=self.db_lock, pmp_with_same_vlan=ofc_net_same_vlan, debug=self.config['log_level_of']) @@ -681,7 +685,8 @@ class ovim(): 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) @@ -923,17 +928,17 @@ class ovim(): 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' @@ -945,6 +950,8 @@ class ovim(): 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: @@ -981,7 +988,7 @@ class ovim(): # 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) @@ -1035,12 +1042,13 @@ class ovim(): # 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) @@ -1358,4 +1366,12 @@ class ovim(): controller_host.create_dhcp_interfaces(vlan, first_ip, dhcp_netmask) controller_host.launch_dhcp_server(vlan, ip_range, dhcp_netmask, dhcp_path, gateway) +if __name__ == "__main__": + + parser = argparse.ArgumentParser() + parser.add_argument("-v","--version", help="increase output verbosity", 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')