def present_strategy(api, wished_ip):
    changed = False
    response = api.get('ips')
    if (not response.ok):
        api.module.fail_json(msg='Error getting IPs [{0}: {1}]'.format(response.status_code, response.json['message']))
    ips_list = response.json['ips']
    ip_lookup = dict(((ip['id'], ip) for ip in ips_list))
    if (wished_ip['id'] not in ip_lookup.keys()):
        changed = True
        if api.module.check_mode:
            return (changed, {'status': 'An IP would be created.'})
        creation_response = api.post('/ips', data=payload_from_wished_ip(wished_ip))
        if (not creation_response.ok):
            msg = ("Error during ip creation: %s: '%s' (%s)" % (creation_response.info['msg'], creation_response.json['message'], creation_response.json))
            api.module.fail_json(msg=msg)
        return (changed, creation_response.json['ip'])
    target_ip = ip_lookup[wished_ip['id']]
    patch_payload = ip_attributes_should_be_changed(api=api, target_ip=target_ip, wished_ip=wished_ip)
    if (not patch_payload):
        return (changed, target_ip)
    changed = True
    if api.module.check_mode:
        return (changed, {'status': 'IP attributes would be changed.'})
    ip_patch_response = api.patch(path=('ips/%s' % target_ip['id']), data=patch_payload)
    if (not ip_patch_response.ok):
        api.module.fail_json(msg='Error during IP attributes update: [{0}: {1}]'.format(ip_patch_response.status_code, ip_patch_response.json['message']))
    return (changed, ip_patch_response.json['ip'])
def present_strategy(api, wished_ip):
    changed = False
    response = api.get('ips')
    if (not response.ok):
        api.module.fail_json(msg='Error getting IPs [{0}: {1}]'.format(response.status_code, response.json['message']))
    ips_list = response.json['ips']
    ip_lookup = dict(((ip['id'], ip) for ip in ips_list))
    if (wished_ip['id'] not in ip_lookup.keys()):
        changed = True
        if api.module.check_mode:
            return (changed, {'status': 'An IP would be created.'})
        creation_response = api.post('/ips', data=payload_from_wished_ip(wished_ip))
        if (not creation_response.ok):
            msg = ("Error during ip creation: %s: '%s' (%s)" % (creation_response.info['msg'], creation_response.json['message'], creation_response.json))
            api.module.fail_json(msg=msg)
        return (changed, creation_response.json['ip'])
    target_ip = ip_lookup[wished_ip['id']]
    patch_payload = ip_attributes_should_be_changed(api=api, target_ip=target_ip, wished_ip=wished_ip)
    if (not patch_payload):
        return (changed, target_ip)
    changed = True
    if api.module.check_mode:
        return (changed, {'status': 'IP attributes would be changed.'})
    ip_patch_response = api.patch(path=('ips/%s' % target_ip['id']), data=patch_payload)
    if (not ip_patch_response.ok):
        api.module.fail_json(msg='Error during IP attributes update: [{0}: {1}]'.format(ip_patch_response.status_code, ip_patch_response.json['message']))
    return (changed, ip_patch_response.json['ip'])