Exemplo n.º 1
0
    def _on_snapshot_loaded(self, etcd_snapshot_response):
        """Called whenever a snapshot is loaded from etcd.

        Updates the driver with the current state.
        """
        LOG.info("Started processing status-reporting snapshot from etcd")
        endpoints_by_host = collections.defaultdict(set)
        hosts_with_live_felix = set()

        # First pass: find all the Felixes that are alive.
        for etcd_node in etcd_snapshot_response.leaves:
            key = etcd_node.key
            felix_hostname = datamodel_v1.hostname_from_status_key(key)
            if felix_hostname:
                # Defer to the code for handling an event.
                hosts_with_live_felix.add(felix_hostname)
                self._on_status_set(etcd_node, felix_hostname)
                continue

        # Second pass: find all the endpoints associated with a live Felix.
        for etcd_node in etcd_snapshot_response.leaves:
            key = etcd_node.key
            endpoint_id = datamodel_v1.get_endpoint_id_from_key(key)
            if endpoint_id:
                if endpoint_id.host in hosts_with_live_felix:
                    LOG.debug("Endpoint %s is on a host with a live Felix.",
                              endpoint_id)
                    self._report_status(
                        endpoints_by_host,
                        endpoint_id,
                        etcd_node.value
                    )
                else:
                    LOG.debug("Endpoint %s is not on a host with live Felix;"
                              "marking it down.",
                              endpoint_id)
                    self.calico_driver.on_port_status_changed(
                        endpoint_id.host,
                        endpoint_id.endpoint,
                        None,
                    )
                continue

        # Find any removed endpoints.
        for host, endpoints in self._endpoints_by_host.iteritems():
            current_endpoints = endpoints_by_host.get(host, set())
            removed_endpoints = endpoints - current_endpoints
            for endpoint_id in removed_endpoints:
                LOG.debug("Endpoint %s removed by resync.")
                self.calico_driver.on_port_status_changed(
                    host,
                    endpoint_id.endpoint,
                    None,
                )

        # Swap in the newly-loaded state.
        self._endpoints_by_host = endpoints_by_host
        LOG.info("Finished processing status-reporting snapshot from etcd")
Exemplo n.º 2
0
    def _on_snapshot_loaded(self, etcd_snapshot_response):
        """Called whenever a snapshot is loaded from etcd.

        Updates the driver with the current state.
        """
        LOG.info("Started processing status-reporting snapshot from etcd")
        endpoints_by_host = collections.defaultdict(set)
        hosts_with_live_felix = set()

        # First pass: find all the Felixes that are alive.
        for etcd_node in etcd_snapshot_response.leaves:
            key = etcd_node.key
            felix_hostname = datamodel_v1.hostname_from_status_key(key)
            if felix_hostname:
                # Defer to the code for handling an event.
                hosts_with_live_felix.add(felix_hostname)
                self._on_status_set(etcd_node, felix_hostname)
                continue

        # Second pass: find all the endpoints associated with a live Felix.
        for etcd_node in etcd_snapshot_response.leaves:
            key = etcd_node.key
            endpoint_id = datamodel_v1.get_endpoint_id_from_key(key)
            if endpoint_id:
                if endpoint_id.host in hosts_with_live_felix:
                    LOG.debug("Endpoint %s is on a host with a live Felix.",
                              endpoint_id)
                    self._report_status(
                        endpoints_by_host,
                        endpoint_id,
                        etcd_node.value
                    )
                else:
                    LOG.debug("Endpoint %s is not on a host with live Felix;"
                              "marking it down.",
                              endpoint_id)
                    self.calico_driver.on_port_status_changed(
                        endpoint_id.host,
                        endpoint_id.endpoint,
                        None,
                    )
                continue

        # Find any removed endpoints.
        for host, endpoints in self._endpoints_by_host.iteritems():
            current_endpoints = endpoints_by_host.get(host, set())
            removed_endpoints = endpoints - current_endpoints
            for endpoint_id in removed_endpoints:
                LOG.debug("Endpoint %s removed by resync.")
                self.calico_driver.on_port_status_changed(
                    host,
                    endpoint_id.endpoint,
                    None,
                )

        # Swap in the newly-loaded state.
        self._endpoints_by_host = endpoints_by_host
        LOG.info("Finished processing status-reporting snapshot from etcd")
Exemplo n.º 3
0
    def _on_snapshot_loaded(self, etcd_snapshot_response):
        """
        Called whenever a snapshot is loaded from etcd.

        Updates the driver with the current state.
        """
        for etcd_node in etcd_snapshot_response.leaves:
            key = etcd_node.key
            felix_hostname = hostname_from_status_key(key)
            if felix_hostname:
                # Defer to the code for handling an event.
                self._on_status_set(etcd_node, felix_hostname)