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