def __init__(self, log, log_level, logger_name, logger_section=None): ''' Set up the logger runtime state. ''' super().__init__() self.log = log self.log_level = log_level self.logger_name = logger_name self.logger_section = logger_section self.name = "%s-%s" % (logger_name, logger_section) if logger_section else logger_name self.description = "logger '%s'" % self.name lf = str.format( "%(asctime)s {0}: <{1}> [%(levelname)s] %(message)s", logger_name, logger_section, ) if logger_section else "%(asctime)s %(name)s: [%(levelname)s] %(message)s" self.logger_formatter = logging.Formatter(lf) if self.log: util.directory_create(os.path.dirname(self.log)) self.logger_handler = logging.FileHandler(self.log) os.chmod(self.log, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH) else: self.logger_handler = logging.NullHandler() self.logger_handler.setFormatter(self.logger_formatter)
def start(self): ''' Start the daemon. ''' try: self.set_starting() self.logger.debug("creating lib dir '%s'" % self.lib_dir) if not self.dry_run: util.directory_create(self.lib_dir) except Exception as e: if self.logger.is_running(): self.logger.exception(e) raise for o in self.sorted_overlays: try: o.start() except Exception as e: if o.logger.is_running(): o.logger.exception(e) raise try: self.ipsec_process.start() self.set_started() except Exception as e: if self.logger.is_running(): self.logger.exception(e) raise
def start(self): ''' Start the overlay. ''' if not self.enabled: return self.set_starting() self.logger.info("starting overlay") # Start the network namespace object, so the overlay's # network namespace can be manipulated. self.netns.start() self.logger.debug("creating overlay root directory") if not self.dry_run: util.directory_create(self.root_dir) for mt in self.mesh_tunnels: mt.start() for interface in self.interfaces: interface.start() self.bgp_process.start() self.firewall_process.start() # Shut down the overlay's network namespace object, to # reduce memory consumption by the network namespace's # pyroute2 process. self.netns.stop() self.logger.info("finished starting overlay") self.set_started()
def start(self): ''' Start the BGP process. ''' self.set_starting() self.logger.info("starting BGP process") self.logger.debug("creating BIRD control socket directory") if not self.dry_run: util.directory_create(self.bird_ctl_dir) self.logger.debug("creating BIRD configuration directory") if not self.dry_run: util.directory_create(self.bird_conf_dir) self.logger.debug("creating BIRD logging directory") if not self.dry_run: util.directory_create(self.bird_log_dir) self.logger.debug("creating BIRD PID file directory") if not self.dry_run: util.directory_create(self.bird_pid_dir) self.logger.debug("configuring BIRD") bird_config = {} bird6_config = {} if util.ip_network_is_v6(self.linknet_pool): bird6_config["mesh_tunnels"] = self.mesh_tunnels else: bird_config["mesh_tunnels"] = self.mesh_tunnels for interface in self.interfaces: bc = None if interface.is_ipv6(): bc = bird6_config else: bc = bird_config if isinstance(interface, BGP): self.bird_config_add(bc, "bgps", interface) elif isinstance(interface, Dummy): self.bird_config_add(bc, "dummies", interface) elif isinstance(interface, OverlayLink): self.bird_config_add(bc, "overlay_links", interface) elif isinstance(interface, Tunnel): self.bird_config_add(bc, "tunnels", interface) elif isinstance(interface, Tuntap): self.bird_config_add(bc, "tuntaps", interface) elif isinstance(interface, VETH): self.bird_config_add(bc, "veths", interface) elif isinstance(interface, VLAN): self.bird_config_add(bc, "vlans", interface) if bird_config: bird_config["router_id"] = str(self.mesh_tunnels[0].virtual_local) self._start_bird_daemon( self.bird, self.bird_conf, bird_config, self.bird_log, self.bird_ctl, self.bird_pid, ) if bird6_config: bird6_config["router_id"] = "192.0.2.1" self._start_bird_daemon( self.bird6, self.bird6_conf, bird6_config, self.bird6_log, self.bird6_ctl, self.bird6_pid, ) self.logger.info("finished starting BGP process") self.set_started()