diff --git a/neutron/common/ovn/constants.py b/neutron/common/ovn/constants.py index cbe1b5a1b17..6aacbbee022 100644 --- a/neutron/common/ovn/constants.py +++ b/neutron/common/ovn/constants.py @@ -74,9 +74,13 @@ OVN_AGENT_DESC_KEY = 'neutron:description' OVN_AGENT_METADATA_SB_CFG_KEY = 'neutron:ovn-metadata-sb-cfg' OVN_AGENT_METADATA_DESC_KEY = 'neutron:description-metadata' OVN_AGENT_METADATA_ID_KEY = 'neutron:ovn-metadata-id' +OVN_AGENT_NEUTRON_SB_CFG_KEY = 'neutron:ovn-neutron-agent-sb-cfg' +OVN_AGENT_NEUTRON_DESC_KEY = 'neutron:description-neutron-agent' +OVN_AGENT_NEUTRON_ID_KEY = 'neutron:ovn-neutron-agent-id' OVN_CONTROLLER_AGENT = 'OVN Controller agent' OVN_CONTROLLER_GW_AGENT = 'OVN Controller Gateway agent' OVN_METADATA_AGENT = 'OVN Metadata agent' +OVN_NEUTRON_AGENT = 'OVN Neutron agent' OVN_CONTROLLER_TYPES = (OVN_CONTROLLER_AGENT, OVN_CONTROLLER_GW_AGENT, ) diff --git a/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py b/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py index c0a234019bf..61f8ded970a 100644 --- a/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py +++ b/neutron/plugins/ml2/drivers/ovn/agent/neutron_agent.py @@ -220,6 +220,41 @@ class MetadataAgent(NeutronAgent): ovn_const.OVN_AGENT_METADATA_DESC_KEY, '') +class OVNNeutronAgent(NeutronAgent): + agent_type = ovn_const.OVN_NEUTRON_AGENT + binary = 'neutron-ovn-agent' + + @property + def alive(self): + # If ovn-controller is down, then OVN Neutron Agent is down even + # if the neutron-ovn-agent binary is updating external_ids. + try: + if not AgentCache()[self.chassis_private.name].alive: + return False + except KeyError: + return False + return super().alive + + @property + def nb_cfg(self): + return int(self.chassis_private.external_ids.get( + ovn_const.OVN_AGENT_NEUTRON_SB_CFG_KEY, 0)) + + @staticmethod + def id_from_chassis_private(chassis_private): + return chassis_private.external_ids.get( + ovn_const.OVN_AGENT_NEUTRON_ID_KEY) + + @property + def agent_id(self): + return self.id_from_chassis_private(self.chassis_private) + + @property + def description(self): + return self.chassis_private.external_ids.get( + ovn_const.OVN_AGENT_NEUTRON_DESC_KEY, '') + + @utils.SingletonDecorator class AgentCache: def __init__(self, driver=None):