Coverage for osm_nbi/vnf_instance_topics.py: 93%

27 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2024-06-30 10:14 +0000

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 

19from osm_nbi.base_topic import BaseTopic 

20from .osm_vnfm.vnf_instances import VnfInstances2NsInstances 

21from .osm_vnfm.vnf_instance_actions import VnfLcmOp2NsLcmOp 

22 

23 

24class VnfInstances(BaseTopic): 

25 def __init__(self, db, fs, msg, auth): 

26 """ 

27 Constructor call for vnf instance topic 

28 """ 

29 BaseTopic.__init__(self, db, fs, msg, auth) 

30 self.vnfinstances2nsinstances = VnfInstances2NsInstances(db, fs, msg, auth) 

31 

32 def new(self, rollback, session, indata=None, kwargs=None, headers=None): 

33 """ 

34 Creates new vnf instance 

35 :param rollback: list to append the created items at database in case a rollback must be done 

36 :param session: contains "username", "admin", "force", "public", "project_id", "set_project" 

37 :param indata: params to be used for the vnf instance 

38 :param kwargs: used to override the indata descriptor 

39 :param headers: http request headers 

40 :return: the _id of vnf instance created at database. Or an exception. 

41 """ 

42 return self.vnfinstances2nsinstances.new( 

43 rollback, session, indata, kwargs, headers 

44 ) 

45 

46 def list(self, session, filter_q=None, api_req=False): 

47 """ 

48 Get a list of the vnf instances that match a filter 

49 :param session: contains the used login username and working project 

50 :param filter_q: filter of data to be applied 

51 :param api_req: True if this call is serving an external API request. False if serving internal request. 

52 :return: The list, it can be empty if no one match the filter. 

53 """ 

54 return self.vnfinstances2nsinstances.list(session, filter_q, api_req) 

55 

56 def show(self, session, _id, filter_q=None, api_req=False): 

57 """ 

58 Get complete information on an vnf instance 

59 :param session: contains "username", "admin", "force", "public", "project_id", "set_project" 

60 :param _id: server internal id 

61 :param api_req: True if this call is serving an external API request. False if serving internal request. 

62 :return: dictionary, raise exception if not found. 

63 """ 

64 return self.vnfinstances2nsinstances.show(session, _id, api_req) 

65 

66 def delete(self, session, _id, dry_run=False, not_send_msg=None): 

67 """ 

68 Delete vnf instance by its internal _id 

69 :param session: contains "username", "admin", "force", "public", "project_id", "set_project" 

70 :param _id: server internal id 

71 :param dry_run: make checking but do not delete 

72 :param not_send_msg: To not send message (False) or store content (list) instead 

73 :return: operation id (None if there is not operation), raise exception if error or not found, conflict, ... 

74 """ 

75 return self.vnfinstances2nsinstances.delete(session, _id, dry_run, not_send_msg) 

76 

77 

78class VnfLcmOpTopic(BaseTopic): 

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)