# 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
)

def _update_source_and_target_runtime_props(ctx, **kwargs):
    ctx.source.instance.update()
    ctx.target.instance.update()


@operation(resumable=True)
def create_list(ctx, **kwargs):
    resource_config = ctx.node.properties.get('resource_config', None)

    if not isinstance(resource_config, list):
        raise NonRecoverableError(
            'The "resource_config" property must be of type: list')

    ctx.logger.debug('Initializing resources list...')
    ctx.instance.runtime_properties[RESOURCES_LIST_PROPERTY] = resource_config
    ctx.instance.runtime_properties[FREE_RESOURCES_LIST_PROPERTY] = \
        resource_config
    ctx.instance.runtime_properties[RESERVATIONS_PROPERTY] = {}


@operation(resumable=True)
def create_list_item(ctx, **kwargs):
    ctx.logger.debug('Initializing list item...')
    ctx.instance.runtime_properties[SINGLE_RESERVATION_PROPERTY] = ''


@operation(resumable=True)
def delete_list_item(ctx, **kwargs):
    ctx.logger.debug('Removing list item: {}'.format(

# 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
)


def _update_source_and_target_runtime_props(ctx, **kwargs):
    ctx.source.instance.update()
    ctx.target.instance.update()


@operation(resumable=True)
def create_list(ctx, **kwargs):
    resource_config = ctx.node.properties.get('resource_config', None)

    if not isinstance(resource_config, list):
        raise NonRecoverableError(
            'The "resource_config" property must be of type: list')

    ctx.logger.debug('Initializing resources list...')
    ctx.instance.runtime_properties[RESOURCES_LIST_PROPERTY] = resource_config
    ctx.instance.runtime_properties[FREE_RESOURCES_LIST_PROPERTY] = \
        resource_config
    ctx.instance.runtime_properties[RESERVATIONS_PROPERTY] = {}


@operation(resumable=True)
def create_list_item(ctx, **kwargs):
    ctx.logger.debug('Initializing list item...')
    ctx.instance.runtime_properties[SINGLE_RESERVATION_PROPERTY] = ''


@operation(resumable=True)
def delete_list_item(ctx, **kwargs):
    ctx.logger.debug('Removing list item: {}'.format(

        ctx.instance.runtime_properties.get(SINGLE_RESERVATION_PROPERTY)))