ovirt_networks: Add label to network (#31517)
This commit is contained in:
parent
c71394a13a
commit
23c47a65c1
1 changed files with 22 additions and 1 deletions
|
@ -70,7 +70,10 @@ options:
|
|||
- "C(display) - I(true) if the network should marked as display network."
|
||||
- "C(migration) - I(true) if the network should marked as migration network."
|
||||
- "C(gluster) - I(true) if the network should marked as gluster network."
|
||||
|
||||
label:
|
||||
description:
|
||||
- "Name of the label to assign to the network."
|
||||
version_added: "2.5"
|
||||
extends_documentation_fragment: ovirt
|
||||
'''
|
||||
|
||||
|
@ -142,7 +145,24 @@ class NetworksModule(BaseModule):
|
|||
mtu=self._module.params['mtu'],
|
||||
)
|
||||
|
||||
def post_create(self, entity):
|
||||
self._update_label_assignments(entity)
|
||||
|
||||
def _update_label_assignments(self, entity):
|
||||
labels = [lbl.id for lbl in self._connection.follow_link(entity.network_labels)]
|
||||
labels_service = self._service.service(entity.id).network_labels_service()
|
||||
|
||||
if not self.param('label') in labels:
|
||||
if not self._module.check_mode:
|
||||
if labels:
|
||||
labels_service.label_service(labels[0]).remove()
|
||||
labels_service.add(
|
||||
label=otypes.NetworkLabel(id=self.param('label'))
|
||||
)
|
||||
self.changed = True
|
||||
|
||||
def update_check(self, entity):
|
||||
self._update_label_assignments(entity)
|
||||
return (
|
||||
equal(self._module.params.get('comment'), entity.comment) and
|
||||
equal(self._module.params.get('description'), entity.description) and
|
||||
|
@ -210,6 +230,7 @@ def main():
|
|||
vm_network=dict(default=None, type='bool'),
|
||||
mtu=dict(default=None, type='int'),
|
||||
clusters=dict(default=None, type='list'),
|
||||
label=dict(default=None),
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
|
|
Loading…
Reference in a new issue