Create an LVM Volume Group

    name
        The Volume Group name to create

    devices
        A list of devices that will be added to the Volume Group

    kwargs
        Any supported options to vgcreate. See
        :mod:`linux_lvm <salt.modules.linux_lvm>` for more details.

def vg_present(name, devices=None, **kwargs):
    '''
    Create an LVM Volume Group

    name
        The Volume Group name to create

    devices
        A list of devices that will be added to the Volume Group

    kwargs
        Any supported options to vgcreate. See
        :mod:`linux_lvm <salt.modules.linux_lvm>` for more details.
    '''
    ret = {'changes': {},
           'comment': '',
           'name': name,
           'result': True}
    if isinstance(devices, six.string_types):
        devices = devices.split(',')

    if __salt__['lvm.vgdisplay'](name, quiet=True):
        ret['comment'] = 'Volume Group {0} already present'.format(name)
        for device in devices:
            realdev = os.path.realpath(device)
            pvs = __salt__['lvm.pvdisplay'](realdev, real=True)
            if pvs and pvs.get(realdev, None):
                if pvs[realdev]['Volume Group Name'] == name:
                    ret['comment'] = '{0}\n{1}'.format(
                        ret['comment'],
                        '{0} is part of Volume Group'.format(device))
                elif pvs[realdev]['Volume Group Name'] in ['', '#orphans_lvm2']:
                    __salt__['lvm.vgextend'](name, device)
                    pvs = __salt__['lvm.pvdisplay'](realdev, real=True)
                    if pvs[realdev]['Volume Group Name'] == name:
                        ret['changes'].update(
                            {device: 'added to {0}'.format(name)})
                    else:
                        ret['comment'] = '{0}\n{1}'.format(
                            ret['comment'],
                            '{0} could not be added'.format(device))
                        ret['result'] = False
                else:
                    ret['comment'] = '{0}\n{1}'.format(
                        ret['comment'],
                        '{0} is part of {1}'.format(
                            device, pvs[realdev]['Volume Group Name']))
                    ret['result'] = False
            else:
                ret['comment'] = '{0}\n{1}'.format(
                    ret['comment'],
                    'pv {0} is not present'.format(device))
                ret['result'] = False
    elif __opts__['test']:
        ret['comment'] = 'Volume Group {0} is set to be created'.format(name)
        ret['result'] = None
        return ret
    else:
        changes = __salt__['lvm.vgcreate'](name, devices, **kwargs)

        if __salt__['lvm.vgdisplay'](name):
            ret['comment'] = 'Created Volume Group {0}'.format(name)
            ret['changes']['created'] = changes
        else:
            ret['comment'] = 'Failed to create Volume Group {0}'.format(name)
            ret['result'] = False
    return ret