summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhewei-cmss <hewei@cmss.chinamobile.com>2020-01-20 12:27:37 +0800
committerhewei-cmss <hewei@cmss.chinamobile.com>2020-01-20 12:27:37 +0800
commitc7a15bcb4b56f18a55f33a349382355aa3969926 (patch)
tree91415b6eebf29fb2c0d85db75ac38569e57e5178
parente4b163d626bf5526ca4cc38d9a151f4bd87cc1b8 (diff)
Modify get flavors
Issue-ID: VFC-1599 Signed-off-by: hewei-cmss <hewei@cmss.chinamobile.com> Change-Id: I71f1e5a2316053c60b02075f8fce1fa8acccf7f3
-rw-r--r--res/res/biz/flavors_get.py51
-rw-r--r--res/res/resources/urls.py3
-rw-r--r--res/res/resources/views/get_flavors_view.py34
-rw-r--r--res/res/resources/views/views.py36
4 files changed, 87 insertions, 37 deletions
diff --git a/res/res/biz/flavors_get.py b/res/res/biz/flavors_get.py
new file mode 100644
index 0000000..5ae41e2
--- /dev/null
+++ b/res/res/biz/flavors_get.py
@@ -0,0 +1,51 @@
+# Copyright @ 2020 China Mobile (SuZhou) Software Technology Co.,Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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 logging
+
+from res.biz.base import BaseService
+from res.pub.database.models import FlavourInstModel
+from res.resources.serializers import FlavorInfoSerializer
+
+logger = logging.getLogger(__name__)
+
+
+class GetFlavorsService(BaseService):
+
+ def __init__(self):
+ super(GetFlavorsService, self).__init__()
+
+ def get_flavors(self, vnf_instance_id):
+ return self.query_resources(
+ res_type="Flavors",
+ logger=logger,
+ resources=FlavourInstModel.objects.filter(
+ instid=vnf_instance_id),
+ cvt_fun=self.fill_flavours_data,
+ res_serializer=FlavorInfoSerializer
+ )
+
+ def fill_flavours_data(self, flavor):
+ flavours_data = {
+ "flavourid": flavor.flavourid,
+ "name": flavor.name,
+ "vcpu": flavor.vcpu,
+ "memory": flavor.memory,
+ "extraspecs": flavor.extraspecs,
+ "instid": flavor.instid,
+ "tenant": flavor.tenant,
+ "vimid": flavor.vimid,
+ "resouceid": flavor.resouceid,
+ "create_time": flavor.create_time
+ }
+ return flavours_data
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py
index dff2d94..2088caf 100644
--- a/res/res/resources/urls.py
+++ b/res/res/resources/urls.py
@@ -14,6 +14,7 @@
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
@@ -24,7 +25,7 @@ urlpatterns = [
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'),
diff --git a/res/res/resources/views/get_flavors_view.py b/res/res/resources/views/get_flavors_view.py
new file mode 100644
index 0000000..583ea04
--- /dev/null
+++ b/res/res/resources/views/get_flavors_view.py
@@ -0,0 +1,34 @@
+# Copyright @ 2020 China Mobile (SuZhou) Software Technology Co.,Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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 logging
+
+from rest_framework import status
+from rest_framework.views import APIView
+from drf_yasg.utils import swagger_auto_schema
+from res.resources.serializers import FlavorInfoSerializer
+from res.resources.views.base_view import view_safe_call_with_log
+from res.biz.flavors_get import GetFlavorsService
+logger = logging.getLogger(__name__)
+
+
+class GetFlavorsView(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: FlavorInfoSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'
+ }
+ )
+ @view_safe_call_with_log(logger=logger)
+ def get(self, request, vnf_instance_id):
+ return GetFlavorsService().get_flavors(vnf_instance_id)
diff --git a/res/res/resources/views/views.py b/res/res/resources/views/views.py
index c863f7d..cb5e6b5 100644
--- a/res/res/resources/views/views.py
+++ b/res/res/resources/views/views.py
@@ -22,14 +22,12 @@ from rest_framework.views import APIView
from res.pub.exceptions import VNFRESException
from res.pub.database.models import StorageInstModel
from res.pub.database.models import NetworkInstModel
-from res.pub.database.models import FlavourInstModel
from res.pub.database.models import SubNetworkInstModel
from res.pub.database.models import CPInstModel
from res.resources.serializers import VolumeInfoSerializer
from res.resources.serializers import CpsInfoSerializer
from res.resources.serializers import SubnetInfoSerializer
from res.resources.serializers import NetworkInfoSerializer
-from res.resources.serializers import FlavorInfoSerializer
from res.resources.views.base_view import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -52,40 +50,6 @@ def query_resources(res_type, logger, resources, cvt_fun, res_serializer):
)
-class getFlavors(APIView):
- @swagger_auto_schema(
- responses={
- status.HTTP_200_OK: FlavorInfoSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'
- }
- )
- @view_safe_call_with_log(logger=logger)
- def get(self, request, vnfInstanceId):
- return query_resources(
- res_type="Flavors",
- logger=logger,
- resources=FlavourInstModel.objects.filter(instid=vnfInstanceId),
- cvt_fun=fill_flavours_data,
- res_serializer=FlavorInfoSerializer
- )
-
-
-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,
- "vimid": f.vimid,
- "resouceid": f.resouceid,
- "create_time": f.create_time
- }
- return flavours_data
-
-
class getNetworks(APIView):
@swagger_auto_schema(
responses={