# -*- coding: utf-8 -*-
'''
Management of Cinder resources
===============================
:depends:   - cinderclient Python module
'''
import ast
import logging
from functools import wraps
LOG = logging.getLogger(__name__)


def __virtual__():
    '''
    Only load if python-cinderclient is present in __salt__
    '''
    return 'cinderng'

def volume_type_present(name=None, profile=None):
    '''
    Ensures that the specified volume type is present.
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': 'Volume type "{0}" already exists'.format(name)}
    signal = __salt__['cinderng.create_volume_type'](name, profile)
    if 'exists' in signal:
        pass
    elif 'created' in signal:
        ret['comment'] = 'Volume type {0} has been created'.format(name)
        ret['changes']['Volume type'] = 'Created'
    elif 'failed' in signal:
        ret = {'name': name,
               'changes': {},
               'result': False,
               'comment': 'Volume type "{0}" failed to create'.format(name)}
    return ret

def volume_type_key_present(name=None, key=None, value=None, profile=None):
    '''
    Ensures that the extra specs are present on a volume type.
    '''
    keys = "{u'" + key + "': u'" + value + "'}"
    keys = ast.literal_eval(keys)
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': 'Volume type keys "{0}" in volume type "{1}" already exist'.format(keys, name)}
    signal = __salt__['cinderng.set_keys_volume_type'](name, keys, profile)
    if 'exist' in signal:
        pass
    elif 'updated' in signal:
        ret['comment'] = 'Volume type keys "{0}" in volume type "{1}" have been updated'.format(keys, name)
        ret['changes']['Volume type keys'] = 'Updated'
    elif 'failed' in signal:
        ret = {'name': name,
               'changes': {},
               'result': False,
               'comment': 'Volume type keys "{0}" in volume type "{1}" failed to update'.format(keys, name)}
    elif 'not found' in signal:
        ret = {'name': name,
               'changes': {},
               'result': False,
               'comment': 'Volume type "{0}" was not found'.format(name)}
    return ret


def _already_exists(name, resource):
    changes_dict = {'name': name,
                    'changes': {},
                    'result': True}
    changes_dict['comment'] = \
        '{0} {1} already exists'.format(resource, name)
    return changes_dict


def _created(name, resource, resource_definition):
    changes_dict = {'name': name,
                    'changes': resource_definition,
                    'result': True,
                    'comment': '{0} {1} created'.format(resource, name)}
    return changes_dict

def _updated(name, resource, resource_definition):
    changes_dict = {'name': name,
                    'changes': resource_definition,
                    'result': True,
                    'comment': '{0} {1} tenant was updated'.format(resource, name)}
    return changes_dict

def _update_failed(name, resource):
    changes_dict = {'name': name,
                    'changes': {},
                    'comment': '{0} {1} failed to update'.format(resource, name),
                    'result': False}
    return changes_dict

def _no_change(name, resource, test=False):
    changes_dict = {'name': name,
                    'changes': {},
                    'result': True}
    if test:
        changes_dict['comment'] = \
            '{0} {1} will be {2}'.format(resource, name, test)
    else:
        changes_dict['comment'] = \
            '{0} {1} is in correct state'.format(resource, name)
    return changes_dict
