Exemple #1
0
    def stop_import(self, request):
        """@description-title Stop import boot resources
        @description Stop import the boot resources.

        @success (http-status-code) "server-success" 200
        @success (content) "success-content"
            Import of boot resources is being stopped.
        """
        stop_import_resources()
        return HttpResponse(
            "Import of boot resources is being stopped",
            content_type=("text/plain; charset=%s" % settings.DEFAULT_CHARSET),
        )
Exemple #2
0
    def save_other(self, params):
        """Update `BootSourceSelection`'s to only include the selected
        images."""
        # Must be administrator.
        assert self.user.is_superuser, "Permission denied."

        @transactional
        def update_selections(params):
            # Remove all selections that are not Ubuntu.
            BootSourceSelection.objects.exclude(
                Q(os="ubuntu") | Q(os="ubuntu-core")).delete()

            # Break down the images into os/release with multiple arches.
            selections = defaultdict(list)
            for image in params["images"]:
                os, arch, _, release = image.split("/", 4)
                name = "%s/%s" % (os, release)
                selections[name].append(arch)

            # Create each selection for the source.
            for name, arches in selections.items():
                os, release = name.split("/")
                cache = BootSourceCache.objects.filter(
                    os=os, arch=arch, release=release).first()
                if cache is None:
                    # It is possible the cache changed while waiting for the
                    # user to perform an action. Ignore the selection as its
                    # no longer available.
                    continue
                # Create the selection for the source.
                BootSourceSelection.objects.create(
                    boot_source=cache.boot_source,
                    os=os,
                    release=release,
                    arches=arches,
                    subarches=["*"],
                    labels=["*"],
                )

        notify = Deferred()
        d = stop_import_resources()
        d.addCallback(lambda _: deferToDatabase(update_selections, params))
        d.addCallback(callOut, import_resources, notify=notify)
        d.addCallback(lambda _: notify)
        d.addCallback(lambda _: deferToDatabase(transactional(self.poll), {}))
        d.addErrback(
            log.err,
            "Failed to start the image import. Unable to save the non-Ubuntu "
            "image(s) source information",
        )
        return d
Exemple #3
0
    def save_ubuntu(self, params):
        """Called to save the Ubuntu section of the websocket."""
        # Must be administrator.
        assert self.user.is_superuser, "Permission denied."

        @transactional
        def update_source(params):
            os = "ubuntu"
            releases = params["releases"]
            arches = params["arches"]
            boot_source = self.get_bootsource(params, from_db=True)

            # Remove all selections, that are not of release.
            BootSourceSelection.objects.filter(
                boot_source=boot_source,
                os=os).exclude(release__in=releases).delete()

            if len(releases) > 0:
                # Create or update the selections.
                for release in releases:
                    selection, _ = BootSourceSelection.objects.get_or_create(
                        boot_source=boot_source, os=os, release=release)
                    selection.arches = arches
                    selection.subarches = ["*"]
                    selection.labels = ["*"]
                    selection.save()
            else:
                # Create a selection that will cause nothing to be downloaded,
                # since no releases are selected.
                selection, _ = BootSourceSelection.objects.get_or_create(
                    boot_source=boot_source, os=os, release="")
                selection.arches = arches
                selection.subarches = ["*"]
                selection.labels = ["*"]
                selection.save()

        notify = Deferred()
        d = stop_import_resources()
        d.addCallback(lambda _: deferToDatabase(update_source, params))
        d.addCallback(callOut, import_resources, notify=notify)
        d.addCallback(lambda _: notify)
        d.addCallback(lambda _: deferToDatabase(transactional(self.poll), {}))
        d.addErrback(
            log.err,
            "Failed to start the image import. Unable to save the Ubuntu "
            "image(s) source information.",
        )
        return d
Exemple #4
0
    def save_ubuntu(self, params):
        """Called to save the Ubuntu section of the websocket."""
        # Must be administrator.
        assert self.user.is_superuser, "Permission denied."

        @transactional
        def update_source(params):
            boot_source = self.get_bootsource(params, from_db=True)

            releases = set()
            for osystem in params.get("osystems", []):
                release = osystem.get("release")
                if release:
                    releases.add(release)
                else:
                    continue
                selection, _ = BootSourceSelection.objects.get_or_create(
                    boot_source=boot_source, os="ubuntu", release=release)
                selection.arches = osystem.get("arches", ["*"])
                selection.subarches = ["*"]
                selection.labels = ["*"]
                selection.save()

            if releases:
                # Remove all selections, that are not of release.
                BootSourceSelection.objects.filter(
                    boot_source=boot_source,
                    os="ubuntu").exclude(release__in=releases).delete()

        notify = Deferred()
        d = stop_import_resources()
        d.addCallback(lambda _: deferToDatabase(update_source, params))
        d.addCallback(callOut, import_resources, notify=notify)
        d.addCallback(lambda _: notify)
        d.addCallback(lambda _: deferToDatabase(transactional(self.poll), {}))
        d.addErrback(
            log.err,
            "Failed to start the image import. Unable to save the Ubuntu "
            "image(s) source information.",
        )
        return d
Exemple #5
0
 def stop_import(self, params):
     """Called to stop the current import process."""
     d = stop_import_resources()
     d.addCallback(lambda _: deferToDatabase(transactional(self.poll), {}))
     d.addErrback(log.err, "Failed to stop the image import process.")
     return d