mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
add external provider to ovirt network (#43636)
* add external provider to ovirt network * add version added * add example * test of importing external network * ovirt correct datacenter search in external provider * repair importing external provider * update external provider docs * update pep8 syntax
This commit is contained in:
parent
aec263df8a
commit
d79be6a00c
1 changed files with 25 additions and 2 deletions
|
@ -58,6 +58,10 @@ options:
|
||||||
vlan_tag:
|
vlan_tag:
|
||||||
description:
|
description:
|
||||||
- "Specify VLAN tag."
|
- "Specify VLAN tag."
|
||||||
|
external_provider:
|
||||||
|
description:
|
||||||
|
- "Name of external network provider."
|
||||||
|
version_added: 2.8
|
||||||
vm_network:
|
vm_network:
|
||||||
description:
|
description:
|
||||||
- "If I(True) network will be marked as network for VM."
|
- "If I(True) network will be marked as network for VM."
|
||||||
|
@ -103,6 +107,12 @@ EXAMPLES = '''
|
||||||
id: 00000000-0000-0000-0000-000000000000
|
id: 00000000-0000-0000-0000-000000000000
|
||||||
name: "new_network_name"
|
name: "new_network_name"
|
||||||
data_center: mydatacenter
|
data_center: mydatacenter
|
||||||
|
|
||||||
|
# Add network from external provider
|
||||||
|
- ovirt_networks:
|
||||||
|
data_center: mydatacenter
|
||||||
|
name: mynetwork
|
||||||
|
external_provider: ovirt-provider-ovn
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -134,10 +144,19 @@ from ansible.module_utils.ovirt import (
|
||||||
equal,
|
equal,
|
||||||
ovirt_full_argument_spec,
|
ovirt_full_argument_spec,
|
||||||
search_by_name,
|
search_by_name,
|
||||||
|
get_id_by_name,
|
||||||
|
get_dict_of_struct,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NetworksModule(BaseModule):
|
class NetworksModule(BaseModule):
|
||||||
|
def import_external_network(self):
|
||||||
|
ons_service = self._connection.system_service().openstack_network_providers_service()
|
||||||
|
on_service = ons_service.provider_service(get_id_by_name(ons_service, self.param('external_provider')))
|
||||||
|
networks_service = on_service.networks_service()
|
||||||
|
network_service = networks_service.network_service(get_id_by_name(networks_service, self.param('name')))
|
||||||
|
network_service.import_(data_center=otypes.DataCenter(name=self._module.params['data_center']))
|
||||||
|
return {"network": get_dict_of_struct(network_service.get()), "changed": True}
|
||||||
|
|
||||||
def build_entity(self):
|
def build_entity(self):
|
||||||
return otypes.Network(
|
return otypes.Network(
|
||||||
|
@ -180,6 +199,7 @@ class NetworksModule(BaseModule):
|
||||||
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('name'), entity.name) and
|
equal(self._module.params.get('name'), entity.name) and
|
||||||
|
equal(self._module.params.get('external_provider'), entity.external_provider) and
|
||||||
equal(self._module.params.get('description'), entity.description) and
|
equal(self._module.params.get('description'), entity.description) and
|
||||||
equal(self._module.params.get('vlan_tag'), getattr(entity.vlan, 'id', None)) and
|
equal(self._module.params.get('vlan_tag'), getattr(entity.vlan, 'id', None)) and
|
||||||
equal(self._module.params.get('vm_network'), True if entity.usages else False) and
|
equal(self._module.params.get('vm_network'), True if entity.usages else False) and
|
||||||
|
@ -242,6 +262,7 @@ def main():
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
description=dict(default=None),
|
description=dict(default=None),
|
||||||
comment=dict(default=None),
|
comment=dict(default=None),
|
||||||
|
external_provider=dict(default=None),
|
||||||
vlan_tag=dict(default=None, type='int'),
|
vlan_tag=dict(default=None, type='int'),
|
||||||
vm_network=dict(default=None, type='bool'),
|
vm_network=dict(default=None, type='bool'),
|
||||||
mtu=dict(default=None, type='int'),
|
mtu=dict(default=None, type='int'),
|
||||||
|
@ -272,8 +293,10 @@ def main():
|
||||||
'datacenter': module.params['data_center'],
|
'datacenter': module.params['data_center'],
|
||||||
}
|
}
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
if module.params.get('external_provider'):
|
||||||
|
ret = networks_module.import_external_network()
|
||||||
|
else:
|
||||||
ret = networks_module.create(search_params=search_params)
|
ret = networks_module.create(search_params=search_params)
|
||||||
|
|
||||||
# Update clusters networks:
|
# Update clusters networks:
|
||||||
if module.params.get('clusters') is not None:
|
if module.params.get('clusters') is not None:
|
||||||
for param_cluster in module.params.get('clusters'):
|
for param_cluster in module.params.get('clusters'):
|
||||||
|
|
Loading…
Reference in a new issue