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

VMEditCPUMem.run()   A

Complexity

Conditions 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 12
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 VMEditCPUMem(BaseAction):
10
11
    def run(self, vm_id, cpu, memory):
12
        # convert ids to stubs
13
        vm = inventory.get_virtualmachine(self.si_content, moid=vm_id)
14
        spec = vim.vm.ConfigSpec()
15
        spec.numCPUs = cpu
16
        spec.memoryMB = memory
17
        task = vm.ReconfigVM_Task(spec)
18
19
        while task.info.state == vim.TaskInfo.State.running:
20
            eventlet.sleep(1)
21
22
        return {'state': str(task.info.state)}
23