1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
"""VF module instance."""
# Copyright 2022 Orange, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from onapsdk.so.deletion import VfModuleDeletionRequest
from onapsdk.exceptions import ResourceNotFound
from .instance import Instance
class VfModuleInstance(Instance): # pylint: disable=too-many-instance-attributes
"""Vf module instance class."""
def __init__(self, # pylint: disable=too-many-arguments, too-many-locals
vnf_instance: "VnfInstance",
vf_module_id: str,
is_base_vf_module: bool,
automated_assignment: bool,
vf_module_name: str = None,
heat_stack_id: str = None,
resource_version: str = None,
model_invariant_id: str = None,
orchestration_status: str = None,
persona_model_version: str = None,
model_version_id: str = None,
model_customization_id: str = None,
widget_model_id: str = None,
widget_model_version: str = None,
contrail_service_instance_fqdn: str = None,
module_index: int = None,
selflink: str = None) -> None:
"""Vf module initialization.
Args:
vnf_instance (VnfInstance): VnfInstance
vf_module_id (str): Unique ID of vf-module
is_base_vf_module (bool): used to indicate whether or not this object is base vf module
automated_assignment (bool): ndicates whether vf-module assignment was done via
automation or manually
vf_module_name (str, optional): Name of vf-module. Defaults to None.
heat_stack_id (str, optional): Heat stack id corresponding to this instance.
Defaults to None.
orchestration_status (str, optional): orchestration status of this vf-module,
mastered by MSO. Defaults to None.
resource_version (str, optional): Used for optimistic concurrency.
Must be empty on create, valid on update and delete. Defaults to None.
model_invariant_id (str, optional): the ASDC model id for this resource or
service model. Defaults to None.
model_version_id (str, optional): the ASDC model version for this resource or
service model. Defaults to None.
persona_model_version (str, optional): the ASDC model version for this resource or
service model. Defaults to None.
model_customization_id (str, optional): captures the id of all the configuration
used to customize the resource for the service. Defaults to None.
widget_model_id (str, optional): the ASDC data dictionary widget model.
This maps directly to the A&AI widget. Defaults to None.
widget_model_version (str, optional): the ASDC data dictionary version of
the widget model. This maps directly to the A&AI version of the widget.
Defaults to None.
contrail_service_instance_fqdn (str, optional): the Contrail unique ID
for a service-instance. Defaults to None.
module_index (int, optional): the index will track the number of modules
of a given type that have been deployed in a VNF, starting with 0,
and always choosing the lowest available digit. Defaults to None.
selflink (str, optional): Path to the controller object. Defaults to None.
"""
super().__init__(resource_version=resource_version, model_version_id=model_version_id,
model_invariant_id=model_invariant_id)
self.vnf_instance: "VnfInstance" = vnf_instance
self.vf_module_id: str = vf_module_id
self.is_base_vf_module: bool = is_base_vf_module
self.automated_assignment: bool = automated_assignment
self.vf_module_name: str = vf_module_name
self.heat_stack_id: str = heat_stack_id
self.orchestration_status: str = orchestration_status
self.model_customization_id: str = model_customization_id
self.contrail_service_instance_fqdn: str = contrail_service_instance_fqdn
self.module_index: int = module_index
self.selflink: str = selflink
self.persona_model_version: str = persona_model_version
self.widget_model_id: str = widget_model_id
self.widget_model_version: str = widget_model_version
self._vf_module: "VfModule" = None
def __repr__(self) -> str:
"""Object represetation.
Returns:
str: Human readble VfModuleInstance representation
"""
return (f"VfModuleInstance(vf_module_id={self.vf_module_id}, "
f"is_base_vf_module={self.is_base_vf_module}, "
f"automated_assignment={self.automated_assignment})")
@classmethod
def get_all_url(cls, vnf_instance: "VnfInstance") -> str: # pylint: disable=arguments-differ
"""Return url to get all vf modules for vnf instance.
Args:
vnf_instance (VnfInstance): VNF instance object
Returns:
str: Url to get all vf modules for vnf instance
"""
return f"{vnf_instance.url}/vf-modules/"
@property
def url(self) -> str:
"""Resource url.
Returns:
str: VfModuleInstance url
"""
return f"{self.vnf_instance.url}/vf-modules/vf-module/{self.vf_module_id}"
@property
def vf_module(self) -> "VfModule":
"""Vf module associated with that vf module instance.
Returns:
VfModule: VfModule object associated with vf module instance
"""
if not self._vf_module:
for vf_module in self.vnf_instance.vnf.vf_modules:
if vf_module.model_version_id == self.model_version_id:
self._vf_module = vf_module
return self._vf_module
msg = (
f'Could not find VF modules for the VF Module instance'
f' with model version ID "{self.model_version_id}"'
)
raise ResourceNotFound(msg)
return self._vf_module
@classmethod
def create_from_api_response(cls,
api_response: dict,
vnf_instance: "VnfInstance") -> "VfModuleInstance":
"""Create vf module instance object using HTTP API response dictionary.
Args:
api_response (dict): HTTP API response content
vnf_instance (VnfInstance): VnfInstance associated with VfModuleInstance
Returns:
VfModuleInstance: VfModuleInstance object
"""
return cls(
vnf_instance=vnf_instance,
vf_module_id=api_response.get("vf-module-id"),
is_base_vf_module=api_response.get("is-base-vf-module"),
automated_assignment=api_response.get("automated-assignment"),
vf_module_name=api_response.get("vf-module-name"),
heat_stack_id=api_response.get("heat-stack-id"),
orchestration_status=api_response.get("orchestration-status"),
resource_version=api_response.get("resource-version"),
model_invariant_id=api_response.get("model-invariant-id"),
model_version_id=api_response.get("model-version-id"),
persona_model_version=api_response.get("persona-model-version"),
model_customization_id=api_response.get("model-customization-id"),
widget_model_id=api_response.get("widget-model-id"),
widget_model_version=api_response.get("widget-model-version"),
contrail_service_instance_fqdn=api_response.get("contrail-service-instance-fqdn"),
module_index=api_response.get("module-index"),
selflink=api_response.get("selflink")
)
def delete(self, a_la_carte: bool = True) -> "VfModuleDeletionRequest":
"""Create deletion request.
Send request to delete VF module instance
Args:
a_la_carte (boolean): deletion mode
Returns:
VfModuleDeletionRequest: Deletion request object
"""
self._logger.debug("Delete %s VF module", self.vf_module_id)
return VfModuleDeletionRequest.send_request(self, a_la_carte)
|