def perspective_load(self, profile='jcli-prod'): path = '%s/%s.smppccs' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile configuration from %s', profile, path) try: # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='smppccs', header=lines[0], data=''.join(lines[1:])) # Remove current configuration CIDs = [] for c in self.connectors: CIDs.append(c['id']) for cid in CIDs: remRet = yield self.perspective_connector_remove(cid) if not remRet: raise ConfigProfileLoadingError( 'Error removing connector %s' % cid) self.log.info('Removed connector [%s]', cid) # Apply configuration loadedConnectors = cf.getMigratedData() for loadedConnector in loadedConnectors: # Add connector addRet = yield self.perspective_connector_add( pickle.dumps(loadedConnector['config'], self.pickleProtocol)) if not addRet: raise ConfigProfileLoadingError( 'Error adding connector %s' % loadedConnector['id']) # Start it if it's service where started when persisted if loadedConnector['service_status'] == 1: startRet = yield self.perspective_connector_start( loadedConnector['id']) if not startRet: self.log.error('Error starting connector %s', loadedConnector['id']) # Set persistance state to True self.persisted = True except IOError, e: self.log.error('Cannot load configuration from %s: %s', path, str(e)) defer.returnValue(False)
def perspective_load(self, profile='jcli-prod'): path = '%s/%s.smppccs' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile configuration from %s', profile, path) try: # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='smppccs', header=lines[0], data=''.join(lines[1:])) # Remove current configuration CIDs = [] for c in self.connectors: CIDs.append(c['id']) for cid in CIDs: remRet = yield self.perspective_connector_remove(cid) if not remRet: raise ConfigProfileLoadingError('Error removing connector %s' % cid) self.log.info('Removed connector [%s]', cid) # Apply configuration loadedConnectors = cf.getMigratedData() for loadedConnector in loadedConnectors: # Add connector addRet = yield self.perspective_connector_add( pickle.dumps(loadedConnector['config'], self.pickleProtocol)) if not addRet: raise ConfigProfileLoadingError('Error adding connector %s' % loadedConnector['id']) # Start it if it's service where started when persisted if loadedConnector['service_status'] == 1: startRet = yield self.perspective_connector_start(loadedConnector['id']) if not startRet: self.log.error('Error starting connector %s', loadedConnector['id']) # Set persistance state to True self.persisted = True except IOError as e: self.log.error('Cannot load configuration from %s: %s', path, str(e)) defer.returnValue(False) except ConfigProfileLoadingError as e: self.log.error('Error while loading configuration: %s', e) defer.returnValue(False) except Exception as e: self.log.error('Unknown error occurred while loading configuration: %s', e) defer.returnValue(False) defer.returnValue(True)
def _load(self, profile="jcli-prod"): path = "%s/%s.filters" % (CONFIG_STORE_PATH, profile) try: # Load configuration from file fh = open(path, "r") lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context="filters", header=lines[0], data="".join(lines[1:])) # Apply configuration self.filters = cf.getMigratedData() except IOError, e: raise Exception("Cannot load from %s: %s" % (path, str(e)))
def _load(self, profile='jcli-prod'): path = '%s/%s.filters' % (CONFIG_STORE_PATH, profile) try: # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='filters', header=lines[0], data=''.join(lines[1:])) # Apply configuration self.filters = cf.getMigratedData() except IOError, e: raise Exception('Cannot load from %s: %s' % (path, str(e)))
def _load(self, profile='jcli-prod'): path = '%s/%s.httpccs' % (CONFIG_STORE_PATH, profile) try: # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='httpcs', header=lines[0], data=''.join(lines[1:])) # Apply configuration self.httpccs = cf.getMigratedData() except IOError, e: raise Exception('Cannot load from %s: %s' % (path, str(e)))
def _load(self, profile='jcli-prod'): path = '%s/%s.filters' % (STORE_PATH, profile) try: # Load configuration from file fh = open(path, mode='rb') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='filters', header=lines[0].decode('ascii'), data=b''.join(lines[1:])) # Apply configuration self.filters = cf.getMigratedData() except IOError as e: raise Exception('Cannot load from %s: %s' % (path, str(e))) except Exception as e: raise Exception('Unknown error while loading configuration: %s' % e)
def perspective_load(self, profile='jcli-prod', scope='all'): try: if scope in ['all', 'groups']: # Load groups configuration path = '%s/%s.router-groups' % (self.config.store_path, profile) self.log.info( 'Loading/Activating [%s] profile Groups configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='groups', header=lines[0], data=''.join(lines[1:])) # Remove current configuration self.log.info('Removing current Groups (%d)', len(self.groups)) self.perspective_group_remove_all() # Adding new groups self.groups = cf.getMigratedData() self.log.info('Added new Groups (%d)', len(self.groups)) # Set persistance state to True self.persistenceState['groups'] = True if scope in ['all', 'users']: # Load users configuration path = '%s/%s.router-users' % (self.config.store_path, profile) self.log.info( 'Loading/Activating [%s] profile Users configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='users', header=lines[0], data=''.join(lines[1:])) # Remove current configuration self.log.info('Removing current Users (%d)', len(self.users)) self.perspective_user_remove_all() # Adding new users self.users = cf.getMigratedData() self.log.info('Added new Users (%d)', len(self.users)) # Set persistance state to True self.persistenceState['users'] = True for u in self.users: u.mt_credential.quotas_updated = False if scope in ['all', 'mointerceptors']: # Load mointerceptors configuration path = '%s/%s.router-mointerceptors' % (self.config.store_path, profile) self.log.info( 'Loading/Activating [%s] profile MO Interceptors configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='mointerceptors', header=lines[0], data=''.join(lines[1:])) # Adding new MO Interceptors self.mo_interception_table = cf.getMigratedData() self.log.info('Added new MOInterceptionTable with %d routes', len(self.mo_interception_table.getAll())) # Set persistance state to True self.persistenceState['mointerceptors'] = True if scope in ['all', 'mtinterceptors']: # Load mtinterceptors configuration path = '%s/%s.router-mtinterceptors' % (self.config.store_path, profile) self.log.info( 'Loading/Activating [%s] profile MT Interceptors configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='mtinterceptors', header=lines[0], data=''.join(lines[1:])) # Adding new MT Interceptors self.mt_interception_table = cf.getMigratedData() self.log.info('Added new MTInterceptionTable with %d routes', len(self.mt_interception_table.getAll())) # Set persistance state to True self.persistenceState['mtinterceptors'] = True if scope in ['all', 'moroutes']: # Load moroutes configuration path = '%s/%s.router-moroutes' % (self.config.store_path, profile) self.log.info( 'Loading/Activating [%s] profile MO Routes configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='moroutes', header=lines[0], data=''.join(lines[1:])) # Adding new MO Routes self.mo_routing_table = cf.getMigratedData() self.log.info('Added new MORoutingTable with %d routes', len(self.mo_routing_table.getAll())) # Set persistance state to True self.persistenceState['moroutes'] = True if scope in ['all', 'mtroutes']: # Load mtroutes configuration path = '%s/%s.router-mtroutes' % (self.config.store_path, profile) self.log.info( 'Loading/Activating [%s] profile MT Routes configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='mtroutes', header=lines[0], data=''.join(lines[1:])) # Adding new MT Routes self.mt_routing_table = cf.getMigratedData() self.log.info('Added new MTRoutingTable with %d routes', len(self.mt_routing_table.getAll())) # Set persistance state to True self.persistenceState['mtroutes'] = True except IOError, e: self.log.error('Cannot load configuration from %s: %s', path, str(e)) return False
def perspective_load(self, profile='jcli-prod', scope='all'): try: if scope in ['all', 'groups']: # Load groups configuration path = '%s/%s.router-groups' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile Groups configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='groups', header=lines[0], data=''.join(lines[1:])) # Remove current configuration self.log.info('Removing current Groups (%d)', len(self.groups)) self.perspective_group_remove_all() # Adding new groups self.groups = cf.getMigratedData() self.log.info('Added new Groups (%d)', len(self.groups)) # Set persistance state to True self.persistenceState['groups'] = True if scope in ['all', 'users']: # Load users configuration path = '%s/%s.router-users' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile Users configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='users', header=lines[0], data=''.join(lines[1:])) # Remove current configuration self.log.info('Removing current Users (%d)', len(self.users)) self.perspective_user_remove_all() # Adding new users self.users = cf.getMigratedData() self.log.info('Added new Users (%d)', len(self.users)) # Set persistance state to True self.persistenceState['users'] = True for u in self.users: u.mt_credential.quotas_updated = False if scope in ['all', 'mointerceptors']: # Load mointerceptors configuration path = '%s/%s.router-mointerceptors' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile MO Interceptors configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='mointerceptors', header=lines[0], data=''.join(lines[1:])) # Adding new MO Interceptors self.mo_interception_table = cf.getMigratedData() self.log.info('Added new MOInterceptionTable with %d routes', len(self.mo_interception_table.getAll())) # Set persistance state to True self.persistenceState['mointerceptors'] = True if scope in ['all', 'mtinterceptors']: # Load mtinterceptors configuration path = '%s/%s.router-mtinterceptors' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile MT Interceptors configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='mtinterceptors', header=lines[0], data=''.join(lines[1:])) # Adding new MT Interceptors self.mt_interception_table = cf.getMigratedData() self.log.info('Added new MTInterceptionTable with %d routes', len(self.mt_interception_table.getAll())) # Set persistance state to True self.persistenceState['mtinterceptors'] = True if scope in ['all', 'moroutes']: # Load moroutes configuration path = '%s/%s.router-moroutes' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile MO Routes configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='moroutes', header=lines[0], data=''.join(lines[1:])) # Adding new MO Routes self.mo_routing_table = cf.getMigratedData() self.log.info('Added new MORoutingTable with %d routes', len(self.mo_routing_table.getAll())) # Set persistance state to True self.persistenceState['moroutes'] = True if scope in ['all', 'mtroutes']: # Load mtroutes configuration path = '%s/%s.router-mtroutes' % (self.config.store_path, profile) self.log.info('Loading/Activating [%s] profile MT Routes configuration from %s', profile, path) # Load configuration from file fh = open(path, 'r') lines = fh.readlines() fh.close() # Init migrator cf = ConfigurationMigrator(context='mtroutes', header=lines[0], data=''.join(lines[1:])) # Adding new MT Routes self.mt_routing_table = cf.getMigratedData() self.log.info('Added new MTRoutingTable with %d routes', len(self.mt_routing_table.getAll())) # Set persistance state to True self.persistenceState['mtroutes'] = True except IOError as e: self.log.error('Cannot load configuration from %s: %s', path, str(e)) return False except Exception as e: self.log.error('Unknown error occurred while loading configuration: %s', e) return False return True