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

VMEditCPUMem   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %
Metric Value
dl 0
loc 14
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 12 2
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