Beispiel #1
0
    def get(self, request, *args, **kwargs):
        item_name = kwargs['item_name']
        resource_type = kwargs['resource_type']
        item = Item.objects.get(name=item_name)
        data = []
        result = {}
        result2 = None
        resource_ids = ItemResource.objects.filter(item_id=item.id).values_list('resource_id', flat=True)
        if resource_type == ItemResource.RESOURCE_TYPE_CLUSTER:
            result = Cluster.objects.exclude(id__in=resource_ids)
        if resource_type == ItemResource.RESOURCE_TYPE_HOST:
            result = Host.objects.exclude(id__in=resource_ids).filter(node_id=None)
        if resource_type == ItemResource.RESOURCE_TYPE_PLAN:
            result = Plan.objects.exclude(id__in=resource_ids)
        if resource_type == ItemResource.RESOURCE_TYPE_STORAGE:
            nfs = NfsStorage.objects.exclude(id__in=resource_ids)
            result = nfs
            ceph = CephStorage.objects.exclude(id__in=resource_ids)
            result2 = ceph
        if resource_type == ItemResource.RESOURCE_TYPE_BACKUP_STORAGE:
            result = BackupStorage.objects.exclude(id__in=resource_ids)

        for re in result:
            item_resource_dto = Resource(resource_id=re.id, resource_type=resource_type, data=re, checked=False)
            data.append(item_resource_dto.__dict__)
        if result2 is not None:
            for re in result2:
                item_resource_dto = Resource(resource_id=re.id, resource_type=resource_type, data=re, checked=False)
                data.append(item_resource_dto.__dict__)
        response = HttpResponse(content_type='application/json')
        response.write(json.dumps(data, cls=JsonResourceEncoder))
        return response
Beispiel #2
0
    def get(self, request, *args, **kwargs):
        item_name = kwargs['item_name']
        item = Item.objects.get(name=item_name)
        resource_ids = ItemResource.objects.filter(
            item_id=item.id).values_list('resource_id', flat=True)
        resources = []
        clusters = Cluster.objects.filter(id__in=resource_ids)
        for c in clusters:
            resource = Resource(
                resource_id=c.id,
                resource_type=ItemResource.RESOURCE_TYPE_CLUSTER,
                data=c,
                checked=True)
            resources.append(resource.__dict__)
        hosts = Host.objects.filter(id__in=resource_ids)
        for h in hosts:
            resource = Resource(resource_id=h.id,
                                resource_type=ItemResource.RESOURCE_TYPE_HOST,
                                data=h,
                                checked=True)
            resources.append(resource.__dict__)
        backup_storage = BackupStorage.objects.filter(id__in=resource_ids)
        for b in backup_storage:
            resource = Resource(
                resource_id=b.id,
                resource_type=ItemResource.RESOURCE_TYPE_BACKUP_STORAGE,
                data=b,
                checked=True)
            resources.append(resource.__dict__)
        plan = Plan.objects.filter(id__in=resource_ids)
        for p in plan:
            resource = Resource(resource_id=p.id,
                                resource_type=ItemResource.RESOURCE_TYPE_PLAN,
                                data=p,
                                checked=True)
            resources.append(resource.__dict__)
        nfs = NfsStorage.objects.filter(id__in=resource_ids)
        for n in nfs:
            resource = Resource(
                resource_id=n.id,
                resource_type=ItemResource.RESOURCE_TYPE_STORAGE,
                data=n,
                checked=True)
            resources.append(resource.__dict__)
        ceph = CephStorage.objects.filter(id__in=resource_ids)
        for c in ceph:
            resource = Resource(
                resource_id=c.id,
                resource_type=ItemResource.RESOURCE_TYPE_STORAGE,
                data=n,
                checked=True)
            resources.append(resource)

        response = HttpResponse(content_type='application/json')
        response.write(json.dumps(resources, cls=JsonResourceEncoder))
        return response