def check_backlogged_devices(self): """"Checks the status of backlogged devices. Skips newly spun up instances during their booting time as specified in the boot time parameter. :return A dict of the format: {'reachable': [<hd_id>,..], 'dead': [<hd_id>,..]} """ response_dict = {'reachable': [], 'dead': []} LOG.debug("Current Backlogged devices: %s", self.backlog_devices.keys()) for hd_id in self.backlog_devices.keys(): hd = self.backlog_devices[hd_id] if hd.get('mgmt_url'): if not timeutils.is_older_than(hd['created_at'], BOOT_TIME_INTERVAL): LOG.debug("Hosting device: %(hd_id)s @ %(ip)s hasn't " "passed minimum boot time. Skipping it. ", {'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None)}) continue LOG.debug("Checking device: %(hd_id)s @ %(ip)s for " "reachability.", {'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None)}) if _is_pingable(hd['mgmt_url'].get('ip_address', None)): response_dict['reachable'].append(hd_id) LOG.debug("Hosting device: %(hd_id)s @ %(ip)s is now " "reachable. Adding it to response", {'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None)}) else: LOG.debug("Hosting device: %(hd_id)s @ %(ip)s still not " "reachable ", {'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None)}) if hd.get('backlog_insertion_ts'): if timeutils.is_older_than( hd['backlog_insertion_ts'], cfg.CONF.servicevm_agent.device_dead_timeout): LOG.debug("Hosting device: %(hd_id)s @ %(ip)s hasn't " "been reachable for the last %(time)d seconds. " "Marking it dead.", {'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None), 'time': cfg.CONF.servicevm_agent. device_dead_timeout}) response_dict['dead'].append(hd_id) else: response_dict['dead'].append(hd_id) else: response_dict['dead'].append(hd_id) return response_dict
def check_backlogged_hosting_devices(self): """"Checks the status of backlogged hosting devices. Skips newly spun up instances during their booting time as specified in the boot time parameter. :return A dict of the format: {'reachable': [<hd_id>,..], 'dead': [<hd_id>,..]} """ response_dict = {'reachable': [], 'dead': []} LOG.debug("Current Backlogged hosting devices: %s", self.backlog_hosting_devices.keys()) for hd_id in self.backlog_hosting_devices.keys(): hd = self.backlog_hosting_devices[hd_id]['hd'] if not timeutils.is_older_than(hd['created_at'], hd['booting_time']): LOG.info(_("Hosting device: %(hd_id)s @ %(ip)s hasn't passed " "minimum boot time. Skipping it. "), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) continue LOG.info(_("Checking hosting device: %(hd_id)s @ %(ip)s for " "reachability."), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) if _is_pingable(hd['management_ip_address']): hd.pop('backlog_insertion_ts', None) del self.backlog_hosting_devices[hd_id] response_dict['reachable'].append(hd_id) LOG.info(_("Hosting device: %(hd_id)s @ %(ip)s is now " "reachable. Adding it to response"), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) else: LOG.info(_("Hosting device: %(hd_id)s @ %(ip)s still not " "reachable "), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) if timeutils.is_older_than( hd['backlog_insertion_ts'], cfg.CONF.cfg_agent.hosting_device_dead_timeout): LOG.debug("Hosting device: %(hd_id)s @ %(ip)s hasn't " "been reachable for the last %(time)d seconds. " "Marking it dead.", {'hd_id': hd_id, 'ip': hd['management_ip_address'], 'time': cfg.CONF.cfg_agent. hosting_device_dead_timeout}) response_dict['dead'].append(hd_id) hd.pop('backlog_insertion_ts', None) del self.backlog_hosting_devices[hd_id] LOG.debug("Response: %s", response_dict) return response_dict
def check_backlogged_hosting_devices(self): """"Checks the status of backlogged hosting devices. Skips newly spun up instances during their booting time as specified in the boot time parameter. :return A dict of the format: {'reachable': [<hd_id>,..], 'dead': [<hd_id>,..]} """ response_dict = {'reachable': [], 'dead': []} LOG.debug("Current Backlogged hosting devices: %s", self.backlog_hosting_devices.keys()) for hd_id in self.backlog_hosting_devices.keys(): hd = self.backlog_hosting_devices[hd_id]['hd'] if not timeutils.is_older_than(hd['created_at'], hd['booting_time']): LOG.info(_("Hosting device: %(hd_id)s @ %(ip)s hasn't passed " "minimum boot time. Skipping it. "), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) continue LOG.info(_("Checking hosting device: %(hd_id)s @ %(ip)s for " "reachability."), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) if _is_pingable(hd['management_ip_address']): hd.pop('backlog_insertion_ts', None) del self.backlog_hosting_devices[hd_id] response_dict['reachable'].append(hd_id) LOG.info(_("Hosting device: %(hd_id)s @ %(ip)s is now " "reachable. Adding it to response"), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) else: LOG.info(_("Hosting device: %(hd_id)s @ %(ip)s still not " "reachable "), {'hd_id': hd_id, 'ip': hd['management_ip_address']}) if timeutils.is_older_than( hd['backlog_insertion_ts'], cfg.CONF.hosting_device_dead_timeout): LOG.debug("Hosting device: %(hd_id)s @ %(ip)s hasn't " "been reachable for the last %(time)d seconds. " "Marking it dead.", {'hd_id': hd_id, 'ip': hd['management_ip_address'], 'time': cfg.CONF.hosting_device_dead_timeout}) response_dict['dead'].append(hd_id) hd.pop('backlog_insertion_ts', None) del self.backlog_hosting_devices[hd_id] LOG.debug("Response: %s", response_dict) return response_dict
def _process_static_route(self, ip, info): heart_beat_time = info['time'] flag = info['flag'] static_route = { "next_hop_address": ip, "priority":"60", "description":"SLB static route" } if timeutils.is_older_than(heart_beat_time, self.conf.haproxy_int.proxy_down_time): for external_network in self.external_networks: strs = external_network.split('/') static_route["ip_address"] = strs[0] static_route["mask_length"] = strs[1] success = self.ngfw_client.clear_static_route(static_route) if not success: LOG.warn(_('Failed to remove static route to proxy %s'), ip) return del self.proxy_ips[ip] LOG.debug(_('Remove static route to proxy %s'), ip) else: if not flag: for external_network in self.external_networks: strs = external_network.split('/') static_route["ip_address"] = strs[0] static_route["mask_length"] = strs[1] success = self.ngfw_client.make_static_route(static_route) if not success: LOG.warn(_('Failed to add static route to proxy %s'), ip) return info['flag'] = True LOG.debug(_('Add static route to proxy %s'), ip)
def monitor_agent_state(self): """Represents a thread which maintains list of active and inactive agents based on the heartbeat recorded """ #Do nothing until plugin is initialized agents_to_process = [] if not self.plugin: status = self.get_plugin_and_initialize() if not status: LOG.debug("Plugin not defined...returning") return if not self.agent_ext_support: LOG.debug("Agent extension is not loaded by plugin") return try: self.agents = self.plugin.get_agents(self.context, filters={'agent_type': [AGENT_TYPE_OVSVAPP]}) except Exception: LOG.exception(_("Unable to get agent list continue...")) return for agent in self.agents: agent_time_stamp = agent['heartbeat_timestamp'] agent_id = agent['id'] status = timeutils.is_older_than(agent_time_stamp, cfg.CONF.agent_down_time * 2) LOG.debug(_("for agent %(agent)s agent_state %(state)s"), {'agent': agent, 'state': status}) try: if not status: if agent_id not in self.active_agents: LOG.debug("Moving agent: %s from inactive to " "active", agent_id) self.active_agents.append(agent_id) self._update_agent_state(agent_id, True) if agent_id in self.inactive_agents: LOG.debug("Removing agent: %s from inactive " "agent list", agent_id) self.inactive_agents.remove(agent_id) else: if agent_id not in self.inactive_agents: LOG.debug("Moving agent: %s from active to " "inactive", agent_id) self.inactive_agents.append(agent_id) if self._update_agent_state(agent_id, False): agents_to_process.append(agent) if agent_id in self.active_agents: LOG.debug("Removing agent: %s from active " "agent list", agent_id) self.active_agents.remove(agent_id) except Exception: LOG.exception(_("Exception occurred in monitor_agent_state..")) LOG.debug("Number of agents for processing: %s", len(agents_to_process)) for agent in agents_to_process: self.process_ovsvapp_agent(agent) return
def _process_static_route(self, ip, info): heart_beat_time = info['time'] flag = info['flag'] static_route = { "next_hop_address": ip, "priority": "60", "description": "SLB static route" } if timeutils.is_older_than(heart_beat_time, self.conf.haproxy_int.proxy_down_time): for external_network in self.external_networks: strs = external_network.split('/') static_route["ip_address"] = strs[0] static_route["mask_length"] = strs[1] success = self.ngfw_client.clear_static_route(static_route) if not success: LOG.warn(_('Failed to remove static route to proxy %s'), ip) return del self.proxy_ips[ip] LOG.debug(_('Remove static route to proxy %s'), ip) else: if not flag: for external_network in self.external_networks: strs = external_network.split('/') static_route["ip_address"] = strs[0] static_route["mask_length"] = strs[1] success = self.ngfw_client.make_static_route(static_route) if not success: LOG.warn(_('Failed to add static route to proxy %s'), ip) return info['flag'] = True LOG.debug(_('Add static route to proxy %s'), ip)
def is_agent_down(cls, heart_beat_time): return timeutils.is_older_than(heart_beat_time, cfg.CONF.agent_down_time)
def is_agent_down(cls, heart_beat_time, timeout=cfg.CONF.general.cfg_agent_down_time): return timeutils.is_older_than(heart_beat_time, timeout)
def check_backlogged_devices(self): """"Checks the status of backlogged devices. Skips newly spun up instances during their booting time as specified in the boot time parameter. :return A dict of the format: {'reachable': [<hd_id>,..], 'dead': [<hd_id>,..]} """ response_dict = {'reachable': [], 'dead': []} LOG.debug("Current Backlogged devices: %s", self.backlog_devices.keys()) for hd_id in self.backlog_devices.keys(): hd = self.backlog_devices[hd_id] if hd.get('mgmt_url'): if not timeutils.is_older_than(hd['created_at'], BOOT_TIME_INTERVAL): LOG.debug( "Hosting device: %(hd_id)s @ %(ip)s hasn't " "passed minimum boot time. Skipping it. ", { 'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None) }) continue LOG.debug( "Checking device: %(hd_id)s @ %(ip)s for " "reachability.", { 'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None) }) if _is_pingable(hd['mgmt_url'].get('ip_address', None)): response_dict['reachable'].append(hd_id) LOG.debug( "Hosting device: %(hd_id)s @ %(ip)s is now " "reachable. Adding it to response", { 'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None) }) else: LOG.debug( "Hosting device: %(hd_id)s @ %(ip)s still not " "reachable ", { 'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None) }) if hd.get('backlog_insertion_ts'): if timeutils.is_older_than( hd['backlog_insertion_ts'], cfg.CONF.servicevm_agent.device_dead_timeout): LOG.debug( "Hosting device: %(hd_id)s @ %(ip)s hasn't " "been reachable for the last %(time)d seconds. " "Marking it dead.", { 'hd_id': hd_id, 'ip': hd['mgmt_url'].get('ip_address', None), 'time': cfg.CONF.servicevm_agent. device_dead_timeout }) response_dict['dead'].append(hd_id) else: response_dict['dead'].append(hd_id) else: response_dict['dead'].append(hd_id) return response_dict