Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ovirt attach host devic #44714

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 49 additions & 2 deletions lib/ansible/modules/cloud/ovirt/ovirt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,14 @@
custom_compatibility_version:
description:
- "Enables a virtual machine to be customized to its own compatibility version. If
`C(custom_compatibility_version)` is set, it overrides the cluster's compatibility version
'C(custom_compatibility_version)' is set, it overrides the cluster's compatibility version
for this particular virtual machine."
version_added: "2.7"

host_devices:
description:
- Single Root I/O Virtualization - technology that allows single device to expose multiple endpoints that can be passed to VMs
- host_devices is an list which contain dictinary with name and state of device
version_added: "2.7"
delete_protected:
description:
- If I(yes) Virtual Machine will be set as delete protected.
Expand Down Expand Up @@ -853,6 +857,7 @@
protocol:
- spice
- vnc

# Execute remote viever to VM
- block:
- name: Create a ticket for console for a running VM
Expand All @@ -870,6 +875,19 @@
- name: Run remote viewer with file
command: remote-viewer ~/vvfile.vv

# Default value of host_device state is present
- name: Attach host devices to virtual machine
ovirt_vm:
name: myvm
host: myhost
placement_policy: pinned
host_devices:
- name: pci_0000_00_06_0
- name: pci_0000_00_07_0
state: absent
- name: pci_0000_00_08_0
state: present

'''


Expand Down Expand Up @@ -1214,6 +1232,7 @@ def post_present(self, entity_id):
self.changed = self.__attach_numa_nodes(entity)
self.changed = self.__attach_watchdog(entity)
self.changed = self.__attach_graphical_console(entity)
self.changed = self.__attach_host_devices(entity)

def pre_remove(self, entity):
# Forcibly stop the VM, if it's not in DOWN state:
Expand Down Expand Up @@ -1608,6 +1627,33 @@ def get_initialization(self):
)
return self._initialization

def __attach_host_devices(self, entity):
vm_service = self._service.service(entity.id)
host_devices_service = vm_service.host_devices_service()
host_devices = self.param('host_devices')
updated = False
if host_devices:
device_names = [dev.name for dev in host_devices_service.list()]
for device in host_devices:
device_name = device.get('name')
state = device.get('state', 'present')
if state == 'absent' and device_name in device_names:
updated = True
if not self._module.check_mode:
device_id = get_id_by_name(host_devices_service, device.get('name'))
host_devices_service.device_service(device_id).remove()

elif state == 'present' and device_name not in device_names:
updated = True
if not self._module.check_mode:
host_devices_service.add(
otypes.HostDevice(
name=device.get('name'),
)
)

return updated


def _get_role_mappings(module):
roleMappings = list()
Expand Down Expand Up @@ -1925,6 +1971,7 @@ def main():
numa_nodes=dict(type='list', default=[]),
custom_properties=dict(type='list'),
watchdog=dict(type='dict'),
host_devices=dict(type='list'),
graphical_console=dict(type='dict'),
)
module = AnsibleModule(
Expand Down