|
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 VMAddSCSIController(BaseAction): |
|
9
|
|
|
|
|
10
|
|
|
def run(self, vm_id, vm_name, controller_type, scsi_sharing): |
|
11
|
|
|
# VM name or ID given? |
|
12
|
|
|
checkinputs.vm_identifier(vm_id, vm_name) |
|
13
|
|
|
|
|
14
|
|
|
# Create object for VM |
|
15
|
|
|
vm = inventory.get_virtualmachine(self.si_content, vm_id, vm_name) |
|
16
|
|
|
|
|
17
|
|
|
# Create SCSI Controller Object |
|
18
|
|
|
configspec = vim.vm.ConfigSpec() |
|
19
|
|
|
scsictrl = vim.vm.device.VirtualDeviceSpec() |
|
20
|
|
|
scsictrl.operation = vim.vm.device.VirtualDeviceSpec.Operation.add |
|
21
|
|
|
|
|
22
|
|
|
# Select object type |
|
23
|
|
|
if controller_type == 'ParaVirtual': |
|
24
|
|
|
scsictrl.device = vim.vm.device.ParaVirtualSCSIController() |
|
25
|
|
|
elif controller_type == 'BusLogic': |
|
26
|
|
|
scsictrl.device = vim.vm.device.VirtualBusLogicController() |
|
27
|
|
|
elif controller_type == 'LSILogic': |
|
28
|
|
|
scsictrl.device = vim.vm.device.VirtualLsiLogicController() |
|
29
|
|
|
elif controller_type == 'LSILogicSAS': |
|
30
|
|
|
scsictrl.device = vim.vm.device.VirtualLsiLogicSASController() |
|
31
|
|
|
|
|
32
|
|
|
# Set SCSI Bus Sharing type |
|
33
|
|
|
if scsi_sharing == 'None': |
|
34
|
|
|
scsictrl.device.sharedBus = 'noSharing' |
|
35
|
|
|
elif scsi_sharing == 'Physical': |
|
36
|
|
|
scsictrl.device.sharedBus = 'physicalSharing' |
|
37
|
|
|
elif scsi_sharing == 'Virtual': |
|
38
|
|
|
scsictrl.device.sharedBus = 'virtualSharing' |
|
39
|
|
|
|
|
40
|
|
|
# Create Task to add to VM |
|
41
|
|
|
configspec.deviceChange = [scsictrl] |
|
42
|
|
|
add_ctrl_task = vm.ReconfigVM_Task(configspec) |
|
43
|
|
|
successfully_added_ctrl = self._wait_for_task(add_ctrl_task) |
|
44
|
|
|
|
|
45
|
|
|
return {'state': successfully_added_ctrl} |
|
46
|
|
|
|