More work on monitless installer

This commit is contained in:
Duncan Sommerville 2014-12-16 19:42:07 -05:00
parent ad4b61e89f
commit 8a2c155289
5 changed files with 30 additions and 29 deletions

View file

@ -183,17 +183,17 @@ class RequestProvider(object):
def __init__(self, cfg):
self.config = cfg
self.requests = {}
if self.config["base_dir"].startswith("/"):
self.config["base_dir"] = self.config["base_dir"][1:]
if self.config["general"]["base_dir"].startswith("/"):
self.config["general"]["base_dir"] = self.config["general"]["base_dir"][1:]
self.url = ApcUrl("http://%s:%s/%s%s/%s" \
% (self.config["host"], str(self.config["base_port"]),
self.config["base_dir"], self.config["api_base"],
% (self.config["general"]["base_url"], str(self.config["general"]["base_port"]),
self.config["general"]["base_dir"], self.config["api_base"],
'%%action%%'))
# Now we must discover the possible actions
actions = dict( (k,v) for k,v in cfg.iteritems() if '%%api_key%%' in v)
for action_name, action_value in actions.iteritems():
new_url = self.url.params(action=action_value).params(
api_key=self.config['api_key'])
api_key=self.config["general"]['api_key'])
self.requests[action_name] = ApiRequest(action_name, new_url)
def available_requests(self) : return self.requests.keys()
@ -321,13 +321,13 @@ class AirtimeApiClient(object):
def construct_url(self,config_action_key):
"""Constructs the base url for every request"""
# TODO : Make other methods in this class use this this method.
if self.config["base_dir"].startswith("/"):
self.config["base_dir"] = self.config["base_dir"][1:]
if self.config["general"]["base_dir"].startswith("/"):
self.config["general"]["base_dir"] = self.config["general"]["base_dir"][1:]
url = "http://%s:%s/%s%s/%s" % \
(self.config["host"], str(self.config["base_port"]),
self.config["base_dir"], self.config["api_base"],
(self.config["general"]["base_url"], str(self.config["general"]["base_port"]),
self.config["general"]["base_dir"], self.config["api_base"],
self.config[config_action_key])
url = url.replace("%%api_key%%", self.config["api_key"])
url = url.replace("%%api_key%%", self.config["general"]["api_key"])
return url
"""

View file

@ -45,7 +45,7 @@ class AirtimeNotifier(Notifier):
try:
schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
self.connection = BrokerConnection(self.config.cfg["rabbitmq_host"], self.config.cfg["rabbitmq_user"], self.config.cfg["rabbitmq_password"], self.config.cfg["rabbitmq_vhost"])
self.connection = BrokerConnection(self.config.cfg["rabbitmq"]["rabbitmq_host"], self.config.cfg["rabbitmq"]["rabbitmq_user"], self.config.cfg["rabbitmq"]["rabbitmq_password"], self.config.cfg["rabbitmq"]["rabbitmq_vhost"])
channel = self.connection.channel()
consumer = Consumer(channel, schedule_queue)
consumer.register_callback(self.handle_message)

View file

@ -38,9 +38,9 @@ class AirtimeNotifier(Loggable):
durable=True, auto_delete=True)
schedule_queue = Queue("media-monitor", exchange=schedule_exchange,
key="filesystem")
self.connection = BrokerConnection(self.cfg["rabbitmq_host"],
self.cfg["rabbitmq_user"], self.cfg["rabbitmq_password"],
self.cfg["rabbitmq_vhost"])
self.connection = BrokerConnection(self.cfg["rabbitmq"]["rabbitmq_host"],
self.cfg["rabbitmq"]["rabbitmq_user"], self.cfg["rabbitmq"]["rabbitmq_password"],
self.cfg["rabbitmq"]["rabbitmq_vhost"])
channel = self.connection.channel()
self.simple_queue = SimpleQueue(channel, schedule_queue)

View file

@ -23,10 +23,10 @@ class MM2(InstanceThread, Loggable):
def index_create(self, index_create_attempt=False):
config = user().mm_config
if not index_create_attempt:
if not os.path.exists(config['index_path']):
if not os.path.exists(config['media-monitor']['index_path']):
self.logger.info("Attempting to create index file:...")
try:
with open(config['index_path'], 'w') as f: f.write(" ")
with open(config['media-monitor']['index_path'], 'w') as f: f.write(" ")
except Exception as e:
self.logger.info("Failed to create index file with exception: %s" \
% str(e))
@ -36,8 +36,8 @@ class MM2(InstanceThread, Loggable):
else:
self.logger.info("Already tried to create index. Will not try again ")
if not os.path.exists(config['index_path']):
raise CouldNotCreateIndexFile(config['index_path'])
if not os.path.exists(config['media-monitor']['index_path']):
raise CouldNotCreateIndexFile(config['media-monitor']['index_path'])
def run(self):
self.index_create()
@ -45,8 +45,8 @@ class MM2(InstanceThread, Loggable):
apiclient = apc()
config = user().mm_config
WatchSyncer(signal=getsig('watch'),
chunking_number=config['chunking_number'],
timeout=config['request_max_wait'])
chunking_number=config['media-monitor']['chunking_number'],
timeout=config['media-monitor']['request_max_wait'])
airtime_receiver = AirtimeMessageReceiver(config,manager)
airtime_notifier = AirtimeNotifier(config, airtime_receiver)
@ -76,14 +76,14 @@ class MM2(InstanceThread, Loggable):
else: self.logger.info("Failed to add watch on %s" % str(watch_dir))
EventDrainer(airtime_notifier,
interval=float(config['rmq_event_wait']))
interval=float(config['media-monitor']['rmq_event_wait']))
# Launch the toucher that updates the last time when the script was
# ran every n seconds.
# TODO : verify that this does not interfere with bootstrapping because the
# toucher thread might update the last_ran variable too fast
ToucherThread(path=user().touch_file_path(),
interval=int(config['touch_interval']))
interval=int(config['media-monitor']['touch_interval']))
success = False
while not success:

View file

@ -137,7 +137,7 @@ configure_locale()
# loading config file
try:
config = ConfigObj('/etc/airtime/pypo.cfg')
config = ConfigObj('/etc/airtime/airtime.conf')
except Exception, e:
logger.error('Error loading config file: %s', e)
sys.exit(1)
@ -241,8 +241,8 @@ if __name__ == '__main__':
telnet_lock = Lock()
ls_host = config['ls_host']
ls_port = config['ls_port']
ls_host = config['pypo']['ls_host']
ls_port = config['pypo']['ls_port']
liquidsoap_startup_test()
@ -269,19 +269,20 @@ if __name__ == '__main__':
"""
media_q = Queue()
pmh = PypoMessageHandler(pypoFetch_q, recorder_q, config)
# Pass only the configuration sections needed; PypoMessageHandler only needs rabbitmq settings
pmh = PypoMessageHandler(pypoFetch_q, recorder_q, config['rabbitmq'])
pmh.daemon = True
pmh.start()
pfile = PypoFile(media_q, config)
pfile = PypoFile(media_q, config['pypo'])
pfile.daemon = True
pfile.start()
pf = PypoFetch(pypoFetch_q, pypoPush_q, media_q, telnet_lock, pypo_liquidsoap, config)
pf = PypoFetch(pypoFetch_q, pypoPush_q, media_q, telnet_lock, pypo_liquidsoap, config['pypo'])
pf.daemon = True
pf.start()
pp = PypoPush(pypoPush_q, telnet_lock, pypo_liquidsoap, config)
pp = PypoPush(pypoPush_q, telnet_lock, pypo_liquidsoap, config['pypo'])
pp.daemon = True
pp.start()