def show_config(args): ret = True if (args[0] != "startup-config"): print("Unknown config \"%s\" (Use --help for help)" % args[0]) return False cfg = cfgdb.Cfgdb() #OPS TODO: To get confg type from user as args row, tbl_found = cfg.find_row_by_type("startup") if tbl_found: try: parsed = json.loads(row.config) print("Startup configuration:") if (args[1] == "json"): print json.dumps(parsed, indent=4, sort_keys=True) elif (args[1] == "cli"): # Here we copy saved configuration from config DB to temporary # DB and the current startup configuration command displays # output by traversing the temporary DB. manager = OvsdbConnectionManager(TEMPORARY_DB_SHOW_STARTUP, settings.get('ovs_schema')) manager.start() cnt = 30 while not manager.idl.run() and cnt > 0: time.sleep(.1) cnt -= 1 if cnt <= 0: print("IDL connection timeout") return False # read the schema schema = restparser.parseSchema(settings.get('ext_schema')) run_config_util = RunConfigUtil(manager.idl, schema) run_config_util.write_config_to_db(parsed) manager.idl.close() except ValueError, e: print("Invalid json from configdb. Exception: %s\n" % e) ret = False
def push_config_to_db(): ''' Take the previously discovered startup configuration and push it to the database. ''' global saved_config if saved_config is None: vlog.info('No saved configuration exists') else: #OPS_TODO: Change this log msg to the actual push code when available vlog.info('Config data found') try: data = json.loads(saved_config) except ValueError, e: print("Invalid json from configdb. Exception: %s\n" % e) return # set up IDL manager = OvsdbConnectionManager(settings.get('ovs_remote'), settings.get('ovs_schema')) manager.start() manager.idl.run() init_seq_no = manager.idl.change_seqno while True: manager.idl.run() if init_seq_no != manager.idl.change_seqno: break sleep(1) # read the schema schema = restparser.parseSchema(settings.get('ext_schema')) run_config_util = RunConfigUtil(manager.idl, schema) run_config_util.write_config_to_db(data)
# set up IDL manager = OvsdbConnectionManager(settings.get('ovs_remote'), settings.get('ovs_schema')) manager.start() init_seq_no = manager.idl.change_seqno while True: manager.idl.run() if init_seq_no != manager.idl.change_seqno: break time.sleep(1) # read the schema schema = restparser.parseSchema(settings.get('ext_schema')) run_config_util = RunConfigUtil(manager.idl, schema) run_config_util.write_config_to_db(data) cfg.close() return True def copy_config(args): ret = True if (args[0] == "running-config" and args[1] == "startup-config"): ret = copy_running_startup() elif (args[0] == "startup-config" and args[1] == "running-config"): ret = copy_startup_running() else: print("Unknow config (use --help for help)") ret = False return ret