1 # Copyright @ 2020 China Mobile (SuZhou) Software Technology Co.,Ltd.
\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
7 # http://www.apache.org/licenses/LICENSE-2.0
\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
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
20 logger = logging.getLogger(__name__)
\r
23 class GetNetworksService(BaseService):
\r
26 super(GetNetworksService, self).__init__()
\r
28 def get_networks(self, vnf_instance_id):
\r
29 return self.query_resources(
\r
30 res_type="Networks",
\r
32 resources=NetworkInstModel.objects.filter(instid=vnf_instance_id),
\r
33 cvt_fun=self.fill_networks_data,
\r
34 res_serializer=NetworkInfoSerializer
\r
37 def fill_networks_data(self, network):
\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
46 return networks_data
\r