Exemple #1
0
def write_toml_files(tp, ia, file_path=GEN_PATH):
    def replace(filename, replacement):
        '''Replace the toml dictionary in filename with the replacement dict'''
        with open(filename, 'r') as f:
            d = toml.load(f)
        nested_dicts_update(d, replacement)
        with open(filename, 'w') as f:
            toml.dump(d, f)

    used_prometheus_ports = set()
    def prom_params(elem):
        IP, port = _prom_addr_of_element(elem)
        if port in used_prometheus_ports:
            raise Exception('Duplicated Prometheus port {} found. The list of used ports is {}'.format(port, list(used_prometheus_ports)))
        used_prometheus_ports.add(port)
        return IP, port
    args = GoGenArgs(dict_to_namedtuple({'docker': False, 'trace': False,
                    'output_dir': file_path}), {ia: tp})
    go_gen = GoGenerator(args)

    go_gen.generate_sciond()
    IP, port = prom_params(next(iter(tp['Sciond'].values())))
    sciond_sock = 'sd%s.sock' % ia.file_fmt()
    sciond_unix = 'sd%s.unix' % ia.file_fmt()
    config_path = os.path.join(GEN_PATH, 'ISD%s/AS%s' % (ia.isd_str(), ia.as_file_fmt()), 'endhost')
    filename = os.path.join(get_elem_dir(file_path, ia, 'endhost'), 'sciond.toml')
    replace(filename, {'sd': {'Reliable': os.path.join(SCIOND_API_SOCKDIR, sciond_sock),
                                  'Unix': os.path.join(SCIOND_API_SOCKDIR, sciond_unix)},
                       'metrics': {'Prometheus': '{}:{}'.format(IP, port)},
                       'general': {'ConfigDir': config_path}
                      })
    go_gen.generate_cs()
    IP, port = prom_params(next(iter(tp['CertificateService'].values())))
    filename = os.path.join(get_elem_dir(file_path, ia, next(iter(tp['CertificateService'].keys()))), 'csconfig.toml')
    replace(filename, {'sd_client': {'Path': os.path.join(SCIOND_API_SOCKDIR, sciond_sock)},
                        'metrics': {'Prometheus': '{}:{}'.format(IP,port)},
                       'general': {'ConfigDir': config_path}
                      })
    go_gen.generate_ps()
    IP, port = prom_params(next(iter(tp['PathService'].values())))
    filename = os.path.join(get_elem_dir(file_path, ia, next(iter(tp['PathService'].keys()))), 'psconfig.toml')
    replace(filename, {'metrics': {'Prometheus': '{}:{}'.format(IP, port)},
                       'general': {'ConfigDir': config_path}})
Exemple #2
0
 def _go_args(self, topo_dicts):
     return GoGenArgs(self.args, topo_dicts, self.networks)
Exemple #3
0
 def _go_args(self, topo_dicts):
     return GoGenArgs(self.args, topo_dicts)
Exemple #4
0
 def _go_args(self, topo_dicts):
     return GoGenArgs(self.args, topo_dicts, self.port_gen)