Ensure that an item is created

    name
        Irrelevant, not used
    item
        config, property, resource, constraint etc.
    item_id
        id of the item
    item_type
        item type
    show
        show command (probably None, default: show)
    create
        create command (create or set f.e., default: create)
    extra_args
        additional options for the pcs command
    cibname
        use a cached CIB-file named like cibname instead of the live CIB

def _item_present(name, item, item_id, item_type, show='show', create='create', extra_args=None, cibname=None):
    '''
    Ensure that an item is created

    name
        Irrelevant, not used
    item
        config, property, resource, constraint etc.
    item_id
        id of the item
    item_type
        item type
    show
        show command (probably None, default: show)
    create
        create command (create or set f.e., default: create)
    extra_args
        additional options for the pcs command
    cibname
        use a cached CIB-file named like cibname instead of the live CIB
    '''
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    item_create_required = True

    cibfile = None
    if isinstance(cibname, six.string_types):
        cibfile = _get_cibfile(cibname)

    if not isinstance(extra_args, (list, tuple)):
        extra_args = []

    # split off key and value (item_id contains =)
    item_id_key = item_id
    item_id_value = None
    if '=' in item_id:
        item_id_key = item_id.split('=')[0].strip()
        item_id_value = item_id.replace(item_id.split('=')[0] + '=', '').strip()
        log.trace('item_id_key=%s item_id_value=%s', item_id_key, item_id_value)

    # constraints, properties, resource defaults or resource op defaults
    # do not support specifying an id on 'show' command
    item_id_show = item_id
    if item in ['constraint'] or '=' in item_id:
        item_id_show = None

    is_existing = __salt__['pcs.item_show'](item=item,
                                            item_id=item_id_show,
                                            item_type=item_type,
                                            show=show,
                                            cibfile=cibfile)
    log.trace(
        'Output of pcs.item_show item=%s item_id=%s item_type=%s cibfile=%s: %s',
        item, item_id_show, item_type, cibfile, is_existing
    )

    # key,value pairs (item_id contains =) - match key and value
    if item_id_value is not None:
        for line in is_existing['stdout'].splitlines():
            if len(line.split(':')) in [2]:
                key = line.split(':')[0].strip()
                value = line.split(':')[1].strip()
                if item_id_key in [key]:
                    if item_id_value in [value]:
                        item_create_required = False

    # constraints match on '(id:<id>)'
    elif item in ['constraint']:
        for line in is_existing['stdout'].splitlines():
            if '(id:{0})'.format(item_id) in line:
                item_create_required = False

    # item_id was provided,
    # return code 0 indicates, that resource already exists
    else:
        if is_existing['retcode'] in [0]:
            item_create_required = False

    if not item_create_required:
        ret['comment'] += '{0} {1} ({2}) is already existing\n'.format(
            six.text_type(item), six.text_type(item_id), six.text_type(item_type)
        )
        return ret

    if __opts__['test']:
        ret['result'] = None
        ret['comment'] += '{0} {1} ({2}) is set to be created\n'.format(
            six.text_type(item), six.text_type(item_id), six.text_type(item_type)
        )
        return ret

    item_create = __salt__['pcs.item_create'](
        item=item,
        item_id=item_id,
        item_type=item_type,
        create=create,
        extra_args=extra_args,
        cibfile=cibfile)

    log.trace('Output of pcs.item_create: %s', item_create)

    if item_create['retcode'] in [0]:
        ret['comment'] += 'Created {0} {1} ({2})\n'.format(item, item_id, item_type)
        ret['changes'].update({item_id: {'old': '', 'new': six.text_type(item_id)}})
    else:
        ret['result'] = False
        ret['comment'] += 'Failed to create {0} {1} ({2})\n'.format(item, item_id, item_type)

    log.trace('ret: %s', ret)

    return ret