--- /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 VmInstModel\r
+from res.resources.serializers import VmInfoSerializer\r
+\r
+logger = logging.getLogger(__name__)\r
+\r
+\r
+class GetVmsService(BaseService):\r
+\r
+ def __init__(self):\r
+ super(GetVmsService, self).__init__()\r
+\r
+ def get_vms(self, vnf_instance_id):\r
+ return self.query_resources(\r
+ res_type="Vms",\r
+ logger=logger,\r
+ resources=VmInstModel.objects.filter(instid=vnf_instance_id),\r
+ cvt_fun=self.fill_vms_data,\r
+ res_serializer=VmInfoSerializer\r
+ )\r
+\r
+ def fill_vms_data(self, vm):\r
+ vms_data = {\r
+ "vmid": vm.vmid,\r
+ "vimid": vm.vimid,\r
+ "resouceid": vm.resouceid,\r
+ "insttype": vm.insttype,\r
+ "instid": vm.instid,\r
+ "vmname": vm.vmname,\r
+ "operationalstate": vm.operationalstate,\r
+ "tenant": vm.tenant,\r
+ "is_predefined": vm.is_predefined,\r
+ "security_groups": vm.security_groups,\r
+ "flavor_id": vm.flavor_id,\r
+ "availability_zone": vm.availability_zone,\r
+ "server_group": vm.server_group,\r
+ "volume_array": vm.volume_array,\r
+ "metadata": vm.metadata,\r
+ "nic_array": vm.nic_array\r
+ }\r
+ return vms_data\r
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'),
--- /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 VmInfoSerializer\r
+from res.resources.views.base_view import view_safe_call_with_log\r
+from res.biz.vms_get import GetVmsService\r
+logger = logging.getLogger(__name__)\r
+\r
+\r
+class GetVmsView(APIView):\r
+ @swagger_auto_schema(\r
+ responses={\r
+ status.HTTP_200_OK: VmInfoSerializer(),\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 GetVmsService().get_vms(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 VmInstModel\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 SubnetInfoSerializer\r
from res.resources.serializers import NetworkInfoSerializer\r
from res.resources.serializers import FlavorInfoSerializer\r
-from res.resources.serializers import VmInfoSerializer\r
from res.resources.views.base_view import view_safe_call_with_log\r
\r
logger = logging.getLogger(__name__)\r
)\r
\r
\r
-class getVms(APIView):\r
- @swagger_auto_schema(\r
- responses={\r
- status.HTTP_200_OK: VmInfoSerializer(),\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="Vms",\r
- logger=logger,\r
- resources=VmInstModel.objects.filter(instid=vnfInstanceId),\r
- cvt_fun=fill_vms_data,\r
- res_serializer=VmInfoSerializer\r
- )\r
-\r
-\r
-def fill_vms_data(vm):\r
- vms_data = {\r
- "vmid": vm.vmid,\r
- "vimid": vm.vimid,\r
- "resouceid": vm.resouceid,\r
- "insttype": vm.insttype,\r
- "instid": vm.instid,\r
- "vmname": vm.vmname,\r
- "operationalstate": vm.operationalstate,\r
- "tenant": vm.tenant,\r
- "is_predefined": vm.is_predefined,\r
- "security_groups": vm.security_groups,\r
- "flavor_id": vm.flavor_id,\r
- "availability_zone": vm.availability_zone,\r
- "server_group": vm.server_group,\r
- "volume_array": vm.volume_array,\r
- "metadata": vm.metadata,\r
- "nic_array": vm.nic_array\r
- }\r
- return vms_data\r
-\r
-\r
class getFlavors(APIView):\r
@swagger_auto_schema(\r
responses={\r