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

SetVM.run()   B

Complexity

Conditions 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 27
rs 8.5806
cc 4
1
from pyVmomi import vim
2
3
from vmwarelib import inventory
4
from vmwarelib.actions import BaseAction
5
6
7
class SetVM(BaseAction):
8
    def run(self, vm, alternate_guest_name=None, description=None, guest_id=None, memory_mb=None, name=None, num_cpu=None, vm_swapfile_policy=None):
9
        vm_swapfile_policy = vm_swapfile_policy.lower() if vm_swapfile_policy else None
10
11
        si = self.si
12
13
        vm_obj = vim.VirtualMachine(vm, stub=si._stub)
14
15
        # convert ids to stubs
16
        spec = vim.vm.ConfigSpec()
17
        spec.alternateGuestName = alternate_guest_name
18
        spec.annotation = description
19
        spec.guestId = guest_id
20
        spec.memoryMB = memory_mb
21
        spec.name = name
22
        spec.numCPUs = num_cpu
23
        if vm_swapfile_policy == 'inhostdatastore':
24
            spec.swapPlacement = 'hostLocal'
25
        elif vm_swapfile_policy == 'withvm':
26
            spec.swapPlacement = 'vmDirectory'
27
28
29
        task = vm_obj.ReconfigVM_Task(spec)
30
31
        success = self._wait_for_task(task)
32
33
34
        return {'success': success}
35