コード例 #1
0
 def _parse_machine_ip(machine):
     machine_ip_data = {}
     for ip_field, fields in MACHINE_IP_FIELDS.items():
         try:
             raw_field = machine.get(ip_field, None)
             machine_ip = ipaddress.ip_address(raw_field)
             machine_subnet = ipaddress.ip_network(machine_ip).supernet(
                 new_prefix=MACHINE_IP_PREFIXES[ip_field])
         except ValueError:
             machine_ip = None
             machine_subnet = None
         machine_ip_data[ip_field] = ''
         if machine_ip:
             machine_ip_data.update({
                 ip_field:
                 str(machine_ip),
                 '_'.join((ip_field, 'rdns')):
                 get_rdns_lookup(str(machine_ip)),
                 '_'.join((ip_field, 'subnet')):
                 str(machine_subnet)
             })
         for field in fields:
             if field not in machine_ip_data:
                 machine_ip_data[field] = NO_DATA
     return machine_ip_data
コード例 #2
0
 def _parse_machine_ip(self, machine):
     machine_ips = set()
     machine_ip_data = {}
     for ip_field, fields in MACHINE_IP_FIELDS.items():
         try:
             raw_field = machine.get(ip_field, None)
             machine_ip = str(ipaddress.ip_address(raw_field))
             machine_subnet = str(
                 ipaddress.ip_network(machine_ip).supernet(
                     new_prefix=MACHINE_IP_PREFIXES[ip_field]))
         except ValueError:
             machine_ip = None
             machine_subnet = None
         machine_ip_data[ip_field] = ''
         if machine_ip:
             machine_ips.add(machine_ip)
             machine_ip_data.update({
                 ip_field:
                 machine_ip,
                 '_'.join((ip_field, 'subnet')):
                 machine_subnet
             })
         for field in fields:
             if field not in machine_ip_data:
                 machine_ip_data[field] = NO_DATA
     machine.update(machine_ip_data)
     return machine_ips
コード例 #3
0
 def merge_machine_ip(old_machine, new_machine):
     for ip_field, fields in MACHINE_IP_FIELDS.items():
         ip = new_machine.get(ip_field, None)
         old_ip = old_machine.get(ip_field, None)
         if not ip and old_ip:
             new_machine[ip_field] = old_ip
             for field in fields:
                 if field in old_machine:
                     new_machine[field] = old_machine[field]