def add_endpoint(self, endpoint): self.__add_endpoint(endpoint) def local_lock(fn): def wrapped_fn(*args, **kwargs): try: self.cond.acquire() return fn(*args, **kwargs) finally: self.cond.release() return wrapped_fn @local_lock def update_state(value): endpoint.update_state(value) if self.endpoint_owned(endpoint): endpoint.update() @local_lock def update_config(value): endpoint.update_config(value) if self.endpoint_owned(endpoint): endpoint.update() @local_lock def update_confirmed(ips): if ips: self.confirmed[endpoint.name] = ips elif endpoint.name in self.confirmed: del self.confirmed[endpoint.name] # Kick off a loadbalancer update. self.update_loadbalancer(endpoint) # Watch the config for this endpoint. logging.info("Watching endpoint %s." % (endpoint.name)) update_state( self.zk_conn.watch_contents(paths.endpoint_state(endpoint.name), update_state, '', clean=True)) update_config( self.zk_conn.watch_contents(paths.endpoint(endpoint.name), update_config, '', clean=True)) # Select the manager for this endpoint. self.manager_select(endpoint) # Update the loadbalancer for this endpoint. update_confirmed( self.zk_conn.watch_children(paths.confirmed_ips(endpoint.name), update_confirmed, clean=True))
def remove_endpoint(self, endpoint_name, unmanage=False): """ This removes / unmanages the endpoint. """ logging.info("Removing endpoint %s from manager %s" % (endpoint_name, self.uuid)) endpoint = self.endpoints.get(endpoint_name, None) if endpoint: self.zk_conn.clear_watch_path(paths.endpoint_state(endpoint.name)) self.zk_conn.clear_watch_path(paths.endpoint(endpoint.name)) self.zk_conn.clear_watch_path(paths.confirmed_ips(endpoint.name)) # Update the loadbalancer for this endpoint. self.update_loadbalancer(endpoint, remove=True) self.__remove_endpoint(endpoint, unmanage) self.manager_remove(endpoint)
def get_endpoint_ip_addresses(self, endpoint_name): """ Returns all the IP addresses (confirmed or explicitly configured) associated with the endpoint. """ ip_addresses = [] confirmed_ips = self.zk_conn.list_children(\ paths.confirmed_ips(endpoint_name)) if confirmed_ips != None: ip_addresses += confirmed_ips configured_ips = EndpointConfig(\ self.get_endpoint_config(endpoint_name)).static_ips() if configured_ips != None: ip_addresses += configured_ips return ip_addresses