Completed
Pull Request — master (#460)
by Manas
02:06
created

VMPowerOff.run()   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 7
rs 9.4285
1
import eventlet
2
3
from pyVmomi import vim
4
5
from vmwarelib import inventory
6
from vmwarelib.actions import BaseAction
7
8
9
class VMPowerOff(BaseAction):
10
11
    def run(self, vm_id):
12
        # convert ids to stubs
13
        vm = inventory.get_virtualmachine(self.si_content, moid=vm_id)
14
        task = vm.PowerOffVM_Task()
15
        while task.info.state == vim.TaskInfo.State.running:
16
            eventlet.sleep(1)
17
        return task.info.state == vim.TaskInfo.State.success
18