Example #1
0
    def get_objects(cls,
                    context,
                    _pager=None,
                    validate_filters=True,
                    **kwargs):
        if 'network_id' in kwargs and 'router_id' not in kwargs:
            ports = Port.get_objects(
                context,
                network_id=kwargs.pop('network_id'),
                device_owner=constants.DEVICE_OWNER_ROUTER_INTF)

            router_assocs = []
            for port in ports:
                router_assocs.extend(
                    super(BGPVPNRouterAssociation,
                          cls).get_objects(context,
                                           _pager=_pager,
                                           validate_filters=validate_filters,
                                           router_id=RouterPort.get_object(
                                               context,
                                               port_id=port.id).router_id,
                                           **kwargs))
            return router_assocs

        return super(BGPVPNRouterAssociation,
                     cls).get_objects(context,
                                      _pager=_pager,
                                      validate_filters=validate_filters,
                                      **kwargs)
Example #2
0
    def _is_deleted_port_in_use(self, physnet, mac, db):
        # Go through all ports with this mac addr and find which
        # network segment they are on, which will contain physnet
        # and net type
        #
        # if a port with this mac on the same physical provider
        # is attached to this port then don't delete the interface.
        # Don't need to check the segment since delete will remove all
        # segments, and bind also deletes before adding
        #
        # These checks are required because a second tenant could
        # set their mac address to the ironic port one and attempt
        # meddle with the port delete. This wouldn't do anything
        # bad today because bind deletes the interface and recreates
        # it on the physical switch, but that's an implementation
        # detail we shouldn't rely on.

        # get port by mac
        mports = Port.get_objects(db, mac_address=mac)

        if len(mports) > 1:
            # This isn't technically a problem, but it may indicate something
            # fishy is going on
            LOG.warn('multiple ports matching ironic '
                     'port mac: {mac}'.format(mac=mac))

        for port in mports:
            if port.bindings:
                lli = self._get_port_lli(port)
                if lli:
                    net = Network.get_object(db, id=port.network_id)
                    if net:
                        for seg in net.segments:
                            if (seg.physical_network == physnet
                                    and seg.network_type == 'vlan'):
                                return True
        return False
Example #3
0
    def _load_ports_by_side(self, side):
        ports = []
        if getattr(self, side + '_ppg'):
            # pylint: disable=no-member
            reverse_side = (side if self.reverse_hop else
                            constants.REVERSE_PORT_SIDE[side])

            ports = ([
                getattr(pp, reverse_side)
                for pp in model_query.get_collection_query(
                    self.obj_context,
                    sfc_db.PortPair,
                    filters={
                        'portpairgroup_id': [getattr(self, side + '_ppg')]
                    })
            ])
        elif getattr(self, side + '_network'):
            port_objs = (Port.get_objects(self.obj_context,
                                          network_id=getattr(
                                              self, side + '_network')))
            ports = [port_obj.id for port_obj in port_objs]

        setattr(self, side + '_ports', ports)
        self.obj_reset_changes([side + '_ports'])