How to use the kobo.hub.models.Worker.objects.get function in kobo

To help you get started, we’ve selected a few kobo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github release-engineering / kobo / tests / test_xmlrpc_client.py View on Github external
def test_enable_worker(self):
        w = Worker.objects.create(
            worker_key='disabled-worker',
            name='disabled-worker',
            enabled=False,
        )
        self.assertFalse(w.enabled)

        client.enable_worker(_make_request(), w.name)

        w = Worker.objects.get(id=w.id)
        self.assertTrue(w.enabled)
github release-engineering / kobo / tests / test_models.py View on Github external
self.assertEquals(worker.task_count, 0)
        self.assertEquals(worker.current_load, 0)
        self.assertEquals(worker.ready, True)

        Task.objects.create(
            worker=worker,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            method='DummyTask',
            state=TASK_STATES['OPEN'],
            weight=100,
        )

        worker.save()
        worker = Worker.objects.get(id=worker.id)
        self.assertEquals(worker.task_count, 1)
        self.assertEquals(worker.current_load, 100)
        self.assertEquals(worker.ready, False)
github release-engineering / kobo / kobo / hub / middleware.py View on Github external
def get_worker(request):
    try:
        if "/" not in request.user.username:
            return None

        hostname = request.user.username.split("/")[1]
        worker = Worker.objects.get(name=hostname)
        return worker
    except:
        return None
github release-engineering / kobo / kobo / hub / models.py View on Github external
cursor.execute(query, (new_state, new_worker_id, dt_started, dt_finished, waiting, self.id, worker_id))

            if cursor.rowcount == 0:
                if self.state in FINISHED_STATES:
                    logger.debug("Trying to interrupt closed task %s, ignoring.", self.id)
                    return
                else:
                    raise ObjectDoesNotExist()

            if cursor.rowcount > 1:
                raise MultipleObjectsReturned()

        self.dt_started = dt_started
        self.dt_finished = dt_finished
        if new_worker_id is not None:
            self.worker = Worker.objects.get(id=new_worker_id)
        self.state = new_state
        self.waiting = waiting
github release-engineering / kobo / kobo / hub / xmlrpc / auth.py View on Github external
def login_worker_key(request, worker_key):
    """login_worker_key(worker_key): session_key"""
    try:
        worker = Worker.objects.get(worker_key=worker_key)
    except ObjectDoesNotExist:
        raise PermissionDenied()

    username = "worker/%s" % worker.name
    backend = Krb5RemoteUserBackend()
    if django_version_ge('1.11.0'):
        user = backend.authenticate(None, username)
    else:
        user = backend.authenticate(username)
    if user is None:
        raise PermissionDenied()
    user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
    user = django.contrib.auth.login(request, user)
    return request.session.session_key
github release-engineering / kobo / kobo / hub / models.py View on Github external
"""Create a new task."""
        task = cls()
        task.owner = get_user_model().objects.get(username=owner_name)
        task.label = label
        task.method = method
        task.args = args or {}
        task.comment = comment

        if parent_id is not None:
            task.parent = cls.objects.get(id=parent_id)

        if state is not None:
            task.state = state

        if worker_name is not None:
            task.worker = Worker.objects.get(name=worker_name)
            task.state = TASK_STATES["ASSIGNED"]

        task.resubmitted_by = resubmitted_by
        task.resubmitted_from = resubmitted_from

        task.arch = Arch.objects.get(name=arch_name)
        task.channel = Channel.objects.get(name=channel_name)
        task.priority = priority
        task.timeout = timeout
        task.weight = weight
        task.exclusive = exclusive

        # TODO: unsupported in Django 1.0
        #task.validate()
        task.save()
        return task.id
github release-engineering / kobo / kobo / hub / xmlrpc / client.py View on Github external
def get_worker_info(request, worker_name):
    try:
        return models.Worker.objects.get(name=worker_name).export()
    except models.Worker.DoesNotExist:
        return {}