Exemple #1
0
    def test_pass_a(self):
        """Local AS only."""
        config = {"local_asn": 666}
        actual = render("eos", "bgppeer", config)
        expected = """router bgp 666
"""
        assert actual == expected
    def test_pass_a(self):
        """Name only."""
        config = {"name": "Ethernet1"}
        actual = render("eos", "interface", config)
        expected = """interface Ethernet1
    no lldp transmit
    no lldp receive
"""
        assert actual == expected
    def test_pass_b(self):
        """Good ipv4 only."""
        config = {"name": "Ethernet1", "ipv4": {"address": "192.0.2.0", "mask": 31}}
        actual = render("eos", "interface", config)
        expected = """interface Ethernet1
    ip address 192.0.2.0/31
    no lldp transmit
    no lldp receive
"""
        assert actual == expected
 def get(self, config_id):
     """Render a given config."""
     args = render_parser.parse_args()
     config = get_config(config_id)
     if config is None:
         api.abort(404)
     ret = {
         "hostname": config.hostname,
         "config": render(args["family"], config.schema, config.config),
     }
     return ret
    def test_pass_a(self):
        """Name only."""
        config = {"name": "et-0/0/0"}
        actual = render("junos", "interface", config)
        expected = """interfaces {
    et-0/0/0 {
        unit 0 {
        }
    }
}
"""
        assert actual == expected
Exemple #6
0
    def test_pass_b(self):
        """Good ipv4 only."""
        config = {
            "local_asn": "666",
            "peer_asn": "666",
            "peer_v4": "192.0.2.1"
        }
        actual = render("eos", "bgppeer", config)
        expected = """router bgp 666
    neighbor 192.0.2.1 remote-as 666
"""
        assert actual == expected
    def test_pass_a_internal(self):
        """Internal AS only."""
        config = {"local_asn": 666, "peer_asn": 666}
        actual = render("junos", "bgppeer", config)
        expected = """autonomous-system 666;
bgp {
    group internal-peers {
        type internal;
    }
}
"""
        assert actual == expected
    def test_pass_b_internal_v4(self):
        """Internal and ipv4."""
        config = {"local_asn": 666, "peer_asn": 666, "peer_v4": "192.0.2.1"}
        actual = render("junos", "bgppeer", config)
        expected = """autonomous-system 666;
bgp {
    group internal-peers {
        type internal;
        neighbor 192.0.2.1;
    }
}
"""
        assert actual == expected
Exemple #9
0
    def test_pass_c(self):
        """Good ipv4 and ipv6."""
        config = {
            "local_asn": "666",
            "peer_asn": "666",
            "peer_v4": "192.0.2.1",
            "peer_v6": "2001:db8:c057:e110::1",
        }
        actual = render("eos", "bgppeer", config)
        expected = """router bgp 666
    neighbor 192.0.2.1 remote-as 666
    neighbor 2001:db8:c057:e110::1 remote-as 666
"""
        assert actual == expected
    def test_pass_b(self):
        """Good ipv4 only."""
        config = {"name": "et-0/0/0", "ipv4": {"address": "192.0.2.0", "mask": 31}}
        actual = render("junos", "interface", config)
        expected = """interfaces {
    et-0/0/0 {
        unit 0 {
            family inet {
                address 192.0.2.0/31;
            }
        }
    }
}
"""
        assert actual == expected
    def test_pass_c(self):
        """Good ipv4 and ipv6."""
        config = {
            "name": "Ethernet1",
            "ipv4": {"address": "192.0.2.0", "mask": 31},
            "ipv6": {"address": "2001:db8:c057:e110::0", "mask": 127},
        }
        actual = render("eos", "interface", config)
        expected = """interface Ethernet1
    ip address 192.0.2.0/31
    ipv6 address 2001:db8:c057:e110::0/127
    no lldp transmit
    no lldp receive
"""
        assert actual == expected
    def get(self, service_id):
        """Render a given service."""
        args = render_parser.parse_args()
        service = get_service(service_id)
        if service is None:
            api.abort(404)

        return_list = []
        for hostname, configs in service["config"].items():
            return_config = []
            for schema, config in configs.items():
                return_config.append(render(args["family"], schema, config))
            return_list.append({
                "hostname": hostname,
                "config": "!\n".join(return_config)
            })
        return return_list
    def test_pass_c_internal_v4_v6(self):
        """Internal and ipv4 and ipv6."""
        config = {
            "local_asn": 666,
            "peer_asn": 666,
            "peer_v4": "192.0.2.1",
            "peer_v6": "2001:db8:c057:e110::1",
        }
        actual = render("junos", "bgppeer", config)
        expected = """autonomous-system 666;
bgp {
    group internal-peers {
        type internal;
        neighbor 192.0.2.1;
        neighbor 2001:db8:c057:e110::1;
    }
}
"""
        assert actual == expected
    def test_pass_c(self):
        """Good ipv4 and ipv6."""
        config = {
            "name": "et-0/0/0",
            "ipv4": {"address": "192.0.2.0", "mask": 31},
            "ipv6": {"address": "2001:db8:c057:e110::0", "mask": 127},
        }
        actual = render("junos", "interface", config)
        expected = """interfaces {
    et-0/0/0 {
        unit 0 {
            family inet {
                address 192.0.2.0/31;
            }
            family inet6 {
                address 2001:db8:c057:e110::0/127;
            }
        }
    }
}
"""
        assert actual == expected