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:
parent
8cfa3d97c4
commit
bd9515bf54
@ -53,6 +53,10 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
conf, app = config.Config.load_paste_app('reddwarf-guestagent',
|
conf, app = config.Config.load_paste_app('reddwarf-guestagent',
|
||||||
options, args)
|
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)
|
db_api.configure_db(conf)
|
||||||
server = service.Service.create(binary='reddwarf-guestagent',
|
server = service.Service.create(binary='reddwarf-guestagent',
|
||||||
host=socket.gethostname())
|
host=socket.gethostname())
|
||||||
|
4
etc/reddwarf/conf.d/README
Normal file
4
etc/reddwarf/conf.d/README
Normal 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.
|
1
etc/reddwarf/conf.d/guest_info
Normal file
1
etc/reddwarf/conf.d/guest_info
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Arbitrary information that the guest needs to work
|
@ -16,6 +16,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
"""Routines for configuring Reddwarf."""
|
"""Routines for configuring Reddwarf."""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from reddwarf.openstack.common import config as openstack_config
|
from reddwarf.openstack.common import config as openstack_config
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +44,33 @@ class Config(object):
|
|||||||
cls.instance = conf
|
cls.instance = conf
|
||||||
return 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
|
@classmethod
|
||||||
def get(cls, key, default=None):
|
def get(cls, key, default=None):
|
||||||
return cls.instance.get(key, default)
|
return cls.instance.get(key, default)
|
||||||
|
@ -40,6 +40,7 @@ from sqlalchemy.sql.expression import text
|
|||||||
|
|
||||||
from reddwarf import db
|
from reddwarf import db
|
||||||
from reddwarf.common.exception import ProcessExecutionError
|
from reddwarf.common.exception import ProcessExecutionError
|
||||||
|
from reddwarf.common import config
|
||||||
from reddwarf.common import utils
|
from reddwarf.common import utils
|
||||||
from reddwarf.guestagent.db import models
|
from reddwarf.guestagent.db import models
|
||||||
from reddwarf.instance import models
|
from reddwarf.instance import models
|
||||||
@ -266,18 +267,17 @@ class DBaaSAgent(object):
|
|||||||
preparer.prepare()
|
preparer.prepare()
|
||||||
self.create_database(databases)
|
self.create_database(databases)
|
||||||
PREPARING = False
|
PREPARING = False
|
||||||
# TODO(hub-cap):fix this UGLY hack!
|
# Writing the UUID to the guest agent guest_info file
|
||||||
global UUID
|
conf_loc = '%s/%s' % (config.Config.get('here'), 'conf.d/guest_info')
|
||||||
UUID = uuid
|
config.Config.write_config_values('reddwarf-guestagent',
|
||||||
|
{'config_file': conf_loc}, None, guest_id=uuid)
|
||||||
|
|
||||||
def update_status(self):
|
def update_status(self):
|
||||||
"""Update the status of the MySQL service"""
|
"""Update the status of the MySQL service"""
|
||||||
global MYSQLD_ARGS
|
global MYSQLD_ARGS
|
||||||
global PREPARING
|
global PREPARING
|
||||||
# TODO(hub-cap):fix this UGLY hack!
|
id = config.Config.get('guest_id')
|
||||||
global UUID
|
status = models.InstanceServiceStatus.find_by(instance_id=id)
|
||||||
# instance_id = guest_utils.get_instance_id()
|
|
||||||
status = models.InstanceServiceStatus.find_by(instance_id=UUID)
|
|
||||||
|
|
||||||
if PREPARING:
|
if PREPARING:
|
||||||
status.set_status(models.ServiceStatuses.BUILDING)
|
status.set_status(models.ServiceStatuses.BUILDING)
|
||||||
|
Loading…
Reference in New Issue
Block a user