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
This commit is contained in:
Martin Nečas 2019-01-17 20:24:08 +01:00 committed by ansibot
parent d95c716249
commit 8206ee96e3

View file

@ -76,6 +76,12 @@ options:
description: description:
- "If I(true) network configuration will be persistent, by default they are temporarily." - "If I(true) network configuration will be persistent, by default they are temporarily."
type: bool 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 extends_documentation_fragment: ovirt
''' '''
@ -320,6 +326,16 @@ class HostNetworksModule(BaseModule):
self.changed = True 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(): def main():
argument_spec = ovirt_full_argument_spec( argument_spec = ovirt_full_argument_spec(
state=dict( state=dict(
@ -333,6 +349,7 @@ def main():
labels=dict(default=None, type='list'), labels=dict(default=None, type='list'),
check=dict(default=None, type='bool'), check=dict(default=None, type='bool'),
save=dict(default=None, type='bool'), save=dict(default=None, type='bool'),
sync_networks=dict(default=False, type='bool'),
) )
module = AnsibleModule(argument_spec=argument_spec) module = AnsibleModule(argument_spec=argument_spec)
@ -362,8 +379,15 @@ def main():
nics_service = host_service.nics_service() nics_service = host_service.nics_service()
nic = search_by_name(nics_service, nic_name) 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 []] network_names = [network['name'] for network in networks or []]
state = module.params['state'] state = module.params['state']
if ( if (
state == 'present' and state == 'present' and
(nic is None or host_networks_module.has_update(nics_service.service(nic.id))) (nic is None or host_networks_module.has_update(nics_service.service(nic.id)))