Example #1
0
    def fetch_pending(self, deleted):
        if (not deleted):
            objs = ONOSService.get_service_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
        else:
            objs = ONOSService.get_deleted_service_objects()

        return objs
Example #2
0
 def get_fabric_onos_service(self):
     fos = None
     fs = FabricService.get_service_objects().all()[0]
     if fs.subscribed_tenants.exists():
         app = fs.subscribed_tenants.all()[0]
         if app.provider_service:
             ps = app.provider_service
             fos = ONOSService.get_service_objects().filter(id=ps.id)[0]
     return fos
Example #3
0
    def get_onos_service(self, o):
        if not o.provider_service:
            return None

        onoses = ONOSService.get_service_objects().filter(id=o.provider_service.id)
        if not onoses:
            return None

        return onoses[0]
 def get_fabric_onos_service(self):
     fos = None
     fs = FabricService.get_service_objects().all()[0]
     if fs.subscribed_tenants.exists():
         app = fs.subscribed_tenants.all()[0]
         if app.provider_service:
             ps = app.provider_service
             fos = ONOSService.get_service_objects().filter(id=ps.id)[0]
     return fos
Example #5
0
    def get_vtn_onos_service(self):
        from services.onos.models import ONOSService

        vtn_service = ONOSService.get_service_objects().filter(
            name="ONOS_CORD")  # XXX fixme - harcoded
        if not vtn_service:
            raise "No VTN Onos Service"

        return vtn_service[0]
Example #6
0
    def get_onos_service(self, o):
        if not o.provider_service:
            return None

        onoses = ONOSService.get_service_objects().filter(
            id=o.provider_service.id)
        if not onoses:
            return None

        return onoses[0]
Example #7
0
def get_default_onos_service():
    onos_services = ONOSService.get_service_objects().all()
    if onos_services:
        return onos_services[0].id
    return None
Example #8
0
class ONOSServiceViewSet(XOSViewSet):
    base_name = "onos"
    method_name = "onos"
    method_kind = "viewset"
    queryset = ONOSService.get_service_objects().all()
    serializer_class = ONOSServiceSerializer

    custom_serializers = {"set_attribute": ServiceAttributeSerializer}

    @classmethod
    def get_urlpatterns(self, api_path="^"):
        patterns = super(ONOSServiceViewSet,
                         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):
        svc = self.get_object()
        return Response(
            ServiceAttributeSerializer(svc.serviceattributes.all(),
                                       many=True).data)

    def add_attribute(self, request, pk=None):
        svc = self.get_object()
        ser = ServiceAttributeSerializer(data=request.data)
        ser.is_valid(raise_exception=True)
        att = ServiceAttribute(service=svc, **ser.validated_data)
        att.save()
        return Response(ServiceAttributeSerializer(att).data)

    def get_attribute(self, request, pk=None, attribute=None):
        svc = self.get_object()
        att = ServiceAttribute.objects.get(pk=attribute)
        return Response(ServiceAttributeSerializer(att).data)

    def set_attribute(self, request, pk=None, attribute=None):
        svc = self.get_object()
        att = ServiceAttribute.objects.get(pk=attribute)
        ser = ServicettributeSerializer(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(ServiceAttributeSerializer(att).data)

    def delete_attribute(self, request, pk=None, attribute=None):
        att = ServiceAttribute.objects.get(pk=attribute)
        att.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Example #9
0
def get_default_onos_service():
    onos_services = ONOSService.get_service_objects().all()
    if onos_services:
        return onos_services[0].id
    return None