@ -67,6 +67,7 @@ options:
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. "
- " When enabled C(qos) and C(network_filter) are automatically set to None and C(port_mirroring) to False. "
- " Port mirroring, QoS and network filters are not supported on passthrough profiles. "
choices : [ ' disabled ' , ' enabled ' ]
choices : [ ' disabled ' , ' enabled ' ]
migratable :
migratable :
description :
description :
@ -170,8 +171,10 @@ class EntityVnicPorfileModule(BaseModule):
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 ( )
if self . param ( ' qos ' ) :
return get_id_by_name ( qoss_service , 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 ) :
def _get_network_filter_id ( self ) :
nf_service = self . _connection . system_service ( ) . network_filters_service ( )
nf_service = self . _connection . system_service ( ) . network_filters_service ( )
@ -179,18 +182,21 @@ class EntityVnicPorfileModule(BaseModule):
def _get_network_filter ( self ) :
def _get_network_filter ( self ) :
network_filter = None
network_filter = None
if self . param ( ' network_filter ' ) :
# The order of these condition is necessary.
network_filter = otypes . NetworkFilter ( id = self . _get_network_filter_id ( ) )
# When would network_filter and pass_through specified it would try to create and network_filter and fail on engine.
el if self . param ( ' network_filter ' ) == ' ' or self . param ( ' pass_through ' ) == ' enabled ' :
if self . param ( ' network_filter ' ) == ' ' or self . param ( ' pass_through ' ) == ' enabled ' :
network_filter = otypes . NetworkFilter ( )
network_filter = otypes . NetworkFilter ( )
elif self . param ( ' network_filter ' ) :
network_filter = otypes . NetworkFilter ( id = self . _get_network_filter_id ( ) )
return network_filter
return network_filter
def _get_qos ( self ) :
def _get_qos ( self ) :
qos = None
qos = None
if self . param ( ' qos ' ) :
# 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.
qos = otypes . Qos ( id = self . _get_qos_id ( ) )
if self . param ( ' qos ' ) == ' ' or self . param ( ' pass_through ' ) == ' enabled ' :
elif self . param ( ' qos ' ) == ' ' or self . param ( ' pass_through ' ) == ' enabled ' :
qos = otypes . Qos ( )
qos = otypes . Qos ( )
elif self . param ( ' qos ' ) :
qos = otypes . Qos ( id = self . _get_qos_id ( ) )
return qos
return qos
def _get_port_mirroring ( self ) :
def _get_port_mirroring ( self ) :
@ -198,13 +204,18 @@ class EntityVnicPorfileModule(BaseModule):
return False
return False
return self . param ( ' port_mirroring ' )
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 ) :
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 ' ) 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 ,
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 = [
custom_properties = [
otypes . CustomProperty (
otypes . CustomProperty (
name = cp . get ( ' name ' ) ,
name = cp . get ( ' name ' ) ,
@ -212,6 +223,7 @@ class EntityVnicPorfileModule(BaseModule):
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 ' ) else None ,
] if self . param ( ' custom_properties ' ) else None ,
migratable = self . _get_migratable ( ) ,
qos = self . _get_qos ( ) ,
qos = self . _get_qos ( ) ,
port_mirroring = self . _get_port_mirroring ( ) ,
port_mirroring = self . _get_port_mirroring ( ) ,
network_filter = self . _get_network_filter ( )
network_filter = self . _get_network_filter ( )
@ -227,13 +239,14 @@ class EntityVnicPorfileModule(BaseModule):
return sorted ( current ) == sorted ( passed )
return sorted ( current ) == sorted ( passed )
return True
return True
pass_through = getattr ( entity . pass_through . mode , ' name ' , None )
return (
return (
check_custom_properties ( ) and
check_custom_properties ( ) and
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 ( ' 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 ( ' 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 ) )
equal ( self . param ( ' port_mirroring ' ) , getattr ( entity , ' port_mirroring ' , None ) )
)
)
@ -247,6 +260,12 @@ def get_entity(vnic_services, entitynics_module):
return vnic
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 ( ) :
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 ' ] ) ,
@ -267,6 +286,7 @@ def main():
)
)
check_sdk ( module )
check_sdk ( module )
check_params ( module )
try :
try :
auth = module . params . pop ( ' auth ' )
auth = module . params . pop ( ' auth ' )
connection = create_connection ( auth )
connection = create_connection ( auth )