Beispiel #1
0
 def destroy_port(self, port_id):
     with _session_for_write():
         query = model_query(models.Port)
         query = add_port_filter(query, port_id)
         count = query.delete()
         if count == 0:
             raise exception.PortNotFound(port=port_id)
Beispiel #2
0
    def test_find_ports_by_macs_bad_params(self, mock_get_port):
        mock_get_port.side_effect = exception.PortNotFound(port="123")

        macs = ['aa:bb:cc:dd:ee:ff']
        with task_manager.acquire(self.context, self.node['uuid'],
                                  shared=True) as task:
            empty_ids = self.passthru._find_ports_by_macs(task, macs)
        self.assertEqual([], empty_ids)
Beispiel #3
0
 def destroy_port(self, port_id):
     session = get_session()
     with session.begin():
         query = model_query(models.Port, session=session)
         query = add_port_filter(query, port_id)
         count = query.delete()
         if count == 0:
             raise exception.PortNotFound(port=port_id)
Beispiel #4
0
    def get_port(self, port):
        query = model_query(models.Port)
        query = add_port_filter(query, port)

        try:
            result = query.one()
        except NoResultFound:
            raise exception.PortNotFound(port=port)

        return result
Beispiel #5
0
    def update_port(self, port, values):
        session = get_session()
        with session.begin():
            query = model_query(models.Port, session=session)
            query = add_mac_filter(query, port)

            count = query.update(values)
            if count != 1:
                raise exception.PortNotFound(port=port)
            ref = query.one()
        return ref
Beispiel #6
0
    def destroy_port(self, port_id):
        session = get_session()
        with session.begin():
            query = model_query(models.Port, session=session)
            query = add_port_filter(query, port_id)

            try:
                ref = query.one()
            except NoResultFound:
                raise exception.PortNotFound(port=port_id)
            _check_port_change_forbidden(ref, session)

            query.delete()
Beispiel #7
0
 def update_port(self, port_id, values):
     session = get_session()
     try:
         with session.begin():
             query = model_query(models.Port, session=session)
             query = add_port_filter(query, port_id)
             ref = query.one()
             ref.update(values)
     except NoResultFound:
         raise exception.PortNotFound(port=port_id)
     except db_exc.DBDuplicateEntry:
         raise exception.MACAlreadyExists(mac=values['address'])
     return ref
Beispiel #8
0
    def update_port(self, port, values):
        session = get_session()
        with session.begin():
            query = model_query(models.Port, session=session)
            query = add_port_filter(query, port)
            try:
                ref = query.one()
            except NoResultFound:
                raise exception.PortNotFound(port=port)
            _check_port_change_forbidden(ref, session)

            ref.update(values)

        return ref
Beispiel #9
0
    def update_port(self, port_id, values):
        # NOTE(dtantsur): this can lead to very strange errors
        if 'uuid' in values:
            msg = _("Cannot overwrite UUID for an existing Port.")
            raise exception.InvalidParameterValue(err=msg)

        session = get_session()
        try:
            with session.begin():
                query = model_query(models.Port, session=session)
                query = add_port_filter(query, port_id)
                ref = query.one()
                ref.update(values)
        except NoResultFound:
            raise exception.PortNotFound(port=port_id)
        except db_exc.DBDuplicateEntry:
            raise exception.MACAlreadyExists(mac=values['address'])
        return ref
Beispiel #10
0
 def get_port_by_address(self, address):
     query = model_query(models.Port).filter_by(address=address)
     try:
         return query.one()
     except NoResultFound:
         raise exception.PortNotFound(port=address)
Beispiel #11
0
 def get_port_by_uuid(self, port_uuid):
     query = model_query(models.Port).filter_by(uuid=port_uuid)
     try:
         return query.one()
     except NoResultFound:
         raise exception.PortNotFound(port=port_uuid)