From 21fa5048fc0ebd9fe1310a3f26d108831a3c92b0 Mon Sep 17 00:00:00 2001 From: naisanzaa Date: Mon, 27 May 2024 19:27:00 +0800 Subject: [PATCH] swift: add is_ready() --- automon/integrations/swift/config.py | 60 ++++++++++++++++++---------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/automon/integrations/swift/config.py b/automon/integrations/swift/config.py index a5a61232..9511099a 100644 --- a/automon/integrations/swift/config.py +++ b/automon/integrations/swift/config.py @@ -1,48 +1,64 @@ import os from automon import log +from automon import environ logger = log.logging.getLogger(__name__) logger.setLevel(log.DEBUG) class SwiftConfig: - OPENSTACK_USERNAME = os.getenv('OPENSTACK_USERNAME') or '' - OPENSTACK_PASSWORD = os.getenv('OPENSTACK_PASSWORD') or '' - OPENSTACK_AUTH_URL = os.getenv('OPENSTACK_AUTH_URL') or '' - OPENSTACK_PROJECT_ID = os.getenv('OPENSTACK_PROJECT_ID') or '' - OPENSTACK_PROJECT_NAME = os.getenv('OPENSTACK_PROJECT_NAME') or '' - OPENSTACK_USER_DOMAIN_NAME = os.getenv('OPENSTACK_USER_DOMAIN_NAME') or '' - OPENSTACK_PROJECT_DOMAIN_ID = os.getenv('OPENSTACK_PROJECT_DOMAIN_ID') or '' - OPENSTACK_REGION_NAME = os.getenv('OPENSTACK_REGION_NAME') or 'RegionOne' - OPENSTACK_INTERFACE = os.getenv('OPENSTACK_INTERFACE') or 'public' - OPENSTACK_IDENTITY_API_VERSION = os.getenv('OPENSTACK_IDENTITY_API_VERSION') or '3' - SWIFTCLIENT_INSECURE = os.getenv('SWIFTCLIENT_INSECURE') or 'True' + OPENSTACK_USERNAME = environ('OPENSTACK_USERNAME', '') + OPENSTACK_PASSWORD = environ('OPENSTACK_PASSWORD', '') + OPENSTACK_AUTH_URL = environ('OPENSTACK_AUTH_URL', '') + OPENSTACK_PROJECT_ID = environ('OPENSTACK_PROJECT_ID', '') + OPENSTACK_PROJECT_NAME = environ('OPENSTACK_PROJECT_NAME', '') + OPENSTACK_USER_DOMAIN_NAME = environ('OPENSTACK_USER_DOMAIN_NAME', '') + OPENSTACK_PROJECT_DOMAIN_ID = environ('OPENSTACK_PROJECT_DOMAIN_ID', '') + OPENSTACK_REGION_NAME = environ('OPENSTACK_REGION_NAME', 'RegionOne') + OPENSTACK_INTERFACE = environ('OPENSTACK_INTERFACE', 'public') + OPENSTACK_IDENTITY_API_VERSION = environ('OPENSTACK_IDENTITY_API_VERSION', 3) + SWIFTCLIENT_INSECURE = environ('SWIFTCLIENT_INSECURE', True) def __init__(self): + pass + def is_ready(self): if not self.OPENSTACK_USERNAME: - logger.warning(f'missing OPENSTACK_USERNAME') + logger.error(f'missing OPENSTACK_USERNAME') + return False if not self.OPENSTACK_PASSWORD: - logger.warning(f'missing OPENSTACK_PASSWORD') + logger.error(f'missing OPENSTACK_PASSWORD') + return False if not self.OPENSTACK_AUTH_URL: - logger.warning(f'missing OPENSTACK_AUTH_URL') + logger.error(f'missing OPENSTACK_AUTH_URL') + return False if not self.OPENSTACK_PROJECT_ID: - logger.warning(f'missing OPENSTACK_PROJECT_ID') + logger.error(f'missing OPENSTACK_PROJECT_ID') + return False if not self.OPENSTACK_PROJECT_NAME: - logger.warning(f'missing OPENSTACK_PROJECT_NAME') + logger.error(f'missing OPENSTACK_PROJECT_NAME') + return False if not self.OPENSTACK_USER_DOMAIN_NAME: - logger.warning(f'missing OPENSTACK_USER_DOMAIN_NAME') + logger.error(f'missing OPENSTACK_USER_DOMAIN_NAME') + return False if not self.OPENSTACK_PROJECT_DOMAIN_ID: - logger.warning(f'missing OPENSTACK_PROJECT_DOMAIN_ID') + logger.error(f'missing OPENSTACK_PROJECT_DOMAIN_ID') + return False if not self.OPENSTACK_REGION_NAME: - logger.warning(f'missing OPENSTACK_REGION_NAME') + logger.error(f'missing OPENSTACK_REGION_NAME') + return False if not self.OPENSTACK_INTERFACE: - logger.warning(f'missing OPENSTACK_INTERFACE') + logger.error(f'missing OPENSTACK_INTERFACE') + return False if not self.OPENSTACK_IDENTITY_API_VERSION: - logger.warning(f'missing OPENSTACK_IDENTITY_API_VERSION') + logger.error(f'missing OPENSTACK_IDENTITY_API_VERSION') + return False if not self.SWIFTCLIENT_INSECURE: - logger.warning(f'missing SWIFTCLIENT_INSECURE') + logger.error(f'missing SWIFTCLIENT_INSECURE') + return False + + return True def __eq__(self, other): if not isinstance(other, SwiftConfig):