Creates Nova flavor if it does not exist

    :param name: Flavor name
    :param params: Definition of the Flavor (see Compute API documentation)

    .. code-block:: yaml

        nova-flavor-present:
            nova.flavor_present:
                - name: myflavor
                - params:
                    ram: 2
                    vcpus: 1
                    disk: 10
                    is_public: False

def flavor_present(name, params=None, **kwargs):
    '''
    Creates Nova flavor if it does not exist

    :param name: Flavor name
    :param params: Definition of the Flavor (see Compute API documentation)

    .. code-block:: yaml

        nova-flavor-present:
            nova.flavor_present:
                - name: myflavor
                - params:
                    ram: 2
                    vcpus: 1
                    disk: 10
                    is_public: False
    '''
    dry_run = __opts__['test']
    ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}

    if params is None:
        params = {}

    try:
        kwargs.update({'filter': {'is_public': None}})
        object_list = __salt__['nova.flavor_list'](**kwargs)
        object_exists = True if object_list[name]['name'] == name else False
    except KeyError:
        object_exists = False

    if object_exists:
        ret['result'] = True
        ret['comment'] = 'Flavor "{0}" already exists.'.format(name)
    else:
        if dry_run:
            ret['result'] = None
            ret['comment'] = 'Flavor "{0}" would be created.'.format(name)
            ret['changes'] = {name: {'old': 'Flavor "{0}" does not exist.'.format(name),
                                     'new': params}}
        else:
            combined = kwargs.copy()
            combined.update(params)
            flavor_create = __salt__['nova.flavor_create'](name, **combined)

            if flavor_create:
                ret['result'] = True
                ret['comment'] = 'Flavor "{0}" created.'.format(name)
                ret['changes'] = {name: {'old': 'Flavor "{0}" does not exist.'.format(name),
                                         'new': flavor_create}}

    return ret