1 |
|
# -*- coding: utf-8 -*- |
2 |
|
# pylint: disable=no-member |
3 |
|
|
4 |
|
# Copyright 2018 Whitestack, LLC |
5 |
|
# ************************************************************* |
6 |
|
|
7 |
|
# This file is part of OSM Monitoring module |
8 |
|
# All Rights Reserved to Whitestack, LLC |
9 |
|
|
10 |
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
11 |
|
# not use this file except in compliance with the License. You may obtain |
12 |
|
# a copy of the License at |
13 |
|
|
14 |
|
# http://www.apache.org/licenses/LICENSE-2.0 |
15 |
|
|
16 |
|
# Unless required by applicable law or agreed to in writing, software |
17 |
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
18 |
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
19 |
|
# License for the specific language governing permissions and limitations |
20 |
|
# under the License. |
21 |
|
|
22 |
|
# For those usages not covered by the Apache License, Version 2.0 please |
23 |
|
# contact: bdiaz@whitestack.com or glavado@whitestack.com |
24 |
|
## |
25 |
1 |
import datetime |
26 |
1 |
import json |
27 |
1 |
import logging |
28 |
1 |
import operator |
29 |
1 |
import functools |
30 |
|
|
31 |
1 |
from osm_policy_module.common.common_db_client import CommonDbClient |
32 |
1 |
from osm_policy_module.common.lcm_client import LcmClient |
33 |
1 |
from osm_policy_module.common.mon_client import MonClient |
34 |
1 |
from osm_policy_module.core import database |
35 |
1 |
from osm_policy_module.core.config import Config |
36 |
1 |
from osm_policy_module.core.database import ( |
37 |
|
ScalingGroup, |
38 |
|
ScalingAlarm, |
39 |
|
ScalingPolicy, |
40 |
|
ScalingCriteria, |
41 |
|
ScalingAlarmRepository, |
42 |
|
ScalingGroupRepository, |
43 |
|
ScalingPolicyRepository, |
44 |
|
ScalingCriteriaRepository, |
45 |
|
) |
46 |
1 |
from osm_policy_module.core.exceptions import VdurNotFound |
47 |
|
|
48 |
1 |
log = logging.getLogger(__name__) |
49 |
|
|
50 |
|
|
51 |
1 |
class AutoscalingService: |
52 |
1 |
def __init__(self, config: Config): |
53 |
1 |
self.conf = config |
54 |
1 |
self.db_client = CommonDbClient(config) |
55 |
1 |
self.mon_client = MonClient(config) |
56 |
1 |
self.lcm_client = LcmClient(config) |
57 |
|
|
58 |
1 |
async def configure_scaling_groups(self, nsr_id: str, vnf_member_index=None): |
59 |
|
""" |
60 |
|
Configures scaling groups for a network service. Creates records in DB. Creates alarms in MON. |
61 |
|
:param nsr_id: Network service record id |
62 |
|
:return: |
63 |
|
""" |
64 |
1 |
log.info( |
65 |
|
"Configuring scaling groups for network service with nsr_id: %s", nsr_id |
66 |
|
) |
67 |
1 |
alarms_created = [] |
68 |
1 |
database.db.connect() |
69 |
1 |
try: |
70 |
1 |
with database.db.atomic() as tx: |
71 |
1 |
try: |
72 |
1 |
if vnf_member_index is None: |
73 |
1 |
vnfrs = self.db_client.get_vnfrs(nsr_id) |
74 |
|
else: |
75 |
0 |
vnfrs = [] |
76 |
0 |
vnfr = self.db_client.get_vnfr(nsr_id, vnf_member_index) |
77 |
0 |
vnfrs.append(vnfr) |
78 |
|
# vnfrs = self.db_client.get_vnfrs(nsr_id) |
79 |
1 |
for vnfr in vnfrs: |
80 |
1 |
log.debug("Processing vnfr: %s", vnfr) |
81 |
1 |
vnfd = self.db_client.get_vnfd(vnfr["vnfd-id"]) |
82 |
|
# TODO: Change for multiple DF support |
83 |
1 |
df = vnfd.get("df", [{}])[0] |
84 |
1 |
if "scaling-aspect" not in df: |
85 |
0 |
log.debug("No scaling aspect present in vnfd") |
86 |
0 |
continue |
87 |
|
# TODO: Change for multiple instantiation levels support |
88 |
1 |
scaling_aspects = df["scaling-aspect"] |
89 |
1 |
all_vnfd_monitoring_params = ( |
90 |
|
self._get_all_vnfd_monitoring_params(vnfd) |
91 |
|
) |
92 |
1 |
for scaling_aspect in scaling_aspects: |
93 |
1 |
scaling_group_record = self._get_or_create_scaling_group( |
94 |
|
nsr_id, vnfr["member-vnf-index-ref"], scaling_aspect |
95 |
|
) |
96 |
1 |
vdurs = self._get_monitored_vdurs( |
97 |
|
scaling_aspect, vnfr["vdur"] |
98 |
|
) |
99 |
1 |
for scaling_policy in scaling_aspect.get( |
100 |
|
"scaling-policy", () |
101 |
|
): |
102 |
1 |
if scaling_policy["scaling-type"] != "automatic": |
103 |
0 |
continue |
104 |
1 |
scaling_policy_record = ( |
105 |
|
self._get_or_create_scaling_policy( |
106 |
|
nsr_id, scaling_policy, scaling_group_record |
107 |
|
) |
108 |
|
) |
109 |
|
|
110 |
1 |
for scaling_criteria in scaling_policy[ |
111 |
|
"scaling-criteria" |
112 |
|
]: |
113 |
1 |
scaling_criteria_record = ( |
114 |
|
self._get_or_create_scaling_criteria( |
115 |
|
nsr_id, |
116 |
|
scaling_criteria, |
117 |
|
scaling_policy_record, |
118 |
|
) |
119 |
|
) |
120 |
1 |
monitoring_param_ref = scaling_criteria.get( |
121 |
|
"vnf-monitoring-param-ref" |
122 |
|
) |
123 |
1 |
vnf_monitoring_param = all_vnfd_monitoring_params[ |
124 |
|
monitoring_param_ref |
125 |
|
] |
126 |
|
|
127 |
1 |
for vdur in vdurs: |
128 |
1 |
vdu_id = vdur["vdu-id-ref"] |
129 |
1 |
log.debug("Creating alarm for vdur %s ", vdur) |
130 |
1 |
try: |
131 |
1 |
ScalingAlarmRepository.get( |
132 |
|
ScalingAlarm.vdu_name == vdur["name"], |
133 |
|
ScalingCriteria.name |
134 |
|
== scaling_criteria["name"], |
135 |
|
ScalingPolicy.name |
136 |
|
== scaling_policy["name"], |
137 |
|
ScalingGroup.nsr_id == nsr_id, |
138 |
|
join_classes=[ |
139 |
|
ScalingCriteria, |
140 |
|
ScalingPolicy, |
141 |
|
ScalingGroup, |
142 |
|
], |
143 |
|
) |
144 |
0 |
log.debug( |
145 |
|
"vdu %s already has an alarm configured", |
146 |
|
vdur["name"], |
147 |
|
) |
148 |
0 |
continue |
149 |
1 |
except ScalingAlarm.DoesNotExist: |
150 |
1 |
pass |
151 |
1 |
metric_name = self._get_metric_name( |
152 |
|
vnf_monitoring_param |
153 |
|
) |
154 |
|
|
155 |
1 |
db_nsr = self.db_client.get_nsr(nsr_id) |
156 |
1 |
nb_scale_op = 0 |
157 |
1 |
if db_nsr["_admin"].get("scaling-group"): |
158 |
0 |
db_nsr_admin = db_nsr["_admin"][ |
159 |
|
"scaling-group" |
160 |
|
] |
161 |
0 |
for ( |
162 |
|
admin_scale_index, |
163 |
|
admin_scale_info, |
164 |
|
) in enumerate(db_nsr_admin): |
165 |
0 |
if ( |
166 |
|
admin_scale_info["name"] |
167 |
|
== scaling_aspect["name"] |
168 |
|
): |
169 |
0 |
nb_scale_op = admin_scale_info.get( |
170 |
|
"nb-scale-op", 0 |
171 |
|
) |
172 |
0 |
break |
173 |
1 |
min_instance_count = 1 |
174 |
1 |
for vdu_profile in df.get("vdu-profile", ()): |
175 |
1 |
if vdu_profile.get("id") == vdu_id: |
176 |
1 |
min_instance_count = int( |
177 |
|
vdu_profile.get( |
178 |
|
"min-number-of-instances ", 1 |
179 |
|
) |
180 |
|
) |
181 |
1 |
break |
182 |
1 |
if nb_scale_op >= min_instance_count: |
183 |
0 |
alarm_uuid = ( |
184 |
|
await self.mon_client.create_alarm( |
185 |
|
metric_name=metric_name, |
186 |
|
ns_id=nsr_id, |
187 |
|
vdu_name=vdur["name"], |
188 |
|
vnf_member_index=vnfr[ |
189 |
|
"member-vnf-index-ref" |
190 |
|
], |
191 |
|
threshold=scaling_criteria[ |
192 |
|
"scale-in-threshold" |
193 |
|
], |
194 |
|
operation=scaling_criteria[ |
195 |
|
"scale-in-relational-operation" |
196 |
|
], |
197 |
|
action="scale_in", |
198 |
|
) |
199 |
|
) |
200 |
0 |
alarm = ScalingAlarmRepository.create( |
201 |
|
alarm_uuid=alarm_uuid, |
202 |
|
action="scale_in", |
203 |
|
vnf_member_index=vnfr[ |
204 |
|
"member-vnf-index-ref" |
205 |
|
], |
206 |
|
vdu_name=vdur["name"], |
207 |
|
scaling_criteria=scaling_criteria_record, |
208 |
|
) |
209 |
0 |
alarms_created.append(alarm) |
210 |
1 |
alarm_uuid = await self.mon_client.create_alarm( |
211 |
|
metric_name=metric_name, |
212 |
|
ns_id=nsr_id, |
213 |
|
vdu_name=vdur["name"], |
214 |
|
vnf_member_index=vnfr[ |
215 |
|
"member-vnf-index-ref" |
216 |
|
], |
217 |
|
threshold=scaling_criteria[ |
218 |
|
"scale-out-threshold" |
219 |
|
], |
220 |
|
operation=scaling_criteria[ |
221 |
|
"scale-out-relational-operation" |
222 |
|
], |
223 |
|
action="scale_out", |
224 |
|
) |
225 |
1 |
alarm = ScalingAlarmRepository.create( |
226 |
|
alarm_uuid=alarm_uuid, |
227 |
|
action="scale_out", |
228 |
|
vnf_member_index=vnfr[ |
229 |
|
"member-vnf-index-ref" |
230 |
|
], |
231 |
|
vdu_name=vdur["name"], |
232 |
|
scaling_criteria=scaling_criteria_record, |
233 |
|
) |
234 |
1 |
alarms_created.append(alarm) |
235 |
|
|
236 |
0 |
except Exception as e: |
237 |
0 |
log.exception("Error configuring scaling groups:") |
238 |
0 |
tx.rollback() |
239 |
0 |
if len(alarms_created) > 0: |
240 |
0 |
log.info("Cleaning alarm resources in MON") |
241 |
0 |
for alarm in alarms_created: |
242 |
0 |
await self.mon_client.delete_alarm( |
243 |
|
alarm.scaling_criteria.scaling_policy.scaling_group.nsr_id, |
244 |
|
alarm.vnf_member_index, |
245 |
|
alarm.vdu_name, |
246 |
|
alarm.alarm_uuid, |
247 |
|
) |
248 |
0 |
raise e |
249 |
|
finally: |
250 |
1 |
database.db.close() |
251 |
|
|
252 |
1 |
async def delete_scaling_groups(self, nsr_id: str, vnf_member_index=None): |
253 |
0 |
log.debug("Deleting scaling groups for network service %s", nsr_id) |
254 |
0 |
database.db.connect() |
255 |
0 |
try: |
256 |
0 |
with database.db.atomic() as tx: |
257 |
0 |
try: |
258 |
0 |
if vnf_member_index is None: |
259 |
0 |
scale_conditions = ScalingGroup.nsr_id == nsr_id |
260 |
|
else: |
261 |
0 |
query_list = [ |
262 |
|
ScalingGroup.nsr_id == nsr_id, |
263 |
|
ScalingGroup.vnf_member_index == vnf_member_index, |
264 |
|
] |
265 |
0 |
scale_conditions = functools.reduce(operator.and_, query_list) |
266 |
0 |
for scaling_group in ScalingGroupRepository.list(scale_conditions): |
267 |
0 |
for scaling_policy in scaling_group.scaling_policies: |
268 |
0 |
for scaling_criteria in scaling_policy.scaling_criterias: |
269 |
0 |
for alarm in scaling_criteria.scaling_alarms: |
270 |
0 |
try: |
271 |
0 |
await self.mon_client.delete_alarm( |
272 |
|
alarm.scaling_criteria.scaling_policy.scaling_group.nsr_id, |
273 |
|
alarm.vnf_member_index, |
274 |
|
alarm.vdu_name, |
275 |
|
alarm.alarm_uuid, |
276 |
|
) |
277 |
0 |
except ValueError: |
278 |
0 |
log.exception( |
279 |
|
"Error deleting alarm in MON %s", |
280 |
|
alarm.alarm_uuid, |
281 |
|
) |
282 |
0 |
alarm.delete_instance() |
283 |
0 |
scaling_criteria.delete_instance() |
284 |
0 |
scaling_policy.delete_instance() |
285 |
0 |
scaling_group.delete_instance() |
286 |
|
|
287 |
0 |
except Exception as e: |
288 |
0 |
log.exception("Error deleting scaling groups and alarms:") |
289 |
0 |
tx.rollback() |
290 |
0 |
raise e |
291 |
|
finally: |
292 |
0 |
database.db.close() |
293 |
|
|
294 |
1 |
async def delete_orphaned_alarms(self, nsr_id): |
295 |
0 |
log.info("Deleting orphaned scaling alarms for network service %s", nsr_id) |
296 |
0 |
database.db.connect() |
297 |
0 |
try: |
298 |
0 |
with database.db.atomic() as tx: |
299 |
0 |
try: |
300 |
0 |
for scaling_group in ScalingGroupRepository.list( |
301 |
|
ScalingGroup.nsr_id == nsr_id |
302 |
|
): |
303 |
0 |
for scaling_policy in scaling_group.scaling_policies: |
304 |
0 |
for scaling_criteria in scaling_policy.scaling_criterias: |
305 |
0 |
for alarm in scaling_criteria.scaling_alarms: |
306 |
0 |
try: |
307 |
0 |
self.db_client.get_vdur( |
308 |
|
nsr_id, |
309 |
|
alarm.vnf_member_index, |
310 |
|
alarm.vdu_name, |
311 |
|
) |
312 |
0 |
except VdurNotFound: |
313 |
0 |
log.debug( |
314 |
|
"Deleting orphaned scaling alarm %s", |
315 |
|
alarm.alarm_uuid, |
316 |
|
) |
317 |
0 |
try: |
318 |
0 |
await self.mon_client.delete_alarm( |
319 |
|
alarm.scaling_criteria.scaling_policy.scaling_group.nsr_id, |
320 |
|
alarm.vnf_member_index, |
321 |
|
alarm.vdu_name, |
322 |
|
alarm.alarm_uuid, |
323 |
|
) |
324 |
0 |
except ValueError: |
325 |
0 |
log.exception( |
326 |
|
"Error deleting alarm in MON %s", |
327 |
|
alarm.alarm_uuid, |
328 |
|
) |
329 |
0 |
alarm.delete_instance() |
330 |
|
|
331 |
0 |
except Exception as e: |
332 |
0 |
log.exception("Error deleting orphaned alarms:") |
333 |
0 |
tx.rollback() |
334 |
0 |
raise e |
335 |
|
finally: |
336 |
0 |
database.db.close() |
337 |
|
|
338 |
1 |
async def handle_alarm(self, alarm_uuid: str, status: str): |
339 |
0 |
await self.update_alarm_status(alarm_uuid, status) |
340 |
0 |
await self.evaluate_policy(alarm_uuid) |
341 |
|
|
342 |
1 |
async def update_alarm_status(self, alarm_uuid: str, status: str): |
343 |
1 |
database.db.connect() |
344 |
1 |
try: |
345 |
1 |
with database.db.atomic(): |
346 |
1 |
alarm = ScalingAlarmRepository.get( |
347 |
|
ScalingAlarm.alarm_uuid == alarm_uuid |
348 |
|
) |
349 |
1 |
alarm.last_status = status |
350 |
1 |
alarm.save() |
351 |
0 |
except ScalingAlarm.DoesNotExist: |
352 |
0 |
log.debug( |
353 |
|
"There is no autoscaling action configured for alarm %s.", alarm_uuid |
354 |
|
) |
355 |
|
finally: |
356 |
1 |
database.db.close() |
357 |
|
|
358 |
1 |
async def evaluate_policy(self, alarm_uuid): |
359 |
1 |
database.db.connect() |
360 |
1 |
try: |
361 |
1 |
with database.db.atomic(): |
362 |
1 |
alarm = ScalingAlarmRepository.get( |
363 |
|
ScalingAlarm.alarm_uuid == alarm_uuid |
364 |
|
) |
365 |
1 |
vnf_member_index = alarm.vnf_member_index |
366 |
1 |
action = alarm.action |
367 |
1 |
scaling_policy = alarm.scaling_criteria.scaling_policy |
368 |
1 |
if not scaling_policy.enabled: |
369 |
1 |
return |
370 |
1 |
if action == "scale_in": |
371 |
1 |
operation = scaling_policy.scale_in_operation |
372 |
1 |
elif action == "scale_out": |
373 |
1 |
operation = scaling_policy.scale_out_operation |
374 |
|
else: |
375 |
0 |
raise Exception("Unknown alarm action {}".format(alarm.action)) |
376 |
1 |
alarms = ScalingAlarmRepository.list( |
377 |
|
ScalingAlarm.scaling_criteria == alarm.scaling_criteria, |
378 |
|
ScalingAlarm.action == alarm.action, |
379 |
|
ScalingAlarm.vnf_member_index == vnf_member_index, |
380 |
|
ScalingAlarm.vdu_name == alarm.vdu_name, |
381 |
|
) |
382 |
1 |
statuses = [] |
383 |
1 |
for alarm in alarms: |
384 |
1 |
statuses.append(alarm.last_status) |
385 |
1 |
if (operation == "AND" and set(statuses) == {"alarm"}) or ( |
386 |
|
operation == "OR" and "alarm" in statuses |
387 |
|
): |
388 |
1 |
delta = datetime.datetime.now() - scaling_policy.last_scale |
389 |
1 |
if delta.total_seconds() > scaling_policy.cooldown_time: |
390 |
1 |
log.info( |
391 |
|
"Sending %s action message for ns: %s", |
392 |
|
alarm.action, |
393 |
|
scaling_policy.scaling_group.nsr_id, |
394 |
|
) |
395 |
1 |
await self.lcm_client.scale( |
396 |
|
scaling_policy.scaling_group.nsr_id, |
397 |
|
scaling_policy.scaling_group.name, |
398 |
|
vnf_member_index, |
399 |
|
action, |
400 |
|
) |
401 |
1 |
scaling_policy.last_scale = datetime.datetime.now() |
402 |
1 |
scaling_policy.save() |
403 |
|
|
404 |
0 |
except ScalingAlarm.DoesNotExist: |
405 |
0 |
log.debug( |
406 |
|
"There is no autoscaling action configured for alarm %s.", alarm_uuid |
407 |
|
) |
408 |
|
finally: |
409 |
1 |
database.db.close() |
410 |
|
|
411 |
1 |
def _get_all_vnfd_monitoring_params(self, vnfd): |
412 |
1 |
all_monitoring_params = {} |
413 |
1 |
for ivld in vnfd.get("int-virtual-link-desc", ()): |
414 |
0 |
for mp in ivld.get("monitoring-parameters", ()): |
415 |
0 |
all_monitoring_params[mp.get("id")] = mp |
416 |
|
|
417 |
1 |
for vdu in vnfd.get("vdu", ()): |
418 |
1 |
for mp in vdu.get("monitoring-parameter", ()): |
419 |
1 |
all_monitoring_params[mp.get("id")] = mp |
420 |
|
|
421 |
1 |
for df in vnfd.get("df", ()): |
422 |
1 |
for mp in df.get("monitoring-parameter", ()): |
423 |
0 |
all_monitoring_params[mp.get("id")] = mp |
424 |
|
|
425 |
1 |
return all_monitoring_params |
426 |
|
|
427 |
1 |
def _get_or_create_scaling_group( |
428 |
|
self, nsr_id: str, vnf_member_index: str, scaling_aspect: dict |
429 |
|
): |
430 |
1 |
try: |
431 |
1 |
scaling_group_record = ScalingGroupRepository.get( |
432 |
|
ScalingGroup.nsr_id == nsr_id, |
433 |
|
ScalingGroup.vnf_member_index == vnf_member_index, |
434 |
|
ScalingGroup.name == scaling_aspect["name"], |
435 |
|
) |
436 |
0 |
log.debug("Found existing scaling group record in DB...") |
437 |
1 |
except ScalingGroup.DoesNotExist: |
438 |
1 |
log.debug("Creating scaling group record in DB...") |
439 |
1 |
scaling_group_record = ScalingGroupRepository.create( |
440 |
|
nsr_id=nsr_id, |
441 |
|
vnf_member_index=vnf_member_index, |
442 |
|
name=scaling_aspect["name"], |
443 |
|
content=json.dumps(scaling_aspect), |
444 |
|
) |
445 |
1 |
log.debug( |
446 |
|
"Created scaling group record in DB : nsr_id=%s, vnf_member_index=%s, name=%s", |
447 |
|
scaling_group_record.nsr_id, |
448 |
|
scaling_group_record.vnf_member_index, |
449 |
|
scaling_group_record.name, |
450 |
|
) |
451 |
1 |
return scaling_group_record |
452 |
|
|
453 |
1 |
def _get_or_create_scaling_policy( |
454 |
|
self, nsr_id: str, scaling_policy: dict, scaling_group_record: ScalingGroup |
455 |
|
): |
456 |
1 |
try: |
457 |
1 |
scaling_policy_record = ScalingPolicyRepository.get( |
458 |
|
ScalingPolicy.name == scaling_policy["name"], |
459 |
|
ScalingGroup.id == scaling_group_record.id, |
460 |
|
join_classes=[ScalingGroup], |
461 |
|
) |
462 |
0 |
log.debug("Found existing scaling policy record in DB...") |
463 |
1 |
except ScalingPolicy.DoesNotExist: |
464 |
1 |
log.debug("Creating scaling policy record in DB...") |
465 |
1 |
scaling_policy_record = ScalingPolicyRepository.create( |
466 |
|
nsr_id=nsr_id, |
467 |
|
name=scaling_policy["name"], |
468 |
|
cooldown_time=scaling_policy["cooldown-time"], |
469 |
|
scaling_group=scaling_group_record, |
470 |
|
) |
471 |
1 |
if "scale-in-operation-type" in scaling_policy: |
472 |
0 |
scaling_policy_record.scale_in_operation = scaling_policy[ |
473 |
|
"scale-in-operation-type" |
474 |
|
] |
475 |
1 |
if "scale-out-operation-type" in scaling_policy: |
476 |
0 |
scaling_policy_record.scale_out_operation = scaling_policy[ |
477 |
|
"scale-out-operation-type" |
478 |
|
] |
479 |
1 |
if "enabled" in scaling_policy: |
480 |
0 |
scaling_policy_record.enabled = scaling_policy["enabled"] |
481 |
1 |
scaling_policy_record.save() |
482 |
1 |
log.debug( |
483 |
|
"Created scaling policy record in DB : name=%s, scaling_group.name=%s", |
484 |
|
scaling_policy_record.name, |
485 |
|
scaling_policy_record.scaling_group.name, |
486 |
|
) |
487 |
1 |
return scaling_policy_record |
488 |
|
|
489 |
1 |
def _get_or_create_scaling_criteria( |
490 |
|
self, nsr_id: str, scaling_criteria: dict, scaling_policy_record: ScalingPolicy |
491 |
|
): |
492 |
1 |
try: |
493 |
1 |
scaling_criteria_record = ScalingCriteriaRepository.get( |
494 |
|
ScalingPolicy.id == scaling_policy_record.id, |
495 |
|
ScalingCriteria.name == scaling_criteria["name"], |
496 |
|
join_classes=[ScalingPolicy], |
497 |
|
) |
498 |
0 |
log.debug("Found existing scaling criteria record in DB...") |
499 |
1 |
except ScalingCriteria.DoesNotExist: |
500 |
1 |
log.debug("Creating scaling criteria record in DB...") |
501 |
1 |
scaling_criteria_record = ScalingCriteriaRepository.create( |
502 |
|
nsr_id=nsr_id, |
503 |
|
name=scaling_criteria["name"], |
504 |
|
scaling_policy=scaling_policy_record, |
505 |
|
) |
506 |
1 |
log.debug( |
507 |
|
"Created scaling criteria record in DB : name=%s, scaling_policy.name=%s", |
508 |
|
scaling_criteria_record.name, |
509 |
|
scaling_criteria_record.scaling_policy.name, |
510 |
|
) |
511 |
1 |
return scaling_criteria_record |
512 |
|
|
513 |
1 |
def _get_monitored_vdurs(self, scaling_aspect: dict, vdurs): |
514 |
1 |
all_monitored_vdus = set() |
515 |
1 |
for delta in scaling_aspect.get("aspect-delta-details", {}).get("deltas", ()): |
516 |
1 |
for vdu_delta in delta.get("vdu-delta", ()): |
517 |
1 |
all_monitored_vdus.add(vdu_delta.get("id")) |
518 |
|
|
519 |
1 |
monitored_vdurs = list( |
520 |
|
filter(lambda vdur: vdur["vdu-id-ref"] in all_monitored_vdus, vdurs) |
521 |
|
) |
522 |
|
|
523 |
1 |
if not monitored_vdurs: |
524 |
0 |
log.warning( |
525 |
|
"Scaling criteria is referring to a vnf-monitoring-param that does not " |
526 |
|
"contain a reference to a vdu or vnf metric." |
527 |
|
) |
528 |
1 |
return monitored_vdurs |
529 |
|
|
530 |
1 |
def _get_metric_name(self, vnf_monitoring_param: dict): |
531 |
1 |
if "performance-metric" in vnf_monitoring_param: |
532 |
1 |
return vnf_monitoring_param["performance-metric"] |
533 |
0 |
raise ValueError( |
534 |
|
"No metric name found for vnf_monitoring_param %s" |
535 |
|
% vnf_monitoring_param["id"] |
536 |
|
) |