def is_importing(self, request): """@description-title Importing status @description Get the status of importing resources. @success (http-status-code) "server-success" 200 @success (content) "success-content-true" true @success (content) "success-content-false" false """ return is_import_resources_running()
def poll(self, params): """Polling method that the websocket client calls. Since boot resource information is split between the region and the rack controllers the websocket uses a polling method to get the updated information. Pushing the information at the moment is not possible as no rack information is cached on the region side. """ try: sources, releases, arches = get_os_info_from_boot_sources('ubuntu') self.connection_error = False self.ubuntu_sources = sources self.ubuntu_releases = releases self.ubuntu_arches = arches except ConnectionError: self.connection_error = True self.ubuntu_sources = [] self.ubuntu_releases = set() self.ubuntu_arches = set() # Load all the nodes, so its not done on every call # to the method get_number_of_nodes_deployed_for. # XXX Danilo 2017-06-29: this used to also do # .only('osystem', 'distro_series') # but that caused "RecursionError: maximum recursion depth exceeded # while calling a Python object" errors with Django 1.11 in # maasserver.websockets.handlers.tests.test_bootresource # tests. Since we are filtering on status field which is not in # "only" anyway, I don't think we ever had the benefit of prefetching # only those two fields. self.nodes = Node.objects.filter( status__in=[NODE_STATUS.DEPLOYED, NODE_STATUS.DEPLOYING]) self.default_osystem = Config.objects.get_config('default_osystem') self.default_distro_series = Config.objects.get_config( 'default_distro_series') # Load list of boot resources that currently exist on all racks. rack_images = get_common_available_boot_images() self.racks_syncing = is_import_boot_images_running() self.rack_resources = (BootResource.objects. get_resources_matching_boot_images(rack_images)) # Load all the resources and generate the JSON result. resources = self.combine_resources( BootResource.objects.filter(bootloader_type=None)) json_resources = [ dict(id=resource.id, rtype=resource.rtype, name=resource.name, title=resource.title, arch=resource.arch, size=resource.size, complete=resource.complete, status=resource.status, icon=resource.icon, downloading=resource.downloading, numberOfNodes=resource.number_of_nodes, lastUpdate=resource.last_update.strftime( "%a, %d %b. %Y %H:%M:%S")) for resource in resources ] commissioning_series = Config.objects.get_config( name='commissioning_distro_series') json_ubuntu = dict( sources=self.format_ubuntu_sources(), releases=self.format_ubuntu_releases(), arches=self.format_ubuntu_arches(), commissioning_series=commissioning_series, ) data = dict( connection_error=self.connection_error, region_import_running=is_import_resources_running(), rack_import_running=self.racks_syncing, resources=json_resources, ubuntu=json_ubuntu, ubuntu_core_images=self.format_ubuntu_core_images(), other_images=self.format_other_images(), ) return json.dumps(data)