How to use the fmcapi.IPv4StaticRoutes function in fmcapi

To help you get started, we’ve selected a few fmcapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github daxm / fmcapi / unit_tests / ipv4staticroutes.py View on Github external
iphost1 = fmcapi.Hosts(fmc=fmc, name="_iphost1" + namer, value="10.254.0.1")
    iphost1.post()
    ipnet1 = fmcapi.Networks(fmc=fmc, name="_ipnet1" + namer, value="192.0.2.0/25")
    ipnet2 = fmcapi.Networks(fmc=fmc, name="_ipnet2" + namer, value="192.0.2.128/25")
    ipnet1.post()
    ipnet2.post()

    ipv4route1 = fmcapi.IPv4StaticRoutes(fmc=fmc, name="_ipv4route1")
    ipv4route1.device(device_name="ftdv01.ccie.lab")
    ipv4route1.networks(action="add", networks=[ipnet1.name, ipnet2.name])
    ipv4route1.gw(name=iphost1.name)
    ipv4route1.interfaceName = "ifname"
    ipv4route1.metricValue = 1
    result = ipv4route1.post()

    ipv4route2 = fmcapi.IPv4StaticRoutes(fmc=fmc, name="_ipv4route1")
    ipv4route2.device(device_name="device_name")
    ipv4route2.id = result["id"]
    ipv4route2.get()

    del ipv4route1
    ipv4route2.networks(action="remove", networks=[ipnet2.name])
    ipv4route2.put()

    ipv4route2.delete()
    ipnet1.delete()
    ipnet2.delete()
    iphost1.delete()
    logging.info("Testing IPv4StaticRoutes class done.\n")
github daxm / fmcapi / unit_tests / ipv6staticroutes.py View on Github external
iphost1 = fmcapi.Hosts(fmc=fmc, name="_iphost1" + namer, value="2001:db8::1")
    iphost1.post()
    ipnet1 = fmcapi.Networks(fmc=fmc, name="_ipnet1" + namer, value="2001:db8:1::/64")
    ipnet2 = fmcapi.Networks(fmc=fmc, name="_ipnet2" + namer, value="2001:db8:2::/64")
    ipnet1.post()
    ipnet2.post()

    ipv4route1 = fmcapi.IPv6StaticRoutes(fmc=fmc, name="_ipv6route1")
    ipv4route1.device(device_name="ftdv01.ccie.lab")
    ipv4route1.networks(action="add", networks=[ipnet1.name, ipnet2.name])
    ipv4route1.gw(name=iphost1.name)
    ipv4route1.interfaceName = "ifname"
    ipv4route1.metricValue = 1
    result = ipv4route1.post()

    ipv4route2 = fmcapi.IPv4StaticRoutes(fmc=fmc, name="_ipv6route1")
    ipv4route2.device(device_name="device_name")
    ipv4route2.id = result["id"]
    ipv4route2.get()

    del ipv4route1
    ipv4route2.networks(action="remove", networks=[ipnet2.name])
    ipv4route2.put()

    ipv4route2.delete()
    ipnet1.delete()
    ipnet2.delete()
    iphost1.delete()
    logging.info("Testing IPv6StaticRoutes class done.\n")
github daxm / fmcapi / unit_tests / ipv4staticroutes.py View on Github external
def test__ipv4staticroutes(fmc):
    logging.info(
        "Testing IPv4StaticRoutes class. get, post, put, delete IPv4StaticRoute Objects. Requires a registered device"
    )

    starttime = str(int(time.time()))
    namer = f"_fmcapi_test_{starttime}"

    iphost1 = fmcapi.Hosts(fmc=fmc, name="_iphost1" + namer, value="10.254.0.1")
    iphost1.post()
    ipnet1 = fmcapi.Networks(fmc=fmc, name="_ipnet1" + namer, value="192.0.2.0/25")
    ipnet2 = fmcapi.Networks(fmc=fmc, name="_ipnet2" + namer, value="192.0.2.128/25")
    ipnet1.post()
    ipnet2.post()

    ipv4route1 = fmcapi.IPv4StaticRoutes(fmc=fmc, name="_ipv4route1")
    ipv4route1.device(device_name="ftdv01.ccie.lab")
    ipv4route1.networks(action="add", networks=[ipnet1.name, ipnet2.name])
    ipv4route1.gw(name=iphost1.name)
    ipv4route1.interfaceName = "ifname"
    ipv4route1.metricValue = 1
    result = ipv4route1.post()

    ipv4route2 = fmcapi.IPv4StaticRoutes(fmc=fmc, name="_ipv4route1")
    ipv4route2.device(device_name="device_name")
    ipv4route2.id = result["id"]
    ipv4route2.get()

    del ipv4route1
    ipv4route2.networks(action="remove", networks=[ipnet2.name])
    ipv4route2.put()
github daxm / fmcapi / example / logic_separate_from_data / program_logic.py View on Github external
"dhcp"
                                    ]["enable_default"],
                                    routeMetric=interface["addresses"]["ipv4"]["dhcp"][
                                        "route_metric"
                                    ],
                                )
                        if "ipv6" in interface["addresses"]:
                            pass
                    int1.put()

        # Any routing related to this device.
        if "routing" in dr:
            if "static" in dr["routing"]:
                if "ipv4" in dr["routing"]["static"]:
                    for route in dr["routing"]["static"]["ipv4"]:
                        rt = fmcapi.IPv4StaticRoutes(fmc=fmc, device_name=dr["name"])
                        if "name" in route:
                            rt.name = route["name"]
                        if "networks" in route:
                            for network in route["networks"]:
                                if "name" in network:
                                    rt.networks(
                                        action="add", networks=[network["name"]]
                                    )
                        if "gateway" in route:
                            rt.gw(name=route["gateway"])
                        if "interface_name" in route:
                            rt.interfaceName = route["interface_name"]
                        if "metric" in route:
                            rt.metricValue = route["metric"]
                        rt.post()
                if "ipv6" in dr["routing"]["static"]:
github daxm / fmcapi / example / mixed_logic_and_data / hq-ftd.py View on Github external
hq_ftd_g00.enabled = True
        hq_ftd_g00.ifname = "IN"
        hq_ftd_g00.static(ipv4addr="10.0.0.1", ipv4mask=24)
        hq_ftd_g00.sz(name="inside")
        hq_ftd_g00.put()

        hq_ftd_g01 = fmcapi.PhysicalInterfaces(fmc=fmc1, device_name=hq_ftd.name)
        hq_ftd_g01.get(name="GigabitEthernet0/1")
        hq_ftd_g01.enabled = True
        hq_ftd_g01.ifname = "OUT"
        hq_ftd_g01.static(ipv4addr="100.64.0.200", ipv4mask=24)
        hq_ftd_g01.sz(name="outside")
        hq_ftd_g01.put()

        # Build static default route for HQ FTD
        hq_default_route = fmcapi.IPv4StaticRoutes(fmc=fmc1, name="hq_default_route")
        hq_default_route.device(device_name=hq_ftd.name)
        hq_default_route.networks(action="add", networks=["any-ipv4"])
        hq_default_route.gw(name=hq_dfgw_gateway.name)
        hq_default_route.interfaceName = hq_ftd_g01.ifname
        hq_default_route.metricValue = 1
        hq_default_route.post()

        # Associate NAT policy with HQ FTD device.
        devices = [{"name": hq_ftd.name, "type": "device"}]
        assign_nat_policy = fmcapi.PolicyAssignments(fmc=fmc1)
        assign_nat_policy.ftd_natpolicy(name=nat.name, devices=devices)
        assign_nat_policy.post()