How to use the fmcapi.api_objects.object_services.networkgroups.NetworkGroups 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 / fmcapi / api_objects / policy_services / manualnatrules.py View on Github external
def patPool(self, name, options={}):
        """
        Associate a PAT Pool.

        :param name: (str) Name of PAT Pool.
        :param options: (dict) key/value of options.
        :return: None
        """
        ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
        networkgroup_json = NetworkGroups(fmc=self.fmc).get()
        items = ipaddresses_json.get("items", []) + networkgroup_json.get("items", [])
        new_net = None
        for item in items:
            if item["name"] == name:
                new_net = {"name": item["name"], "id": item["id"], "type": item["type"]}
                break
        if new_net is None:
            logging.warning(
                f'Network "{name}" is not found in FMC.  Cannot add to patPool.'
            )
        else:
            self.natType = "DYNAMIC"
            self.unidirectional = True
            self.patOptions = {"patPoolAddress": new_net}
            self.patOptions["interfacePat"] = (
                options.interfacePat if "interfacePat" in options.keys() else False
github daxm / fmcapi / fmcapi / api_objects / policy_services / prefilterrules.py View on Github external
def find_group_object(self, name):
        """
        Search for group object by name
        Args:
            name (str): Name of group object
        Returns:
            id (str), type (str) or None None
        """
        group_object = NetworkGroups(fmc=self.fmc, name=name)
        resp = group_object.get()

        return self._return_id_type(resp)
github daxm / fmcapi / fmcapi / api_objects / object_services / networkgroups.py View on Github external
)
                else:
                    if "objects" in self.__dict__:
                        duplicate = False
                        for obj in self.objects:
                            if obj["name"] == new_net["name"]:
                                duplicate = True
                                break
                        if not duplicate:
                            self.objects.append(new_net)
                            logging.info(f'Adding "{name}" to NetworkGroups.')
                    else:
                        self.objects = [new_net]
                        logging.info(f'Adding "{name}" to NetworkGroups.')
        if action == "addgroup":
            netg1 = NetworkGroups(fmc=self.fmc)
            response = netg1.get()
            if "items" in response:
                new_net = None
                for item in response["items"]:
                    if item["name"] == name:
                        new_net = {
                            "name": item["name"],
                            "id": item["id"],
                            "type": item["type"],
                        }
                        break
                if new_net is None:
                    logging.warning(
                        f'Network "{name}" is not found in FMC.  Cannot add to NetworkGroups.'
                    )
                else:
github daxm / fmcapi / fmcapi / api_objects / object_services / networkgroups.py View on Github external
for obj in self.literals:
                    if obj["value"] != value:
                        literals_list.append(obj)
                self.literals = literals_list
                logging.info(f'Removed "{value}" from NetworkGroup.')
            else:
                logging.info(
                    "This NetworkGroups has no unnamed_networks.  Nothing to remove."
                )
        elif action == "clear":
            if "literals" in self.__dict__:
                del self.literals
                logging.info("All unnamed_networks removed from this NetworkGroups.")


class NetworkGroup(NetworkGroups):
    """
    Dispose of this Class after 20210101.

    Use NetworkGroups() instead.
    """

    def __init__(self, fmc, **kwargs):
        warnings.resetwarnings()
        warnings.warn(
            "Deprecated: NetworkGroup() should be called via NetworkGroups()."
        )
        super().__init__(fmc, **kwargs)
github daxm / fmcapi / fmcapi / api_objects / policy_services / autonatrules.py View on Github external
def patPool(self, name, options={}):
        """
        Associate a PAT Pool with this rule.

        :param name: (str) Name of PAT Pool.
        :param options: (dict) Dictionary of options.
        :return: None
        """
        # Network Group Object permitted for patPool
        ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
        networkgroup_json = NetworkGroups(fmc=self.fmc).get()
        items = ipaddresses_json.get("items", []) + networkgroup_json.get("items", [])
        new_net = None
        for item in items:
            if item["name"] == name:
                new_net = {"name": item["name"], "id": item["id"], "type": item["type"]}
                break
        if new_net is None:
            logging.warning(
                f'Network "{name}" is not found in FMC.  Cannot add to patPool.'
            )
        else:
            self.natType = "DYNAMIC"
            self.patOptions = {"patPoolAddress": new_net}
            self.patOptions["interfacePat"] = (
                options.interfacePat if "interfacePat" in options.keys() else False
            )
