Beispiel #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]
Beispiel #2
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 __init__(self, host_dict):
     self._host = models.Host(**host_dict)
     self._inventory = models.Inventory(**json.loads(self._host.inventory))