def power_off_instance(session, instance, vm_ref=None):

    if vm_ref is None:
        vm_ref = get_vm_ref(session, instance)

    LOG.debug("Powering off the VM", instance=instance)
    try:
        poweroff_task = session._call_method(session.vim,
                                         "PowerOffVM_Task", vm_ref)
        session._wait_for_task(poweroff_task)
        LOG.debug("Powered off the VM", instance=instance)
    except vexc.InvalidPowerStateException:
        LOG.debug("VM already powered off", instance=instance)
Power off the specified instance.
dataset/ETHPy150Open openstack/nova/nova/virt/vmwareapi/vm_util.py/power_off_instance