def generate_local_gen(my_asid, as_obj, tp): """ Creates the usual gen folder structure for an ISD/AS under gen :param str my_asid: ISD-AS as a string :param obj as_obj: An object that stores crypto information for AS :param dict tp: the topology parameter file as a dict of dicts """ ia = my_asid write_dispatcher_config(GEN_PATH) as_path = get_elem_dir(GEN_PATH, ia, "") rmtree(as_path, True) for service_type, type_key in TYPES_TO_KEYS.items(): executable_name = TYPES_TO_EXECUTABLES[service_type] instances = tp[type_key].keys() for instance_name in instances: config = prep_supervisord_conf(tp[type_key][instance_name], executable_name, service_type, instance_name, ia) instance_path = get_elem_dir(GEN_PATH, ia, instance_name) write_certs_trc_keys(ia, as_obj, instance_path) write_as_conf_and_path_policy(ia, as_obj, instance_path) write_supervisord_config(config, instance_path) write_topology_file(tp, type_key, instance_path) write_zlog_file(service_type, instance_name, instance_path) write_endhost_config(tp, ia, as_obj, GEN_PATH) generate_sciond_config(tp, ia, GEN_PATH, as_obj)
def create_local_gen(isdas, tp): """ Creates the usual gen folder structure for an ISD/AS under web_scion/gen, ready for Ansible deployment :param str isdas: ISD-AS as a string :param dict tp: the topology parameter file as a dict of dicts """ ia = ISD_AS(isdas) as_obj = _get_as_obj(ia) check_simple_conf_mode(tp, ia[0], ia[1]) local_gen_path = os.path.join(WEB_ROOT, 'gen') write_dispatcher_config(local_gen_path) as_path = 'ISD%s/AS%s/' % (ia[0], ia[1]) as_path = get_elem_dir(local_gen_path, ia, "") rmtree(as_path, True) for service_type, type_key in TYPES_TO_KEYS.items(): executable_name = TYPES_TO_EXECUTABLES[service_type] instances = tp[type_key].keys() for instance_name in instances: config = prep_supervisord_conf(tp[type_key][instance_name], executable_name, service_type, instance_name, ia) instance_path = get_elem_dir(local_gen_path, ia, instance_name) write_certs_trc_keys(ia, as_obj, instance_path) write_as_conf_and_path_policy(ia, as_obj, instance_path) write_supervisord_config(config, instance_path) write_topology_file(tp, type_key, instance_path) write_zlog_file(service_type, instance_name, instance_path) write_endhost_config(tp, ia, as_obj, local_gen_path) generate_zk_config(tp, ia, local_gen_path, as_obj.simple_conf_mode) generate_prometheus_config(tp, local_gen_path, as_path)
def create_scionlab_vm_local_gen(args, tp): """ Creates the usual gen folder structure for an ISD/AS under web_scion/gen, ready for Ansible deployment :param str isdas: ISD-AS as a string :param dict tp: the topology parameter file as a dict of dicts """ new_ia = ISD_AS(args.joining_ia) core_ia = ISD_AS(args.core_ia) local_gen_path = os.path.join(args.package_path, args.user_id, 'gen') as_obj = generate_certificate(new_ia, core_ia, args.core_sign_priv_key_file, args.core_cert_file, args.trc_file) write_dispatcher_config(local_gen_path) for service_type, type_key in TYPES_TO_KEYS.items(): executable_name = TYPES_TO_EXECUTABLES[service_type] instances = tp[type_key].keys() for instance_name in instances: config = prep_supervisord_conf(tp[type_key][instance_name], executable_name, service_type, instance_name, new_ia) instance_path = get_elem_dir(local_gen_path, new_ia, instance_name) # TODO (ercanucan): pass the TRC file as a parameter write_certs_trc_keys(new_ia, as_obj, instance_path) write_as_conf_and_path_policy(new_ia, as_obj, instance_path) write_supervisord_config(config, instance_path) write_topology_file(tp, type_key, instance_path) write_zlog_file(service_type, instance_name, instance_path) write_endhost_config(tp, new_ia, as_obj, local_gen_path) generate_zk_config(tp, new_ia, local_gen_path, simple_conf_mode=True) generate_sciond_config(tp, new_ia, local_gen_path, as_obj)
def prep_supervisord_conf(instance_dict, executable_name, service_type, instance_name, isd_as): """ Prepares the supervisord configuration for the infrastructure elements and returns it as a ConfigParser object. :param dict instance_dict: topology information of the given instance. :param str executable_name: the name of the executable. :param str service_type: the type of the service (e.g. beacon_server). :param str instance_name: the instance of the service (e.g. br1-8-1). :param ISD_AS isd_as: the ISD-AS the service belongs to. :returns: supervisord configuration as a ConfigParser object :rtype: ConfigParser """ config = configparser.ConfigParser() env_tmpl = 'PYTHONPATH=python:.,ZLOG_CFG="%s/%s.zlog.conf"' if service_type == 'router': # go router env_tmpl += ',GODEBUG="cgocheck=0"' cmd = ('bash -c \'exec bin/%s -id "%s" -confd "%s" &>logs/%s.OUT\'' ) % (executable_name, instance_name, get_elem_dir(GEN_PATH, isd_as, instance_name), instance_name) else: # other infrastructure elements cmd = ('bash -c \'exec bin/%s "%s" "%s" &>logs/%s.OUT\'') % ( executable_name, instance_name, get_elem_dir(GEN_PATH, isd_as, instance_name), instance_name) env = env_tmpl % (get_elem_dir(GEN_PATH, isd_as, instance_name), instance_name) config['program:' + instance_name] = { 'autostart': 'false', 'autorestart': 'false', 'environment': env, 'stdout_logfile': 'NONE', 'stderr_logfile': 'NONE', 'startretries': '0', 'startsecs': '5', 'priority': '100', 'command': cmd } return config
def generate_sciond_config(tp, ia, local_gen_path, as_obj): executable_name = "sciond" instance_name = "sd%s" % str(ia) service_type = "sciond" processes = [] for svc_type in ["BorderRouters", "BeaconService", "CertificateService", "HiddenPathService", "PathService"]: if svc_type not in tp: continue for elem_id, elem in tp[svc_type].items(): processes.append(elem_id) processes.append(instance_name) config = prep_supervisord_conf(None, executable_name, service_type, instance_name, ia) config['group:' "as%s" % str(ia)] = {'programs': ",".join(processes)} sciond_conf_path = get_elem_dir(local_gen_path, ia, "") write_supervisord_config(config, sciond_conf_path)
def _generate_toplevel_prom_config(local_gen_path): """ Generates the top level prometheus config file. :param str local_gen_path: The gen path of scion-web. """ job_dict = defaultdict(list) all_ases = AD.objects.all() for as_obj in all_ases: ia = ISD_AS.from_values(as_obj.isd_id, as_obj.as_id) for ele_type, target_file in PrometheusGenerator.TARGET_FILES.items(): targets_path = os.path.join(get_elem_dir(local_gen_path, ia, ""), PrometheusGenerator.PROM_DIR, target_file) job_dict[PrometheusGenerator.JOB_NAMES[ele_type]].append( targets_path) _write_prometheus_config_file(local_gen_path, job_dict)