Exemplo n.º 1
0
    def _write_common_config_to_zookeeper(self, zk, jinja_vars):
        # 1. At first write global tools to ZK. FIXME: Make it a common profile
        conf_path = os.path.join(self.config_dir, 'common',
                                 'common_config.yml.j2')
        common_cfg = yaml.load(jinja_utils.jinja_render(conf_path, jinja_vars))
        common_node = os.path.join('kolla', 'common')
        for script in common_cfg:
            script_node = os.path.join(common_node, script)
            zk.ensure_path(script_node)
            source_path = common_cfg[script]['source']

            src_file = source_path
            if not source_path.startswith('/'):
                src_file = file_utils.find_file(source_path)
            with open(src_file) as fp:
                content = fp.read()
            zk.set(script_node, content)

        # 2. Add startup config
        start_conf = os.path.join(self.config_dir,
                                  'common/kolla-start-config.json')
        # override container_config_directory
        cont_conf_dir = 'zk://%s' % (CONF.zookeeper.host)
        jinja_vars['container_config_directory'] = cont_conf_dir
        jinja_vars['deployment_id'] = self.deployment_id
        kolla_config = jinja_utils.jinja_render(start_conf, jinja_vars)
        kolla_config = kolla_config.replace('"', '\\"').replace('\n', '')

        return kolla_config
Exemplo n.º 2
0
 def write_to_zookeeper(self, zk, base_node):
     dest_node = os.path.join(base_node, self._service_name,
                              'files', self._name)
     zk.ensure_path(dest_node)
     if isinstance(self._conf['source'], list):
         content = self.merge_ini_files(self._conf['source'])
     else:
         src_file = self._conf['source']
         if not src_file.startswith('/'):
             src_file = file_utils.find_file(src_file)
         with open(src_file) as fp:
             content = fp.read()
     zk.set(dest_node, content.encode('utf-8'))
Exemplo n.º 3
0
 def write_to_zookeeper(self, zk, base_node):
     _, proj, service = self._service_name.split('/')
     # for the moment keep the config/files in the same location
     # TODO(asalkeld) move to a child of the command.
     dest_node = os.path.join(base_node, 'config', proj,
                              service, self._name)
     zk.ensure_path(dest_node)
     if isinstance(self._conf['source'], list):
         content = self.merge_ini_files(self._conf['source'])
     else:
         src_file = self._conf['source']
         if not src_file.startswith('/'):
             src_file = file_utils.find_file(src_file)
         with open(src_file) as fp:
             content = fp.read()
     zk.set(dest_node, content)
Exemplo n.º 4
0
def write_common_config_to_zookeeper(config_dir, zk, jinja_vars,
                                     overwrite=True):
    # 1. At first write global tools to ZK. FIXME: Make it a common profile
    conf_path = os.path.join(config_dir, 'common',
                             'common_config.yml.j2')
    common_cfg = yaml.load(jinja_utils.jinja_render(conf_path, jinja_vars))
    common_node = os.path.join('kolla', 'common')
    for script in common_cfg:
        script_node = os.path.join(common_node, script)
        if not overwrite and zk.exists(script_node):
            LOG.debug('NOT Updating "%s" node in zookeeper(overwrite=False).',
                      script_node)
            continue

        zk.ensure_path(script_node)
        source_path = common_cfg[script]['source']
        src_file = source_path
        if not source_path.startswith('/'):
            src_file = file_utils.find_file(source_path)
        with open(src_file) as fp:
            content = fp.read()
        zk.set(script_node, content.encode('utf-8'))
Exemplo n.º 5
0
    def write_config_to_zookeeper(self, zk):
        jinja_vars = self.get_jinja_vars()
        self.required_vars = jinja_vars

        for var in jinja_vars:
            if not jinja_vars[var]:
                LOG.info('empty %s=%s' % (var, jinja_vars[var]))
            if 'image' in var:
                LOG.info('%s=%s' % (var, jinja_vars[var]))

        for proj in self.get_projects():
            proj_dir = os.path.join(self.config_dir, proj)
            if not os.path.exists(proj_dir):
                continue

            conf_path = os.path.join(self.config_dir, proj,
                                     '%s_config.yml.j2' % proj)
            extra = yaml.load(jinja_utils.jinja_render(conf_path, jinja_vars))

            dest_node = os.path.join('kolla', 'config',
                                     proj, proj)  # TODO() should be service
            zk.ensure_path(dest_node)
            zk.set(dest_node, json.dumps(extra))

            for service in extra['config'][proj]:
                # write the config files
                for name, item in extra['config'][proj][service].iteritems():
                    dest_node = os.path.join('kolla', 'config',
                                             proj, service, name)
                    zk.ensure_path(dest_node)

                    if isinstance(item['source'], list):
                        content = self.merge_ini_files(item['source'])
                    else:
                        src_file = item['source']
                        if not src_file.startswith('/'):
                            src_file = file_utils.find_file(src_file)
                        with open(src_file) as fp:
                            content = fp.read()
                    zk.set(dest_node, content)

                # write the commands
                for name, item in extra['commands'][proj][service].iteritems():
                    dest_node = os.path.join('kolla', 'commands',
                                             proj, service, name)
                    zk.ensure_path(dest_node)
                    try:
                        zk.set(dest_node, json.dumps(item))
                    except Exception as te:
                        LOG.error('%s=%s -> %s' % (dest_node,
                                                   item, te))

                # 3. do the service's config.json (now KOLLA_CONFIG)
                kc_name = os.path.join(self.config_dir, 'config.json')
                # override container_config_directory
                cont_conf_dir = 'zk://%s' % (
                    CONF.zookeeper.host)
                jinja_vars['container_config_directory'] = cont_conf_dir
                kolla_config = jinja_utils.jinja_render(kc_name, jinja_vars)
                kolla_config = kolla_config.replace('"', '\\"').replace(
                    '\n', '')

                # 4. parse the marathon app file and add the KOLLA_CONFIG
                values = {
                    'kolla_config': kolla_config,
                    'zookeeper_hosts': CONF.zookeeper.host
                }
                for app_type in ['marathon', 'chronos']:
                    app_file = os.path.join(self.base_dir,
                                            'deployment_files',
                                            proj,
                                            '%s.%s.j2' % (service, app_type))
                    if not os.path.exists(app_file):
                        LOG.debug('potentially missing file %s' % app_file)
                        continue
                    content = jinja_utils.jinja_render(app_file, jinja_vars,
                                                       extra=values)
                    dest_file = os.path.join(self.temp_dir, proj,
                                             '%s.%s' % (service, app_type))
                    file_utils.mkdir_p(os.path.dirname(dest_file))
                    with open(dest_file, 'w') as f:
                        f.write(content)