ac5fe411ea82efb31163e1b045078454207a8b83
[osm/NBI.git] / osm_nbi / vnf_instance_topics.py
1 # Copyright 2021 K Sai Kiran (Tata Elxsi)
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 __author__ = "K Sai Kiran <saikiran.k@tataelxsi.co.in>, Selvi Jayaraman <selvi.j@tataelxsi.co.in>"
17 __date__ = "$12-June-2021 8:30:59$"
18
19 from osm_nbi.base_topic import BaseTopic
20 from .osm_vnfm.vnf_instances import VnfInstances2NsInstances
21 from .osm_vnfm.vnf_instance_actions import VnfLcmOp2NsLcmOp
22
23
24 class VnfInstances(BaseTopic):
25
26 def __init__(self, db, fs, msg, auth):
27 """
28 Constructor call for vnf instance topic
29 """
30 BaseTopic.__init__(self, db, fs, msg, auth)
31 self.vnfinstances2nsinstances = VnfInstances2NsInstances(db, fs, msg, auth)
32
33 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
34 """
35 Creates new vnf instance
36 :param rollback: list to append the created items at database in case a rollback must be done
37 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
38 :param indata: params to be used for the vnf instance
39 :param kwargs: used to override the indata descriptor
40 :param headers: http request headers
41 :return: the _id of vnf instance created at database. Or an exception.
42 """
43 return self.vnfinstances2nsinstances.new(rollback, session, indata, kwargs, headers)
44
45 def list(self, session, filter_q=None, api_req=False):
46 """
47 Get a list of the vnf instances that match a filter
48 :param session: contains the used login username and working project
49 :param filter_q: filter of data to be applied
50 :param api_req: True if this call is serving an external API request. False if serving internal request.
51 :return: The list, it can be empty if no one match the filter.
52 """
53 return self.vnfinstances2nsinstances.list(session, filter_q, api_req)
54
55 def show(self, session, _id, filter_q=None, api_req=False):
56 """
57 Get complete information on an vnf instance
58 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
59 :param _id: server internal id
60 :param api_req: True if this call is serving an external API request. False if serving internal request.
61 :return: dictionary, raise exception if not found.
62 """
63 return self.vnfinstances2nsinstances.show(session, _id, api_req)
64
65 def delete(self, session, _id, dry_run=False, not_send_msg=None):
66 """
67 Delete vnf instance by its internal _id
68 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
69 :param _id: server internal id
70 :param dry_run: make checking but do not delete
71 :param not_send_msg: To not send message (False) or store content (list) instead
72 :return: operation id (None if there is not operation), raise exception if error or not found, conflict, ...
73 """
74 return self.vnfinstances2nsinstances.delete(session, _id, dry_run, not_send_msg)
75
76
77 class VnfLcmOpTopic(BaseTopic):
78
79 def __init__(self, db, fs, msg, auth):
80 """
81 Constructor call for vnf lcm op topic
82 """
83 BaseTopic.__init__(self, db, fs, msg, auth)
84 self.vnflcmop2nslcmop = VnfLcmOp2NsLcmOp(db, fs, msg, auth)
85
86 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
87 """
88 Creates new vnf lcm op
89 :param rollback: list to append the created items at database in case a rollback must be done
90 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
91 :param indata: params to be used for the vnf instance
92 :param kwargs: used to override the indata descriptor
93 :param headers: http request headers
94 :return: the _id of vnf lcm op created at database. Or an exception.
95 """
96 return self.vnflcmop2nslcmop.new(rollback, session, indata, kwargs, headers)
97
98 def list(self, session, filter_q=None, api_req=False):
99 """
100 Get a list of the vnf lcm op that match a filter
101 :param session: contains the used login username and working project
102 :param filter_q: filter of data to be applied
103 :param api_req: True if this call is serving an external API request. False if serving internal request.
104 :return: The list, it can be empty if no one match the filter.
105 """
106 return self.vnflcmop2nslcmop.list(session, filter_q, api_req)
107
108 def show(self, session, _id, filter_q=None, api_req=False):
109 """
110 Get complete information on an vnf lcm op
111 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
112 :param _id: server internal id
113 :param api_req: True if this call is serving an external API request. False if serving internal request.
114 :return: dictionary, raise exception if not found.
115 """
116 return self.vnflcmop2nslcmop.show(session, _id, api_req)