示例#1
0
 def setUp(self):
     super(_TestPathDispatcherBase, self).setUp()
     self.dispatcher = PathDispatcher()
     self.handlers = {
         "delete": {},
         "set": {},
     }
     self.register("/")
     self.register("/a")
     self.register("/a/<b>")
     self.register("/a/<b>/c")
     self.register("/a/<b>/d")
     self.register("/a/<b>/d/<e>")
示例#2
0
 def __init__(self, config, etcd_api, status_reporter, hosts_ipset):
     super(_FelixEtcdWatcher, self).__init__()
     self._config = config
     self._etcd_api = etcd_api
     self._status_reporter = status_reporter
     self.hosts_ipset = hosts_ipset
     # Whether we've been in sync with etcd at some point.
     self._been_in_sync = False
     # Keep track of the config loaded from etcd so we can spot if it
     # changes.
     self.last_global_config = None
     self.last_host_config = None
     self.my_config_dir = dir_for_per_host_config(self._config.HOSTNAME)
     # Events triggered by the EtcdAPI Actor to tell us to load the config
     # and start polling.  These are one-way flags.
     self.load_config = Event()
     self.begin_polling = Event()
     # Event that we trigger once the config is loaded.
     self.configured = Event()
     # Polling state initialized at poll start time.
     self.splitter = None
     # Next-hop IP addresses of our hosts, if populated in etcd.
     self.ipv4_by_hostname = {}
     # Forces a resync after the current poll if set.  Safe to set from
     # another thread.  Automatically reset to False after the resync is
     # triggered.
     self.resync_requested = False
     self.dispatcher = PathDispatcher()
     # The Popen object for the driver.
     self._driver_process = None
     # Stats.
     self.read_count = 0
     self.msgs_processed = 0
     self.last_rate_log_time = monotonic_time()
     # Register for events when values change.
     self._register_paths()
     self._usage_report_greenlet = gevent.Greenlet(
         self._periodically_usage_report)
示例#3
0
    def __init__(self, config, hosts_ipset):
        super(_EtcdWatcher, self).__init__()
        self.config = config
        self.hosts_ipset = hosts_ipset

        # Events triggered by the EtcdAPI Actor to tell us to load the config
        # and start polling.  These are one-way flags.
        self.load_config = Event()
        self.begin_polling = Event()

        # Flag used to trigger a resync.  this is modified from other
        # greenlets, which is safe in Python.
        self.resync_after_current_poll = False

        # Event that we trigger once the config is loaded.
        self.configured = Event()

        # Etcd client, initialised lazily.
        self.client = None
        self.my_config_dir = dir_for_per_host_config(self.config.HOSTNAME)

        # Polling state initialized at poll start time.
        self.splitter = None
        self.next_etcd_index = None

        # Cache of known endpoints, used to resolve deletions of whole
        # directory trees.
        self.endpoint_ids_per_host = defaultdict(set)

        # Next-hop IP addresses of our hosts, if populated in etcd.
        self.ipv4_by_hostname = {}

        # Program the dispatcher with the paths we care about.  Since etcd
        # gives us a single event for a recursive directory deletion, we have
        # to handle deletes for lots of directories that we otherwise wouldn't
        # care about.
        self.dispatcher = PathDispatcher()
        reg = self.dispatcher.register
        # Top-level directories etc.  If these go away, stop polling and
        # resync.
        for key in RESYNC_KEYS:
            reg(key, on_del=self._resync)
        reg(READY_KEY, on_set=self.on_ready_flag_set, on_del=self._resync)
        # Profiles and their contents.
        reg(PER_PROFILE_DIR, on_del=self.on_profile_delete)
        reg(TAGS_KEY, on_set=self.on_tags_set, on_del=self.on_tags_delete)
        reg(RULES_KEY, on_set=self.on_rules_set, on_del=self.on_rules_delete)
        # Hosts, workloads and endpoints.
        reg(PER_HOST_DIR, on_del=self.on_host_delete)
        reg(HOST_IP_KEY,
            on_set=self.on_host_ip_set,
            on_del=self.on_host_ip_delete)
        reg(WORKLOAD_DIR, on_del=self.on_host_delete)
        reg(PER_ORCH_DIR, on_del=self.on_orch_delete)
        reg(PER_WORKLOAD_DIR, on_del=self.on_workload_delete)
        reg(ENDPOINT_DIR, on_del=self.on_workload_delete)
        reg(PER_ENDPOINT_KEY,
            on_set=self.on_endpoint_set,
            on_del=self.on_endpoint_delete)
        reg(CIDR_V4_KEY,
            on_set=self.on_ipam_v4_pool_set,
            on_del=self.on_ipam_v4_pool_delete)