summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhewei-cmss <hewei@cmss.chinamobile.com>2020-01-14 19:04:39 +0800
committerwei he <hewei@cmss.chinamobile.com>2020-01-15 01:01:29 +0000
commite4b163d626bf5526ca4cc38d9a151f4bd87cc1b8 (patch)
tree83e0f6b3112628d8bb384eea8107e2b0a2a95f6c
parenta8193cb44bd1c1649f93589f905f583ef4811102 (diff)
Modify get vms
Issue-ID: VFC-1599 Signed-off-by: hewei-cmss <hewei@cmss.chinamobile.com> Change-Id: I4f9f20b8dfc85e49e319a9c27c254bf706e8b9fd
-rw-r--r--res/res/biz/vms_get.py56
-rw-r--r--res/res/resources/urls.py3
-rw-r--r--res/res/resources/views/get_vms_view.py34
-rw-r--r--res/res/resources/views/views.py42
4 files changed, 92 insertions, 43 deletions
diff --git a/res/res/biz/vms_get.py b/res/res/biz/vms_get.py
new file mode 100644
index 0000000..091a278
--- /dev/null
+++ b/res/res/biz/vms_get.py
@@ -0,0 +1,56 @@
+# 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 VmInstModel
+from res.resources.serializers import VmInfoSerializer
+
+logger = logging.getLogger(__name__)
+
+
+class GetVmsService(BaseService):
+
+ def __init__(self):
+ super(GetVmsService, self).__init__()
+
+ def get_vms(self, vnf_instance_id):
+ return self.query_resources(
+ res_type="Vms",
+ logger=logger,
+ resources=VmInstModel.objects.filter(instid=vnf_instance_id),
+ cvt_fun=self.fill_vms_data,
+ res_serializer=VmInfoSerializer
+ )
+
+ def fill_vms_data(self, vm):
+ vms_data = {
+ "vmid": vm.vmid,
+ "vimid": vm.vimid,
+ "resouceid": vm.resouceid,
+ "insttype": vm.insttype,
+ "instid": vm.instid,
+ "vmname": vm.vmname,
+ "operationalstate": vm.operationalstate,
+ "tenant": vm.tenant,
+ "is_predefined": vm.is_predefined,
+ "security_groups": vm.security_groups,
+ "flavor_id": vm.flavor_id,
+ "availability_zone": vm.availability_zone,
+ "server_group": vm.server_group,
+ "volume_array": vm.volume_array,
+ "metadata": vm.metadata,
+ "nic_array": vm.nic_array
+ }
+ return vms_data
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py
index f0906d4..dff2d94 100644
--- a/res/res/resources/urls.py
+++ b/res/res/resources/urls.py
@@ -16,13 +16,14 @@ from django.conf.urls import url
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
from res.resources.views import views
from res.resources.health_check_views import HealthCheckView
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<vnfInstanceId>[0-9a-zA-Z\-\_]+)/vms$', views.getVms.as_view(), name='get_vms'),
+ 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<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'),
diff --git a/res/res/resources/views/get_vms_view.py b/res/res/resources/views/get_vms_view.py
new file mode 100644
index 0000000..a58334a
--- /dev/null
+++ b/res/res/resources/views/get_vms_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 VmInfoSerializer
+from res.resources.views.base_view import view_safe_call_with_log
+from res.biz.vms_get import GetVmsService
+logger = logging.getLogger(__name__)
+
+
+class GetVmsView(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: VmInfoSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'
+ }
+ )
+ @view_safe_call_with_log(logger=logger)
+ def get(self, request, vnf_instance_id):
+ return GetVmsService().get_vms(vnf_instance_id)
diff --git a/res/res/resources/views/views.py b/res/res/resources/views/views.py
index a0a5897..c863f7d 100644
--- a/res/res/resources/views/views.py
+++ b/res/res/resources/views/views.py
@@ -22,7 +22,6 @@ 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 VmInstModel
from res.pub.database.models import FlavourInstModel
from res.pub.database.models import SubNetworkInstModel
from res.pub.database.models import CPInstModel
@@ -31,7 +30,6 @@ 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.serializers import VmInfoSerializer
from res.resources.views.base_view import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -54,46 +52,6 @@ def query_resources(res_type, logger, resources, cvt_fun, res_serializer):
)
-class getVms(APIView):
- @swagger_auto_schema(
- responses={
- status.HTTP_200_OK: VmInfoSerializer(),
- 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="Vms",
- logger=logger,
- resources=VmInstModel.objects.filter(instid=vnfInstanceId),
- cvt_fun=fill_vms_data,
- res_serializer=VmInfoSerializer
- )
-
-
-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,
- "tenant": vm.tenant,
- "is_predefined": vm.is_predefined,
- "security_groups": vm.security_groups,
- "flavor_id": vm.flavor_id,
- "availability_zone": vm.availability_zone,
- "server_group": vm.server_group,
- "volume_array": vm.volume_array,
- "metadata": vm.metadata,
- "nic_array": vm.nic_array
- }
- return vms_data
-
-
class getFlavors(APIView):
@swagger_auto_schema(
responses={