def get_config(self, request, object_id): """ View to retrieve configuration tar ball for a host. Returns same content as api/host/<int:pk>/config, but authentication is by user (admin), not host/secret. """ host = get_object_or_404(Host, pk=object_id) filename = '{host}_v{version}.tar.gz'.format( host=host.path_str(), version=host.config_version) resp = HttpResponseAttachment(filename=filename, content_type='application/gzip') config_tar.generate_host_config_tar(host, resp) return resp
def get_host_config_tar_response(host): """ Build the tar.gz attachment response for the GetHostConfig view. Note: This is re-used to download host config from the admin interface. :returns: HttpResponseAttachment """ filename = '{host}_v{version}.tar.gz'.format(host=host.path_str(), version=host.config_version) # Use the response as file-like object to write the tar resp = HttpResponseAttachment(filename=filename, content_type='application/gzip') with closing(tarfile.open(mode='w:gz', fileobj=resp)) as tar: config_tar.generate_host_config_tar(host, TarWriter(tar)) return resp
def get(self, request, *args, **kwargs): host = self.get_object() version = _get_version_param(request.GET) if version is _BAD_VERSION: return HttpResponseBadRequest() if version and version >= host.config_version: return HttpResponseNotModified() if config_tar.is_empty_config(host): return HttpResponse(status=204) # All good, return generate and return the config # Use the response as file-like object to write the tar filename = '{host}_v{version}.tar.gz'.format( host=host.path_str(), version=host.config_version) resp = HttpResponseAttachment(filename=filename, content_type='application/gzip') config_tar.generate_host_config_tar(host, resp) return resp
def test_host(self): extra_srv = Service.objects.filter(type__in=[Service.BW]).first() host = extra_srv.host archive = DictWriter() generate_host_config_tar(host, archive) self._check_archive('host_%i' % host.id, archive)
def _test_host(self, host): archive = DictWriter() generate_host_config_tar(host, archive) self._check_archive('host_%i' % host.id, archive)