Getting the guest status update working.

* Added the db calls to the guest code
* Changed the default for the confs to use MySQL
* Added HACKISH uuid as a global var for status lookups
* * This is because the ip is no longer saved
    in the reddwarf db. We can do something
    better in the future since this does
    not persist if the agent stops.
This commit is contained in:
Michael Basnight 2012-03-21 23:15:46 -05:00
parent a5f978bae3
commit 8cfa3d97c4
5 changed files with 28 additions and 26 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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):