update get network structre
[vfc/gvnfm/vnfres.git] / res / res / biz / networks_get.py
1 # Copyright @ 2020 China Mobile (SuZhou) Software Technology Co.,Ltd.\r
2 #\r
3 # Licensed under the Apache License, Version 2.0 (the "License");\r
4 # you may not use this file except in compliance with the License.\r
5 # You may obtain a copy of the License at\r
6 #\r
7 #         http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 # Unless required by applicable law or agreed to in writing, software\r
10 # distributed under the License is distributed on an "AS IS" BASIS,\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 # See the License for the specific language governing permissions and\r
13 # limitations under the License.\r
14 import logging\r
15 \r
16 from res.biz.base import BaseService\r
17 from res.pub.database.models import NetworkInstModel\r
18 from res.resources.serializers import NetworkInfoSerializer\r
19 \r
20 logger = logging.getLogger(__name__)\r
21 \r
22 \r
23 class GetNetworksService(BaseService):\r
24 \r
25     def __init__(self):\r
26         super(GetNetworksService, self).__init__()\r
27 \r
28     def get_networks(self, vnf_instance_id):\r
29         return self.query_resources(\r
30             res_type="Networks",\r
31             logger=logger,\r
32             resources=NetworkInstModel.objects.filter(instid=vnf_instance_id),\r
33             cvt_fun=self.fill_networks_data,\r
34             res_serializer=NetworkInfoSerializer\r
35         )\r
36 \r
37     def fill_networks_data(self, network):\r
38         networks_data = {\r
39             "networkid": network.networkid,\r
40             "vimid": network.vimid,\r
41             "resouceid": network.resouceid,\r
42             "insttype": network.insttype,\r
43             "instid": network.instid,\r
44             "name": network.name\r
45         }\r
46         return networks_data\r