Add code and test case of gvnfmres
authorying.yunlong <ying.yunlong@zte.com.cn>
Thu, 23 Feb 2017 11:58:01 +0000 (19:58 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Thu, 23 Feb 2017 11:58:01 +0000 (19:58 +0800)
Change-Id: Id9545f8765b0ebd2d815b9d02a2e6c82904a98ad
Issue-Id: GVNFM-34
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
res/res/pub/database/models.py
res/res/resources/swagger.json [new file with mode: 0644]
res/res/resources/tests.py
res/res/resources/urls.py
res/res/resources/views.py

index 0ec1b2e..919ee6b 100644 (file)
@@ -259,6 +259,24 @@ class VimUserModel(models.Model):
         return '%s' % self.username
 
 
+class FlavourInstModel(models.Model):
+    class Meta:
+        db_table = 'FLAVOURINST'
+
+    flavourid = models.CharField(db_column='FLAVOURID', max_length=255, primary_key=True)
+    name = models.CharField(db_column='NAME', max_length=255)
+    vcpu = models.CharField(db_column='VCPU', max_length=255)
+    memory = models.CharField(db_column='MEMORY', max_length=255)
+    extraspecs = models.CharField(db_column='EXTRASPECS', max_length=255)
+    instid = models.CharField(db_column='INSTID', max_length=255)
+    tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
+    vmid = models.CharField(db_column='VMID', max_length=255)
+    create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
+
+    def __unicode__(self):
+        return '%s' % self.name
+
+
 
 
 
diff --git a/res/res/resources/swagger.json b/res/res/resources/swagger.json
new file mode 100644 (file)
index 0000000..86da1b4
--- /dev/null
@@ -0,0 +1,331 @@
+{
+  "swagger": "2.0",
+  "info": {
+    "version": "1.0.0",
+    "title": "ZTE vManager Service rest API"
+  },
+  "host": "10.43.104.27:8000",
+  "basePath": "/openoapi/vnfres/v1",
+  "tags": [
+    {
+      "name": "res Resource"
+    }
+  ],
+  "paths": {
+    "/vnfs/{vnfInstanceId}": {
+      "get": {
+        "tags": [
+          "vnf Resource"
+        ],
+        "summary": "query the specified vnf info",
+        "description": "",
+        "operationId": "query_vnf",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "vnfInstanceId",
+            "in": "path",
+            "description": "vnf instance id",
+            "required": true,
+            "type": "string"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/VNFInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    },
+    "/vnfs": {
+      "get": {
+        "tags": [
+          "vnfs Resource"
+        ],
+        "summary": "query the specified vnfs info",
+        "description": "",
+        "operationId": "query_vnfs",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "body",
+            "in": "body",
+            "description": "request param",
+            "required": true,
+            "schema": {
+              "$ref": "#/definitions/SfcPostRequest"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/VNFSInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    },
+    "/{instid}/vms": {
+      "get": {
+        "tags": [
+          "vms Resource"
+        ],
+        "summary": "query the specified vm info",
+        "description": "",
+        "operationId": "query_vms",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "instid",
+            "in": "path",
+            "description": "vnf instance id",
+            "required": true,
+            "type": "string"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/VMInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    },
+    "/{instid}/flavors": {
+      "get": {
+        "tags": [
+          "flavors Resource"
+        ],
+        "summary": "query the specified flavor info",
+        "description": "",
+        "operationId": "query_flavors",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "instid",
+            "in": "path",
+            "description": "vnf instance id",
+            "required": true,
+            "type": "string"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/FlavorInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    },
+    "/{instid}/networks": {
+      "get": {
+        "tags": [
+          "networks Resource"
+        ],
+        "summary": "query the specified network info",
+        "description": "",
+        "operationId": "query_networks",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "instid",
+            "in": "path",
+            "description": "vnf instance id",
+            "required": true,
+            "type": "string"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/NetworkInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    },
+    "/{instid}/subnets": {
+      "get": {
+        "tags": [
+          "subnets Resource"
+        ],
+        "summary": "query the specified subnet info",
+        "description": "",
+        "operationId": "query_subnet",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "instid",
+            "in": "path",
+            "description": "vnf instance id",
+            "required": true,
+            "type": "string"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/SubnetInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    },
+    "/{ownerid}/cps": {
+      "get": {
+        "tags": [
+          "sps Resource"
+        ],
+        "summary": "query the specified cp info",
+        "description": "",
+        "operationId": "query_cp",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "ownerid",
+            "in": "path",
+            "description": "vnf instance id",
+            "required": true,
+            "type": "string"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/CpInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    },
+    "/{instid}/volumes": {
+      "get": {
+        "tags": [
+          "sps Resource"
+        ],
+        "summary": "query the specified volumes info",
+        "description": "",
+        "operationId": "query_volumes",
+        "consumes": [
+          "application/json"
+        ],
+        "produces": [
+          "application/json"
+        ],
+        "parameters": [
+          {
+            "name": "instid",
+            "in": "path",
+            "description": "vnf instance id",
+            "required": true,
+            "type": "string"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "successful operation",
+            "schema": {
+              "$ref": "#/definitions/VolumesInfo"
+            }
+          },
+          "404": {
+            "description": "the vnf instance id is wrong"
+          },
+          "500": {
+            "description": "the url is invalid"
+          }
+        }
+      }
+    }
+
+  }
+}
\ No newline at end of file
index 4ca694a..689ceff 100644 (file)
 from django.test import TestCase, Client
 from rest_framework import status
 
-from res.pub.database.models import NfInstModel, StorageInstModel
+from res.pub.database.models import NfInstModel, StorageInstModel, VmInstModel, FlavourInstModel, NetworkInstModel, \
+    SubNetworkInstModel, CPInstModel
 
 
 class ResourceTest(TestCase):
     def setUp(self):
         self.client = Client()
+        self.nf_inst_id = "01"
         NfInstModel.objects.all().delete()
         self.test_data = {
             "vnfInstanceId": u'1',
@@ -46,7 +48,7 @@ class ResourceTest(TestCase):
                 "virtualLinkResourceInfo": [],
                 "virtualStorageResourceInfo": [
                     {
-                        "virtualStorageInstanceId": "s01",
+                        "virtualStorageInstanceId": "s02",
                         "virtualStorageDescId": "desc01",
                         "storageResource": {
                             "vimId": "vim01",
@@ -59,6 +61,82 @@ class ResourceTest(TestCase):
             "metadata": None,
             "extensions": None
         }
+        self.vms_data = {
+            "resp_data": [{
+                "vmid": u"vm0",
+                "vimid": u"vim0",
+                "resouceid": u"res0",
+                "insttype": 0,
+                "instid": u"01",
+                "vmname": u"v1",
+                "operationalstate": None,
+                "zoneid": None,
+                "tenant": None,
+                "hostid": None,
+                "detailinfo": None,
+                "is_predefined": 0
+            }]
+        }
+        self.flavors_data = {
+            "resp_data": [{
+                "flavourid": "fla0",
+                "name": "fname0",
+                "vcpu": "cpu0",
+                "memory": "mem0",
+                "extraspecs": "ext0",
+                "instid": "01",
+                "tenant": None,
+                "vmid": "vm0",
+                "create_time": None
+            }]
+        }
+        self.networks_data = {
+            "resp_data": [{
+                "networkid": "net0",
+                "vimid": "vim0",
+                "resouceid": "res0",
+                "insttype": 0,
+                "instid": "01",
+                "name": "net_name0"
+                # "tenant": None
+            }]
+        }
+        self.subnets_data = {
+            "resp_data": [{
+                "subnetworkid": "sub0",
+                "vimid": "vim0",
+                "resouceid": "res0",
+                "networkid": "net0",
+                "insttype": 0,
+                "instid": "01",
+                "name": "sub_name0",
+                "cidr": "cidr0"
+            }]
+        }
+        self.cps_data = {
+            "resp_data": [{
+                "cpinstanceid": "cp0",
+                "cpdid": "cpd0",
+                "cpinstancename": "cpinstname0",
+                "vlinstanceid": "vlinst0",
+                "ownertype": 0,
+                "ownerid": "01",
+                "relatedtype": 0
+            }]
+        }
+
+        self.volumes_data = {
+            "resp_data": [{
+                "storageid": "st0",
+                "vimid": "vim0",
+                "resouceid": "res0",
+                "insttype": 0,
+                "instid": "01",
+                "storagetype": "stype0",
+                "size": "0",
+                "disktype": "disk0"
+            }]
+        }
 
     def tearDown(self):
         pass
@@ -66,7 +144,7 @@ class ResourceTest(TestCase):
     def test_get_vnf(self):
         vnf_inst_id = "1"
         NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
-        StorageInstModel(storageid='s01', vimid='vim01', resouceid='resource01', insttype=1,\
+        StorageInstModel(storageid='s02', vimid='vim01', resouceid='resource01', insttype=1,\
                          instid=vnf_inst_id, storageDesc='desc01').save()
         response = self.client.get("/openoapi/vnfres/v1/vnfs/%s" % vnf_inst_id)
         self.assertEqual(self.test_data, response.data)
@@ -78,4 +156,55 @@ class ResourceTest(TestCase):
             StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, resouceid='resource0%s' % i, insttype=1, instid='%s' % i, storageDesc='desc%s' % i).save()
         response = self.client.get("/openoapi/vnfres/v1/vnfs")
         # self.assertEqual(self.test_data, response.data)
-        self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
\ No newline at end of file
+        self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+    def test_get_vms(self):
+        NfInstModel(nfinstid='%s' % '01', nf_name='VFS%s' % '01').save()
+        nfInst = NfInstModel.objects.get(pk='01')
+        for i in range(1):
+            VmInstModel(vmid='vm%s' % i, vimid='vim%s' % i, resouceid='res%s' % i, instid='%s' % nfInst.nfinstid, insttype=0, vmname='v1').save()
+        response = self.client.get("/openoapi/vnfres/v1/%s/vms" % nfInst.nfinstid)
+        self.assertEqual(self.vms_data, response.data)
+        # self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+    def test_get_flavors(self):
+        NfInstModel(nfinstid='%s' % '01', nf_name='VFS%s' % '01').save()
+        nfInst = NfInstModel.objects.get(pk='01')
+        for i in range(1):
+            FlavourInstModel(flavourid='fla%s' % i, name='fname%s' % i, vcpu='cpu%s' % i, instid='%s' % nfInst.nfinstid, memory='mem%s' % i, extraspecs='ext%s' % i, vmid='vm%s' % i).save()
+        response = self.client.get("/openoapi/vnfres/v1/%s/flavors" % nfInst.nfinstid)
+        self.assertEqual(self.flavors_data, response.data)
+        # self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+    def test_get_networks(self):
+        for i in range(1):
+            NetworkInstModel(networkid='net%s' % i, name='net_name%s' % i, vimid='vim%s' % i, instid='%s' % self.nf_inst_id,
+                             resouceid='res%s' % i, insttype='%d' % i).save()
+        response = self.client.get("/openoapi/vnfres/v1/%s/networks" % self.nf_inst_id)
+        self.assertEqual(self.networks_data, response.data)
+        # self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+    def test_get_subnets(self):
+        for i in range(1):
+            SubNetworkInstModel(subnetworkid="sub%s" % i, vimid='vim%s' % i, resouceid='res%s' % i, networkid='net%s' % i, insttype='%d' % i, instid='%s' % self.nf_inst_id, name='sub_name%s' % i, cidr="cidr%s" % i).save()
+        response = self.client.get("/openoapi/vnfres/v1/%s/subnets" % self.nf_inst_id)
+        self.assertEqual(self.subnets_data, response.data)
+        # self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+    def test_get_cps(self):
+        for i in range(1):
+            CPInstModel(cpinstanceid="cp%s" % i, cpdid='cpd%s' % i, cpinstancename='cpinstname%s' % i, vlinstanceid='vlinst%s' % i, ownertype='%d' % i, ownerid='%s' % self.nf_inst_id, relatedtype='%d' % i).save()
+        response = self.client.get("/openoapi/vnfres/v1/%s/cps" % self.nf_inst_id)
+        self.assertEqual(self.cps_data, response.data)
+        # self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+    def test_get_volumes(self):
+        for i in range(1):
+            StorageInstModel(storageid="st%s" % i, vimid='vim%s' % i, resouceid='res%s' % i, insttype='%d' % i, instid='%s' % self.nf_inst_id, storagetype='stype%s' % i, size='%s' % i, disktype='disk%s' % i).save()
+        response = self.client.get("/openoapi/vnfres/v1/%s/volumes" % self.nf_inst_id)
+        self.assertEqual(self.volumes_data, response.data)
+        # self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+    def test_swagger_ok(self):
+        resp = self.client.get("/openoapi/vnfres/v1/resources/swagger.json", format='json')
+        self.assertEqual(resp.status_code, status.HTTP_200_OK)
\ No newline at end of file
index 09fb95d..d7447d0 100644 (file)
@@ -16,10 +16,18 @@ from django.conf.urls import url
 from rest_framework.urlpatterns import format_suffix_patterns
 
 from res.resources import views
+from res.resources.views import SwaggerJsonView
 
 urlpatterns = [
     url(r'^openoapi/vnfres/v1/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$', views.get_vnf, name='get_vnf'),
     url(r'^openoapi/vnfres/v1/vnfs$', views.get_vnfs, name='get_vnfs'),
+    url(r'^'+'openoapi/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/vms$', views.get_vms, name='get_vms'),
+    url(r'^'+'openoapi/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/flavors$', views.get_flavors, name='get_flavors'),
+    url(r'^'+'openoapi/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/networks$', views.get_networks, name='get_networks'),
+    url(r'^'+'openoapi/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/subnets$', views.get_subnets, name='get_subnets'),
+    url(r'^'+'openoapi/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/cps$', views.get_cps, name='get_cps'),
+    url(r'^'+'openoapi/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/volumes$', views.get_volumes, name='get_volumes'),
+    url(r'^openoapi/vnfres/v1/resources/swagger.json$', SwaggerJsonView.as_view()),
 ]
 
 urlpatterns = format_suffix_patterns(urlpatterns)
index 81c4e4a..fa639a6 100644 (file)
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+import json
 import logging
+import os
 import traceback
 
 from rest_framework import status
 from rest_framework.decorators import api_view
 from rest_framework.response import Response
+from rest_framework.views import APIView
 
 from res.pub.exceptions import VNFRESException
 from res.pub.utils.values import ignore_case_get
 from res.pub.utils.syscomm import fun_name
-from res.pub.database.models import NfInstModel, CPInstModel, StorageInstModel, NetworkInstModel, VLInstModel, \
-    VNFCInstModel, VmInstModel, VimModel, VimUserModel
+from res.pub.database.models import NfInstModel, StorageInstModel, NetworkInstModel, VLInstModel, \
+    VNFCInstModel, VmInstModel, VimModel, VimUserModel, FlavourInstModel, SubNetworkInstModel, CPInstModel
 
 logger = logging.getLogger(__name__)
 
@@ -161,11 +164,223 @@ def get_vnfs(request):
         vnf_insts = NfInstModel.objects.all()
         if not vnf_insts:
             return Response(data={'error': 'Vnfs does not exist'}, status=status.HTTP_404_NOT_FOUND)
-        # FIXME: fill resp_datas
+        # FIXME: fill resp_data
         arr = []
         for vnf_inst in vnf_insts:
             arr.append(fill_resp_data(vnf_inst))
         return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
     except:
         logger.error(traceback.format_exc())
-        return Response(data={'error': 'Failed to get Vnfs'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
\ No newline at end of file
+        return Response(data={'error': 'Failed to get Vnfs'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+@api_view(http_method_names=['GET'])
+def get_vms(request, *args, **kwargs):
+    logger.debug("Query all the vms by vnfInstanceId[%s]", fun_name())
+    try:
+        vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
+        vms = VmInstModel.objects.filter(instid=vnf_inst_id)
+        if not vms:
+            return Response(data={'error': 'Vms does not exist'}, status=status.HTTP_404_NOT_FOUND)
+        # FIXME: fill resp_data
+        arr = []
+        for vm in vms:
+            arr.append(fill_vms_data(vm))
+        return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
+    except:
+        logger.error(traceback.format_exc())
+        return Response(data={'error': 'Failed to get Vms'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def fill_vms_data(vm):
+    vms_data = {
+        "vmid": vm.vmid,
+        "vimid": vm.vimid,
+        "resouceid": vm.resouceid,
+        "insttype": vm.insttype,
+        "instid": vm.instid,
+        "vmname": vm.vmname,
+        "operationalstate": vm.operationalstate,
+        "zoneid": vm.zoneid,
+        "tenant": vm.tenant,
+        "hostid": vm.hostid,
+        "detailinfo": vm.detailinfo,
+        "is_predefined": vm.is_predefined
+    }
+    return vms_data
+
+
+@api_view(http_method_names=['GET'])
+def get_flavors(request, *args, **kwargs):
+    logger.debug("Query all the flavors by vnfInstanceId[%s]", fun_name())
+    try:
+        vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
+        flavours = FlavourInstModel.objects.filter(instid=vnf_inst_id)
+        if not flavours:
+            return Response(data={'error': 'Flavours does not exist'}, status=status.HTTP_404_NOT_FOUND)
+        # FIXME: fill resp_data
+        arr = []
+        for flavour in flavours:
+            arr.append(fill_flavours_data(flavour))
+        return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
+    except:
+        logger.error(traceback.format_exc())
+        return Response(data={'error': 'Failed to get flavours'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def fill_flavours_data(f):
+    flavours_data = {
+        "flavourid": f.flavourid,
+        "name": f.name,
+        "vcpu": f.vcpu,
+        "memory": f.memory,
+        "extraspecs": f.extraspecs,
+        "instid": f.instid,
+        "tenant": f.tenant,
+        "vmid": f.vmid,
+        "create_time": f.create_time
+    }
+    return flavours_data
+
+@api_view(http_method_names=['GET'])
+def get_networks(request, *args, **kwargs):
+    logger.debug("Query all the networks by vnfInstanceId[%s]", fun_name())
+    try:
+        vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
+        networks = NetworkInstModel.objects.filter(instid=vnf_inst_id)
+        if not networks:
+            return Response(data={'error': 'Networks does not exist'}, status=status.HTTP_404_NOT_FOUND)
+        # FIXME: fill resp_data
+        arr = []
+        for network in networks:
+            arr.append(fill_networks_data(network))
+        return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
+    except:
+        logger.error(traceback.format_exc())
+        return Response(data={'error': 'Failed to get networks'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def fill_networks_data(network):
+    networks_data = {
+        "networkid": network.networkid,
+        "vimid": network.vimid,
+        "resouceid": network.resouceid,
+        "insttype": network.insttype,
+        "instid": network.instid,
+        "name": network.name
+        # "tenant": network.tenant,
+        # "is_shared": network.is_shared,
+        # "is_predefined": network.is_predefined,
+        # "desc": network.desc,
+        # "vendor": network.vendor,
+        # "bandwidth": network.bandwidth,
+        # "mtu": network.mtu,
+        # "network_type": network.network_type,
+        # "segmentid": network.segmentid,
+        # "vlantrans": network.vlantrans,
+        # "networkqos": network.networkqos
+    }
+    return networks_data
+
+
+@api_view(http_method_names=['GET'])
+def get_subnets(request, *args, **kwargs):
+    logger.debug("Query all the subnets by vnfInstanceId[%s]", fun_name())
+    try:
+        vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
+        subnets = SubNetworkInstModel.objects.filter(instid=vnf_inst_id)
+        if not subnets:
+            return Response(data={'error': 'Subnets does not exist'}, status=status.HTTP_404_NOT_FOUND)
+        # FIXME: fill resp_data
+        arr = []
+        for subnet in subnets:
+            arr.append(fill_subnets_data(subnet))
+        return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
+    except:
+        logger.error(traceback.format_exc())
+        return Response(data={'error': 'Failed to get subnets'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def fill_subnets_data(subnet):
+    subnets_data = {
+        "subnetworkid": subnet.subnetworkid,
+        "vimid": subnet.vimid,
+        "resouceid": subnet.resouceid,
+        "networkid": subnet.networkid,
+        "insttype": subnet.insttype,
+        "instid": subnet.instid,
+        "name": subnet.name,
+        "cidr": subnet.cidr
+    }
+    return subnets_data
+
+
+@api_view(http_method_names=['GET'])
+def get_cps(request, *args, **kwargs):
+    logger.debug("Query all the cps by vnfInstanceId[%s]", fun_name())
+    try:
+        vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
+        cps = CPInstModel.objects.filter(ownerid=vnf_inst_id)
+        if not cps:
+            return Response(data={'error': 'Cps does not exist'}, status=status.HTTP_404_NOT_FOUND)
+        # FIXME: fill resp_data
+        arr = []
+        for cp in cps:
+            arr.append(fill_cps_data(cp))
+        return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
+    except:
+        logger.error(traceback.format_exc())
+        return Response(data={'error': 'Failed to get cps'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def fill_cps_data(cp):
+    cps_data = {
+        "cpinstanceid": cp.cpinstanceid,
+        "cpdid": cp.cpdid,
+        "cpinstancename": cp.cpinstancename,
+        "vlinstanceid": cp.vlinstanceid,
+        "ownertype": cp.ownertype,
+        "ownerid": cp.ownerid,
+        "relatedtype": cp.relatedtype
+    }
+    return cps_data
+
+@api_view(http_method_names=['GET'])
+def get_volumes(request, *args, **kwargs):
+    logger.debug("Query all the volumes by vnfInstanceId[%s]", fun_name())
+    try:
+        vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
+        volumes = StorageInstModel.objects.filter(instid=vnf_inst_id)
+        if not volumes:
+            return Response(data={'error': 'Volumes does not exist'}, status=status.HTTP_404_NOT_FOUND)
+        # FIXME: fill resp_data
+        arr = []
+        for v in volumes:
+            arr.append(fill_volumes_data(v))
+        return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
+    except:
+        logger.error(traceback.format_exc())
+        return Response(data={'error': 'Failed to get volumes'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
+def fill_volumes_data(v):
+    volumes_data = {
+        "storageid": v.storageid,
+        "vimid": v.vimid,
+        "resouceid": v.resouceid,
+        "insttype": v.insttype,
+        "instid": v.instid,
+        "storagetype": v.storagetype,
+        "size": v.size,
+        "disktype": v.disktype
+    }
+    return volumes_data
+
+
+class SwaggerJsonView(APIView):
+    def get(self, request):
+        json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
+        f = open(json_file)
+        json_data = json.JSONDecoder().decode(f.read())
+        f.close()
+        return Response(json_data)
\ No newline at end of file