From 8206ee96e3e14a597071d65db8676a78d29ec276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ne=C4=8Das?= Date: Thu, 17 Jan 2019 20:24:08 +0100 Subject: [PATCH] ovirt add sync_networks (#49298) * ovirt add sync_networks * ovirt add network sync check * ovirt rename check sync function * correct python syntax ovirt host networks * ovirt sync networks update docs * ovirt sync network update check controll --- .../modules/cloud/ovirt/ovirt_host_network.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_host_network.py b/lib/ansible/modules/cloud/ovirt/ovirt_host_network.py index 7a655c8745d..44215fec0bc 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_host_network.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_host_network.py @@ -76,6 +76,12 @@ options: description: - "If I(true) network configuration will be persistent, by default they are temporarily." type: bool + sync_networks: + description: + - "If I(true) all networks will be synchronized before modification" + type: bool + default: false + version_added: 2.8 extends_documentation_fragment: ovirt ''' @@ -320,6 +326,16 @@ class HostNetworksModule(BaseModule): self.changed = True +def needs_sync(nics_service): + nics = nics_service.list() + for nic in nics: + nic_service = nics_service.nic_service(nic.id) + for network_attachment_service in nic_service.network_attachments_service().list(): + if not network_attachment_service.in_sync: + return True + return False + + def main(): argument_spec = ovirt_full_argument_spec( state=dict( @@ -333,6 +349,7 @@ def main(): labels=dict(default=None, type='list'), check=dict(default=None, type='bool'), save=dict(default=None, type='bool'), + sync_networks=dict(default=False, type='bool'), ) module = AnsibleModule(argument_spec=argument_spec) @@ -362,8 +379,15 @@ def main(): nics_service = host_service.nics_service() nic = search_by_name(nics_service, nic_name) + if module.params["sync_networks"]: + if needs_sync(nics_service): + if not module.check_mode: + host_service.sync_all_networks() + host_networks_module.changed = True + network_names = [network['name'] for network in networks or []] state = module.params['state'] + if ( state == 'present' and (nic is None or host_networks_module.has_update(nics_service.service(nic.id)))