# Path: cloudify_resources/constants.py
# RESOURCES_LIST_PROPERTY = 'resource_config'
# 
# FREE_RESOURCES_LIST_PROPERTY = 'free_resources'
# 
# RESERVATIONS_PROPERTY = 'reservations'
# 
# SINGLE_RESERVATION_PROPERTY = 'reservation'


from cloudify.decorators import operation
from cloudify.exceptions import NonRecoverableError
from .constants import (
    RESOURCES_LIST_PROPERTY,
    FREE_RESOURCES_LIST_PROPERTY,
    RESERVATIONS_PROPERTY,
    SINGLE_RESERVATION_PROPERTY
)
    _refresh_source_and_target_runtime_props(ctx)

    free_resources = \
        ctx.target.instance.runtime_properties.get(
            FREE_RESOURCES_LIST_PROPERTY)
    reservations = \
        ctx.target.instance.runtime_properties.get(
            RESERVATIONS_PROPERTY, {})

    ctx.source.instance.runtime_properties[SINGLE_RESERVATION_PROPERTY] = \
        free_resources.pop(0)

    ctx.target.instance.runtime_properties[FREE_RESOURCES_LIST_PROPERTY] = \
        free_resources

    reservations[ctx.source.instance.id] = \
        ctx.source.instance.runtime_properties.get(SINGLE_RESERVATION_PROPERTY)
    ctx.target.instance.runtime_properties[RESERVATIONS_PROPERTY] = \
        reservations

    _update_source_and_target_runtime_props(ctx)

    ctx.logger.debug('Reservation successful: {0}\
            \nLeft resources: {1}\
            \nReservations: {2}'.format(
        ctx.source.instance.runtime_properties.get(
            SINGLE_RESERVATION_PROPERTY),
        ctx.target.instance.runtime_properties.get(
            FREE_RESOURCES_LIST_PROPERTY),
        ctx.target.instance.runtime_properties.get(

# Path: cloudify_resources/constants.py
# RESOURCES_LIST_PROPERTY = 'resource_config'
# 
# FREE_RESOURCES_LIST_PROPERTY = 'free_resources'
# 
# RESERVATIONS_PROPERTY = 'reservations'
# 
# SINGLE_RESERVATION_PROPERTY = 'reservation'


# Path: cloudify_resources/tasks.py
from cloudify.decorators import operation
from cloudify.exceptions import NonRecoverableError
from .constants import (
    RESOURCES_LIST_PROPERTY,
    FREE_RESOURCES_LIST_PROPERTY,
    RESERVATIONS_PROPERTY,
    SINGLE_RESERVATION_PROPERTY
)

    _refresh_source_and_target_runtime_props(ctx)

    free_resources = \
        ctx.target.instance.runtime_properties.get(
            FREE_RESOURCES_LIST_PROPERTY)
    reservations = \
        ctx.target.instance.runtime_properties.get(
            RESERVATIONS_PROPERTY, {})

    ctx.source.instance.runtime_properties[SINGLE_RESERVATION_PROPERTY] = \
        free_resources.pop(0)

    ctx.target.instance.runtime_properties[FREE_RESOURCES_LIST_PROPERTY] = \
        free_resources

    reservations[ctx.source.instance.id] = \
        ctx.source.instance.runtime_properties.get(SINGLE_RESERVATION_PROPERTY)
    ctx.target.instance.runtime_properties[RESERVATIONS_PROPERTY] = \
        reservations

    _update_source_and_target_runtime_props(ctx)

    ctx.logger.debug('Reservation successful: {0}\
            \nLeft resources: {1}\
            \nReservations: {2}'.format(
        ctx.source.instance.runtime_properties.get(
            SINGLE_RESERVATION_PROPERTY),
        ctx.target.instance.runtime_properties.get(
            FREE_RESOURCES_LIST_PROPERTY),
        ctx.target.instance.runtime_properties.get(

            RESERVATIONS_PROPERTY)