Ovirt_host_network: add custom_properties (#67117)

* init of cp

* set update_custom_properties

* update check_mode

* correct examples

* add version_added

* update sanity
pull/67117/merge
Martin Nečas 5 years ago committed by GitHub
parent 822077fefd
commit 52f2081e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,22 +47,57 @@ options:
bond: bond:
description: description:
- "Dictionary describing network bond:" - "Dictionary describing network bond:"
- "C(name) - Bond name." suboptions:
- "C(mode) - Bonding mode." name:
- "C(options) - Bonding options." description:
- "C(interfaces) - List of interfaces to create a bond." - Bond name.
mode:
description:
- Bonding mode.
options:
description:
- Bonding options.
interfaces:
description:
- List of interfaces to create a bond.
interface: interface:
description: description:
- "Name of the network interface where logical network should be attached." - "Name of the network interface where logical network should be attached."
networks: networks:
description: description:
- "List of dictionary describing networks to be attached to interface or bond:" - "List of dictionary describing networks to be attached to interface or bond:"
- "C(name) - Name of the logical network to be assigned to bond or interface." suboptions:
- "C(boot_protocol) - Boot protocol one of the I(none), I(static) or I(dhcp)." name:
- "C(address) - IP address in case of I(static) boot protocol is used." description:
- "C(netmask) - Subnet mask in case of I(static) boot protocol is used." - Name of the logical network to be assigned to bond or interface.
- "C(gateway) - Gateway in case of I(static) boot protocol is used." boot_protocol:
- "C(version) - IP version. Either v4 or v6. Default is v4." description:
- Boot protocol.
choices: ['none', 'static', 'dhcp']
address:
description:
- IP address in case of I(static) boot protocol is used.
netmask:
description:
- Subnet mask in case of I(static) boot protocol is used.
gateway:
description:
- Gateway in case of I(static) boot protocol is used.
version:
description:
- IP version. Either v4 or v6. Default is v4.
custom_properties:
description:
- "Custom properties applied to the host network."
- "Custom properties is a list of dictionary which can have following values."
suboptions:
name:
description:
- Name of custom property.
value:
description:
- Value of custom property.
version_added: 2.10
labels: labels:
description: description:
- "List of names of the network label to be assigned to bond or interface." - "List of names of the network label to be assigned to bond or interface."
@ -152,6 +187,16 @@ EXAMPLES = '''
state: absent state: absent
name: myhost name: myhost
interface: eth0 interface: eth0
# Add custom_properties to network:
- ovirt_host_network:
name: myhost
interface: eth0
networks:
- name: myvlan1
custom_properties:
- name: bridge_opts
value: gc_timer=10
''' '''
RETURN = ''' RETURN = '''
@ -252,6 +297,23 @@ class HostNetworksModule(BaseModule):
def build_entity(self): def build_entity(self):
return otypes.Host() return otypes.Host()
def update_custom_properties(self, attachments_service, attachment, network):
if network.get('custom_properties'):
current = []
if attachment.properties:
current = [(cp.name, str(cp.value)) for cp in attachment.properties]
passed = [(cp.get('name'), str(cp.get('value'))) for cp in network.get('custom_properties') if cp]
if sorted(current) != sorted(passed):
attachment.properties = [
otypes.Property(
name=prop.get('name'),
value=prop.get('value')
) for prop in network.get('custom_properties')
]
if not self._module.check_mode:
attachments_service.service(attachment.id).update(attachment)
self.changed = True
def update_address(self, attachments_service, attachment, network): def update_address(self, attachments_service, attachment, network):
# Check if there is any change in address assignments and # Check if there is any change in address assignments and
# update it if needed: # update it if needed:
@ -320,7 +382,7 @@ class HostNetworksModule(BaseModule):
# If attachment don't exists, we need to create it: # If attachment don't exists, we need to create it:
if attachment is None: if attachment is None:
return True return True
self.update_custom_properties(attachments_service, attachment, network)
self.update_address(attachments_service, attachment, network) self.update_address(attachments_service, attachment, network)
return update return update
@ -464,6 +526,12 @@ def main():
), ),
), ),
], ],
properties=[
otypes.Property(
name=prop.get('name'),
value=prop.get('value')
) for prop in network.get('custom_properties')
]
) for network in networks ) for network in networks
] if networks else None, ] if networks else None,
) )

Loading…
Cancel
Save