def flavor_access_list(name, projects, **kwargs):
    '''
    Grants access of the flavor to a project. Flavor must be private.

    :param name: non-public flavor name
    :param projects: list of projects which should have the access to the flavor

    .. code-block:: yaml

        nova-flavor-share:
            nova.flavor_project_access:
                - name: myflavor
                - project:
                    - project1
                    - project2

    To remove all project from access list:
    .. code-block:: yaml
        - project: []
    '''
    dry_run = __opts__['test']
    ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
    kwargs.update({'filter': {'is_public': False}})
    try:
        flavor_list = __salt__['nova.flavor_list'](**kwargs)
        flavor_id = flavor_list[name]['id']
    except KeyError:
        raise

    project_list = __salt__['keystone.project_list'](**kwargs)
    access_list = __salt__['nova.flavor_access_list'](flavor_id, **kwargs)
    existing_list = [six.text_type(pname) for pname in project_list
                     if project_list[pname]['id'] in access_list[flavor_id]]
    defined_list = [six.text_type(project) for project in projects]
    add_list = set(defined_list) - set(existing_list)
    remove_list = set(existing_list) - set(defined_list)

    if not add_list and not remove_list:
        ret['result'] = True
        ret['comment'] = 'Flavor "{0}" access list corresponds to defined one.'.format(name)
    else:
        if dry_run:
            ret['result'] = None
            ret['comment'] = 'Flavor "{0}" access list would be corrected.'.format(name)
            ret['changes'] = {name: {'new': defined_list, 'old': existing_list}}
        else:
            added = []
            removed = []
            if add_list:
                for project in add_list:
                    added.append(__salt__['nova.flavor_access_add'](flavor_id, project_list[project]['id'], **kwargs))
            if remove_list:
                for project in remove_list:
                    removed.append(__salt__['nova.flavor_access_remove'](flavor_id,
                                                                         project_list[project]['id'], **kwargs))
            if any(add_list) or any(remove_list):
                ret['result'] = True
                ret['comment'] = 'Flavor "{0}" access list corrected.'.format(name)
                ret['changes'] = {name: {'new': defined_list, 'old': existing_list}}

    return ret
def flavor_access_list ( name , projects , ** kwargs ) : dry_run = __opts__ [ 'test' ] ret = { 'name' : name , 'result' : False , 'comment' : '' , 'changes' : { } } kwargs . update ( { 'filter' : { 'is_public' : False } } ) try : flavor_list = __salt__ [ 'nova.flavor_list' ] ( ** kwargs ) flavor_id = flavor_list [ name ] [ 'id' ] except KeyError : raise project_list = __salt__ [ 'keystone.project_list' ] ( ** kwargs ) access_list = __salt__ [ 'nova.flavor_access_list' ] ( flavor_id , ** kwargs ) existing_list = [ six . text_type ( pname ) for pname in project_list if project_list [ pname ] [ 'id' ] in access_list [ flavor_id ] ] defined_list = [ six . text_type ( project ) for project in projects ] add_list = set ( defined_list ) - set ( existing_list ) remove_list = set ( existing_list ) - set ( defined_list ) if not add_list and not remove_list : ret [ 'result' ] = True ret [ 'comment' ] = 'Flavor "{0}" access list corresponds to defined one.' . format ( name ) else : if dry_run : ret [ 'result' ] = None ret [ 'comment' ] = 'Flavor "{0}" access list would be corrected.' . format ( name ) ret [ 'changes' ] = { name : { 'new' : defined_list , 'old' : existing_list } } else : added = [ ] removed = [ ] if add_list : for project in add_list : added . append ( __salt__ [ 'nova.flavor_access_add' ] ( flavor_id , project_list [ project ] [ 'id' ] , ** kwargs ) ) if remove_list : for project in remove_list : removed . append ( __salt__ [ 'nova.flavor_access_remove' ] ( flavor_id , project_list [ project ] [ 'id' ] , ** kwargs ) ) if any ( add_list ) or any ( remove_list ) : ret [ 'result' ] = True ret [ 'comment' ] = 'Flavor "{0}" access list corrected.' . format ( name ) ret [ 'changes' ] = { name : { 'new' : defined_list , 'old' : existing_list } } return ret
Grants access of the flavor to a project. Flavor must be private.

    :param name: non-public flavor name
    :param projects: list of projects which should have the access to the flavor

    .. code-block:: yaml

        nova-flavor-share:
            nova.flavor_project_access:
                - name: myflavor
                - project:
                    - project1
                    - project2

    To remove all project from access list:
    .. code-block:: yaml
        - project: []