class LogicalPort(mf.ModelBase, mixins.Name, mixins.Version, mixins.Topic, mixins.UniqueKey, mixins.BasicEvents): table_name = "lport" ips = df_fields.ListOfField(df_fields.IpAddressField()) subnets = df_fields.ReferenceListField(Subnet) macs = df_fields.ListOfField(df_fields.MacAddressField()) enabled = fields.BoolField() binding = fields.EmbeddedField(PortBinding) lswitch = df_fields.ReferenceField(LogicalSwitch) security_groups = df_fields.ReferenceListField(secgroups.SecurityGroup) allowed_address_pairs = fields.ListField(AddressPair) port_security_enabled = fields.BoolField() device_owner = fields.StringField() device_id = fields.StringField() qos_policy = df_fields.ReferenceField(qos.QosPolicy) dhcp_params = fields.EmbeddedField(DhcpParams) binding_vnic_type = df_fields.EnumField(portbindings.VNIC_TYPES) @property def ip(self): try: return self.ips[0] except IndexError: return None @property def mac(self): try: return self.macs[0] except IndexError: return None @property def is_local(self): return port_locator.is_port_local(self) @property def is_remote(self): return port_locator.is_port_remote(self) @property def all_ips(self): ips = set(self.ips) ips.update(pair.ip_address for pair in self.allowed_address_pairs) return ips def __str__(self): data = {} for name in dir(self): if name.startswith('_'): continue cls_definition = getattr(self.__class__, name, None) if isinstance(cls_definition, fields.BaseField): if name in self._set_fields: data[name] = getattr(self, name) elif not cls_definition: # Display only instnaces, not classes data[name] = getattr(self, name) return str(data)
class PortChain(mf.ModelBase, mixins.BasicEvents, mixins.Topic, mixins.Name): table_name = 'sfc_portchain' protocol = df_fields.EnumField([PROTO_MPLS]) chain_id = fields.IntField() port_pair_groups = df_fields.ReferenceListField(PortPairGroup) flow_classifiers = df_fields.ReferenceListField(FlowClassifier) def find_flow_classifier(self, fc_id): for fc in self.flow_classifiers: if fc.id == fc_id: return fc
class FieldTestModel(mf.ModelBase): enum = df_fields.EnumField(('a', 'b', 'c')) enum_list = df_fields.EnumListField(('a', 'b', 'c')) ipaddr = df_fields.IpAddressField() ipnetwork = df_fields.IpNetworkField() ref = df_fields.ReferenceField(ReffedTestModel) ref_list = df_fields.ReferenceListField(ReffedTestModel) ip_list = df_fields.ListOfField(df_fields.IpAddressField()) def __init__(self, **kwargs): super(FieldTestModel, self).__init__(id='id1', **kwargs)
class BGPSpeaker(mf.ModelBase, mixins.Topic, mixins.Name): table_name = "bgp_speaker" local_as = fields.IntField(required=True) peers = df_fields.ReferenceListField(BGPPeer) host_routes = fields.ListField(host_route.HostRoute) prefix_routes = fields.ListField(host_route.HostRoute) ip_version = fields.IntField(required=True) def remove_peer(self, peer_id): self.peers[:] = [peer for peer in self.peers if peer.id != peer_id]
class FieldTestModel(mf.ModelBase): enum = df_fields.EnumField(('a', 'b', 'c')) enum_list = df_fields.EnumListField(('a', 'b', 'c')) ipaddr = df_fields.IpAddressField() ipnetwork = df_fields.IpNetworkField() ref = df_fields.ReferenceField(ReffedTestModel) ref_list = df_fields.ReferenceListField(ReffedTestModel) ip_list = df_fields.ListOfField(df_fields.IpAddressField()) port_range = df_fields.PortRangeField() dhcp_opts = df_fields.DhcpOptsDictField() def __init__(self, **kwargs): id = kwargs.pop("id", 'id1') super(FieldTestModel, self).__init__(id=id, **kwargs)
class LogicalSimplePort(mf.ModelBase, mixins.Name, mixins.BasicEvents): table_name = "lport" port_num = fields.IntField(False) ips = df_fields.ListOfField(df_fields.IpAddressField()) subnets = df_fields.ReferenceListField(Subnet) macs = df_fields.ListOfField(df_fields.MacAddressField()) enabled = fields.BoolField() lswitch = df_fields.ReferenceField(LogicalSwitch) qos_policy = df_fields.ReferenceField(qos.QosPolicy) @property def ip(self): try: return self.ips[0] except IndexError: return None @property def mac(self): try: return self.macs[0] except IndexError: return None def __str__(self): data = {} for name in dir(self): if name.startswith('_'): continue cls_definition = getattr(self.__class__, name, None) if isinstance(cls_definition, fields.BaseField): if name in self._set_fields: data[name] = getattr(self, name) elif not cls_definition: # Display only instnaces, not classes data[name] = getattr(self, name) return str(data)
class LocalListReffingModel(model_framework.ModelBase): table_name = 'LocalListReffingModel' ref2 = df_fields.ReferenceListField(LocalReffingModel)
class ListReffingModel(mf.ModelBase): table_name = 'ListReffingModel' ref2 = df_fields.ReferenceListField(ReffingModel)
class LogicalPort(mf.ModelBase, mixins.Name, mixins.Version, mixins.Topic, mixins.UniqueKey): table_name = "lport" ips = df_fields.ListOfField(df_fields.IpAddressField()) subnets = df_fields.ReferenceListField(Subnet) macs = df_fields.ListOfField(df_fields.MacAddressField()) enabled = fields.BoolField() chassis = df_fields.ReferenceField(core.Chassis) lswitch = df_fields.ReferenceField(LogicalSwitch) security_groups = df_fields.ReferenceListField(secgroups.SecurityGroup) allowed_address_pairs = fields.ListField(AddressPair) port_security_enabled = fields.BoolField() device_owner = fields.StringField() device_id = fields.StringField() qos_policy = df_fields.ReferenceField(qos.QosPolicy) remote_vtep = fields.BoolField() extra_dhcp_options = df_fields.IntStringDictField() binding_vnic_type = df_fields.EnumField(portbindings.VNIC_TYPES) def __init__(self, ofport=None, is_local=None, peer_vtep_address=None, **kwargs): super(LogicalPort, self).__init__(**kwargs) self.ofport = ofport self.is_local = is_local self.peer_vtep_address = peer_vtep_address @property def ip(self): try: return self.ips[0] except IndexError: return None @property def mac(self): try: return self.macs[0] except IndexError: return None def is_vm_port(self): """ Return True if the device owner starts with 'compute:' (or is None) """ owner = self.device_owner if not owner or owner.startswith(n_const.DEVICE_OWNER_COMPUTE_PREFIX): return True return False def __str__(self): data = {} for name in dir(self): if name.startswith('_'): continue cls_definition = getattr(self.__class__, name, None) if isinstance(cls_definition, fields.BaseField): if name in self._set_fields: data[name] = getattr(self, name) elif not cls_definition: # Display only instnaces, not classes data[name] = getattr(self, name) return str(data) def emit_created(self): ofport = getattr(self, 'ofport', None) if not ofport: return is_local = getattr(self, 'is_local', None) LOG.info("Adding new logical port = %s", self) if is_local: self.emit_local_created() else: self.emit_remote_created() def emit_updated(self, original_lport): ofport = getattr(self, 'ofport', None) if not ofport: return is_local = getattr(self, 'is_local', None) LOG.info( "Updating %(location)s logical port = %(port)s, " "original port = %(original_port)s", { 'port': self, 'original_port': original_lport, 'location': 'local' if is_local else 'remote' }) if is_local: self.emit_local_updated(original_lport) else: self.emit_remote_updated(original_lport) def emit_deleted(self): is_local = getattr(self, 'is_local', None) ofport = getattr(self, 'ofport', None) if not ofport: return if is_local: self.emit_local_deleted() else: self.emit_remote_deleted()
class PortPairGroup(mf.ModelBase, mixins.BasicEvents, mixins.Topic, mixins.Name): table_name = 'sfc_portpairgroup' port_pairs = df_fields.ReferenceListField(PortPair)