예제 #1
0
    def fetch_pending(self, deleted):
        if (not deleted):
            objs = ONOSApp.get_tenant_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
        else:
            objs = ONOSApp.get_deleted_tenant_objects()

        return objs
예제 #2
0
    def fetch_pending(self, deleted):
        if (not deleted):
            objs = ONOSApp.get_tenant_objects().filter(
                Q(enacted__lt=F('updated')) | Q(enacted=None),
                Q(lazy_blocked=False))
        else:
            objs = ONOSApp.get_deleted_tenant_objects()

        return objs
예제 #3
0
    def get_queryset(self):
        queryset = ONOSApp.get_tenant_objects().all()

        # Since name isn't a real database field of the Tenant object, we have
        # to go through some extra work...
        name = self.request.query_params.get('name', None)
        if name is not None:
            ids = [x.id for x in queryset.all() if x.name == name]
            return queryset.filter(id__in=ids)

        return queryset
예제 #4
0
파일: onosapp.py 프로젝트: digideskio/xos
 def get_existing_objs(self):
     objs = ONOSApp.get_tenant_objects().all()
     objs = [x for x in objs if x.name == self.nodetemplate.name]
     return objs
예제 #5
0
 def get_existing_objs(self):
     objs = ONOSApp.get_tenant_objects().all()
     objs = [x for x in objs if x.name == self.obj_name]
     return objs
예제 #6
0
class ONOSAppViewSet(XOSViewSet):
    base_name = "app"
    method_name = "app"
    method_kind = "viewset"
    queryset = ONOSApp.get_tenant_objects().all()
    serializer_class = ONOSAppSerializer

    custom_serializers = {"set_attribute": TenantAttributeSerializer}

    @classmethod
    def get_urlpatterns(self, api_path="^"):
        patterns = super(ONOSAppViewSet,
                         self).get_urlpatterns(api_path=api_path)

        patterns.append(
            self.detail_url("attributes/$", {
                "get": "get_attributes",
                "post": "add_attribute"
            }, "attributes"))
        patterns.append(
            self.detail_url(
                "attributes/(?P<attribute>[0-9]+)/$", {
                    "get": "get_attribute",
                    "put": "set_attribute",
                    "delete": "delete_attribute"
                }, "attribute"))

        return patterns

    def get_attributes(self, request, pk=None):
        app = self.get_object()
        return Response(
            TenantAttributeSerializer(app.tenantattributes.all(),
                                      many=True).data)

    def add_attribute(self, request, pk=None):
        app = self.get_object()
        ser = TenantAttributeSerializer(data=request.data)
        ser.is_valid(raise_exception=True)
        att = TenantAttribute(tenant=app, **ser.validated_data)
        att.save()
        return Response(TenantAttributeSerializer(att).data)

    def get_attribute(self, request, pk=None, attribute=None):
        app = self.get_object()
        att = TenantAttribute.objects.get(pk=attribute)
        return Response(TenantAttributeSerializer(att).data)

    def set_attribute(self, request, pk=None, attribute=None):
        app = self.get_object()
        att = TenantAttribute.objects.get(pk=attribute)
        ser = TenantAttributeSerializer(att, data=request.data)
        ser.is_valid(raise_exception=True)
        att.name = ser.validated_data.get("name", att.name)
        att.value = ser.validated_data.get("value", att.value)
        att.save()
        return Response(TenantAttributeSerializer(att).data)

    def delete_attribute(self, request, pk=None, attribute=None):
        att = TenantAttribute.objects.get(pk=attribute)
        att.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)