Exemple #1
0
    def get_inventory_host_nics_data(host: dict, ipv4_first=True):

        def get_network_interface_ip(interface):
            addresses = interface.ipv4_addresses + interface.ipv6_addresses if ipv4_first else \
                interface.ipv6_addresses + interface.ipv4_addresses
            return addresses[0].split("/")[0] if len(addresses) > 0 else None

        inventory = models.Inventory(**json.loads(host["inventory"]))
        interfaces_list = [models.Interface(**interface) for interface in inventory.interfaces]
        return [{'name': interface.name, 'model': interface.product, 'mac': interface.mac_address,
                 'ip': get_network_interface_ip(interface), 'speed': interface.speed_mbps} for interface in interfaces_list]
 def get_inventory_host_nics_data(self):
     interfaces_list = [
         models.Interface(**interface)
         for interface in self._inventory.interfaces
     ]
     return [{
         'name': interface.name,
         'model': interface.product,
         'mac': interface.mac_address,
         'ip': self._get_network_interface_ip(interface),
         'speed': interface.speed_mbps
     } for interface in interfaces_list]
Exemple #3
0
    def get_inventory_host_nics_data(host: dict, ipv4_first=True):
        def get_network_interface_ip(interface):
            addresses = (interface.ipv4_addresses + interface.ipv6_addresses
                         if ipv4_first else interface.ipv6_addresses +
                         interface.ipv4_addresses)
            return addresses[0].split("/")[0] if len(addresses) > 0 else None

        inventory = models.Inventory(**json.loads(host["inventory"]))
        interfaces_list = [
            models.Interface(**interface) for interface in inventory.interfaces
        ]
        return [{
            "name": interface.name,
            "model": interface.product,
            "mac": interface.mac_address,
            "ip": get_network_interface_ip(interface),
            "speed": interface.speed_mbps,
        } for interface in interfaces_list]