class OpflexDevice(resource.AciResourceBase): """Information about Opflex device reported by ACI. Read-only.""" root = 'topology' identity_attributes = t.identity( ('pod_id', t.id), ('node_id', t.id), ('bridge_interface', t.id), ('dev_id', t.id)) other_attributes = t.other( ('host_name', t.string(128)), ('ip', t.string(64)), ('fabric_path_dn', t.string()), ('domain_name', t.string(64)), ('controller_name', t.string(64))) _aci_mo_name = 'opflexODev' _tree_parent = resource.Pod def __init__(self, **kwargs): super(OpflexDevice, self).__init__({'host_name': '', 'ip': '', 'fabric_path_dn': '', 'domain_name': '', 'controller_name': ''}, **kwargs) # force read-only object to be in monitored tree self.monitored = True
class SecurityGroupRule(AciResourceBase): """Resource representing a SG subject's rule in ACI. Identity attributes: name of ACI tenant, name of security group, name of subject and name of rule """ identity_attributes = t.identity( ('tenant_name', t.name), ('security_group_name', t.name), ('security_group_subject_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('direction', t.enum("", "ingress", "egress")), ('ethertype', t.enum("", "undefined", "ipv4", "ipv6")), ('remote_ips', t.list_of_strings), ('ip_protocol', t.string()), ('from_port', t.port), ('to_port', t.port), ('conn_track', t.enum('normal', 'reflexive')), ('monitored', t.bool)) _aci_mo_name = 'hostprotRule' _tree_parent = SecurityGroupSubject def __init__(self, **kwargs): super(SecurityGroupRule, self).__init__( {'direction': 'ingress', 'ethertype': "undefined", 'remote_ips': [], 'ip_protocol': self.UNSPECIFIED, 'from_port': self.UNSPECIFIED, 'to_port': self.UNSPECIFIED, 'conn_track': 'reflexive', 'monitored': False}, **kwargs)
class ContractSubject(AciResourceBase): """Resource representing a subject within a contract in ACI. Identity attributes: name of ACI tenant, name of contract and name of subject. """ identity_attributes = t.identity( ('tenant_name', t.name), ('contract_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('in_filters', t.list_of_names), ('out_filters', t.list_of_names), ('bi_filters', t.list_of_names), ('service_graph_name', t.name), ('in_service_graph_name', t.name), ('out_service_graph_name', t.name), ('monitored', t.bool)) _aci_mo_name = 'vzSubj' _tree_parent = Contract def __init__(self, **kwargs): super(ContractSubject, self).__init__( {'in_filters': [], 'out_filters': [], 'bi_filters': [], 'service_graph_name': '', 'in_service_graph_name': '', 'out_service_graph_name': '', 'monitored': False}, **kwargs)
class Tree(api_res.ResourceBase): identity_attributes = t.identity(('root_rn', t.string(64))) other_attributes = t.other(('needs_reset', t.bool)) db_attributes = t.db() def __init__(self, **kwargs): super(Tree, self).__init__({}, **kwargs)
class ExternalNetwork(AciResourceBase): """Resource representing an external network instance profile. External network is a group of external subnets that have the same security behavior. Identity attributes: name of ACI tenant, name of L3Out, name of external network. """ identity_attributes = t.identity( ('tenant_name', t.name), ('l3out_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('nat_epg_dn', t.string()), ('provided_contract_names', t.list_of_names), ('consumed_contract_names', t.list_of_names), ('monitored', t.bool)) _aci_mo_name = 'l3extInstP' _tree_parent = L3Outside def __init__(self, **kwargs): super(ExternalNetwork, self).__init__( {'nat_epg_dn': '', 'provided_contract_names': [], 'consumed_contract_names': [], 'monitored': False}, **kwargs)
class Subnet(AciResourceBase): """Resource representing a Subnet in ACI. Identity attributes: name of ACI tenant, name of bridge-domain and IP-address & mask of the default gateway in CIDR format (that is <gateway-address>/<prefix-len>). Helper function 'to_gw_ip_mask' may be used to construct the IP-address & mask value. """ identity_attributes = t.identity( ('tenant_name', t.name), ('bd_name', t.name), ('gw_ip_mask', t.ip_cidr)) other_attributes = t.other( ('scope', t.enum("", "public", "private", "shared")), ('display_name', t.name), ('monitored', t.bool)) _aci_mo_name = 'fvSubnet' _tree_parent = BridgeDomain SCOPE_PRIVATE = 'private' SCOPE_PUBLIC = 'public' def __init__(self, **kwargs): super(Subnet, self).__init__({'scope': self.SCOPE_PUBLIC, 'monitored': False}, **kwargs) @staticmethod def to_gw_ip_mask(gateway_ip_address, prefix_len): return '%s/%d' % (gateway_ip_address, prefix_len)
class VRF(AciResourceBase): """Resource representing a VRF (Layer3 network context) in ACI. Identity attributes: name of ACI tenant, name of VRF. """ identity_attributes = t.identity( ('tenant_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('policy_enforcement_pref', t.enum("", "enforced", "unenforced")), ('monitored', t.bool)) _aci_mo_name = 'fvCtx' _tree_parent = Tenant POLICY_ENFORCED = 'enforced' POLICY_UNENFORCED = 'unenforced' def __init__(self, **kwargs): super(VRF, self).__init__( {'policy_enforcement_pref': self.POLICY_ENFORCED, 'monitored': False}, **kwargs)
class L3OutInterfaceBgpPeerP(AciResourceBase): """Resource representing a bgp peer prefix. Identity attributes: name of ACI tenant, name of L3Out, name of node profile, name of interface profile, interface_path, bgp peer prefix. """ identity_attributes = t.identity( ('tenant_name', t.name), ('l3out_name', t.name), ('node_profile_name', t.name), ('interface_profile_name', t.name), ('interface_path', t.string()), ('addr', t.ip_cidr)) other_attributes = t.other( ('asn', t.string()), ('monitored', t.bool)) _aci_mo_name = 'bgpPeerP' _tree_parent = L3OutInterface def __init__(self, **kwargs): asn = kwargs.get('asn') if asn and (int(asn) < 0 or int(asn) > 4294967295): raise exc.AciResourceValueError(klass=type(self).__name__, value=asn, attr='asn') super(L3OutInterfaceBgpPeerP, self).__init__( {'asn': "0", 'monitored': False}, **kwargs)
class ExternalSubnet(AciResourceBase): """Resource representing an external subnet. Identity attributes: name of ACI tenant, name of L3Out, name of external network, network CIDR of the subnet. """ identity_attributes = t.identity( ('tenant_name', t.name), ('l3out_name', t.name), ('external_network_name', t.name), ('cidr', t.ip_cidr)) other_attributes = t.other( ('display_name', t.name), ('aggregate', t.string()), ('scope', t.string()), ('monitored', t.bool)) _aci_mo_name = 'l3extSubnet' _tree_parent = ExternalNetwork def __init__(self, **kwargs): super(ExternalSubnet, self).__init__({'monitored': False, 'aggregate': "", 'scope': "import-security"}, **kwargs)
class VmmInjectedHost(AciResourceBase): """Resource representing a VMM injected host in ACI. Identity attributes: VMM domain type, VMM domain name, controller name and host name. """ identity_attributes = t.identity( ('domain_type', t.name), ('domain_name', t.name), ('controller_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('host_name', t.string()), ('kernel_version', t.string()), ('os', t.string())) _aci_mo_name = 'vmmInjectedHost' _tree_parent = VMMController def __init__(self, **kwargs): super(VmmInjectedHost, self).__init__({'host_name': '', 'kernel_version': '', 'os': ''}, **kwargs)
class VmmInjectedContGroup(AciResourceBase): """Resource representing a VMM injected container group in ACI. Identity attributes: VMM domain type, VMM domain name, controller name, namespace name and group name. """ identity_attributes = t.identity( ('domain_type', t.name), ('domain_name', t.name), ('controller_name', t.name), ('namespace_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('host_name', t.name), ('compute_node_name', t.name), ('replica_set_name', t.name)) db_attributes = t.db(('guid', t.string())) _aci_mo_name = 'vmmInjectedContGrp' _tree_parent = VmmInjectedNamespace def __init__(self, **kwargs): super(VmmInjectedContGroup, self).__init__({'host_name': '', 'compute_node_name': '', 'replica_set_name': '', 'guid': ''}, **kwargs)
class ServiceGraphNode(resource.AciResourceBase): """Resource representing a function-node in service graph. """ identity_attributes = t.identity(('tenant_name', t.name), ('service_graph_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('function_type', t.enum('GoTo', 'GoThrough')), ('managed', t.bool), ('routing_mode', t.enum('unspecified', 'Redirect')), ('connectors', t.list_of_names), ('device_cluster_name', t.name), ('device_cluster_tenant_name', t.name), ('monitored', t.bool)) _aci_mo_name = 'vnsAbsNode' _tree_parent = ServiceGraph def __init__(self, **kwargs): super(ServiceGraphNode, self).__init__( { 'display_name': '', 'function_type': 'GoTo', 'managed': True, 'routing_mode': 'unspecified', 'connectors': [], 'device_cluster_name': '', 'device_cluster_tenant_name': '', 'monitored': False }, **kwargs)
class ServiceGraphConnection(resource.AciResourceBase): """Resource representing connections among function-nodes in service graph. """ identity_attributes = t.identity(('tenant_name', t.name), ('service_graph_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('adjacency_type', t.enum('L2', 'L3')), ('connector_direction', t.enum('consumer', 'provider')), ('connector_type', t.enum('internal', 'external')), ('direct_connect', t.bool), ('unicast_route', t.bool), ('connector_dns', t.list_of_strings), ('monitored', t.bool)) _aci_mo_name = 'vnsAbsConnection' _tree_parent = ServiceGraph def __init__(self, **kwargs): super(ServiceGraphConnection, self).__init__( { 'display_name': '', 'adjacency_type': 'L2', 'connector_direction': 'provider', 'connector_type': 'external', 'direct_connect': False, 'unicast_route': False, 'connector_dns': [], 'monitored': False }, **kwargs)
class DeviceCluster(resource.AciResourceBase): """Represents a device-cluster and associated ACI objects. """ identity_attributes = t.identity(('tenant_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('device_type', t.enum("PHYSICAL", "VIRTUAL")), ('service_type', t.enum("ADC", "FW", "OTHERS", "IDSIPS", "COPY")), ('context_aware', t.enum("single-Context", "multi-Context")), ('managed', t.bool), ('physical_domain_name', t.name), ('encap', t.string(24)), ('devices', t.list_of_dicts( ('name', t.name), ('path', t.string(512)))), ('monitored', t.bool)) _aci_mo_name = 'vnsLDevVip' _tree_parent = resource.Tenant def __init__(self, **kwargs): super(DeviceCluster, self).__init__( { 'display_name': '', 'device_type': 'PHYSICAL', 'service_type': 'OTHERS', 'context_aware': 'single-Context', 'managed': True, 'physical_domain_name': '', 'encap': '', 'devices': [], 'monitored': False }, **kwargs)
class DeviceClusterInterfaceContext(resource.AciResourceBase): """Resource representing a device-cluster logical interface context. """ identity_attributes = t.identity( ('tenant_name', t.name), ('contract_name', t.name), ('service_graph_name', t.name), ('node_name', t.name), ('connector_name', t.name)) other_attributes = t.other( ('display_name', t.name), ('device_cluster_interface_dn', t.string()), ('service_redirect_policy_dn', t.string()), ('bridge_domain_dn', t.string()), ('monitored', t.bool)) _aci_mo_name = 'vnsLIfCtx' _tree_parent = DeviceClusterContext def __init__(self, **kwargs): super(DeviceClusterInterfaceContext, self).__init__( { 'display_name': '', 'device_cluster_interface_dn': '', 'service_redirect_policy_dn': '', 'bridge_domain_dn': '', 'monitored': False }, **kwargs)
class ApicAssignment(resource.ResourceBase): """Track the APIC to aim-aid mapping""" identity_attributes = t.identity( ('apic_host', t.string(128))) other_attributes = t.other( ('aim_aid_id', t.string(64))) db_attributes = t.db( ('last_update_timestamp', t.string())) def __init__(self, **kwargs): super(ApicAssignment, self).__init__({'aim_aid_id': ''}, **kwargs) def is_available(self, context): current = context.store.current_timestamp # When the store doesn't support time stamp, the APIC can never # be considered available. if current is None: return False result = current - self.last_update_timestamp >= datetime.timedelta( seconds=cfg.CONF.aim.apic_available_time) if result: LOG.info("APIC %s is available. Last update time was %s" % (self.apic_host, self.last_update_timestamp)) return True else: LOG.debug("APIC %s is not available. Last update time was %s" % (self.apic_host, self.last_update_timestamp)) return False
class L3OutStaticRoute(AciResourceBase): """Resource representing a static route. Identity attributes: name of ACI tenant, name of L3Out, name of node profile, node_path of the node, cidr of the static route. """ identity_attributes = t.identity( ('tenant_name', t.name), ('l3out_name', t.name), ('node_profile_name', t.name), ('node_path', t.string()), ('cidr', t.ip_cidr)) other_attributes = t.other( ('next_hop_list', t.list_of_next_hop), ('preference', t.string()), ('display_name', t.name), ('monitored', t.bool)) _aci_mo_name = 'ipRouteP' _tree_parent = L3OutNode def __init__(self, **kwargs): super(L3OutStaticRoute, self).__init__( {'next_hop_list': [], 'preference': '1', 'monitored': False}, **kwargs)
class BridgeDomain(AciResourceBase): """Resource representing a BridgeDomain in ACI. Identity attributes are RNs for ACI tenant and bridge-domain. """ identity_attributes = t.identity( ('tenant_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('vrf_name', t.name), ('enable_arp_flood', t.bool), ('enable_routing', t.bool), ('limit_ip_learn_to_subnets', t.bool), ('ip_learning', t.bool), ('l2_unknown_unicast_mode', t.enum("", "flood", "proxy")), ('ep_move_detect_mode', t.enum("", "garp")), ('l3out_names', t.list_of_names), ('monitored', t.bool)) _aci_mo_name = 'fvBD' _tree_parent = Tenant def __init__(self, **kwargs): super(BridgeDomain, self).__init__({'vrf_name': '', 'enable_arp_flood': True, 'enable_routing': True, 'limit_ip_learn_to_subnets': False, 'ip_learning': True, 'l2_unknown_unicast_mode': 'proxy', 'ep_move_detect_mode': 'garp', 'l3out_names': [], 'monitored': False}, **kwargs)
class L3OutInterface(AciResourceBase): """Resource representing a logical interface. Identity attributes: name of ACI tenant, name of L3Out, name of node profile, name of interface profile, interface_path. """ identity_attributes = t.identity( ('tenant_name', t.name), ('l3out_name', t.name), ('node_profile_name', t.name), ('interface_profile_name', t.name), ('interface_path', t.string())) other_attributes = t.other( ('primary_addr_a', t.ip_cidr), ('secondary_addr_a_list', t.list_of_ip_cidr_obj), ('primary_addr_b', t.ip_cidr), ('secondary_addr_b_list', t.list_of_ip_cidr_obj), ('encap', t.string()), ('mode', t.enum(*t.spmodes.values())), ('host', t.string()), ('type', t.enum("ext-svi")), ('monitored', t.bool)) _aci_mo_name = 'l3extRsPathL3OutAtt' _tree_parent = L3OutInterfaceProfile def __init__(self, **kwargs): super(L3OutInterface, self).__init__( {'primary_addr_a': '', 'secondary_addr_a_list': [], 'primary_addr_b': '', 'secondary_addr_b_list': [], 'encap': '', 'type': 'ext-svi', 'mode': 'regular', 'monitored': False, 'host': ''}, **kwargs)
class Contract(AciResourceBase): """Resource representing a contract in ACI. Identity attributes: name of ACI tenant and name of contract. """ identity_attributes = t.identity( ('tenant_name', t.name), ('name', t.name)) other_attributes = t.other( ('scope', t.enum("", "tenant", "context", "global", "application-profile")), ('display_name', t.name), ('monitored', t.bool)) _aci_mo_name = 'vzBrCP' _tree_parent = Tenant SCOPE_APP_PROFILE = 'application-profile' SCOPE_TENANT = 'tenant' SCOPE_CONTEXT = 'context' SCOPE_GLOBAL = 'global' def __init__(self, **kwargs): super(Contract, self).__init__({'scope': self.SCOPE_CONTEXT, 'monitored': False}, **kwargs)
class TypeTreeBase(object): identity_attributes = t.identity(('root_rn', t.string(64))) other_attributes = t.other(('root_full_hash', t.string(256)), ('tree', t.string())) db_attributes = t.db() def __init__(self, **kwargs): super(TypeTreeBase, self).__init__({}, **kwargs)
class AciFault(resource.ResourceBase, OperationalResource): """Fault information reported by ACI.""" LC_UNKNOWN = 0x0 LC_SOAKING = 0x1 LC_RETAINING = 0x10 LC_RAISED = 0x2 LC_SOAKING_CLEARING = 0x4 LC_RAISED_CLEARING = 0x8 SEV_CLEARED = 'cleared' SEV_INFO = 'info' SEV_WARNING = 'warning' SEV_MINOR = 'minor' SEV_MAJOR = 'major' SEV_CRITICAL = 'critical' _aci_mo_name = 'faultInst' identity_attributes = t.identity(('fault_code', t.string()), ('external_identifier', t.string())) other_attributes = t.other(('severity', t.enum(SEV_CLEARED, SEV_CRITICAL, SEV_INFO, SEV_WARNING, SEV_MAJOR, SEV_MINOR)), ('status_id', t.id), ('cause', t.string()), ('description', t.string(255))) db_attributes = t.db(('last_update_timestamp', t.string())) def __eq__(self, other): try: return self.identity == other.identity except AttributeError: return False def __init__(self, **kwargs): super(AciFault, self).__init__( { 'severity': self.SEV_INFO, 'lifecycle_status': self.LC_UNKNOWN, 'cause': '', 'description': "" }, **kwargs) def is_error(self): return self.severity in [self.SEV_MAJOR, self.SEV_CRITICAL] @property def dn(self): return self.external_identifier @property def root(self): mos_and_types = utils.decompose_dn(self._aci_mo_name, self.dn) if mos_and_types: # Faults associated with unrecognized MOs will not decompose mo = apic_client.ManagedObjectClass(mos_and_types[0][0]) return (mo.rn(mos_and_types[0][1]) if mo.rn_param_count else mo.rn())
class FilterEntry(AciResourceBase): """Resource representing a classifier entry of a filter in ACI. Identity attributes: name of ACI tenant, name of filter and name of entry. Values for classification fields may be integers as per standards (e.g. ip_protocol = 6 for TCP, 17 for UDP), or special strings listed below. UNSPECIFIED may be used to indicate that a particular field should be ignored. Field | Special string values -------------------------------------------------------------------------- arp_opcode | req, reply ether_type | trill, arp, mpls_ucast, mac_security, fcoe, ip ip_protocol | icmp, igmp, tcp, egp, igp, udp, icmpv6, eigrp, ospfigp icmpv4_type | echo-rep, dst-unreach, src-quench, echo, time-exceeded icmpv6_type | dst-unreach, time-exceeded, echo-req, echo-rep, | nbr-solicit, nbr-advert, redirect source_from_port, | ftpData, smtp, dns, http, pop3, https, rtsp source_to_port, | dest_from_port, | dest_to_port | tcp_flags | est, syn, ack, fin, rst """ identity_attributes = t.identity(('tenant_name', t.name), ('filter_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('arp_opcode', t.string()), ('ether_type', t.string()), ('ip_protocol', t.string()), ('icmpv4_type', t.string()), ('icmpv6_type', t.string()), ('source_from_port', t.port), ('source_to_port', t.port), ('dest_from_port', t.port), ('dest_to_port', t.port), ('tcp_flags', t.string()), ('stateful', t.bool), ('fragment_only', t.bool), ('monitored', t.bool)) _aci_mo_name = 'vzEntry' _tree_parent = Filter def __init__(self, **kwargs): super(FilterEntry, self).__init__( { 'arp_opcode': self.UNSPECIFIED, 'ether_type': self.UNSPECIFIED, 'ip_protocol': self.UNSPECIFIED, 'icmpv4_type': self.UNSPECIFIED, 'icmpv6_type': self.UNSPECIFIED, 'source_from_port': self.UNSPECIFIED, 'source_to_port': self.UNSPECIFIED, 'dest_from_port': self.UNSPECIFIED, 'dest_to_port': self.UNSPECIFIED, 'tcp_flags': self.UNSPECIFIED, 'stateful': False, 'fragment_only': False, 'monitored': False }, **kwargs)
class Configuration(ResourceBase): identity_attributes = t.identity( ('key', t.string(52)), ('host', t.string(52)), ('group', t.string(52))) other_attributes = t.other(('value', t.string(512))) db_attributes = t.db(('version', t.string(36))) def __init__(self, **kwargs): super(Configuration, self).__init__({}, **kwargs)
class Topology(AciRoot): identity_attributes = t.identity() other_attributes = t.other(('name', t.name)) _aci_mo_name = 'fabricTopology' _tree_parent = None def __init__(self, **kwargs): super(Topology, self).__init__({}, name='topology', monitored=True)
class HostLinkNetworkLabel(resource.ResourceBase): """A network label to host link""" identity_attributes = t.identity(('host_name', t.string(128)), ('network_label', t.string(64)), ('interface_name', t.string(32))) other_attributes = t.other() def __init__(self, **kwargs): super(HostLinkNetworkLabel, self).__init__({}, **kwargs)
class EndpointGroup(AciResourceBase): """Resource representing an endpoint-group in ACI. Identity attributes: name of ACI tenant, name of application-profile and name of endpoint-group. Attribute 'static_paths' is a list of dicts with the following keys: * path: (Required) path-name of the switch-port which is bound to EndpointGroup * encap: (Required) encapsulation mode and identifier for this EndpointGroup on the specified switch-port. Must be specified in the format 'vlan-<vlan-id>' for VLAN encapsulation """ identity_attributes = t.identity( ('tenant_name', t.name), ('app_profile_name', t.name), ('name', t.name)) other_attributes = t.other( ('display_name', t.name), ('bd_name', t.name), ('policy_enforcement_pref', t.enum("", "enfFAorced", "unenforced")), ('provided_contract_names', t.list_of_names), ('consumed_contract_names', t.list_of_names), ('openstack_vmm_domain_names', t.list_of_names), ('physical_domain_names', t.list_of_names), ('vmm_domains', t.list_of_dicts(('type', t.name), ('name', t.name))), ('physical_domains', t.list_of_dicts(('name', t.name))), ('static_paths', t.list_of_static_paths), ('epg_contract_masters', t.list_of_dicts(('app_profile_name', t.name), ('name', t.name))), ('monitored', t.bool), ('sync', t.bool)) _aci_mo_name = 'fvAEPg' _tree_parent = ApplicationProfile POLICY_UNENFORCED = 'unenforced' POLICY_ENFORCED = 'enforced' def __init__(self, **kwargs): super(EndpointGroup, self).__init__({'bd_name': '', 'provided_contract_names': [], 'consumed_contract_names': [], 'openstack_vmm_domain_names': [], 'physical_domain_names': [], 'vmm_domains': [], 'physical_domains': [], 'policy_enforcement_pref': self.POLICY_UNENFORCED, 'static_paths': [], 'epg_contract_masters': [], 'monitored': False, 'sync': True}, **kwargs)
class VMMPolicy(AciRoot): identity_attributes = t.identity( ('type', t.enum("VMWare", "OpenStack", "Kubernetes"))) other_attributes = t.other(('monitored', t.bool), ('display_name', t.name)) _aci_mo_name = 'vmmProvP' _tree_parent = None def __init__(self, **kwargs): super(VMMPolicy, self).__init__({'monitored': False}, **kwargs)
class Agent(ResourceBase): """Resource representing an AIM Agent""" identity_attributes = t.identity(('id', t.id)) other_attributes = t.other( ('agent_type', t.string(255)), ('host', t.string(255)), ('binary_file', t.string(255)), ('admin_state_up', t.bool), ('description', t.string(255)), ('hash_trees', t.list_of_ids), ('version', t.string())) # Attrbutes completely managed by the DB (eg. timestamps) db_attributes = t.db(('heartbeat_timestamp', t.string())) def __init__(self, **kwargs): super(Agent, self).__init__({'admin_state_up': True, 'id': utils.generate_uuid()}, **kwargs) def __eq__(self, other): return self.id == other.id # An object is hashable if it has a hash value which never changes during # its lifetime (it needs a __hash__() method), and can be compared to # other objects (it needs an __eq__() or __cmp__() method). # Hashable objects which compare equal must have the same hash value. # # If you define __eq__() , the default __hash__() (namely, hashing the # address of the object in memory) goes away. # So for each class defining __eq__() we must also # define __hash__() even though parent class has __hash__(). def __hash__(self): return super(Agent, self).__hash__() def is_down(self, context): current = context.store.current_timestamp # When the store doesn't support timestamps the agent can never # be considered down. if current is None: return False result = current - self.heartbeat_timestamp >= datetime.timedelta( seconds=cfg.CONF.aim.agent_down_time) if result: LOG.warn("Agent %s is down. Last heartbeat was %s" % (self.id, self.heartbeat_timestamp)) else: LOG.debug("Agent %s is alive, its last heartbeat was %s" % (self.id, self.heartbeat_timestamp)) return result def down_time(self, context): if self.is_down(context): current = context.store.current_timestamp return (current - self.heartbeat_timestamp).seconds
class HostDomainMappingV2(resource.ResourceBase): """host to VMM and phys-dom mapping, version 2""" identity_attributes = t.identity( ('host_name', t.string(128)), ('domain_name', t.string(64)), ('domain_type', t.enum('PhysDom', 'OpenStack', 'Kubernetes', 'VMware'))) other_attributes = t.other() def __init__(self, **kwargs): super(HostDomainMappingV2, self).__init__({}, **kwargs)