# -*- coding: utf-8 -*-
'''
Custom Nova state
'''
import logging
import collections
from functools import wraps
LOG = logging.getLogger(__name__)


def __virtual__():
    '''
    Only load if the nova module is in __salt__
    '''
    return 'novang'


def flavor_present(name, flavor_id=0, ram=0, disk=0, vcpus=1, profile=None):
    '''
    Ensures that the nova flavor exists
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': 'Flavor "{0}" already exists'.format(name)}
    project = __salt__['novang.flavor_list'](profile)
    if 'Error' in project:
        pass
    elif name in project:
        pass
    else:
        __salt__['novang.flavor_create'](name, flavor_id, ram, disk, vcpus, profile)
        ret['comment'] = 'Flavor {0} has been created'.format(name)
        ret['changes']['Flavor'] = 'Created'
    return ret


def map_instances(name='cell1'):
    '''
    Ensures that the nova instances are mapped to cell
    '''
    ret = {'name': name,
           'changes': {},
           'result': False,
           'comment': 'Cell "{0}" does not exists'.format(name)}
    cell_uuid = __salt__['cmd.shell']('nova-manage cell_v2 list_cells 2>/dev/null | awk \'/' + name + '/ {print $4}\'')
    if cell_uuid:
        try:
            __salt__['cmd.shell']('nova-manage cell_v2 map_instances --cell_uuid ' + cell_uuid)
            ret['result'] = True
            ret['comment'] = 'Instances were mapped to cell named {0}'.format(name)
            ret['changes']['Instances'] = 'Mapped to cell named {0}'.format(name)
        except:
            ret['result'] = False
            ret['comment'] = 'Error while mapping instances to cell named {0}'.format(name)
            ret['changes']['Instances'] = 'Failed to map to cell named {0}'.format(name)
    return ret


def update_cell(name='cell1', transport_url='none:///', db_engine='mysql', db_name='nova_upgrade', db_user='nova', db_password=None, db_address='0.0.0.0'):
    '''
    Ensures that the nova cell is setup correctly
    '''
    ret = {'name': name,
           'changes': {},
           'result': False,
           'comment': 'Cell "{0}" does not exists'.format(name)}
    cell_uuid, ssl_enable = (__salt__['cmd.shell']('nova-manage cell_v2 list_cells 2>/dev/null | awk \'/' + name + '/ {print $4, $8}\'')).split(' ', 1)
    if 'ssl' in ssl_enable:
        db_options = '?charset=utf8&ssl_ca=/etc/nova/ssl/mysql/ca-cert.pem&ssl_cert=/etc/nova/ssl/mysql/client-cert.pem&ssl_key=/etc/nova/ssl/mysql/client-key.pem'
    else:
        db_options = '?charset=utf8'
    if cell_uuid:
        try:
            __salt__['cmd.shell']('nova-manage cell_v2 update_cell --cell_uuid ' + cell_uuid + ' --transport-url ' + transport_url + ' --database_connection ' + '"' + db_engine + '+pymysql://' + db_user + ':' + db_password + '@' + db_address + '/' + db_name + db_options + '"')
            ret['result'] = True
            ret['comment'] = 'Cell {0} updated'.format(name)
            ret['changes'][name] = 'Cell {0} successfuly updated'.format(name)
        except:
            ret['result'] = False
            ret['comment'] = 'Cell {0} not updated'.format(name)
            ret['changes'][name] = 'Cell {0} failed to be updated'.format(name)
    return ret


def api_db_version_present(name=None, version="20"):
    '''
    Ensures that specific api_db version is present
    '''
    ret = {'name': 'api_db --version',
           'changes': {},
           'result': True,
           'comment': 'Current Api_db version is not < than "{0}".'.format(version)}
    api_db_version = __salt__['cmd.shell']('nova-manage api_db version 2>/dev/null')
    try:
        api_db_version = int(api_db_version)
        version = int(version)
    except:
        # nova is not installed
        ret = _no_change('api_db --version', None, test=True)
        return ret
    if api_db_version < version:
        try:
            __salt__['cmd.shell']('nova-manage api_db sync --version ' + str(version))
            ret['result'] = True
            ret['comment'] = 'Nova-manage api_db sync --version {0} was successfuly executed'.format(version)
            ret['changes']['api_db'] = 'api_db sync --version {0}'.format(version)
        except:
            ret['result'] = False
            ret['comment'] = 'Error while executing nova-manage api_db sync --version {0}'.format(version)
            ret['changes']['api_db'] = 'Failed to execute api_db sync --version {0}'.format(version)
    return ret


def db_version_present(name=None, version="334"):
    '''
    Ensures that specific api_db version is present
    '''
    ret = {'name': 'db --version',
           'changes': {},
           'result': True,
           'comment': 'Current db version is not < than "{0}".'.format(version)}
    db_version = __salt__['cmd.shell']('nova-manage db version 2>/dev/null')
    try:
        db_version = int(db_version)
        version = int(version)
    except:
        # nova is not installed
        ret = _no_change('db --version', None, test=True)
        return ret

    if db_version < version:
        try:
            __salt__['cmd.shell']('nova-manage db sync --version ' + str(version))
            ret['result'] = True
            ret['comment'] = 'Nova-manage db sync --version {0} was successfuly executed'.format(version)
            ret['changes']['db'] = 'db sync --version {0}'.format(version)
        except:
            ret['result'] = False
            ret['comment'] = 'Error while executing nova-manage db sync --version {0}'.format(version)
            ret['changes']['db'] = 'Failed to execute db sync --version {0}'.format(version)
    return ret

def online_data_migrations_present(name=None, api_db_version="20", db_version="334"):
    '''
    Ensures that online_data_migrations are enforced if specific version of api_db and db is present
    '''
    ret = {'name': 'online_data_migrations',
           'changes': {},
           'result': True,
           'comment': 'Current api_db version != {0} a db version != {1}.'.format(api_db_version, db_version)}
    cur_api_db_version = __salt__['cmd.shell']('nova-manage api_db version 2>/dev/null')
    cur_db_version = __salt__['cmd.shell']('nova-manage db version 2>/dev/null')
    try:
        cur_api_db_version = int(cur_api_db_version)
        cur_db_version = int(cur_db_version)
        api_db_version = int(api_db_version)
        db_version = int(db_version)
    except:
        # nova is not installed
        ret = _no_change('online_data_migrations', None, test=True)
        return ret
    if cur_api_db_version == api_db_version and cur_db_version == db_version:
        try:
            __salt__['cmd.shell']('nova-manage db online_data_migrations')
            ret['result'] = True
            ret['comment'] = 'nova-manage db online_data_migrations was successfuly executed'
            ret['changes']['online_data_migrations'] = 'online_data_migrations on api_db version {0} and db version {1}'.format(api_db_version, db_version)
        except:
            ret['result'] = False
            ret['comment'] = 'Error while executing nova-manage db online_data_migrations'
            ret['changes']['online_data_migrations'] = 'Failed to execute online_data_migrations on api_db version {0} and db version {1}'.format(api_db_version, db_version)
    return ret

def quota_present(tenant_name, profile, name=None, **kwargs):
    '''
    Ensures that the nova quota exists
    '''
    changes = {}
    for key, value in kwargs.items():
        quota = __salt__['novang.quota_get'](key, tenant_name, profile)
        if quota != value:
            arg = {}
            arg[key] = value
            changes[key] = value
            __salt__['novang.quota_update'](tenant_name, profile, **arg)
    if bool(changes):
        return _updated(tenant_name, 'tenant', changes)
    else:
        return _no_change(tenant_name, 'tenant')


def availability_zone_present(name=None, availability_zone=None, profile=None):
    '''
    Ensures that the nova availability zone exists
    '''
    name = availability_zone
    zone_exists = __salt__['novang.availability_zone_get'](name, profile)
    if zone_exists == False:
        item_created = __salt__['novang.availability_zone_create'](name, availability_zone, profile)
        if bool(item_created):
            return _created(availability_zone, 'availabilty zone', item_created)
    else:
        return _already_exists(availability_zone, 'availabilty zone')
    return existing_availability_zones

def aggregate_present(name=None, aggregate=None, profile=None):
    '''
    Ensures that the nova aggregate exists
    '''
    name = aggregate
    aggregate_exists = __salt__['novang.aggregate_get'](name, profile)
    if aggregate_exists == False:
        item_created = __salt__['novang.aggregate_create'](name, aggregate, profile)
        if bool(item_created):
            return _created(aggregate, 'aggregate', item_created)
    else:
        return _already_exists(aggregate, 'aggregate')
    return existing_aggregate


def instance_present(name, flavor, image, networks, security_groups=None, profile=None, tenant_name=None):
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': 'Instance "{0}" already exists'.format(name)}
    kwargs = {}
    nics = []
    existing_instances = __salt__['novang.server_list'](profile, tenant_name)
    if name in existing_instances:
        return ret
    existing_flavors = __salt__['novang.flavor_list'](profile)
    if flavor in existing_flavors:
        flavor_id = existing_flavors[flavor]['id']
    else:
        return {'name': name,
                'changes': {},
                'result': False,
                'comment': 'Flavor "{0}" doesn\'t exists'.format(flavor)}

    existing_image = __salt__['novang.image_list'](image, profile)
    if not existing_image:
        return {'name': name,
                'changes': {},
                'result': False,
                'comment': 'Image "{0}" doesn\'t exists'.format(image)}
    else:
        image_id = existing_image.get(image).get('id')
    if security_groups is not None:
        kwargs['security_groups'] = []
        for secgroup in security_groups:
            existing_secgroups = __salt__['novang.secgroup_list'](profile, tenant_name)
            if not secgroup in existing_secgroups:
                return {'name': name,
                        'changes': {},
                        'result': False,
                        'comment': 'Security group "{0}" doesn\'t exists'.format(secgroup)}
            else:
                kwargs['security_groups'].append(secgroup)
    for net in networks:
        existing_network = __salt__['novang.network_show'](net.get('name'), profile)
        if not existing_network:
            return {'name': name,
                    'changes': {},
                    'result': False,
                    'comment': 'Network "{0}" doesn\'t exists'.format(net.get(name))}
        else:
            network_id = existing_network.get('id')
            if net.get('v4_fixed_ip') is not None:
                nics.append({'net-id': network_id, 'v4-fixed-ip': net.get('v4_fixed_ip')})
            else:
                nics.append({'net-id': network_id})
    kwargs['nics'] = nics
    new_instance_id = __salt__['novang.boot'] (name, flavor_id, image_id, profile, tenant_name, **kwargs)
    return {'name': name,
            'changes': {},
            'result': True,
            'comment': 'Instance "{0}" was successfuly created'.format(name)}


def keypair_present(name, pub_file=None, pub_key=None, profile=None):
    """
    Ensures that the Nova key-pair exists
    """

    existing_keypairs = __salt__['novang.keypair_list'](profile)
    if name in existing_keypairs:
        return _already_exists(name, 'Keypair')
    else:
        res = __salt__['novang.keypair_add'](name, pubfile=pub_file,
                                             pubkey=pub_key, profile=profile)
        if res and res['name'] == name:
            return _created(name, 'Keypair', res)
        return _create_failed(name, 'Keypair')


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


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