Add get_security_group_by_id to network driver

Change-Id: I76f00ef9234a615c5ea275532f5fe831345060b8
This commit is contained in:
Gregory Thiemonge 2024-04-05 11:16:10 -04:00
parent 97a8e5ed4c
commit 2274bf123f
3 changed files with 15 additions and 2 deletions

View File

@ -294,13 +294,23 @@ class AbstractNetworkDriver(metaclass=abc.ABCMeta):
@abc.abstractmethod
def get_security_group(self, sg_name):
"""Retrieves the security group by it's name.
"""Retrieves the security group by its name.
:param sg_name: The security group name.
:return: octavia.network.data_models.SecurityGroup, None if not enabled
:raises: NetworkException, SecurityGroupNotFound
"""
@abc.abstractmethod
def get_security_group_by_id(self, sg_id, context=None):
"""Retrieves the security group by its id.
:param sg_id: The security group ID.
:param context: A request context
:return: octavia.network.data_models.SecurityGroup, None if not enabled
:raises: NetworkException, SecurityGroupNotFound
"""
@abc.abstractmethod
def failover_preparation(self, amphora):
"""Prepare an amphora for failover.

View File

@ -876,7 +876,7 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
raise base.CreatePortException(message)
def get_security_group(self, sg_name):
"""Retrieves the security group by it's name.
"""Retrieves the security group by its name.
:param sg_name: The security group name.
:return: octavia.network.data_models.SecurityGroup, None if not enabled

View File

@ -252,6 +252,9 @@ class BaseNeutronDriver(base.AbstractNetworkDriver):
def get_port(self, port_id, context=None):
return self._get_resource('port', port_id, context=context)
def get_security_group_by_id(self, sg_id, context=None):
return self._get_resource('security_group', sg_id, context=context)
def get_network_by_name(self, network_name):
return self._get_resources_by_filters(
'network', unique_item=True, name=network_name)