Ability to read external services from vent.cfg
@@ -309,6 +309,25 @@ class PluginHelper:
tool_d[c_name]['labels']['vent.version'] = version
tool_d[c_name]['labels']['vent.name'] = s[section]['name']
+ # check for log_config settings in external-services
+ externally_configured = False
+ vent_config = Template(template=join(self.path_dirs.meta_dir,
+ "vent.cfg"))
+ if 'log_config' in vent_config.options('external-services')[1]:
+ try:
+ log_config = {}
+ log_dict = json.loads(vent_config.option('external-services',
+ 'log_config')[1])
+ log_config['type'] = log_dict['type']
+ log_config['config'] = {}
+ for option in log_dict['config']:
+ log_config['config'][option] = log_dict['config'][option]
+ externally_configured = True
+ except Exception as e:
+ self.logger.error("external settings for log_config"
+ " couldn't be stored because: " + str(e))
+ externally_configured = False
+ if not externally_configured:
log_config = {'type': 'syslog',
'config': {'syslog-address': 'tcp://0.0.0.0:514',
'syslog-facility': 'daemon',
@@ -390,10 +409,35 @@ class PluginHelper:
branch,
version)
+ # look out for links to delete because they're defined externally
+ links_to_delete = set()
# check and update links, volumes_from, network_mode
for container in tool_d.keys():
if 'links' in tool_d[container]:
for link in tool_d[container]['links']:
+ # add links to external services already running if necessary
+ ext = 'external-services'
+ if link in vent_config.options(ext)[1]:
+ try:
+ link_config = json.loads(vent_config.option(ext,
+ link)[1])
+ ip_adr = link_config['ip_address']
+ port = link_config['port']
+ tool_d[container]['extra_hosts'] = {}
+ tool_d[container]['extra_hosts'][link] = ip_adr
+ # create an environment variable for container
+ # to access port later
+ env_variable = link.upper() + "_PORT=" + port
+ tool_d[container]['environment'].append(env_variable)
+ # remove the entry from links because no
+ # longer connecting to local container
+ links_to_delete.add(link)
+ except Exception as e:
+ self.logger.error("couldn't load external"
+ " settings because: " +
+ str(e))
+ status = (False, str(e))
+ else:
for c in tool_d.keys():
if ('tmp_name' in tool_d[c] and
tool_d[c]['tmp_name'] == link):
@@ -421,11 +465,23 @@ class PluginHelper:
if 'tmp_name' in tool_d[c]:
del tool_d[c]['tmp_name']
+ # remove links section if all were externally configured
+ for c in tool_d.keys():
+ if 'links' in tool_d[c]:
+ for link in links_to_delete:
+ del tool_d[c]['links'][link]
+ # delete links if no more defined
+ if not tool_d[c]['links']:
+ del tool_d[c]['links']
+
# remove containers that shouldn't be started
for c in tool_d.keys():
if 'start' in tool_d[c] and not tool_d[c]['start']:
del tool_d[c]
+ if status[0]:
status = (True, tool_d)
+ else:
+ status = (False, tool_d)
except Exception as e: # pragma: no cover
self.logger.error("prep_start failed with error: "+str(e))
status = (False, e)
