--- /dev/null
+# Copyright @ 2020 China Mobile (SuZhou) Software Technology Co.,Ltd.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+import logging\r
+\r
+from res.biz.base import BaseService\r
+from res.pub.database.models import FlavourInstModel\r
+from res.resources.serializers import FlavorInfoSerializer\r
+\r
+logger = logging.getLogger(__name__)\r
+\r
+\r
+class GetFlavorsService(BaseService):\r
+\r
+ def __init__(self):\r
+ super(GetFlavorsService, self).__init__()\r
+\r
+ def get_flavors(self, vnf_instance_id):\r
+ return self.query_resources(\r
+ res_type="Flavors",\r
+ logger=logger,\r
+ resources=FlavourInstModel.objects.filter(\r
+ instid=vnf_instance_id),\r
+ cvt_fun=self.fill_flavours_data,\r
+ res_serializer=FlavorInfoSerializer\r
+ )\r
+\r
+ def fill_flavours_data(self, flavor):\r
+ flavours_data = {\r
+ "flavourid": flavor.flavourid,\r
+ "name": flavor.name,\r
+ "vcpu": flavor.vcpu,\r
+ "memory": flavor.memory,\r
+ "extraspecs": flavor.extraspecs,\r
+ "instid": flavor.instid,\r
+ "tenant": flavor.tenant,\r
+ "vimid": flavor.vimid,\r
+ "resouceid": flavor.resouceid,\r
+ "create_time": flavor.create_time\r
+ }\r
+ return flavours_data\r
from django.conf.urls import url
+from res.resources.views.get_flavors_view import GetFlavorsView
from res.resources.views.get_vnfs_view import GetVnfView
from res.resources.views.get_vnfs_view import GetVnfsView
from res.resources.views.get_vms_view import GetVmsView
url(r'^api/vnfres/v1/vnfs/(?P<vnf_instance_id>[0-9a-zA-Z\-\_]+)$', GetVnfView.as_view(), name='get_vnf'),
url(r'^api/vnfres/v1/vnfs$', GetVnfsView.as_view(), name='get_vnfs'),
url(r'^api/vnfres/v1/(?P<vnf_instance_id>[0-9a-zA-Z\-\_]+)/vms$', GetVmsView.as_view(), name='get_vms'),
- url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/flavors$', views.getFlavors.as_view(), name='get_flavors'),
+ url(r'^api/vnfres/v1/(?P<vnf_instance_id>[0-9a-zA-Z\-\_]+)/flavors$', GetFlavorsView.as_view(), name='get_flavors'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/networks$', views.getNetworks.as_view(), name='get_networks'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/subnets$', views.getSubnets.as_view(), name='get_subnets'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/cps$', views.getCps.as_view(), name='get_cps'),
--- /dev/null
+# Copyright @ 2020 China Mobile (SuZhou) Software Technology Co.,Ltd.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+import logging\r
+\r
+from rest_framework import status\r
+from rest_framework.views import APIView\r
+from drf_yasg.utils import swagger_auto_schema\r
+from res.resources.serializers import FlavorInfoSerializer\r
+from res.resources.views.base_view import view_safe_call_with_log\r
+from res.biz.flavors_get import GetFlavorsService\r
+logger = logging.getLogger(__name__)\r
+\r
+\r
+class GetFlavorsView(APIView):\r
+ @swagger_auto_schema(\r
+ responses={\r
+ status.HTTP_200_OK: FlavorInfoSerializer(),\r
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'\r
+ }\r
+ )\r
+ @view_safe_call_with_log(logger=logger)\r
+ def get(self, request, vnf_instance_id):\r
+ return GetFlavorsService().get_flavors(vnf_instance_id)\r
from res.pub.exceptions import VNFRESException\r
from res.pub.database.models import StorageInstModel\r
from res.pub.database.models import NetworkInstModel\r
-from res.pub.database.models import FlavourInstModel\r
from res.pub.database.models import SubNetworkInstModel\r
from res.pub.database.models import CPInstModel\r
from res.resources.serializers import VolumeInfoSerializer\r
from res.resources.serializers import CpsInfoSerializer\r
from res.resources.serializers import SubnetInfoSerializer\r
from res.resources.serializers import NetworkInfoSerializer\r
-from res.resources.serializers import FlavorInfoSerializer\r
from res.resources.views.base_view import view_safe_call_with_log\r
\r
logger = logging.getLogger(__name__)\r
)\r
\r
\r
-class getFlavors(APIView):\r
- @swagger_auto_schema(\r
- responses={\r
- status.HTTP_200_OK: FlavorInfoSerializer(),\r
- status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'\r
- }\r
- )\r
- @view_safe_call_with_log(logger=logger)\r
- def get(self, request, vnfInstanceId):\r
- return query_resources(\r
- res_type="Flavors",\r
- logger=logger,\r
- resources=FlavourInstModel.objects.filter(instid=vnfInstanceId),\r
- cvt_fun=fill_flavours_data,\r
- res_serializer=FlavorInfoSerializer\r
- )\r
-\r
-\r
-def fill_flavours_data(f):\r
- flavours_data = {\r
- "flavourid": f.flavourid,\r
- "name": f.name,\r
- "vcpu": f.vcpu,\r
- "memory": f.memory,\r
- "extraspecs": f.extraspecs,\r
- "instid": f.instid,\r
- "tenant": f.tenant,\r
- "vimid": f.vimid,\r
- "resouceid": f.resouceid,\r
- "create_time": f.create_time\r
- }\r
- return flavours_data\r
-\r
-\r
class getNetworks(APIView):\r
@swagger_auto_schema(\r
responses={\r