Example #1
0
    def vpn_interface(self, device_name, ifname):
        """
        Associate an interface.

        :param device_name: (str) Name of device.
        :param ifname: (str) Name of interface.
        """
        logging.debug("In vpn_interface() for Endpoints class.")
        ether_json = EtherchannelInterfaces(fmc=self.fmc, device_name=device_name).get()
        phys_json = PhysicalInterfaces(fmc=self.fmc, device_name=device_name).get()
        redund_json = RedundantInterfaces(fmc=self.fmc, device_name=device_name).get()
        subintf_json = SubInterfaces(fmc=self.fmc, device_name=device_name).get()
        items = (
            ether_json.get("items", [])
            + phys_json.get("items", [])
            + redund_json.get("items", [])
            + subintf_json.get("items", [])
        )
        new_intf = None
        for item in items:
            if item["ifname"] == ifname:
                new_intf = {"id": item["id"], "type": item["type"]}
                break
        if new_intf is None:
            logging.warning(
                f'Interface "{ifname}" is not found in FMC.  Cannot add to interface.'
            )
        else:
            self.interface = new_intf
            logging.info(f'Interface "{ifname}" added.')
    def p_interface(self, device_name="", action="add", names=[]):
        """
        Associate Physical Interface.

        :param device_name: (str) Name of device.
        :param action: (str) 'add', 'remove', or 'clear'
        :param names: (list) List of interface names
        """
        logging.debug("In interfaces() for InterfaceGroups class.")
        if action == "add":
            intfs = []
            for name in names:
                intf = PhysicalInterfaces(fmc=self.fmc)
                intf.get(name=name, device_name=device_name)
                if "id" in intf.__dict__ and "ifname" in intf.__dict__:
                    intfs.append({
                        "name": intf.name,
                        "id": intf.id,
                        "type": intf.type
                    })
                elif "id" in intf.__dict__:
                    logging.warning(
                        f'PhysicalInterface, "{name}", found without logical ifname.  '
                        f"Cannot add to InterfaceGroups.")
                else:
                    logging.warning(
                        f'PhysicalInterface, "{name}", not found.  Cannot add to InterfaceGroups.'
                    )
            if len(intfs) != 0:
                # Make sure we found at least one intf
                self.interfaces = intfs
            else:
                logging.warning(
                    f'No valid PhysicalInterface found: "{names}".  Cannot remove from InterfaceGroups.'
                )
        elif action == "remove":
            if "interfaces" in self.__dict__:
                intfs = []
                for interface in self.interfaces:
                    if interface["name"] not in names:
                        intfs.append(interface)
                    else:
                        logging.info(
                            f"""Removed "{interface['name']}" from InterfaceGroups."""
                        )
                self.interfaces = intfs
            else:
                logging.warning(
                    "This InterfaceObject has no interfaces.  Nothing to remove."
                )
        elif action == "clear" or action == "clear-all":
            if "interfaces" in self.__dict__:
                del self.interfaces
                logging.info(
                    "All PhysicalInterfaces removed from this InterfaceGroups."
                )
Example #3
0
 def p_interface(self, p_interface, device_name):
     logging.debug("In p_interface() for SubInterfaces class.")
     intf1 = PhysicalInterfaces(fmc=self.fmc)
     intf1.get(name=p_interface, device_name=device_name)
     if "id" in intf1.__dict__:
         self.name = intf1.name
         if "MTU" not in self.__dict__:
             self.MTU = intf1.MTU
     else:
         logging.warning(
             f'PhysicalInterface, "{intf1.name}", not found.  Cannot add to SubInterfaces.'
         )
 def p_interface(self, name, device_name):
     logging.debug(
         "In p_interface() for FailoverInterfaceMACAddressConfigs class.")
     intf1 = PhysicalInterfaces(fmc=self.fmc)
     intf1.get(name=name, device_name=device_name)
     if "id" in intf1.__dict__:
         self.physicalInterface = {
             "name": intf1.name,
             "id": intf1.id,
             "type": intf1.type,
         }
     else:
         logging.warning(
             f'PhysicalInterface, "{name}", not found.  '
             f"Cannot add to FailoverInterfaceMACAddressConfigs.")
 def p_interfaces(self, p_interfaces, device_name):
     logging.debug("In p_interfaces() for EtherchannelInterfaces class.")
     list1 = []
     for p_intf in p_interfaces:
         intf1 = PhysicalInterfaces(fmc=self.fmc)
         intf1.get(name=p_intf, device_name=device_name)
         if "id" in intf1.__dict__:
             list1.append({
                 "name": intf1.name,
                 "id": intf1.id,
                 "type": intf1.type
             })
         else:
             logging.warning(
                 f'PhysicalInterface, "{intf1.name}", not found.  Cannot add to EtherchannelInterfaces.'
             )
     self.selectedInterfaces = list1
Example #6
0
    def p_interface(self, p_interface, device_name):
        """
        Define which physical interface on which device is a part of this subinterface.

        :param p_interfaces: (str) Name of physical interface.
        :param device_name: (str) Name of device with that interface.
        :return: None
        """
        logging.debug("In p_interface() for SubInterfaces class.")
        intf1 = PhysicalInterfaces(fmc=self.fmc)
        intf1.get(name=p_interface, device_name=device_name)
        if "id" in intf1.__dict__:
            self.name = intf1.name
            if "MTU" not in self.__dict__:
                self.MTU = intf1.MTU
        else:
            logging.warning(
                f'PhysicalInterface, "{intf1.name}", not found.  Cannot add to SubInterfaces.'
            )
    def p_interfaces(self, p_interfaces, device_name):
        """
        Define which physical interface on which device is a part of this EtherChannel.

        :param p_interfaces: (str) Name of physical interface.
        :param device_name: (str) Name of device with that interface.
        :return: None
        """
        logging.debug("In p_interfaces() for EtherchannelInterfaces class.")
        list1 = []
        for p_intf in p_interfaces:
            intf1 = PhysicalInterfaces(fmc=self.fmc)
            intf1.get(name=p_intf, device_name=device_name)
            if "id" in intf1.__dict__:
                list1.append({"name": intf1.name, "id": intf1.id, "type": intf1.type})
            else:
                logging.warning(
                    f'PhysicalInterface, "{intf1.name}", not found.  Cannot add to EtherchannelInterfaces.'
                )
        self.selectedInterfaces = list1
    def p_interface(self, name, device_name):
        """
        Physical interface of device used for HA.

        :param name: (str) Name of interface.
        :param device_name (str) Name of device.
        :return: None
        """
        logging.debug(
            "In p_interface() for FailoverInterfaceMACAddressConfigs class.")
        intf1 = PhysicalInterfaces(fmc=self.fmc)
        intf1.get(name=name, device_name=device_name)
        if "id" in intf1.__dict__:
            self.physicalInterface = {
                "name": intf1.name,
                "id": intf1.id,
                "type": intf1.type,
            }
        else:
            logging.warning(
                f'PhysicalInterface, "{name}", not found.  '
                f"Cannot add to FailoverInterfaceMACAddressConfigs.")