Commit 2f718b53 authored by garciadeblas's avatar garciadeblas
Browse files

Merge branch 'helm-ee' into 'master'

Added primitive accessing a helm subchart

See merge request !184
parents 503e6bab 953e839b
Loading
Loading
Loading
Loading
Loading
+39.4 KiB

File added.

No diff preview for this file type.

+0 −0

Empty file added.

+3 −0
Original line number Diff line number Diff line
@@ -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
+34 −0
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@
import logging
import asyncio
import asyncssh
import time


from mysql.connector import connect, Error

logger = logging.getLogger("osm_ee.vnf")

@@ -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
+17 −0
Original line number Diff line number Diff line
@@ -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