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
This commit is contained in:
Michael Basnight 2012-03-22 14:21:29 -05:00
parent 8cfa3d97c4
commit bd9515bf54
5 changed files with 45 additions and 7 deletions

View File

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

View File

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

View File

@ -0,0 +1 @@
# Arbitrary information that the guest needs to work

View File

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

View File

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