github daxm / fmcapi / fmcapi / api_objects / policy_services / manualnatrules.py View on Github external
def original_destination(self, name):
        """
        Associate Network to be used as Original Destination.

        :param name: (str) Name of Network.
        :return: None
        """
        logging.debug("In original_destination() for ManualNatRules class.")
        ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
        networkgroup_json = NetworkGroups(
            fmc=self.fmc
        ).get()  # FIXME, shouldn't this be a part of items?
        items = ipaddresses_json.get("items", [])
        new_net = None
        for item in items:
            if item["name"] == name:
                new_net = {"id": item["id"], "type": item["type"]}
                break
        if new_net is None:
            logging.warning(
                f'Network "{name}" is not found in FMC.  Cannot add to original_destination.'
            )
        else:
            self.originalDestination = new_net
            logging.info(
                f'Adding "{name}" to original_destination for this ManualNatRule.'
github daxm / fmcapi / fmcapi / api_objects / policy_services / manualnatrules.py View on Github external
def translated_destination(self, name):
        """
        Associate Network to be used as Translated Destination.

        :param name: (str) Name of Network.
        :return: None
        """
        logging.debug("In translated_destination() for ManualNatRules class.")
        ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
        networkgroup_json = NetworkGroups(
            fmc=self.fmc
        ).get()  # FIXME, shouldn't this be a part of items?
        items = ipaddresses_json.get("items", [])
        new_net = None
        for item in items:
            if item["name"] == name:
                new_net = {"id": item["id"], "type": item["type"]}
                break
        if new_net is None:
            logging.warning(
                f'Network "{name}" is not found in FMC.  Cannot add to translated_destination.'
            )
        else:
            self.translatedDestination = new_net
            logging.info(
                f'Adding "{name}" to translated_destination for this ManualNatRule.'
github daxm / fmcapi / fmcapi / api_objects / device_services / ipv6staticroutes.py View on Github external
)
                    else:
                        self.selectedNetworks = [
                            {
                                "type": net1[0]["type"],
                                "id": net1[0]["id"],
                                "name": net1[0]["name"],
                            }
                        ]
                else:
                    logging.warning(
                        f'Network "{network}" not found.  Cannot set up device for IPv6StaticRoute.'
                    )
        elif action == "remove":
            ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
            networkgroup_json = NetworkGroups(fmc=self.fmc).get()
            items = ipaddresses_json.get("items", []) + networkgroup_json.get(
                "items", []
            )
            for network in networks:
                net1 = list(filter(lambda i: i["name"] == network, items))
                if len(net1) > 0:
                    if "selectedNetworks" in self.__dict__:
                        self.selectedNetworks = list(
                            filter(
                                lambda i: i["id"] != net1[0]["id"],
                                self.selectedNetworks,
                            )
                        )
                    else:
                        logging.warning(
                            "No selectedNetworks found for this Device's IPv6StaticRoute."
github daxm / fmcapi / fmcapi / api_objects / policy_services / endpoints.py View on Github external
def encryption_domain(self, action, names=[]):
        """
        Associate Encryption.

        :param action: (str) 'add', 'remove', or 'clear'.
        :param names: (list) List of Encryption names.
        """
        logging.debug("In endpoint() for Endpoints class.")
        fqdns_json = FQDNS(fmc=self.fmc).get()
        host_json = Hosts(fmc=self.fmc).get()
        net_json = Networks(fmc=self.fmc).get()
        netg_json = NetworkGroups(fmc=self.fmc).get()
        items = (
            fqdns_json.get("items", [])
            + host_json.get("items", [])
            + net_json.get("items", [])
            + netg_json.get("items", [])
        )
        new_network = None

        if action == "add":
            for name in names:
                for item in items:
                    if item["name"] == name:
                        new_network = {"id": item["id"], "type": item["type"]}
                        break
                if new_network is None:
                    logging.warning(