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 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 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 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)