1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
from pyVmomi import vim |
17
|
|
|
|
18
|
|
|
from vmwarelib import inventory |
19
|
|
|
from vmwarelib import checkinputs |
20
|
|
|
from vmwarelib.actions import BaseAction |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class VMAddSCSIController(BaseAction): |
24
|
|
|
|
25
|
|
|
def run(self, vm_id, vm_name, controller_type, scsi_sharing): |
26
|
|
|
# VM name or ID given? |
27
|
|
|
checkinputs.one_of_two_strings(vm_id, vm_name, "ID or Name") |
28
|
|
|
|
29
|
|
|
# Create object for VM |
30
|
|
|
vm = inventory.get_virtualmachine(self.si_content, vm_id, vm_name) |
31
|
|
|
|
32
|
|
|
# Create SCSI Controller Object |
33
|
|
|
configspec = vim.vm.ConfigSpec() |
34
|
|
|
scsictrl = vim.vm.device.VirtualDeviceSpec() |
35
|
|
|
scsictrl.operation = vim.vm.device.VirtualDeviceSpec.Operation.add |
36
|
|
|
|
37
|
|
|
# Select object type |
38
|
|
|
if controller_type == 'ParaVirtual': |
39
|
|
|
scsictrl.device = vim.vm.device.ParaVirtualSCSIController() |
40
|
|
|
elif controller_type == 'BusLogic': |
41
|
|
|
scsictrl.device = vim.vm.device.VirtualBusLogicController() |
42
|
|
|
elif controller_type == 'LSILogic': |
43
|
|
|
scsictrl.device = vim.vm.device.VirtualLsiLogicController() |
44
|
|
|
elif controller_type == 'LSILogicSAS': |
45
|
|
|
scsictrl.device = vim.vm.device.VirtualLsiLogicSASController() |
46
|
|
|
|
47
|
|
|
# Set SCSI Bus Sharing type |
48
|
|
|
if scsi_sharing == 'None': |
49
|
|
|
scsictrl.device.sharedBus = 'noSharing' |
50
|
|
|
elif scsi_sharing == 'Physical': |
51
|
|
|
scsictrl.device.sharedBus = 'physicalSharing' |
52
|
|
|
elif scsi_sharing == 'Virtual': |
53
|
|
|
scsictrl.device.sharedBus = 'virtualSharing' |
54
|
|
|
|
55
|
|
|
# Create Task to add to VM |
56
|
|
|
configspec.deviceChange = [scsictrl] |
57
|
|
|
add_ctrl_task = vm.ReconfigVM_Task(configspec) |
58
|
|
|
successfully_added_ctrl = self._wait_for_task(add_ctrl_task) |
59
|
|
|
|
60
|
|
|
return {'state': successfully_added_ctrl} |
61
|
|
|
|