Loading sample_ee_vnf/helm-charts/eechart/charts.sample/mysql-8.8.26.tgz 0 → 100644 +39.4 KiB File added.No diff preview for this file type. View file sample_ee_vnf/helm-charts/eechart/charts/.gitkeep 0 → 100644 +0 −0 Empty file added. sample_ee_vnf/helm-charts/eechart/source/install.sh +3 −0 Original line number Diff line number Diff line Loading @@ -31,3 +31,6 @@ apt install -y iputils-ping # Install HTTP python library python3 -m pip install requests # Install MySQL library python3 -m pip install mysql-connector-python sample_ee_vnf/helm-charts/eechart/source/mylib.py +34 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ import logging import asyncio import asyncssh import time from mysql.connector import connect, Error logger = logging.getLogger("osm_ee.vnf") Loading @@ -44,3 +48,33 @@ async def ssh_exec(host: str, user: str, command: str except Exception as e: logger.error("Error: {}".format(repr(e))) return -1, str(e) def mysql_query(host: str, user: str, password: str, retries: int, query: str ) -> (int, str): """ Execute a query to a MySQL database. """ text = "" logger.debug("Host: '{}', user: '{}', password: '{}', query: '{}'".format(host, user, password, query)) for i in range(0, retries): try: with connect( host=host, user=user, password=password, ) as connection: with connection.cursor() as cursor: cursor.execute(query) for (db) in cursor: logger.debug(db) text = text + str(db[0]) + ", " return 0, text[0:len(text)-2] except Error as e: text = str(e) logger.debug("Error: {}".format(e)) time.sleep(3) continue return -1, text sample_ee_vnf/helm-charts/eechart/source/vnf_ee.py +17 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,23 @@ class VnfEE: # else: # yield "OK", description # This method implements the "check_database" primitive. Uncomment and modify it if a primitive requires # accessing to a service provided by a helm subchart. Access parameters are read from environment variables # async def check_database(self, id, params): # self.logger.debug("Execute action check_database, params: '{}'".format(params)) # host = os.getenv('mysql_host') # user = os.getenv('mysql_user') # password = os.getenv('mysql_password') # retries = 3 # query = "SHOW DATABASES" # return_code, description = mylib.mysql_query(host, user, password, retries, query) # if return_code != 0: # yield "ERROR", description # else: # yield "OK", description # Static method that verifies whether a parameter exists in the map @staticmethod def _check_required_params(params, required_params): Loading Loading
sample_ee_vnf/helm-charts/eechart/charts.sample/mysql-8.8.26.tgz 0 → 100644 +39.4 KiB File added.No diff preview for this file type. View file
sample_ee_vnf/helm-charts/eechart/source/install.sh +3 −0 Original line number Diff line number Diff line Loading @@ -31,3 +31,6 @@ apt install -y iputils-ping # Install HTTP python library python3 -m pip install requests # Install MySQL library python3 -m pip install mysql-connector-python
sample_ee_vnf/helm-charts/eechart/source/mylib.py +34 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ import logging import asyncio import asyncssh import time from mysql.connector import connect, Error logger = logging.getLogger("osm_ee.vnf") Loading @@ -44,3 +48,33 @@ async def ssh_exec(host: str, user: str, command: str except Exception as e: logger.error("Error: {}".format(repr(e))) return -1, str(e) def mysql_query(host: str, user: str, password: str, retries: int, query: str ) -> (int, str): """ Execute a query to a MySQL database. """ text = "" logger.debug("Host: '{}', user: '{}', password: '{}', query: '{}'".format(host, user, password, query)) for i in range(0, retries): try: with connect( host=host, user=user, password=password, ) as connection: with connection.cursor() as cursor: cursor.execute(query) for (db) in cursor: logger.debug(db) text = text + str(db[0]) + ", " return 0, text[0:len(text)-2] except Error as e: text = str(e) logger.debug("Error: {}".format(e)) time.sleep(3) continue return -1, text
sample_ee_vnf/helm-charts/eechart/source/vnf_ee.py +17 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,23 @@ class VnfEE: # else: # yield "OK", description # This method implements the "check_database" primitive. Uncomment and modify it if a primitive requires # accessing to a service provided by a helm subchart. Access parameters are read from environment variables # async def check_database(self, id, params): # self.logger.debug("Execute action check_database, params: '{}'".format(params)) # host = os.getenv('mysql_host') # user = os.getenv('mysql_user') # password = os.getenv('mysql_password') # retries = 3 # query = "SHOW DATABASES" # return_code, description = mylib.mysql_query(host, user, password, retries, query) # if return_code != 0: # yield "ERROR", description # else: # yield "OK", description # Static method that verifies whether a parameter exists in the map @staticmethod def _check_required_params(params, required_params): Loading