Exemplo n.º 1
0
    def _show_port(self, client, port_id):
        """Return the port for the client given the port id."""

        try:
            result = client.show_port(port_id)
            return result.get('port')
        except neutron_exceptions.PortNotFoundClient:
            raise exception.PortNotFound(port_id=port_id)
        except neutron_exceptions.Unauthorized:
            raise exception.Forbidden()
        except neutron_exceptions.NeutronClientException as e:
            msg = (_("Failed to access port %(port_id)s: %(reason)s") % {
                'port_id': port_id,
                'reason': e
            })
            raise exception.NetworkError(msg)
Exemplo n.º 2
0
    def lock(self, server_uuid, target):
        """Set the lock state of the server.

        :param server_uuid: the UUID of a server.
        :param target: the desired target to change lock state,
                       true or false
        """
        db_server = self._resource or self._get_resource(server_uuid)
        context = pecan.request.context

        # Target is True, means lock a server
        if target:
            pecan.request.engine_api.lock(context, db_server)

        # Else, unlock the server
        else:
            # Try to unlock a server with non-admin or non-owner
            if not pecan.request.engine_api.is_expected_locked_by(
                    context, db_server):
                raise exception.Forbidden()
            pecan.request.engine_api.unlock(context, db_server)