def setvcpus(vm_, vcpus, config=False):
    if vm_state(vm_) != 'shutdown':
        return False

    dom = _get_domain(vm_)

    # see notes in setmem
    flags = libvirt.VIR_DOMAIN_VCPU_MAXIMUM
    if config:
        flags = flags | libvirt.VIR_DOMAIN_AFFECT_CONFIG

    ret1 = dom.setVcpusFlags(vcpus, flags)
    ret2 = dom.setVcpusFlags(vcpus, libvirt.VIR_DOMAIN_AFFECT_CURRENT)

    return ret1 == ret2 == 0
Changes the amount of vcpus allocated to VM. The VM must be shutdown
dataset/ETHPy150Open saltstack/salt/salt/modules/virt.py/setvcpus