--- /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 NetworkInstModel\r
+from res.resources.serializers import NetworkInfoSerializer\r
+\r
+logger = logging.getLogger(__name__)\r
+\r
+\r
+class GetNetworksService(BaseService):\r
+\r
+ def __init__(self):\r
+ super(GetNetworksService, self).__init__()\r
+\r
+ def get_networks(self, vnf_instance_id):\r
+ return self.query_resources(\r
+ res_type="Networks",\r
+ logger=logger,\r
+ resources=NetworkInstModel.objects.filter(instid=vnf_instance_id),\r
+ cvt_fun=self.fill_networks_data,\r
+ res_serializer=NetworkInfoSerializer\r
+ )\r
+\r
+ def fill_networks_data(self, network):\r
+ networks_data = {\r
+ "networkid": network.networkid,\r
+ "vimid": network.vimid,\r
+ "resouceid": network.resouceid,\r
+ "insttype": network.insttype,\r
+ "instid": network.instid,\r
+ "name": network.name\r
+ }\r
+ return networks_data\r