diff --git a/ee/cli/plugins/mysqlstack.py b/ee/cli/plugins/mysqlstack.py index 5c9e6659..339bacab 100644 --- a/ee/cli/plugins/mysqlstack.py +++ b/ee/cli/plugins/mysqlstack.py @@ -1,4 +1,5 @@ import os +import sys import random import string import configparser @@ -7,8 +8,8 @@ from ee.core.aptget import EEAptGet from ee.core.apt_repo import EERepo from ee.cli.plugins.eestack import EEStack from ee.core.shellexec import EEShellExec - -# from ee.core.logging import Log +from ee.core.shellexec import CommandExecutionError +from ee.core.logging import Log from ee.cli.main import app @@ -17,29 +18,26 @@ class EEMysqlStack(EEStack): EasyEngine MYSQL stack """ packages_name = ["mariadb-server", "percona-toolkit"] - # log = app.log + log = app.log + def __init__(self, packages_name=None): """ - Initialize packages list in stack - pkgs_name: list of packages to be intialized for operations - in stack + Initialize packages list in stack + pkgs_name : list of packages to be intialized for operations + in stack """ - self.packages_name = self._get_stack() - - self.log = app.log - print(self.packages_name) + self.packages_name = self._get_stack() super(EEMysqlStack, self).__init__(self.packages_name) def _get_stack(self): - return EEMysqlStack.packages_name + return EEMysqlStack.packages_name - - def _pre_install_stack(self): + def _add_repo(self): """ - Defines pre-install activities done before installing mysql stack + Add repository for packages to be downloaded from """ - + self.log.info("Adding MySQL repository, please wait...") mysql_pref = ("Package: *\nPin: origin mirror.aarnet.edu.au" "\nPin-Priority: 1000\n") with open('/etc/apt/preferences.d/' @@ -53,14 +51,20 @@ class EEMysqlStack(EEStack): .format(EEVariables.ee_mysql_repo)) EERepo.add_key(self, '0xcbcb082a1bb943db', keyserver="keyserver.ubuntu.com") + EEAptGet.update(self) + def _pre_install_stack(self): + """ + Defines pre-install activities done before installing mysql stack + """ + self._add_repo() # Predefine MySQL Credentials chars = ''.join(random.sample(string.ascii_letters, 8)) - print("Pre-seeding MySQL") - print("echo \"mariadb-server-10.0 " - "mysql-server/root_password " - "password \" | " - "debconf-set-selections") + self.log.info("Pre-seeding MySQL") + self.log.debug("echo \"mariadb-server-10.0 " + "mysql-server/root_password " + "password \" | " + "debconf-set-selections") try: EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password " @@ -69,13 +73,13 @@ class EEMysqlStack(EEStack): .format(chars=chars), log=False) except CommandExecutionError as e: - print("Failed to initialize MySQL package") + self.log.error("Failed to initialize MySQL package") # Predefine MySQL credentials - print("echo \"mariadb-server-10.0 " - "mysql-server/root_password_again " - "password \" | " - "debconf-set-selections") + self.log.debug("echo \"mariadb-server-10.0 " + "mysql-server/root_password_again " + "password \" | " + "debconf-set-selections") try: EEShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 " "mysql-server/root_password_again " @@ -84,8 +88,7 @@ class EEMysqlStack(EEStack): .format(chars=chars), log=False) except CommandExecutionError as e: - - print("Failed to initialize MySQL package") + self.log.error("Failed to initialize MySQL package") # Write ~/.my.cnf configuration mysql_config = """ @@ -95,30 +98,33 @@ class EEMysqlStack(EEStack): """.format(chars=chars) config = configparser.ConfigParser() config.read_string(mysql_config) - print('Writting configuration into MySQL file') + self.log.debug('Writting configuration into MySQL file') with open(os.path.expanduser("~")+'/.my.cnf', encoding='utf-8', mode='w') as configfile: config.write(configfile) - print("Done") def _post_install_stack(self): """ - Defines activities done after installing mysql stack + Defines activities done after installing mysql stack """ pass def install_stack(self): - print("Installing MySQL stack") + """ + Install MYSQL stack + """ + self.log.info("Installing MySQL stack, please wait...") self._pre_install_stack() super(EEMysqlStack, self).install_stack() self._post_install_stack() def remove_stack(self): - print("Removing MySQL stack") + """ + Remove MYSQL stack + """ + self.log.info("Removing MySQL stack, please wait...") super(EEMysqlStack, self).remove_stack() def purge_stack(self): - print("Purging MySQL stack") + self.log.info("Purging MySQL stack, please wait...") super(EEMysqlStack, self).purge_stack() - print("Done") -