def copy_running_startup(): cfg = cfgdb.Cfgdb() manager = OvsdbConnectionManager(settings.get('ovs_remote'), settings.get('ovs_schema')) manager.start() idl = manager.idl init_seq_no = idl.change_seqno # Wait until the connection is ready while True: idl.run() # print self.idl.change_seqno if init_seq_no != idl.change_seqno: break time.sleep(1) restschema = restparser.parseSchema(settings.get('ext_schema')) run_config_util = RunConfigUtil(idl, restschema) config = run_config_util.get_running_config() cfg.config = ovs.json.to_string(config) cfg.type = "startup" row, tbl_found = cfg.find_row_by_type("startup") if tbl_found: cfg.update_row(row) else: cfg.insert_row() cfg.close() return True
def test_read(): manager = OvsdbConnectionManager(settings.get('ovs_remote'), settings.get('ovs_schema')) manager.start() idl = manager.idl init_seq_no = 0 # Wait until the connection is ready while True: idl.run() # Print self.idl.change_seqno if init_seq_no != idl.change_seqno: break time.sleep(0.001) schema = restparser.parseSchema(settings.get('ext_schema')) run_config_util = runconfig.RunConfigUtil(idl, schema) config = run_config_util.get_config() ''' TODO: Adding json.dumps and the json.loads as a workaround because the config returned from test_read has a missing unicode character for keys ''' temp_config = json.dumps(config) config = json.loads(temp_config) filename = 'config.db' with open(filename, 'w') as fp: json.dump(config, fp, sort_keys=True, indent=4, separators=(',', ': ')) fp.write('\n') return config
def get_idl(): manager = OvsdbConnectionManager(settings.get('ovs_remote'), settings.get('ovs_schema')) manager.start() idl = manager.idl init_seq_no = 0 while (init_seq_no == idl.change_seqno): idl.run() time.sleep(1) return idl
def __init__(self): manager = OvsdbConnectionManager(settings.get("ovs_remote"), settings.get("cfg_db_schema")) manager.start() self.idl = manager.idl init_seq_no = 0 # Wait until the connection is ready while True: self.idl.run() # print self.idl.change_seqno if init_seq_no != self.idl.change_seqno: break time.sleep(0.001)
def get_runconfig(): manager = OvsdbConnectionManager(settings.get('ovs_remote'), settings.get('ovs_schema')) manager.start() timeout = 10 interval = 0 init_seq_no = manager.idl.change_seqno while (init_seq_no == manager.idl.change_seqno): if interval > timeout: raise TypeError('timeout') manager.idl.run() interval += 1 time.sleep(1) schema = restparser.parseSchema(settings.get('ext_schema')) return runconfig.RunConfigUtil(manager.idl, schema)
def __init__(self, settings): self.settings = settings self.settings['cookie_secret'] = cookiesecret.generate_cookie_secret() schema = self.settings.get('ext_schema') self.restschema = restparser.parseSchema(schema) self.manager = OvsdbConnectionManager(self.settings.get('ovs_remote'), self.settings.get('ovs_schema'), self.restschema) self._url_patterns = self._get_url_patterns() Application.__init__(self, self._url_patterns, **self.settings) # We must block the application start until idl connection # and replica is ready self.manager.start() # Load all custom validators validator.init_plugins(constants.OPSPLUGIN_DIR) self.notification_handler = NotificationHandler( self.restschema, self.manager)
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
class OvsdbApiApplication(Application): def __init__(self, settings): self.settings = settings self.settings['cookie_secret'] = cookiesecret.generate_cookie_secret() schema = self.settings.get('ext_schema') self.restschema = restparser.parseSchema(schema) self.manager = OvsdbConnectionManager(self.settings.get('ovs_remote'), self.settings.get('ovs_schema'), self.restschema) self._url_patterns = self._get_url_patterns() Application.__init__(self, self._url_patterns, **self.settings) # We must block the application start until idl connection # and replica is ready self.manager.start() # Load all custom validators validator.init_plugins(constants.OPSPLUGIN_DIR) self.notification_handler = NotificationHandler( self.restschema, self.manager) # adds 'self' to url_patterns def _get_url_patterns(self): from urls import url_patterns from urls import custom_url_patterns from urls import static_url_patterns modified_url_patterns = [] for url, handler, controller_class in custom_url_patterns: params = {'ref_object': self, 'controller_class': controller_class} modified_url_patterns.append((url, handler, params)) for url in url_patterns: modified_url_patterns.append(url + ({'ref_object': self}, )) modified_url_patterns.extend(static_url_patterns) return modified_url_patterns
def test_write(filename): with open(filename) as json_data: data = json.load(json_data) json_data.close() # Set up IDL manager = OvsdbConnectionManager(settings.get('ovs_remote'), settings.get('ovs_schema')) manager.start() manager.idl.run() init_seq_no = 0 while True: manager.idl.run() if init_seq_no != manager.idl.change_seqno: break # Read the schema schema = restparser.parseSchema(settings.get('ext_schema')) run_config_util = runconfig.RunConfigUtil(manager.idl, schema) run_config_util.write_config_to_db(data)
def start_new_manager(self): app_log.debug("Starting new manager") manager = OvsdbConnectionManager(self.remote, self.schema, self.rest_schema) manager.start(self.tables_monitored, True) # Add callback for detecting changes to subscribed resources manager.add_callback(CHANGES_CB_TYPE, self.notify_cb) # Add callback for detecting when the manager's connection is # established manager.add_callback(ESTABLISHED_CB_TYPE, self.new_monitor_started_callback) return manager
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)
row, tbl_found = cfg.find_row_by_type("startup") if tbl_found: try: data = json.loads(row.config) except ValueError, e: print("Invalid json from configdb. Exception: %s\n" % e) cfg.close() return False else: print('No saved configuration exists') cfg.close() return False # 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