Exemplo n.º 1
0
def create_controller_db(file_path, ip, port, token):
    from utils import config_json_write
    from onos_api.onos_controller_api import onos_api_switches

    switches = {}
    switch_data = onos_api_switches(ip, port, token)["devices"]
    for switch in switch_data:
        if switch["role"] == "MASTER":
            switches[switch["id"]] = switch["id"]

    config_json_write(file_path, switches)
Exemplo n.º 2
0
 def switches(self):
     from onos_api.onos_result_print import print_all_switches
     from onos_api.onos_controller_api import onos_api_switches
     from onos_api.onos_utils import return_sw_names
     
     switches_data = onos_api_switches(self.ip, self.port, self.token)
     if switches_data:
         count_switches = len(switches_data['devices'])
         for x in range(count_switches):
             try:
                 print_all_switches(switches_data,x, self.file_path)
             except KeyError:
                 print "Data not matched"
     else:
         print "No switches."
Exemplo n.º 3
0
def update_controller_db(file_path, ip, port, token):
    from utils import config_json_read, config_json_write
    from onos_api.onos_controller_api import onos_api_switches

    latest_switches = {}
    latest_sw_data = onos_api_switches(ip, port, token)["devices"]
    switches = config_json_read(file_path)
    for switch in latest_sw_data:
        if switch["role"] == "MASTER":
            try:
                sw_alias = switches[switch["id"]]
            except KeyError:
                sw_alias = switch["id"]
            finally:
                latest_switches[switch["id"]] = sw_alias

    config_json_write(file_path, latest_switches)