From 0aaf5d36f5ea1bcdf5ff2cd7dd5498f5624393f5 Mon Sep 17 00:00:00 2001
From: Takashi Kajinami <kajinamit@oss.nttdata.com>
Date: Sat, 26 Oct 2024 21:44:25 +0900
Subject: [PATCH] Use escape_ipv6 from oslo.utils

The utility is available since oslo.utils 3.29.0 .

Change-Id: I12dfd8936a718eacb0ced620efd60546721f7699
---
 zaqar/transport/websocket/driver.py | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/zaqar/transport/websocket/driver.py b/zaqar/transport/websocket/driver.py
index d1a04d8f5..7d328fa4a 100644
--- a/zaqar/transport/websocket/driver.py
+++ b/zaqar/transport/websocket/driver.py
@@ -30,14 +30,6 @@ from zaqar.transport.websocket import factory
 LOG = logging.getLogger(__name__)
 
 
-# TODO(derekh): use escape_ipv6 from oslo.utils once available
-def _escape_ipv6(address):
-    """Escape an IP address in square brackets if IPv6"""
-    if netutils.is_valid_ipv6(address):
-        return "[%s]" % address
-    return address
-
-
 class Driver(base.DriverBase):
 
     def __init__(self, conf, api, cache):
@@ -58,7 +50,7 @@ class Driver(base.DriverBase):
 
     @decorators.lazy_property(write=False)
     def factory(self):
-        uri = 'ws://' + _escape_ipv6(self._ws_conf.bind) + ':' + \
+        uri = 'ws://' + netutils.escape_ipv6(self._ws_conf.bind) + ':' + \
               str(self._ws_conf.port)
         return factory.ProtocolFactory(
             uri,
@@ -101,7 +93,7 @@ class Driver(base.DriverBase):
             else:
                 host = socket.gethostname()
             self.notification_factory.set_subscription_url(
-                'http://%s:%s/' % (_escape_ipv6(host), port))
+                'http://%s:%s/' % (netutils.escape_ipv6(host), port))
             self._api.set_subscription_factory(self.notification_factory)
 
         task = asyncio.Task(coro_notification)