def setUp(self): self.fl = FactoryLoader() self.fl.catalog = { 'RouteTable': { 'item': 'route-table/rt', 'rpc': 'get-route-information', 'args_key': 'destination', 'key': 'rt-destination', 'view': 'RouteTableView' } } self.fl._catalog_dict = { 'RouteTableView': { 'groups': { 'entry': 'rt-entry' }, 'fields_entry': { 'via': 'nh/via | nh/nh-local-interface', 'age': { 'age/@seconds': 'int' }, 'nexthop': 'nh/to', 'protocol': 'protocol-name' }, 'extends': 'test' } }
def load_junos_view(self, view_path): try: with open(view_path) as f: tmp_yaml = f.read() yaml_str = re.sub(r"unicode", "str", tmp_yaml) globals().update(FactoryLoader().load(yaml.safe_load(yaml_str))) except: pass
def setUp(self): self.fl = FactoryLoader() self.fl.catalog = { "RouteTable": { "item": "route-table/rt", "rpc": "get-route-information", "args_key": "destination", "key": "rt-destination", "view": "RouteTableView", } } self.fl._catalog_dict = { "RouteTableView": { "groups": {"entry": "rt-entry"}, "fields_entry": { "via": "nh/via | nh/nh-local-interface", "age": {"age/@seconds": "int"}, "nexthop": "nh/to", "protocol": "protocol-name", }, "extends": "test", } }
view: RouteTableView RouteTableView: groups: entry: rt-entry fields_entry: # fields taken from the group 'entry' protocol: protocol-name via: nh/via | nh/nh-local-interface age: { age/@seconds : int } nexthop: nh/to preference: preference metric: metric | med """ globals().update(FactoryLoader().load(yaml.load(rt_yml, Loader=yaml.FullLoader))) class PyEZNode(GNS3Node): def __init__(self, node_id, port, name, config=None): super().__init__(node_id, port, name) self.pyez_connection = None self.initial_config = os.path.abspath(config) self.detailed_ospf = False self.netmiko_node['device_type'] = 'juniper_junos_telnet' self.netmiko_node['username'] = '******' self.netmiko_node['password'] = '******' self.netmiko_node['default_enter'] = '\r\n'
def _loadyaml_bypass(yaml_str): """Bypass Juniper's loadyaml and directly call FactoryLoader""" return FactoryLoader().load(yaml.load(yaml_str))
def _loadyaml_bypass(yaml_file): """Bypass Juniper's loadyaml to utilize yaml.safe_load, thereby avoiding potential unintended code execution. """ with open(yaml_file) as handle: return FactoryLoader().load(yaml.safe_load(handle.read()))