From bd9515bf541375f187ba7600d0c93b0493850ef1 Mon Sep 17 00:00:00 2001 From: Michael Basnight Date: Thu, 22 Mar 2012 14:21:29 -0500 Subject: [PATCH] Adding the guest conf.d writing * Made sure to append the conf in the startup * Added the methods to append/write * Made the dbaas guest agent write guest uuid --- bin/reddwarf-guestagent | 4 ++++ etc/reddwarf/conf.d/README | 4 ++++ etc/reddwarf/conf.d/guest_info | 1 + reddwarf/common/config.py | 29 +++++++++++++++++++++++++++++ reddwarf/guestagent/dbaas.py | 14 +++++++------- 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 etc/reddwarf/conf.d/README create mode 100644 etc/reddwarf/conf.d/guest_info diff --git a/bin/reddwarf-guestagent b/bin/reddwarf-guestagent index b88b3cb76e..fd0054c3d8 100755 --- a/bin/reddwarf-guestagent +++ b/bin/reddwarf-guestagent @@ -53,6 +53,10 @@ if __name__ == '__main__': try: conf, app = config.Config.load_paste_app('reddwarf-guestagent', options, args) + # Use the config file location for putting the new config values + conf_loc = '%s/%s' % (config.Config.get('here'), 'conf.d/guest_info') + config.Config.append_to_config_values('reddwarf-guestagent', + {'config_file': conf_loc}, None) db_api.configure_db(conf) server = service.Service.create(binary='reddwarf-guestagent', host=socket.gethostname()) diff --git a/etc/reddwarf/conf.d/README b/etc/reddwarf/conf.d/README new file mode 100644 index 0000000000..e72154054f --- /dev/null +++ b/etc/reddwarf/conf.d/README @@ -0,0 +1,4 @@ +These conf files are read and used by the guest to provide extra +information to the guest. The first example of this is the +guest_info which will have the uuid of the instance so that +the guest can report back things to the infra. diff --git a/etc/reddwarf/conf.d/guest_info b/etc/reddwarf/conf.d/guest_info new file mode 100644 index 0000000000..fb5ba36a53 --- /dev/null +++ b/etc/reddwarf/conf.d/guest_info @@ -0,0 +1 @@ +# Arbitrary information that the guest needs to work diff --git a/reddwarf/common/config.py b/reddwarf/common/config.py index 8e96afc478..1563433ce3 100644 --- a/reddwarf/common/config.py +++ b/reddwarf/common/config.py @@ -16,6 +16,8 @@ # under the License. """Routines for configuring Reddwarf.""" +import re + from reddwarf.openstack.common import config as openstack_config @@ -42,6 +44,33 @@ class Config(object): cls.instance = conf return conf + @classmethod + def append_to_config_values(cls, *args): + config_file = openstack_config.find_config_file(*args) + if not config_file: + raise RuntimeError("Unable to locate any configuration file. " + "Cannot load application %s" % app_name) + # Now take the conf file values and append them to the current conf + with open(config_file, 'r') as conf: + for line in conf.readlines(): + m = re.match("\s*([^#]\S+)\s*=\s*(\S+)\s*", line) + if m: + cls.instance[m.group(1)] = m.group(2) + + @classmethod + def write_config_values(cls, *args, **kwargs): + # Pass in empty kwargs so it doesnt mess up the config find + config_file = openstack_config.find_config_file(*args) + if not config_file: + raise RuntimeError("Unable to locate any configuration file. " + "Cannot load application %s" % app_name) + with open(config_file, 'a') as conf: + for k, v in kwargs.items(): + # Start with newline to be sure its on a new line + conf.write("\n%s=%s" % (k, v)) + # Now append them to the cls instance + cls.append_to_config_values(*args) + @classmethod def get(cls, key, default=None): return cls.instance.get(key, default) diff --git a/reddwarf/guestagent/dbaas.py b/reddwarf/guestagent/dbaas.py index 73da50e942..145d5bb96a 100644 --- a/reddwarf/guestagent/dbaas.py +++ b/reddwarf/guestagent/dbaas.py @@ -40,6 +40,7 @@ from sqlalchemy.sql.expression import text from reddwarf import db from reddwarf.common.exception import ProcessExecutionError +from reddwarf.common import config from reddwarf.common import utils from reddwarf.guestagent.db import models from reddwarf.instance import models @@ -266,18 +267,17 @@ class DBaaSAgent(object): preparer.prepare() self.create_database(databases) PREPARING = False - # TODO(hub-cap):fix this UGLY hack! - global UUID - UUID = uuid + # Writing the UUID to the guest agent guest_info file + conf_loc = '%s/%s' % (config.Config.get('here'), 'conf.d/guest_info') + config.Config.write_config_values('reddwarf-guestagent', + {'config_file': conf_loc}, None, guest_id=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) + id = config.Config.get('guest_id') + status = models.InstanceServiceStatus.find_by(instance_id=id) if PREPARING: status.set_status(models.ServiceStatuses.BUILDING)