diff --git a/bin/reddwarf-guestagent b/bin/reddwarf-guestagent index 1201def52a..b88b3cb76e 100755 --- a/bin/reddwarf-guestagent +++ b/bin/reddwarf-guestagent @@ -40,7 +40,7 @@ from reddwarf import version from reddwarf.common import config from reddwarf.common import service # TODO(hub-cap): find out why the db api isint being imported properly -#from reddwarf.db import db_api +from reddwarf.db import db_api if __name__ == '__main__': @@ -53,7 +53,7 @@ if __name__ == '__main__': try: conf, app = config.Config.load_paste_app('reddwarf-guestagent', options, args) - # db_api.configure_db(conf) + db_api.configure_db(conf) server = service.Service.create(binary='reddwarf-guestagent', host=socket.gethostname()) service.serve(server) diff --git a/etc/reddwarf/reddwarf-guestagent.conf.sample b/etc/reddwarf/reddwarf-guestagent.conf.sample index 682b9d4d33..c71259acf4 100644 --- a/etc/reddwarf/reddwarf-guestagent.conf.sample +++ b/etc/reddwarf/reddwarf-guestagent.conf.sample @@ -17,8 +17,8 @@ rabbit_password=f7999d1955c5014aa32c # SQLAlchemy connection string for the reference implementation # registry server. Any valid SQLAlchemy connection string is fine. # See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine -sql_connection = sqlite:///reddwarf_test.sqlite -# sql_connection = mysql://root:root@localhost/reddwarf +#sql_connection = sqlite:///reddwarf_test.sqlite +sql_connection = mysql://root:e1a2c042c828d3566d0a@10.0.0.1/reddwarf #sql_connection = postgresql://reddwarf:reddwarf@localhost/reddwarf # Period in seconds after which SQLAlchemy should reestablish its connection diff --git a/etc/reddwarf/reddwarf.conf.sample b/etc/reddwarf/reddwarf.conf.sample index d68e768692..e9fc2c6c4c 100644 --- a/etc/reddwarf/reddwarf.conf.sample +++ b/etc/reddwarf/reddwarf.conf.sample @@ -17,8 +17,8 @@ rabbit_password=f7999d1955c5014aa32c # SQLAlchemy connection string for the reference implementation # registry server. Any valid SQLAlchemy connection string is fine. # See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine -sql_connection = sqlite:///reddwarf_test.sqlite -# sql_connection = mysql://root:root@localhost/reddwarf +# sql_connection = sqlite:///reddwarf_test.sqlite +sql_connection = mysql://root:e1a2c042c828d3566d0a@localhost/reddwarf #sql_connection = postgresql://reddwarf:reddwarf@localhost/reddwarf # Period in seconds after which SQLAlchemy should reestablish its connection diff --git a/reddwarf/guestagent/api.py b/reddwarf/guestagent/api.py index 0984facc00..c322c9d8bc 100644 --- a/reddwarf/guestagent/api.py +++ b/reddwarf/guestagent/api.py @@ -125,7 +125,8 @@ class API(object): rpc.cast_with_consumer(context, self._get_routing_key(context, id), {"method": "prepare", "args": {"databases": databases, - "memory_mb": memory_mb} + "memory_mb": memory_mb, + "uuid": id} }) def restart(self, context, id): diff --git a/reddwarf/guestagent/dbaas.py b/reddwarf/guestagent/dbaas.py index bba36d3f66..73da50e942 100644 --- a/reddwarf/guestagent/dbaas.py +++ b/reddwarf/guestagent/dbaas.py @@ -38,13 +38,11 @@ from sqlalchemy import exc from sqlalchemy import interfaces from sqlalchemy.sql.expression import text -# from nova.compute import power_state -# from nova.exception import ProcessExecutionError -# from reddwarf.db import api as dbapi +from reddwarf import db from reddwarf.common.exception import ProcessExecutionError from reddwarf.common import utils -# from reddwarf.guestagent import utils as guest_utils from reddwarf.guestagent.db import models +from reddwarf.instance import models ADMIN_USER_NAME = "os_admin" LOG = logging.getLogger(__name__) @@ -53,6 +51,7 @@ FLUSH = text("""FLUSH PRIVILEGES;""") ENGINE = None MYSQLD_ARGS = None PREPARING = False +UUID = False def generate_random_password(): @@ -256,7 +255,7 @@ class DBaaSAgent(object): LOG.debug("result = " + str(result)) return result.rowcount != 0 - def prepare(self, databases, memory_mb): + def prepare(self, databases, memory_mb, uuid): """Makes ready DBAAS on a Guest container.""" global PREPARING PREPARING = True @@ -267,46 +266,48 @@ class DBaaSAgent(object): preparer.prepare() self.create_database(databases) PREPARING = False + # TODO(hub-cap):fix this UGLY hack! + global UUID + UUID = uuid def update_status(self): """Update the status of the MySQL service""" global MYSQLD_ARGS global PREPARING + # TODO(hub-cap):fix this UGLY hack! + global UUID # instance_id = guest_utils.get_instance_id() + status = models.InstanceServiceStatus.find_by(instance_id=UUID) if PREPARING: - #TODO(hub-cap): Fix the guest_status_update - # dbapi.guest_status_update(instance_id, power_state.BUILDING) + status.set_status(models.ServiceStatuses.BUILDING) + status.save() return try: out, err = utils.execute("/usr/bin/mysqladmin", "ping", run_as_root=True) - #TODO(hub-cap): Fix the guest_status_update - # dbapi.guest_status_update(instance_id, power_state.RUNNING) + status.set_status(models.ServiceStatuses.RUNNING) + status.save() except ProcessExecutionError as e: try: out, err = utils.execute("ps", "-C", "mysqld", "h") pid = out.split()[0] # TODO(rnirmal): Need to create new statuses for instances # where the mysql service is up, but unresponsive - #TODO(hub-cap): Fix the guest_status_update - # dbapi.guest_status_update(instance_id, power_state.BLOCKED) + status.set_status(models.ServiceStatuses.BLOCKED) + status.save() except ProcessExecutionError as e: if not MYSQLD_ARGS: MYSQLD_ARGS = load_mysqld_options() pid_file = MYSQLD_ARGS.get('pid-file', '/var/run/mysqld/mysqld.pid') if os.path.exists(pid_file): - pass - #TODO(hub-cap): Fix the guest_status_update - # dbapi.guest_status_update(instance_id, - # power_state.CRASHED) + status.set_status(models.ServiceStatuses.CRASHED) + status.save() else: - pass - #TODO(hub-cap): Fix the guest_status_update - # dbapi.guest_status_update(instance_id, - # power_state.SHUTDOWN) + status.set_status(models.ServiceStatuses.SHUTDOWN) + status.save() class LocalSqlClient(object):