Completed
Pull Request — master (#462)
by
unknown
02:34
created

VMCPUMemFlex   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %
Metric Value
wmc 3
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 17 3
1
from pyVmomi import vim
2
3
from vmwarelib import inventory
4
from vmwarelib import checkinputs
5
from vmwarelib.actions import BaseAction
6
7
8
class VMCPUMemFlex(BaseAction):
9
10
    def run(self, vm_id, vm_name, cpu_flex, mem_flex):
11
        # check a means of finding the VM has been provided
12
        checkinputs.vm_identifier(vm_id, vm_name)
13
14
        vm = inventory.get_virtualmachine(self.si_content,
15
                                          moid=vm_id,
16
                                          name=vm_name)
17
        spec = vim.vm.ConfigSpec()
18
        if cpu_flex:
19
            spec.numCPUs = cpu_flex
20
        if mem_flex:
21
            spec.memoryMB = mem_flex * 1024
22
23
        task = vm.ReconfigVM_Task(spec)
24
        self._wait_for_task(task)
25
26
        return {'state': str(task.info.state)}
27