def add_device(device, config, add_network):
    try:
        ip = device['ip']
        mac = ''
        mac = device['mac']
        family = device['family']
        blk_data = None
        dup_ip = 0
        added_ip = 0
        ip_obj = None
        if (family == '4'):
            blk_data = config.get_ip_range_by_ip('IP4Block', ip)
        else:
            blk_data = config.get_ip_range_by_ip('IP6Block', ip)
        network_data = None
        if (family == '4'):
            network_data = config.get_ip_range_by_ip('IP4Network', ip)
        else:
            network_data = config.get_ip_range_by_ip('IP6Network', ip)
        if ((blk_data is not None) and (network_data is not None)):
            ip_obj = assign_ip(network_data, ip, mac, family)
            added_ip += 1
    except PortalException as e:
        if add_network:
            try:
                if (blk_data is None):
                    block_network = ipaddress.ip_network((ip + '/30'), strict=False)
                    config.add_ip4_block_by_cidr(block_network.exploded)
                    blk_data = config.get_ip_range_by_ip('IP4Block', ip)
                if (blk_data is not None):
                    blk_data.add_ip4_network((ip + '/32'))
                    network_data = config.get_ip_range_by_ip('IP4Network', ip)
                    if (network_data is not None):
                        ip_obj = assign_ip(network_data, ip, mac, family)
                        added_ip += 1
            except APIException as ex:
                if ('Duplicate' in ex.get_message()):
                    dup_ip += 1
    except APIException as ex:
        if ('Duplicate' in ex.get_message()):
            dup_ip += 1
        else:
            app.loggererror(('add_ip: ' + ex.get_message()))
    return (added_ip, dup_ip, ip_obj)
def add_device(device, config, add_network):
    try:
        ip = device['ip']
        mac = 
        mac = device['mac']
        family = device['family']
        blk_data = None
        dup_ip = 0
        added_ip = 0
        ip_obj = None
        if (family == '4'):
            blk_data = config.get_ip_range_by_ip('IP4Block', ip)
        else:
            blk_data = config.get_ip_range_by_ip('IP6Block', ip)
        network_data = None
        if (family == '4'):
            network_data = config.get_ip_range_by_ip('IP4Network', ip)
        else:
            network_data = config.get_ip_range_by_ip('IP6Network', ip)
        if ((blk_data is not None) and (network_data is not None)):
            ip_obj = assign_ip(network_data, ip, mac, family)
            added_ip += 1
    except PortalException as e:
        if add_network:
            try:
                if (blk_data is None):
                    block_network = ipaddress.ip_network((ip + '/30'), strict=False)
                    config.add_ip4_block_by_cidr(block_network.exploded)
                    blk_data = config.get_ip_range_by_ip('IP4Block', ip)
                if (blk_data is not None):
                    blk_data.add_ip4_network((ip + '/32'))
                    network_data = config.get_ip_range_by_ip('IP4Network', ip)
                    if (network_data is not None):
                        ip_obj = assign_ip(network_data, ip, mac, family)
                        added_ip += 1
            except APIException as ex:
                if ('Duplicate' in ex.get_message()):
                    dup_ip += 1
    except APIException as ex:
        if ('Duplicate' in ex.get_message()):
            dup_ip += 1
        else:
            app.loggererror(('add_ip: ' + ex.get_message()))
    return (added_ip, dup_ip, ip_obj)