How to use the fmcapi.Hosts 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
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")
github daxm / fmcapi / unit_tests / acprule.py View on Github external
def test__acp_rule(fmc):
    logging.info(
        "In preparation for testing ACPRule methods, set up some known objects in the FMC."
    )

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

    # Build an IP host object
    iphost1 = fmcapi.Hosts(fmc=fmc, name="_iphost1", value="7.7.7.7")
    iphost1.post()
    # Build an IP Network object
    ipnet1 = fmcapi.Networks(fmc=fmc, name="_ipnet1", value="1.2.3.0/24")
    ipnet1.post()
    # Build an IP range object
    iprange1 = fmcapi.Ranges(fmc=fmc, name="_iprange1", value="6.6.6.6-7.7.7.7")
    iprange1.post()
    # Build a Network Group object
    ipnet2 = fmcapi.Networks(fmc=fmc, name="_ipnet2", value="5.5.5.0/24")
    ipnet2.post()
    time.sleep(1)
    # Build an FQDNS object
    fqdns1 = fmcapi.FQDNS(fmc=fmc, name="_fqdns1", value="www.cisco.com")
    fqdns1.post()

    obj1 = fmcapi.NetworkGroups(fmc=fmc, name="_fmcapi_test_networkgroup")
github daxm / fmcapi / unit_tests / ip_host.py View on Github external
def test__ip_host(fmc):
    logging.info("Test IPHost.  Post, get, put, delete Host Objects.")

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

    obj1 = fmcapi.Hosts(fmc=fmc)
    obj1.name = namer
    obj1.value = "8.8.8.8/32"
    obj1.post()
    time.sleep(1)
    del obj1
    obj1 = fmcapi.Hosts(fmc=fmc, name=namer)
    obj1.get()
    obj1.value = "9.9.9.9"
    obj1.put()
    time.sleep(1)
    obj1.delete()

    logging.info("Test IPHost done.\n")
github daxm / fmcapi / unit_tests / manualnat.py View on Github external
time.sleep(1)

    obj8 = fmcapi.Hosts(fmc=fmc)
    obj8.name = "_net_destination_divert"
    obj8.value = "4.2.2.2"
    obj8.post()
    time.sleep(1)

    # Create port-based NAT objects
    obj9 = fmcapi.Hosts(fmc=fmc)
    obj9.name = "_net_source_portbased"
    obj9.value = "172.30.1.2"
    obj9.post()
    time.sleep(1)

    obj10 = fmcapi.Hosts(fmc=fmc)
    obj10.name = "_net_xlate_portbased"
    obj10.value = "192.0.2.254"
    obj10.post()
    time.sleep(1)

    obj11 = fmcapi.ProtocolPortObjects(fmc=fmc)
    obj11.name = "_port_original"
    obj11.protocol = "TCP"
    obj11.port = "443"
    obj11.post()
    time.sleep(1)

    obj12 = fmcapi.ProtocolPortObjects(fmc=fmc)
    obj12.name = "_port_xlate"
    obj12.protocol = "TCP"
    obj12.port = "8443"
github daxm / fmcapi / example / logic_separate_from_data / program_logic.py View on Github external
def create_hosts(fmc, na_list):
    """Create Hosts Objects"""
    for na in na_list:
        if "name" in na and "value" in na:
            netaddr = fmcapi.Hosts(fmc=fmc, name=na["name"], value=na["value"])
            netaddr.post()
github daxm / fmcapi / example / mixed_logic_and_data / hq-ftd.py View on Github external
fmc=fmc1, name="outside", interfaceMode="ROUTED"
        )
        sz_outside.post()
        sz_dmz = fmcapi.SecurityZones(fmc=fmc1, name="dmz", interfaceMode="ROUTED")
        sz_dmz.post()

        # Create Network Objects
        hq_dfgw_gateway = fmcapi.Hosts(
            fmc=fmc1, name="hq-default-gateway", value="100.64.0.1"
        )
        hq_dfgw_gateway.post()
        hq_lan = fmcapi.Networks(fmc=fmc1, name="hq-lan", value="10.0.0.0/24")
        hq_lan.post()
        all_lans = fmcapi.Networks(fmc=fmc1, name="all-lans", value="10.0.0.0/8")
        all_lans.post()
        hq_fmc = fmcapi.Hosts(fmc=fmc1, name="hq_fmc", value="10.0.0.10")
        hq_fmc.post()
        fmc_public = fmcapi.Hosts(fmc=fmc1, name="fmc_public_ip", value="100.64.0.10")
        fmc_public.post()

        # Create ACP Rule to permit hq_lan traffic inside to outside.
        hq_acprule = fmcapi.AccessRules(
            fmc=fmc1,
            acp_name=acp.name,
            name="Permit HQ LAN",
            action="ALLOW",
            enabled=True,
        )
        hq_acprule.source_zone(action="add", name=sz_inside.name)
        hq_acprule.destination_zone(action="add", name=sz_outside.name)
        hq_acprule.source_network(action="add", name=hq_lan.name)
        hq_acprule.destination_network(action="add", name="any-ipv4")
github daxm / fmcapi / example / mixed_logic_and_data / hq-ftd.py View on Github external
acp.post()

        # Create Security Zones
        sz_inside = fmcapi.SecurityZones(
            fmc=fmc1, name="inside", interfaceMode="ROUTED"
        )
        sz_inside.post()
        sz_outside = fmcapi.SecurityZones(
            fmc=fmc1, name="outside", interfaceMode="ROUTED"
        )
        sz_outside.post()
        sz_dmz = fmcapi.SecurityZones(fmc=fmc1, name="dmz", interfaceMode="ROUTED")
        sz_dmz.post()

        # Create Network Objects
        hq_dfgw_gateway = fmcapi.Hosts(
            fmc=fmc1, name="hq-default-gateway", value="100.64.0.1"
        )
        hq_dfgw_gateway.post()
        hq_lan = fmcapi.Networks(fmc=fmc1, name="hq-lan", value="10.0.0.0/24")
        hq_lan.post()
        all_lans = fmcapi.Networks(fmc=fmc1, name="all-lans", value="10.0.0.0/8")
        all_lans.post()
        hq_fmc = fmcapi.Hosts(fmc=fmc1, name="hq_fmc", value="10.0.0.10")
        hq_fmc.post()
        fmc_public = fmcapi.Hosts(fmc=fmc1, name="fmc_public_ip", value="100.64.0.10")
        fmc_public.post()

        # Create ACP Rule to permit hq_lan traffic inside to outside.
        hq_acprule = fmcapi.AccessRules(
            fmc=fmc1,
            acp_name=acp.name,