From e7d2cd0ad3a9d37132103cacd1fb1a5d5acec52a Mon Sep 17 00:00:00 2001 From: yuval Date: Thu, 14 Aug 2025 12:24:30 +0300 Subject: [PATCH] LightOS: update discovery client configuration The LightOS connector uses hardcoded values for discovery client connection parameters, preventing customization for different deployment environments and containers with custom networks. Example of when this is needed: We have 1 Cinder instance in a Docker container with network 10.10.10.1, and a discovery-service located at 10.10.10.2. In the same cluster, we have a Nova instance in a container with network 20.20.20.1, and a discovery-service at 20.20.20.2. I need to be able to set the network address for each instance. Default values are set for backward compatibility. Change-Id: I19065ad683b9ff8174814d6e8c500178c885bee4 Signed-off-by: yuval --- os_brick/initiator/connectors/lightos.py | 37 +++++++++++++++++-- ...iscovery-client-conf-1a1a5b5a68b5914b.yaml | 28 ++++++++++++++ setup.cfg | 1 + 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add-lightos-discovery-client-conf-1a1a5b5a68b5914b.yaml diff --git a/os_brick/initiator/connectors/lightos.py b/os_brick/initiator/connectors/lightos.py index 61d36034a..baeffafe4 100644 --- a/os_brick/initiator/connectors/lightos.py +++ b/os_brick/initiator/connectors/lightos.py @@ -23,6 +23,7 @@ import time import traceback from oslo_concurrency import processutils as putils +from oslo_config import cfg from oslo_log import log as logging from oslo_utils import netutils import psutil @@ -35,12 +36,30 @@ from os_brick import utils DEVICE_SCAN_ATTEMPTS_DEFAULT = 5 -DISCOVERY_CLIENT_PORT = 6060 LOG = logging.getLogger(__name__) nvmec_pattern = ".*nvme[0-9]+[cp][0-9]+.*" nvmec_match = re.compile(nvmec_pattern) +_opts = [ + cfg.HostAddressOpt('lightos_discovery_client_address', + default="localhost", + help="Address of the LightOS discovery client"), + cfg.PortOpt('lightos_discovery_client_port', + default=6060, + help="Port of the LightOS discovery client"), + cfg.StrOpt('lightos_discovery_client_dir_path', + default='/etc/discovery-client/discovery.d/', + help="Directory path for the LightOS discovery client files.") +] + +cfg.CONF.register_opts(_opts, group='os_brick') + + +def list_opts(): + """oslo.config.opts entrypoint for sample config generation.""" + return [('os_brick', _opts)] + class LightOSConnector(base.BaseLinuxConnector): """Connector class to attach/detach LightOS volumes using NVMe/TCP.""" @@ -62,7 +81,15 @@ class LightOSConnector(base.BaseLinuxConnector): device_scan_attempts=device_scan_attempts, *args, **kwargs) self.message_queue = message_queue - self.DISCOVERY_DIR_PATH = '/etc/discovery-client/discovery.d/' + self.discovery_dir_path = ( + cfg.CONF.os_brick.lightos_discovery_client_dir_path + ) + self.discovery_address = ( + cfg.CONF.os_brick.lightos_discovery_client_address + ) + self.discovery_port = ( + cfg.CONF.os_brick.lightos_discovery_client_port + ) @staticmethod def get_ip_addresses(): @@ -123,10 +150,12 @@ class LightOSConnector(base.BaseLinuxConnector): return props def dsc_file_name(self, uuid): - return os.path.join(self.DISCOVERY_DIR_PATH, "%s.conf" % uuid) + return os.path.join(self.discovery_dir_path, "%s.conf" % uuid) def find_dsc(self): - conn = http.client.HTTPConnection("localhost", DISCOVERY_CLIENT_PORT) + conn = http.client.HTTPConnection( + self.discovery_address, + self.discovery_port) try: conn.request("HEAD", "/metrics") resp = conn.getresponse() diff --git a/releasenotes/notes/add-lightos-discovery-client-conf-1a1a5b5a68b5914b.yaml b/releasenotes/notes/add-lightos-discovery-client-conf-1a1a5b5a68b5914b.yaml new file mode 100644 index 000000000..96aa3c8cc --- /dev/null +++ b/releasenotes/notes/add-lightos-discovery-client-conf-1a1a5b5a68b5914b.yaml @@ -0,0 +1,28 @@ +--- +features: + - | + **LightOS connector**: Introduce new configuration options to customize + the LightOS discovery client’s behavior. + + Operators can now override the default values for: + + - ``discovery_client_address`` + - ``discovery_client_port`` + - ``discovery_client_dir_path`` + + These settings allow fine-tuning of the discovery client’s network + endpoint and configuration directory. + +upgrade: + - | + **LightOS connector**: Introduce new configuration options to customize + the LightOS discovery client’s behavior. + + Operators can now override the default values for: + + - ``discovery_client_address`` + - ``discovery_client_port`` + - ``discovery_client_dir_path`` + + No changes required. Default values are retained for backward compatibility; + no action is needed during upgrade. \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index bc16bda3e..dde2c5bb6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,7 @@ data_files = [entry_points] oslo.config.opts = os_brick = os_brick.opts:list_opts + os_brick.lightos = os_brick.initiator.connectors.lightos:list_opts oslo.config.opts.defaults = os_brick = os_brick.opts:set_defaults