Changes a flag on the partition with number <minor>.

    A flag can be either "on" or "off" (make sure to use proper quoting, see
    :ref:`YAML Idiosyncrasies <yaml-idiosyncrasies>`). Some or all of these
    flags will be available, depending on what disk label you are using.

    Valid flags are:
      * boot
      * root
      * swap
      * hidden
      * raid
      * lvm
      * lba
      * hp-service
      * palo
      * prep
      * msftres
      * bios_grub
      * atvrecv
      * diag
      * legacy_boot
      * msftdata
      * irst
      * esp
      * type

    CLI Example:

    .. code-block:: bash

        salt '*' partition.set /dev/sda 1 boot '"on"'

def set_(device, minor, flag, state):
    '''
    Changes a flag on the partition with number <minor>.

    A flag can be either "on" or "off" (make sure to use proper quoting, see
    :ref:`YAML Idiosyncrasies <yaml-idiosyncrasies>`). Some or all of these
    flags will be available, depending on what disk label you are using.

    Valid flags are:
      * boot
      * root
      * swap
      * hidden
      * raid
      * lvm
      * lba
      * hp-service
      * palo
      * prep
      * msftres
      * bios_grub
      * atvrecv
      * diag
      * legacy_boot
      * msftdata
      * irst
      * esp
      * type

    CLI Example:

    .. code-block:: bash

        salt '*' partition.set /dev/sda 1 boot '"on"'
    '''
    _validate_device(device)

    try:
        int(minor)
    except Exception:
        raise CommandExecutionError(
            'Invalid minor number passed to partition.set'
        )

    if flag not in VALID_PARTITION_FLAGS:
        raise CommandExecutionError('Invalid flag passed to partition.set')

    if state not in set(['on', 'off']):
        raise CommandExecutionError('Invalid state passed to partition.set')

    cmd = 'parted -m -s {0} set {1} {2} {3}'.format(device, minor, flag, state)
    out = __salt__['cmd.run'](cmd).splitlines()
    return out