mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow change kernel boot parameters of oVirt hosts (#20607)
* cloud: ovirt: add override_display parameter * cloud: ovirt: add kernel_params parameter * cloud: ovirt: add reinstall state to ovirt_hosts module * cloud: ovirt: wait before polling entity state
This commit is contained in:
parent
ac527ef86f
commit
937fc1421b
2 changed files with 95 additions and 14 deletions
|
@ -283,6 +283,9 @@ def wait(
|
||||||
if wait:
|
if wait:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
while time.time() < start + timeout:
|
while time.time() < start + timeout:
|
||||||
|
# Sleep for `poll_interval` seconds if none of the conditions apply:
|
||||||
|
time.sleep(float(poll_interval))
|
||||||
|
|
||||||
# Exit if the condition of entity is valid:
|
# Exit if the condition of entity is valid:
|
||||||
entity = get_entity(service)
|
entity = get_entity(service)
|
||||||
if condition(entity):
|
if condition(entity):
|
||||||
|
@ -290,9 +293,6 @@ def wait(
|
||||||
elif fail_condition(entity):
|
elif fail_condition(entity):
|
||||||
raise Exception("Error while waiting on result state of the entity.")
|
raise Exception("Error while waiting on result state of the entity.")
|
||||||
|
|
||||||
# Sleep for `poll_interval` seconds if nor of the conditions apply:
|
|
||||||
time.sleep(float(poll_interval))
|
|
||||||
|
|
||||||
|
|
||||||
def __get_auth_dict():
|
def __get_auth_dict():
|
||||||
OVIRT_URL = os.environ.get('OVIRT_URL')
|
OVIRT_URL = os.environ.get('OVIRT_URL')
|
||||||
|
|
|
@ -59,7 +59,10 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- "State which should a host to be in after successful completion."
|
- "State which should a host to be in after successful completion."
|
||||||
choices: ['present', 'absent', 'maintenance', 'upgraded', 'started', 'restarted', 'stopped']
|
choices: [
|
||||||
|
'present', 'absent', 'maintenance', 'upgraded', 'started',
|
||||||
|
'restarted', 'stopped', 'reinstalled'
|
||||||
|
]
|
||||||
default: present
|
default: present
|
||||||
comment:
|
comment:
|
||||||
description:
|
description:
|
||||||
|
@ -94,6 +97,23 @@ options:
|
||||||
description:
|
description:
|
||||||
- "If True host will be forcibly moved to desired state."
|
- "If True host will be forcibly moved to desired state."
|
||||||
default: False
|
default: False
|
||||||
|
override_display:
|
||||||
|
description:
|
||||||
|
- "Override the display address of all VMs on this host with specified address."
|
||||||
|
kernel_params:
|
||||||
|
description:
|
||||||
|
- "List of kernel boot parameters."
|
||||||
|
- "Following are most common kernel parameters used for host:"
|
||||||
|
- "Hostdev Passthrough & SR-IOV: intel_iommu=on"
|
||||||
|
- "Nested Virtualization: kvm-intel.nested=1"
|
||||||
|
- "Unsafe Interrupts: vfio_iommu_type1.allow_unsafe_interrupts=1"
|
||||||
|
- "PCI Reallocation: pci=realloc"
|
||||||
|
- "C(Note:)"
|
||||||
|
- "Modifying kernel boot parameters settings can lead to a host boot failure.
|
||||||
|
Please consult the product documentation before doing any changes."
|
||||||
|
- "Kernel boot parameters changes require host deploy and restart. The host needs
|
||||||
|
to be I(reinstalled) suceesfully and then to be I(rebooted) for kernel boot parameters
|
||||||
|
to be applied."
|
||||||
extends_documentation_fragment: ovirt
|
extends_documentation_fragment: ovirt
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -101,12 +121,14 @@ EXAMPLES = '''
|
||||||
# Examples don't contain auth parameter for simplicity,
|
# Examples don't contain auth parameter for simplicity,
|
||||||
# look at ovirt_auth module to see how to reuse authentication:
|
# look at ovirt_auth module to see how to reuse authentication:
|
||||||
|
|
||||||
# Add host with username/password
|
# Add host with username/password supporting SR-IOV:
|
||||||
- ovirt_hosts:
|
- ovirt_hosts:
|
||||||
cluster: Default
|
cluster: Default
|
||||||
name: myhost
|
name: myhost
|
||||||
address: 10.34.61.145
|
address: 10.34.61.145
|
||||||
password: secret
|
password: secret
|
||||||
|
kernel_params:
|
||||||
|
- intel_iommu=on
|
||||||
|
|
||||||
# Add host using public key
|
# Add host using public key
|
||||||
- ovirt_hosts:
|
- ovirt_hosts:
|
||||||
|
@ -171,13 +193,25 @@ class HostsModule(BaseModule):
|
||||||
priority=self._module.params['spm_priority'],
|
priority=self._module.params['spm_priority'],
|
||||||
) if self._module.params['spm_priority'] else None,
|
) if self._module.params['spm_priority'] else None,
|
||||||
override_iptables=self._module.params['override_iptables'],
|
override_iptables=self._module.params['override_iptables'],
|
||||||
|
display=otypes.Display(
|
||||||
|
address=self._module.params['override_display'],
|
||||||
|
) if self._module.params['override_display'] else None,
|
||||||
|
os=otypes.OperatingSystem(
|
||||||
|
custom_kernel_cmdline=' '.join(self._module.params['kernel_params']),
|
||||||
|
) if self._module.params['kernel_params'] else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_check(self, entity):
|
def update_check(self, entity):
|
||||||
|
kernel_params = self._module.params.get('kernel_params')
|
||||||
return (
|
return (
|
||||||
equal(self._module.params.get('comment'), entity.comment) and
|
equal(self._module.params.get('comment'), entity.comment) and
|
||||||
equal(self._module.params.get('kdump_integration'), entity.kdump_status) and
|
equal(self._module.params.get('kdump_integration'), entity.kdump_status) and
|
||||||
equal(self._module.params.get('spm_priority'), entity.spm.priority)
|
equal(self._module.params.get('spm_priority'), entity.spm.priority) and
|
||||||
|
equal(self._module.params.get('override_display'), getattr(entity.display, 'address', None)) and
|
||||||
|
equal(
|
||||||
|
sorted(kernel_params) if kernel_params else None,
|
||||||
|
sorted(entity.os.custom_kernel_cmdline.split(' '))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def pre_remove(self, entity):
|
def pre_remove(self, entity):
|
||||||
|
@ -189,7 +223,7 @@ class HostsModule(BaseModule):
|
||||||
)
|
)
|
||||||
|
|
||||||
def post_update(self, entity):
|
def post_update(self, entity):
|
||||||
if entity.status != hoststate.UP:
|
if entity.status != hoststate.UP and self._module.params['state'] == 'present':
|
||||||
if not self._module.check_mode:
|
if not self._module.check_mode:
|
||||||
self._service.host_service(entity.id).activate()
|
self._service.host_service(entity.id).activate()
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
@ -209,9 +243,17 @@ def control_state(host_module):
|
||||||
if host is None:
|
if host is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
state = host_module._module.params['state']
|
||||||
host_service = host_module._service.service(host.id)
|
host_service = host_module._service.service(host.id)
|
||||||
if failed_state(host):
|
if failed_state(host):
|
||||||
raise Exception("Not possible to manage host '%s'." % host.name)
|
# In case host is in INSTALL_FAILED status, we can reinstall it:
|
||||||
|
if hoststate.INSTALL_FAILED == host.status and state != 'reinstalled':
|
||||||
|
raise Exception(
|
||||||
|
"Not possible to manage host '%s' in state '%s'." % (
|
||||||
|
host.name,
|
||||||
|
host.status
|
||||||
|
)
|
||||||
|
)
|
||||||
elif host.status in [
|
elif host.status in [
|
||||||
hoststate.REBOOT,
|
hoststate.REBOOT,
|
||||||
hoststate.CONNECTING,
|
hoststate.CONNECTING,
|
||||||
|
@ -235,7 +277,10 @@ def control_state(host_module):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ovirt_full_argument_spec(
|
argument_spec = ovirt_full_argument_spec(
|
||||||
state=dict(
|
state=dict(
|
||||||
choices=['present', 'absent', 'maintenance', 'upgraded', 'started', 'restarted', 'stopped'],
|
choices=[
|
||||||
|
'present', 'absent', 'maintenance', 'upgraded', 'started',
|
||||||
|
'restarted', 'stopped', 'reinstalled',
|
||||||
|
],
|
||||||
default='present',
|
default='present',
|
||||||
),
|
),
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
|
@ -249,6 +294,8 @@ def main():
|
||||||
override_iptables=dict(default=None, type='bool'),
|
override_iptables=dict(default=None, type='bool'),
|
||||||
force=dict(default=False, type='bool'),
|
force=dict(default=False, type='bool'),
|
||||||
timeout=dict(default=600, type='int'),
|
timeout=dict(default=600, type='int'),
|
||||||
|
override_display=dict(default=None),
|
||||||
|
kernel_params=dict(default=None, type='list'),
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
|
@ -269,12 +316,12 @@ def main():
|
||||||
control_state(hosts_module)
|
control_state(hosts_module)
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
ret = hosts_module.create()
|
ret = hosts_module.create()
|
||||||
hosts_module.action(
|
ret['changed'] = hosts_module.action(
|
||||||
action='activate',
|
action='activate',
|
||||||
action_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
action_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
||||||
wait_condition=lambda h: h.status == hoststate.UP,
|
wait_condition=lambda h: h.status == hoststate.UP,
|
||||||
fail_condition=failed_state,
|
fail_condition=failed_state,
|
||||||
)
|
)['changed'] or ret['changed']
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
ret = hosts_module.remove()
|
ret = hosts_module.remove()
|
||||||
elif state == 'maintenance':
|
elif state == 'maintenance':
|
||||||
|
@ -284,6 +331,7 @@ def main():
|
||||||
wait_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
wait_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
||||||
fail_condition=failed_state,
|
fail_condition=failed_state,
|
||||||
)
|
)
|
||||||
|
ret['changed'] = hosts_module.create()['changed'] or ret['changed']
|
||||||
elif state == 'upgraded':
|
elif state == 'upgraded':
|
||||||
ret = hosts_module.action(
|
ret = hosts_module.action(
|
||||||
action='upgrade',
|
action='upgrade',
|
||||||
|
@ -300,19 +348,19 @@ def main():
|
||||||
fence_type='start',
|
fence_type='start',
|
||||||
)
|
)
|
||||||
elif state == 'stopped':
|
elif state == 'stopped':
|
||||||
hosts_module.action(
|
ret = hosts_module.action(
|
||||||
action='deactivate',
|
action='deactivate',
|
||||||
action_condition=lambda h: h.status not in [hoststate.MAINTENANCE, hoststate.DOWN],
|
action_condition=lambda h: h.status not in [hoststate.MAINTENANCE, hoststate.DOWN],
|
||||||
wait_condition=lambda h: h.status in [hoststate.MAINTENANCE, hoststate.DOWN],
|
wait_condition=lambda h: h.status in [hoststate.MAINTENANCE, hoststate.DOWN],
|
||||||
fail_condition=failed_state,
|
fail_condition=failed_state,
|
||||||
)
|
)
|
||||||
ret = hosts_module.action(
|
ret['changed'] = hosts_module.action(
|
||||||
action='fence',
|
action='fence',
|
||||||
action_condition=lambda h: h.status != hoststate.DOWN,
|
action_condition=lambda h: h.status != hoststate.DOWN,
|
||||||
wait_condition=lambda h: h.status == hoststate.DOWN,
|
wait_condition=lambda h: h.status == hoststate.DOWN,
|
||||||
fail_condition=failed_state,
|
fail_condition=failed_state,
|
||||||
fence_type='stop',
|
fence_type='stop',
|
||||||
)
|
)['changed'] or ret['changed']
|
||||||
elif state == 'restarted':
|
elif state == 'restarted':
|
||||||
ret = hosts_module.action(
|
ret = hosts_module.action(
|
||||||
action='fence',
|
action='fence',
|
||||||
|
@ -320,6 +368,39 @@ def main():
|
||||||
fail_condition=failed_state,
|
fail_condition=failed_state,
|
||||||
fence_type='restart',
|
fence_type='restart',
|
||||||
)
|
)
|
||||||
|
elif state == 'reinstalled':
|
||||||
|
# Deactivate host if not in maintanence:
|
||||||
|
deactivate_changed = hosts_module.action(
|
||||||
|
action='deactivate',
|
||||||
|
action_condition=lambda h: h.status not in [hoststate.MAINTENANCE, hoststate.DOWN],
|
||||||
|
wait_condition=lambda h: h.status in [hoststate.MAINTENANCE, hoststate.DOWN],
|
||||||
|
fail_condition=failed_state,
|
||||||
|
)['changed']
|
||||||
|
|
||||||
|
# Reinstall host:
|
||||||
|
install_changed = hosts_module.action(
|
||||||
|
action='install',
|
||||||
|
action_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
||||||
|
wait_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
||||||
|
fail_condition=failed_state,
|
||||||
|
host=otypes.Host(
|
||||||
|
override_iptables=module.params['override_iptables'],
|
||||||
|
) if module.params['override_iptables'] else None,
|
||||||
|
root_password=module.params['password'],
|
||||||
|
ssh=otypes.Ssh(
|
||||||
|
authentication_method='publickey',
|
||||||
|
) if module.params['public_key'] else None,
|
||||||
|
)['changed']
|
||||||
|
|
||||||
|
# Activate host after reinstall:
|
||||||
|
ret = hosts_module.action(
|
||||||
|
action='activate',
|
||||||
|
action_condition=lambda h: h.status == hoststate.MAINTENANCE,
|
||||||
|
wait_condition=lambda h: h.status == hoststate.UP,
|
||||||
|
fail_condition=failed_state,
|
||||||
|
)
|
||||||
|
ret['changed'] = install_changed or deactivate_changed or ret['changed']
|
||||||
|
|
||||||
|
|
||||||
module.exit_json(**ret)
|
module.exit_json(**ret)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue