Ovirt vnic profile fix backport (#60198)
* update vnic profile docs * vnic profile fix * merge updates * add changelog
This commit is contained in:
parent
0bcfb05bad
commit
b4b76c924c
2 changed files with 38 additions and 13 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- ovirt_vnic_profile - update qos and pass_through logic (https://bugzilla.redhat.com/show_bug.cgi?id=1597537)
|
|
@ -67,6 +67,8 @@ options:
|
|||
description:
|
||||
- "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."
|
||||
- "When enabled and C(migratable) not specified then C(migratable) is enabled."
|
||||
- "Port mirroring, QoS and network filters are not supported on passthrough profiles."
|
||||
choices: ['disabled', 'enabled']
|
||||
migratable:
|
||||
description:
|
||||
|
@ -161,8 +163,10 @@ class EntityVnicPorfileModule(BaseModule):
|
|||
return get_id_by_name(networks_service, self.param('network'))
|
||||
|
||||
def _get_qos_id(self):
|
||||
qoss_service = self._get_dcs_service().service(self._get_dcs_id()).qoss_service()
|
||||
return get_id_by_name(qoss_service, self.param('qos'))
|
||||
if self.param('qos'):
|
||||
qoss_service = self._get_dcs_service().service(self._get_dcs_id()).qoss_service()
|
||||
return get_id_by_name(qoss_service, self.param('qos')) if self.param('qos') else None
|
||||
return None
|
||||
|
||||
def _get_network_filter_id(self):
|
||||
nf_service = self._connection.system_service().network_filters_service()
|
||||
|
@ -170,18 +174,21 @@ class EntityVnicPorfileModule(BaseModule):
|
|||
|
||||
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':
|
||||
# The order of these condition is necessary.
|
||||
# When would network_filter and pass_through specified it would try to create and network_filter and fail on engine.
|
||||
if self.param('network_filter') == '' or self.param('pass_through') == 'enabled':
|
||||
network_filter = otypes.NetworkFilter()
|
||||
elif self.param('network_filter'):
|
||||
network_filter = otypes.NetworkFilter(id=self._get_network_filter_id())
|
||||
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':
|
||||
# The order of these condition is necessary. When would qos and pass_through specified it would try to create and qos and fail on engine.
|
||||
if self.param('qos') == '' or self.param('pass_through') == 'enabled':
|
||||
qos = otypes.Qos()
|
||||
elif self.param('qos'):
|
||||
qos = otypes.Qos(id=self._get_qos_id())
|
||||
return qos
|
||||
|
||||
def _get_port_mirroring(self):
|
||||
|
@ -189,13 +196,18 @@ class EntityVnicPorfileModule(BaseModule):
|
|||
return False
|
||||
return self.param('port_mirroring')
|
||||
|
||||
def _get_migratable(self):
|
||||
if self.param('migratable') is not None:
|
||||
return self.param('migratable')
|
||||
if self.param('pass_through') == 'enabled':
|
||||
return True
|
||||
|
||||
def build_entity(self):
|
||||
return otypes.VnicProfile(
|
||||
name=self.param('name'),
|
||||
network=otypes.Network(id=self._get_network_id()),
|
||||
description=self.param('description') if self.param('description') else None,
|
||||
description=self.param('description') if self.param('description') is not None else None,
|
||||
pass_through=otypes.VnicPassThrough(mode=otypes.VnicPassThroughMode(self.param('pass_through'))) if self.param('pass_through') else None,
|
||||
migratable=self.param('migratable') if self.param('migratable') else None,
|
||||
custom_properties=[
|
||||
otypes.CustomProperty(
|
||||
name=cp.get('name'),
|
||||
|
@ -203,6 +215,7 @@ class EntityVnicPorfileModule(BaseModule):
|
|||
value=str(cp.get('value')),
|
||||
) for cp in self.param('custom_properties') if cp
|
||||
] if self.param('custom_properties') else None,
|
||||
migratable=self._get_migratable(),
|
||||
qos=self._get_qos(),
|
||||
port_mirroring=self._get_port_mirroring(),
|
||||
network_filter=self._get_network_filter()
|
||||
|
@ -218,13 +231,16 @@ class EntityVnicPorfileModule(BaseModule):
|
|||
return sorted(current) == sorted(passed)
|
||||
return True
|
||||
|
||||
pass_through = getattr(entity.pass_through.mode, 'name', None)
|
||||
return (
|
||||
check_custom_properties() and
|
||||
# The reason why we can't use equal method, is we get None from _get_network_filter_id or _get_qos_id method, when passing empty string.
|
||||
# And when first param of equal method is None it retruns true.
|
||||
self._get_network_filter_id() == getattr(entity.network_filter, 'id', None) and
|
||||
self._get_qos_id() == getattr(entity.qos, 'id', None) and
|
||||
equal(self.param('migratable'), getattr(entity, 'migratable', None)) and
|
||||
equal(self.param('pass_through'), getattr(entity.pass_through.mode, 'name', None)) and
|
||||
equal(self.param('pass_through'), pass_through.lower() if pass_through else None) and
|
||||
equal(self.param('description'), entity.description) 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('port_mirroring'), getattr(entity, 'port_mirroring', None))
|
||||
)
|
||||
|
||||
|
@ -238,6 +254,12 @@ def get_entity(vnic_services, entitynics_module):
|
|||
return vnic
|
||||
|
||||
|
||||
def check_params(module):
|
||||
if (module.params.get('port_mirroring') or module.params.get('network_filter') or module.params.get('qos'))\
|
||||
and module.params.get('pass_through') == 'enabled':
|
||||
module.fail_json(msg="Cannot edit VM network interface profile. 'Port Mirroring,'Qos' and 'Network Filter' are not supported on passthrough profiles.")
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = ovirt_full_argument_spec(
|
||||
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||
|
@ -258,6 +280,7 @@ def main():
|
|||
|
||||
)
|
||||
check_sdk(module)
|
||||
check_params(module)
|
||||
try:
|
||||
auth = module.params.pop('auth')
|
||||
connection = create_connection(auth)
|
||||
|
|
Loading…
Reference in a new issue