Added support for invokers, non-docker runtime. Added ETREE and ELAN models, admin GUI, REST API and test domain

Change-Id: Iade143ba72f967390f0782a4e46e5aa289f9ffbb
diff --git a/xos/api/service/metronetworkservice/metronetworkservice.py b/xos/api/service/metronetworkservice/metronetworkservice.py
index 368e52f..8e200ce 100644
--- a/xos/api/service/metronetworkservice/metronetworkservice.py
+++ b/xos/api/service/metronetworkservice/metronetworkservice.py
@@ -1,16 +1,16 @@
 from rest_framework.response import Response
 from rest_framework import serializers, filters, status
 from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
-from services.metronetwork.models import MetroNetworkService, NetworkEdgePort, NetworkEdgeToEdgePointConnection
+from services.metronetwork.models import *
 from django.core.exceptions import ObjectDoesNotExist
 from django.core import serializers as jsonserializer
 
-class MetroNetworkServiceSerializer(PlusModelSerializer):
+class MetroNetworkSystemSerializer(PlusModelSerializer):
         id = ReadOnlyField()
         humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
 
         class Meta:
-            model = MetroNetworkService
+            model = MetroNetworkSystem
             fields = ('humanReadableName',
                       'id',
                       'restUrl',
@@ -20,16 +20,16 @@
         def getHumanReadableName(self, obj):
             return obj.__unicode__()
 
-class MetroNetworkServiceViewSet(XOSViewSet):
-    base_name = "metronetworkservice"
-    method_name = "metronetwork"
+class MetroNetworkSystemViewSet(XOSViewSet):
+    base_name = "metronetworksystem"
+    method_name = "metronetworksystem"
     method_kind = "viewset"
-    queryset = MetroNetworkService.get_service_objects().all()
-    serializer_class = MetroNetworkServiceSerializer
+    queryset = MetroNetworkSystem.objects.all()
+    serializer_class = MetroNetworkSystemSerializer
 
     @classmethod
     def get_urlpatterns(self, api_path="^"):
-        patterns = super(MetroNetworkServiceViewSet, self).get_urlpatterns(api_path=api_path)
+        patterns = super(MetroNetworkSystemViewSet, self).get_urlpatterns(api_path=api_path)
 
         return patterns
 
@@ -64,8 +64,8 @@
         return obj.id
 
 class NetworkEdgePortViewSet(XOSViewSet):
-    base_name = "SCA_ETH_FPP_UNI_N"
-    method_name = "SCA_ETH_FPP_UNI_N"
+    base_name = "UNI"
+    method_name = "UNI"
     method_kind = "viewset"
     queryset = NetworkEdgePort.objects.all()
     serializer_class = NetworkEdgePortSerializer
@@ -105,10 +105,10 @@
         return obj.id
 
 class NetworkEdgeToEdgePointConnectionViewSet(XOSViewSet):
-    base_name = "SCA_ETH_FDFr_EC"
-    method_name = "SCA_ETH_FDFr_EC"
+    base_name = "ELINE"
+    method_name = "ELINE"
     method_kind = "viewset"
-    queryset = NetworkEdgeToEdgePointConnection.objects.all()
+    queryset = NetworkEdgeToEdgePointConnection.get_service_objects().all()
     serializer_class = NetworkEdgeToEdgePointConnectionSerializer
 
     @classmethod
@@ -183,4 +183,201 @@
         response_data['uni2']['location'] = uni1.location
         response_data['uni2']['latlng'] = uni1.latlng
 
-        return Response(response_data)
\ No newline at end of file
+        return Response(response_data)
+
+class NetworkEdgeToMultipointConnectionSerializer(PlusModelSerializer):
+    humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
+    root = NetworkEdgePortSerializer(required=True, read_only=False)
+    eps = NetworkEdgePortSerializer(required=True, read_only=False, many=True)
+
+    class Meta:
+        model = NetworkEdgeToMultipointConnection
+
+        fields = ('humanReadableName',
+                  'sid',
+                  'id',
+                  'type',
+                  'root',
+                  'eps',
+                  'operstate',
+                  'adminstate'
+                  )
+
+    def getHumanReadableName(self, obj):
+        return obj.id
+
+class NetworkEdgeToMultipointConnectionViewSet(XOSViewSet):
+    base_name = "ETREE"
+    method_name = "ETREE"
+    method_kind = "viewset"
+    queryset = NetworkEdgeToMultipointConnection.get_service_objects().all()
+    serializer_class = NetworkEdgeToMultipointConnectionSerializer
+
+    @classmethod
+    def get_urlpatterns(self, api_path="^"):
+        patterns = super(NetworkEdgeToMultipointConnectionViewSet, self).get_urlpatterns(api_path=api_path)
+
+        return patterns
+
+    def list(self, request):
+
+        object_list = self.filter_queryset(self.get_queryset())
+
+        serializer = self.get_serializer(object_list, many=True)
+
+        return Response(serializer.data)
+
+    def destroy(self, request, pk=None):
+        ETreeConnectionToDelete = NetworkEdgeToMultipointConnection.objects.get(pk=pk)
+
+        if (ETreeConnectionToDelete):
+            ETreeConnectionToDelete.adminstate = 'deactivationrequested'
+            ETreeConnectionToDelete.save()
+        else:
+            return Response(status=status.HTTP_400_BAD_REQUEST)
+
+        return Response(status=status.HTTP_200_OK)
+
+    def create(self, validated_data):
+
+        ETreeConnection = NetworkEdgeToMultipointConnection()
+        ETreeConnection.sid = validated_data.data.get('sid')
+        ETreeConnection.adminstate = validated_data.data.get('adminstate')
+        ETreeConnection.operstate = validated_data.data.get('operstate')
+        ETreeConnection.type = validated_data.data.get('type')
+
+        root_id = validated_data.data.get('root')
+        eps_list = validated_data.data.get('eps')
+
+        root = NetworkEdgePort.objects.get(pk=root_id)
+        ETreeConnection.root = root
+        ETreeConnection.save()
+
+        for ep in eps_list:
+            port = NetworkEdgePort.objects.get(pk=ep['id'])
+            ETreeConnection.eps.add(port)
+
+        response_data = {}
+        response_data['sid'] = ETreeConnection.sid
+        response_data['adminstate'] = ETreeConnection.adminstate
+        response_data['operstate'] = ETreeConnection.operstate
+        response_data['type'] = ETreeConnection.type
+
+        response_data['root'] = {}
+        response_data['root']['id'] = root.id
+        response_data['root']['pid'] = root.pid
+        response_data['root']['bwpCfgCbs'] = root.bwpCfgCbs
+        response_data['root']['bwpCfgEbs'] = root.bwpCfgEbs
+        response_data['root']['bwpCfgCir'] = root.bwpCfgCir
+        response_data['root']['bwpCfgEir'] = root.bwpCfgEir
+        response_data['root']['name'] = root.name
+        response_data['root']['location'] = root.location
+        response_data['root']['latlng'] = root.latlng
+
+        eps_data = []
+        for ep in ETreeConnection.eps.all():
+            port = {}
+            port['id'] = ep.id
+            port['pid'] = ep.pid
+            port['bwpCfgCbs'] = ep.bwpCfgCbs
+            port['bwpCfgEbs'] = ep.bwpCfgEbs
+            port['bwpCfgCir'] = ep.bwpCfgCir
+            port['bwpCfgEir'] = ep.bwpCfgEir
+            port['name'] = ep.name
+            port['location'] = ep.location
+            port['latlng'] = ep.latlng
+            eps_data.append(port)
+
+        response_data['eps'] = eps_data
+
+        return Response(response_data)
+
+class NetworkMultipointToMultipointConnectionSerializer(PlusModelSerializer):
+    humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
+    eps = NetworkEdgePortSerializer(required=True, read_only=False, many=True)
+
+    class Meta:
+        model = NetworkMultipointToMultipointConnection
+
+        fields = ('humanReadableName',
+                  'sid',
+                  'id',
+                  'type',
+                  'eps',
+                  'operstate',
+                  'adminstate'
+                  )
+
+    def getHumanReadableName(self, obj):
+        return obj.id
+
+class NetworkMultipointToMultipointConnectionViewSet(XOSViewSet):
+    base_name = "ELAN"
+    method_name = "ELAN"
+    method_kind = "viewset"
+    queryset = NetworkMultipointToMultipointConnection.get_service_objects().all()
+    serializer_class = NetworkMultipointToMultipointConnectionSerializer
+
+    @classmethod
+    def get_urlpatterns(self, api_path="^"):
+        patterns = super(NetworkMultipointToMultipointConnectionViewSet, self).get_urlpatterns(api_path=api_path)
+
+        return patterns
+
+    def list(self, request):
+
+        object_list = self.filter_queryset(self.get_queryset())
+
+        serializer = self.get_serializer(object_list, many=True)
+
+        return Response(serializer.data)
+
+    def destroy(self, request, pk=None):
+        ETreeConnectionToDelete = NetworkMultipointToMultipointConnection.objects.get(pk=pk)
+
+        if (ETreeConnectionToDelete):
+            ETreeConnectionToDelete.adminstate = 'deactivationrequested'
+            ETreeConnectionToDelete.save()
+        else:
+            return Response(status=status.HTTP_400_BAD_REQUEST)
+
+        return Response(status=status.HTTP_200_OK)
+
+    def create(self, validated_data):
+
+        ELanConnection = NetworkMultipointToMultipointConnection()
+        ELanConnection.sid = validated_data.data.get('sid')
+        ELanConnection.adminstate = validated_data.data.get('adminstate')
+        ELanConnection.operstate = validated_data.data.get('operstate')
+        ELanConnection.type = validated_data.data.get('type')
+
+        eps_list = validated_data.data.get('eps')
+        ELanConnection.save()
+
+        for ep in eps_list:
+            port = NetworkEdgePort.objects.get(pk=ep['id'])
+            ELanConnection.eps.add(port)
+
+        response_data = {}
+        response_data['sid'] = ELanConnection.sid
+        response_data['adminstate'] = ELanConnection.adminstate
+        response_data['operstate'] = ELanConnection.operstate
+        response_data['type'] = ELanConnection.type
+
+        eps_data = []
+        for ep in ELanConnection.eps.all():
+            port = {}
+            port['id'] = ep.id
+            port['pid'] = ep.pid
+            port['bwpCfgCbs'] = ep.bwpCfgCbs
+            port['bwpCfgEbs'] = ep.bwpCfgEbs
+            port['bwpCfgCir'] = ep.bwpCfgCir
+            port['bwpCfgEir'] = ep.bwpCfgEir
+            port['name'] = ep.name
+            port['location'] = ep.location
+            port['latlng'] = ep.latlng
+            eps_data.append(port)
+
+        response_data['eps'] = eps_data
+
+        return Response(response_data)