def __init__(self, model, profile, translation=None, keys=None, bookmarks=None, merge=None, replace=None, other=None, extra_vars=None): self.model = model self.profile = profile self._defining_module = model._defining_module self._yang_name = model._yang_name self.translation = translation self.keys = keys or {"parent_key": None} self.extra_vars = extra_vars or {} self.merge = merge self.replace = replace self.other = other or merge or replace self.mapping = helpers.read_yang_map(model._defining_module, model._yang_name, self.profile, "translators") if self.mapping: translator = get_parser(self.mapping["metadata"]["processor"]) self.translator = translator(merge=bool(merge), replace=bool(replace)) if translation is None: self.translation = self.translator.init_translation(self.mapping["metadata"], self.translation) self.bookmarks = bookmarks or {"root_{}".format(self._yang_name): translation, "parent": translation}
def __init__( self, model, device=None, profile=None, is_config=None, native=None, keys=None, bookmarks=None, extra_vars=None, ): self.model = model self.device = device self.profile = profile or device.profile self.is_config = is_config self._defining_module = model._defining_module self._yang_name = model._yang_name parser_path = os.path.join("parsers", "config" if is_config else "state") self.mapping = helpers.read_yang_map(model._defining_module, model._yang_name, self.profile, parser_path) self.keys = keys or {"parent_key": None} self.extra_vars = extra_vars or {} if self.mapping and device: device_output = self._execute_methods( device, self.mapping["metadata"].get("execute", [])) else: device_output = [] native = native or [] self.native = [] for n in native + device_output: if isinstance(n, (str, unicode)): self.native.append(n.replace("\r", "")) # Parsing will be easier else: self.native.append(n) if not self.native: raise Exception("I don't have any data to operate with") if self.mapping: self.parser = get_parser(self.mapping["metadata"]["processor"])( self.keys, self.extra_vars) self.bookmarks = bookmarks or {}
def __init__( self, model, profile, translation=None, keys=None, bookmarks=None, merge=None, replace=None, other=None, extra_vars=None, ): self.model = model self.profile = profile self._defining_module = model._defining_module self._yang_name = model._yang_name self.translation = translation self.keys = keys or {"parent_key": None} self.extra_vars = extra_vars or {} self.merge = merge self.replace = replace self.other = other or merge or replace self.mapping = helpers.read_yang_map(model._defining_module, model._yang_name, self.profile, "translators") if self.mapping: translator = get_parser(self.mapping["metadata"]["processor"]) self.translator = translator(merge=bool(merge), replace=bool(replace)) if translation is None: self.translation = self.translator.init_translation( self.mapping["metadata"], self.translation) self.bookmarks = bookmarks or { "root_{}".format(self._yang_name): translation, "parent": translation }
def __init__(self, model, device=None, profile=None, is_config=None, native=None, keys=None, bookmarks=None, extra_vars=None): self.model = model self.device = device self.profile = profile or device.profile self.is_config = is_config self._defining_module = model._defining_module self._yang_name = model._yang_name parser_path = os.path.join("parsers", "config" if is_config else "state") self.mapping = helpers.read_yang_map(model._defining_module, model._yang_name, self.profile, parser_path) self.keys = keys or {"parent_key": None} self.extra_vars = extra_vars or {} if self.mapping and device: device_output = self._execute_methods(device, self.mapping["metadata"].get("execute", [])) else: device_output = [] native = native or [] self.native = [] for n in native + device_output: if isinstance(n, basestring): self.native.append(n.replace("\r", "")) # Parsing will be easier else: self.native.append(n) if not self.native: raise Exception("I don't have any data to operate with") if self.mapping: self.parser = get_parser(self.mapping["metadata"]["processor"])(self.keys, self.extra_vars) self.bookmarks = bookmarks or {}