Ensure a network exists and is up-to-date

    name
        Name of the network

    provider
        A dict of network provider options.

    shared
        Set the network as shared.

    external
        Whether this network is externally accessible.

    admin_state_up
         Set the network administrative state to up.

    vlan
        Vlan ID. Alias for provider

        - physical_network: provider
        - network_type: vlan
        - segmentation_id: (vlan id)

def present(name, auth=None, **kwargs):
    '''
    Ensure a network exists and is up-to-date

    name
        Name of the network

    provider
        A dict of network provider options.

    shared
        Set the network as shared.

    external
        Whether this network is externally accessible.

    admin_state_up
         Set the network administrative state to up.

    vlan
        Vlan ID. Alias for provider

        - physical_network: provider
        - network_type: vlan
        - segmentation_id: (vlan id)
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    kwargs = __utils__['args.clean_kwargs'](**kwargs)

    __salt__['neutronng.setup_clouds'](auth)

    kwargs['name'] = name
    network = __salt__['neutronng.network_get'](name=name)

    if network is None:
        if __opts__['test'] is True:
            ret['result'] = None
            ret['changes'] = kwargs
            ret['comment'] = 'Network will be created.'
            return ret

        if 'vlan' in kwargs:
            kwargs['provider'] = {"physical_network": "provider",
                                  "network_type": "vlan",
                                  "segmentation_id": kwargs['vlan']}
            del kwargs['vlan']

        if 'project' in kwargs:
            projectname = kwargs['project']
            project = __salt__['keystoneng.project_get'](name=projectname)
            if project:
                kwargs['project_id'] = project.id
                del kwargs['project']
            else:
                ret['result'] = False
                ret['comment'] = "Project:{} not found.".format(projectname)
                return ret

        network = __salt__['neutronng.network_create'](**kwargs)
        ret['changes'] = network
        ret['comment'] = 'Created network'
        return ret

    changes = __salt__['neutronng.compare_changes'](network, **kwargs)

    # there's no method for network update in shade right now;
    # can only delete and recreate
    if changes:
        if __opts__['test'] is True:
            ret['result'] = None
            ret['changes'] = changes
            ret['comment'] = 'Project will be updated.'
            return ret

        __salt__['neutronng.network_delete'](name=network)
        __salt__['neutronng.network_create'](**kwargs)
        ret['changes'].update(changes)
        ret['comment'] = 'Updated network'

    return ret