def reference(self): response = {"key": self.key} Host = load("zbx.config.Host") Template = load("zbx.config.Template") chaining = [self] for parent in self.ancestors(): chaining.append(parent) if isinstance(parent, (Host, Template)): response["host"] = parent.name break logging.debug("chaining: %s", " > ".join(repr(p) for p in chaining)) return response
def reference(self): response = { 'name': self.name, } Host = load('zbx.config.Host') Template = load('zbx.config.Template') chaining = [self] for parent in self.ancestors(): chaining.append(parent) if isinstance(parent, (Host, Template)): response['host'] = parent.name break logging.debug('chaining: %s', ' > '.join(repr(p) for p in chaining)) return response
def get_default(self, parent): """Initialise a value will Model hydratation """ # TODO fix this Reference = load('zbx.config.Reference') return Reference(self.model, parent, self.default, self.append_host)
def __init__(self, model, parent, instances=None): logging.debug('p: %s m: %s', parent.__class__, model.__class__) if isinstance(model, str): model = load(model, 'zbx.config') self.model = model self.parent = parent self.instances = [] if instances: self.update(instances)
def get_default(self, parent): logging.debug('sf: %s > %s', parent, self.model) # TODO fix this Collection = load('zbx.config.Collection') value = Collection(self.model, parent, self.default) value.allow_empty = self.allow_empty return value
def document_host(self): """Returns the document host (used into references...) """ # TODO fix this Config = load('zbx.config.Config') for parent in self.ancestors(): if isinstance(parent.parent.parent, Config): return parent
def __init__(self, model, parent, default=None, append_host=False): self.append_host = append_host if isinstance(model, str): model = load(model, 'zbx.config') self.model = model self.parent = parent self.instance = None self.value = None if default: self.update(default)
def extract(self, model): """Extract model from me and descendant """ if not issubclass(model, Model): raise ValueError('must be a Model type !') # TODO fix this Host = load('zbx.config.Host') groups = set() for key, value in super(Host, self).children(): groups.update(self._extract(value, model)) return groups
def _extract(self, obj, model): # TODO fix this Collection = load('zbx.config.Collection') if isinstance(obj, model): yield obj if isinstance(obj, Model): for key, value in obj.children(): for group in self._extract(value, model): yield group if isinstance(obj, (Collection, set, list, tuple)): for value in obj: for group in self._extract(value, model): yield group