def render(self, session, grn, eon_id, disabled, **arguments): Grn.get_unique(session, grn=grn, preclude=True) Grn.get_unique(session, eon_id=eon_id, preclude=True) if disabled is None: disabled = False dbgrn = Grn(grn=grn, eon_id=eon_id, disabled=disabled) session.add(dbgrn) session.flush() return
def render(self, session, logger, grn, eon_id, rename_to, disabled, **arguments): dbgrn = lookup_grn(session, grn, eon_id, logger=logger, config=self.config, usable_only=False) if rename_to: Grn.get_unique(session, rename_to, preclude=True) dbgrn.grn = rename_to if disabled is not None: dbgrn.disabled = disabled session.flush() return
def lookup_autoupdate(config, session, logger, grn, eon_id): # Check the CDB file first, since that quickly tells us if the cache is # stale or if just the input is wrong if grn and not lookup_by_name(config, grn): return None elif eon_id and not lookup_by_id(config, eon_id): return None with SyncKey(data="grn", logger=logger): # Try again in case a concurrent process have already updated the cache # by the time we got the lock dbgrn = Grn.get_unique(session, grn=grn, eon_id=eon_id) if dbgrn: # pragma: no cover return dbgrn update_grn_map(config, session, logger) dbgrn = Grn.get_unique(session, grn=grn, eon_id=eon_id) return dbgrn
def lookup_grn(session, grn=None, eon_id=None, usable_only=True, logger=None, config=None, autoupdate=True): dbgrn = Grn.get_unique(session, grn=grn, eon_id=eon_id) if not dbgrn and autoupdate: if not config or not config.get("broker", "grn_to_eonid_map_location"): # pragma: no cover return None dbgrn = lookup_autoupdate(config, session, logger, grn, eon_id) if not dbgrn: if grn: raise NotFoundException("GRN %s not found." % grn) else: raise NotFoundException("EON ID %s not found." % eon_id) if usable_only and dbgrn.disabled: raise ArgumentError("GRN %s is not usable for new systems." % dbgrn.grn) return dbgrn