Ovirt vnic profile fix (#57936)
* ovirt vnic profile fix init * ovirt vnic profile fix init * update syntax whitespace * document pass_through * create get entity method * update example syntax * update docs * change force_create style
This commit is contained in:
parent
feae35ab7e
commit
c609fad106
1 changed files with 54 additions and 24 deletions
|
@ -66,6 +66,7 @@ options:
|
||||||
pass_through:
|
pass_through:
|
||||||
description:
|
description:
|
||||||
- "Enables passthrough to an SR-IOV-enabled host NIC."
|
- "Enables passthrough to an SR-IOV-enabled host NIC."
|
||||||
|
- "When enabled C(qos) and C(network_filter) are automatically set to None and C(port_mirroring) to False."
|
||||||
choices: ['disabled', 'enabled']
|
choices: ['disabled', 'enabled']
|
||||||
migratable:
|
migratable:
|
||||||
description:
|
description:
|
||||||
|
@ -149,45 +150,62 @@ class EntityVnicPorfileModule(BaseModule):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(EntityVnicPorfileModule, self).__init__(*args, **kwargs)
|
super(EntityVnicPorfileModule, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __get_dcs_service(self):
|
def _get_dcs_service(self):
|
||||||
return self._connection.system_service().data_centers_service()
|
return self._connection.system_service().data_centers_service()
|
||||||
|
|
||||||
def __get_dcs_id(self):
|
def _get_dcs_id(self):
|
||||||
return get_id_by_name(self.__get_dcs_service(), self.param('data_center'))
|
return get_id_by_name(self._get_dcs_service(), self.param('data_center'))
|
||||||
|
|
||||||
def __get_network_id(self):
|
def _get_network_id(self):
|
||||||
networks_service = self.__get_dcs_service().service(self.__get_dcs_id()).networks_service()
|
networks_service = self._get_dcs_service().service(self._get_dcs_id()).networks_service()
|
||||||
return get_id_by_name(networks_service, self.param('network'))
|
return get_id_by_name(networks_service, self.param('network'))
|
||||||
|
|
||||||
def __get_qos_id(self):
|
def _get_qos_id(self):
|
||||||
qoss_service = self.__get_dcs_service().service(self.__get_dcs_id()).qoss_service()
|
qoss_service = self._get_dcs_service().service(self._get_dcs_id()).qoss_service()
|
||||||
return get_id_by_name(qoss_service, self.param('qos'))
|
return get_id_by_name(qoss_service, self.param('qos'))
|
||||||
|
|
||||||
def __get_network_filter_id(self):
|
def _get_network_filter_id(self):
|
||||||
nf_service = self._connection.system_service().network_filters_service()
|
nf_service = self._connection.system_service().network_filters_service()
|
||||||
return get_id_by_name(nf_service, self.param('network_filter')) if self.param('network_filter') else None
|
return get_id_by_name(nf_service, self.param('network_filter')) if self.param('network_filter') else None
|
||||||
|
|
||||||
|
def _get_network_filter(self):
|
||||||
|
network_filter = None
|
||||||
|
if self.param('network_filter'):
|
||||||
|
network_filter = otypes.NetworkFilter(id=self._get_network_filter_id())
|
||||||
|
elif self.param('network_filter') == '' or self.param('pass_through') == 'enabled':
|
||||||
|
network_filter = otypes.NetworkFilter()
|
||||||
|
return network_filter
|
||||||
|
|
||||||
|
def _get_qos(self):
|
||||||
|
qos = None
|
||||||
|
if self.param('qos'):
|
||||||
|
qos = otypes.Qos(id=self._get_qos_id())
|
||||||
|
elif self.param('qos') == '' or self.param('pass_through') == 'enabled':
|
||||||
|
qos = otypes.Qos()
|
||||||
|
return qos
|
||||||
|
|
||||||
|
def _get_port_mirroring(self):
|
||||||
|
if self.param('pass_through') == 'enabled':
|
||||||
|
return False
|
||||||
|
return self.param('port_mirroring')
|
||||||
|
|
||||||
def build_entity(self):
|
def build_entity(self):
|
||||||
return otypes.VnicProfile(
|
return otypes.VnicProfile(
|
||||||
name=self.param('name'),
|
name=self.param('name'),
|
||||||
network=otypes.Network(id=self.__get_network_id()),
|
network=otypes.Network(id=self._get_network_id()),
|
||||||
description=self.param('description')
|
description=self.param('description') if self.param('description') else None,
|
||||||
if self.param('description') else None,
|
pass_through=otypes.VnicPassThrough(mode=otypes.VnicPassThroughMode(self.param('pass_through'))) if self.param('pass_through') else None,
|
||||||
port_mirroring=self.param('port_mirroring'),
|
migratable=self.param('migratable') if self.param('migratable') else None,
|
||||||
pass_through=otypes.VnicPassThrough(mode=otypes.VnicPassThroughMode(self.param('pass_through')))
|
|
||||||
if self.param('pass_through') else None,
|
|
||||||
migratable=self.param('migratable'),
|
|
||||||
custom_properties=[
|
custom_properties=[
|
||||||
otypes.CustomProperty(
|
otypes.CustomProperty(
|
||||||
name=cp.get('name'),
|
name=cp.get('name'),
|
||||||
regexp=cp.get('regexp'),
|
regexp=cp.get('regexp'),
|
||||||
value=str(cp.get('value')),
|
value=str(cp.get('value')),
|
||||||
) for cp in self.param('custom_properties') if cp
|
) for cp in self.param('custom_properties') if cp
|
||||||
] if self.param('custom_properties') is not None else None,
|
] if self.param('custom_properties') else None,
|
||||||
qos=otypes.Qos(id=self.__get_qos_id())
|
qos=self._get_qos(),
|
||||||
if self.param('qos') else None,
|
port_mirroring=self._get_port_mirroring(),
|
||||||
network_filter=otypes.NetworkFilter(id=self.__get_network_filter_id())
|
network_filter=self._get_network_filter()
|
||||||
if self.param('network_filter') is not None else None
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_check(self, entity):
|
def update_check(self, entity):
|
||||||
|
@ -203,7 +221,7 @@ class EntityVnicPorfileModule(BaseModule):
|
||||||
return (
|
return (
|
||||||
check_custom_properties() and
|
check_custom_properties() and
|
||||||
equal(self.param('migratable'), getattr(entity, 'migratable', None)) and
|
equal(self.param('migratable'), getattr(entity, 'migratable', None)) and
|
||||||
equal(self.param('pass_through'), entity.pass_through.mode.name) and
|
equal(self.param('pass_through'), getattr(entity.pass_through.mode, 'name', None)) and
|
||||||
equal(self.param('description'), entity.description) and
|
equal(self.param('description'), entity.description) and
|
||||||
equal(self.param('network_filter'), getattr(entity.network_filter, 'name', None)) and
|
equal(self.param('network_filter'), getattr(entity.network_filter, 'name', None)) and
|
||||||
equal(self.param('qos'), getattr(entity.qos, 'name', None)) and
|
equal(self.param('qos'), getattr(entity.qos, 'name', None)) and
|
||||||
|
@ -211,6 +229,15 @@ class EntityVnicPorfileModule(BaseModule):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_entity(vnic_services, entitynics_module):
|
||||||
|
vnic_profiles = vnic_services.list()
|
||||||
|
network_id = entitynics_module._get_network_id()
|
||||||
|
for vnic in vnic_profiles:
|
||||||
|
# When vNIC already exist update it, when not create it
|
||||||
|
if vnic.name == entitynics_module.param('name') and network_id == vnic.network.id:
|
||||||
|
return vnic
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ovirt_full_argument_spec(
|
argument_spec = ovirt_full_argument_spec(
|
||||||
state=dict(type='str', default='present', choices=['absent', 'present']),
|
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||||
|
@ -243,11 +270,14 @@ def main():
|
||||||
service=vnic_services,
|
service=vnic_services,
|
||||||
)
|
)
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
entity = get_entity(vnic_services, entitynics_module)
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
ret = entitynics_module.create()
|
ret = entitynics_module.create(entity=entity, force_create=entity is None)
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
ret = entitynics_module.remove()
|
if entity is not None:
|
||||||
|
ret = entitynics_module.remove(entity=entity)
|
||||||
|
else:
|
||||||
|
raise Exception("Vnic profile '%s' in network '%s' was not found." % (module.params['name'], module.params['network']))
|
||||||
module.exit_json(**ret)
|
module.exit_json(**ret)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
||||||
|
|
Loading…
Reference in a new issue