summaryrefslogtreecommitdiff
path: root/trove/common/neutron.py
diff options
context:
space:
mode:
Diffstat (limited to 'trove/common/neutron.py')
-rw-r--r--trove/common/neutron.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/trove/common/neutron.py b/trove/common/neutron.py
index 9f82eb16..d60eda57 100644
--- a/trove/common/neutron.py
+++ b/trove/common/neutron.py
@@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import netaddr
+from oslo_cache import core
from oslo_log import log as logging
from neutronclient.common import exceptions as neutron_exceptions
+from trove.common import cache
from trove.common import cfg
from trove.common import clients
from trove.common import exception
@@ -26,6 +28,11 @@ MGMT_CIDRS = None
NEUTRON_EXTENSION_CACHE = {}
PROJECT_ID_EXT_ALIAS = 'project-id'
+MEMOIZE_PORTS = core.get_memoization_decorator(
+ conf=CONF,
+ region=cache.get_cache_region(),
+ group="instance_ports_cache")
+
def check_extension_enabled(client, extension_alias):
"""Check if an extension is enabled in Neutron."""
@@ -93,6 +100,20 @@ def check_subnet_router(client, subnet_id):
f"associated with router.")
+@MEMOIZE_PORTS
+def get_instance_ports(client, instance_id):
+ """Get ports attached to the trove instance.
+
+ After the trove instance is created, the attached ports are not changed.
+ """
+ LOG.info(f'Getting ports for instance {instance_id}')
+ return client.list_ports(device_id=instance_id)['ports']
+
+
+def get_port_fips(client, port_id):
+ return client.list_floatingips(port_id=port_id)['floatingips']
+
+
def create_port(client, name, description, network_id, security_groups,
is_public=False, subnet_id=None, ip=None, is_mgmt=False,
project_id=None):