diff options
author | hewei-cmss <hewei@cmss.chinamobile.com> | 2020-03-27 15:49:53 +0800 |
---|---|---|
committer | hewei-cmss <hewei@cmss.chinamobile.com> | 2020-03-27 16:01:51 +0800 |
commit | 6d68252d8aa403cec8a087b77b27a9719d8c1350 (patch) | |
tree | e24fcd6ba87168df99b7e9898569ba4420375deb /res | |
parent | 39a7c635ea2c92117d9a610f1d51ac21e0ed9588 (diff) |
update get network structre6.0.0-ONAPfrankfurt
Issue-ID: VFC-1599
Signed-off-by: hewei-cmss <hewei@cmss.chinamobile.com>
Change-Id: I45cebb73e45774d450ed44ee6a31cb036b4684e8
Diffstat (limited to 'res')
-rw-r--r-- | res/res/biz/networks_get.py | 46 | ||||
-rw-r--r-- | res/res/resources/urls.py | 3 | ||||
-rw-r--r-- | res/res/resources/views/get_networks_view.py | 34 | ||||
-rw-r--r-- | res/res/resources/views/views.py | 32 |
4 files changed, 82 insertions, 33 deletions
diff --git a/res/res/biz/networks_get.py b/res/res/biz/networks_get.py new file mode 100644 index 0000000..46b4fa2 --- /dev/null +++ b/res/res/biz/networks_get.py @@ -0,0 +1,46 @@ +# 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 NetworkInstModel
+from res.resources.serializers import NetworkInfoSerializer
+
+logger = logging.getLogger(__name__)
+
+
+class GetNetworksService(BaseService):
+
+ def __init__(self):
+ super(GetNetworksService, self).__init__()
+
+ def get_networks(self, vnf_instance_id):
+ return self.query_resources(
+ res_type="Networks",
+ logger=logger,
+ resources=NetworkInstModel.objects.filter(instid=vnf_instance_id),
+ cvt_fun=self.fill_networks_data,
+ res_serializer=NetworkInfoSerializer
+ )
+
+ def fill_networks_data(self, network):
+ networks_data = {
+ "networkid": network.networkid,
+ "vimid": network.vimid,
+ "resouceid": network.resouceid,
+ "insttype": network.insttype,
+ "instid": network.instid,
+ "name": network.name
+ }
+ return networks_data
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py index 2088caf..0bfcb3a 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_networks_view import GetNetworksView 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 @@ -26,7 +27,7 @@ urlpatterns = [ 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<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<vnf_instance_id>[0-9a-zA-Z\-\_]+)/networks$', GetNetworksView.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'), url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/volumes$', views.getVolumes.as_view(), name='get_volumes'), diff --git a/res/res/resources/views/get_networks_view.py b/res/res/resources/views/get_networks_view.py new file mode 100644 index 0000000..ef07b06 --- /dev/null +++ b/res/res/resources/views/get_networks_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 NetworkInfoSerializer
+from res.resources.views.base_view import view_safe_call_with_log
+from res.biz.networks_get import GetNetworksService
+logger = logging.getLogger(__name__)
+
+
+class GetNetworksView(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: NetworkInfoSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'
+ }
+ )
+ @view_safe_call_with_log(logger=logger)
+ def get(self, request, vnf_instance_id):
+ return GetNetworksService().get_networks(vnf_instance_id)
diff --git a/res/res/resources/views/views.py b/res/res/resources/views/views.py index cb5e6b5..31d4ee8 100644 --- a/res/res/resources/views/views.py +++ b/res/res/resources/views/views.py @@ -21,13 +21,11 @@ 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 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.views.base_view import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -50,36 +48,6 @@ def query_resources(res_type, logger, resources, cvt_fun, res_serializer): )
-class getNetworks(APIView):
- @swagger_auto_schema(
- responses={
- status.HTTP_200_OK: NetworkInfoSerializer(),
- 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="Networks",
- logger=logger,
- resources=NetworkInstModel.objects.filter(instid=vnfInstanceId),
- cvt_fun=fill_networks_data,
- res_serializer=NetworkInfoSerializer
- )
-
-
-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
- }
- return networks_data
-
-
class getSubnets(APIView):
@swagger_auto_schema(
responses={
|