Add cachedir and command options

This commit is contained in:
Clint Byrum 2013-06-27 09:41:02 -07:00
parent ae75926f47
commit 21db93faba
3 changed files with 18 additions and 1 deletions

View File

@ -20,6 +20,17 @@ from os_collect_config import ec2
from oslo.config import cfg
opts = [
cfg.StrOpt('command',
short='c',
help='Command to run on metadata changes.'),
cfg.StrOpt('cachedir',
short='d',
default='/var/run/os-collect-config',
help='Directory in which to store local cache of metadata')
]
def setup_conf():
ec2_group = cfg.OptGroup(name='ec2',
title='EC2 Metadata options')
@ -27,6 +38,8 @@ def setup_conf():
conf = cfg.ConfigOpts()
conf.register_group(ec2_group)
conf.register_opts(ec2.opts, group='ec2')
conf.register_opts(opts)
return conf
@ -34,3 +47,6 @@ def __main__():
conf = setup_conf()
log.setup("os-collect-config")
print json.dumps(ec2.collect(conf), indent=1)
if __name__ == '__main__':
__main__()

View File

@ -35,7 +35,7 @@ def _fetch_metadata(fetch_url):
try:
(resp, content) = h.request(fetch_url)
except httplib2.socks.HTTPError as e:
log.getLogger().warn(e)
log.getLogger(__name__).warn(e)
raise exc.Ec2MetadataNotAvailable
if fetch_url[-1] == '/':
new_content = {}

View File

@ -38,3 +38,4 @@ class TestCollect(testtools.TestCase):
def test_setup_conf(self):
conf = collect.setup_conf()
self.assertThat(conf, matchers.IsInstance(cfg.ConfigOpts))
self.assertEquals('/var/run/os-collect-config', conf.cachedir)