1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: bdiaz@whitestack.com or glavado@whitestack.com
30 from osm_policy_module
.common
.common_db_client
import CommonDbClient
31 from osm_policy_module
.common
.message_bus_client
import MessageBusClient
32 from osm_policy_module
.core
.config
import Config
34 log
= logging
.getLogger(__name__
)
39 Client to communicate with LCM through the message bus.
42 def __init__(self
, config
: Config
):
43 self
.db_client
= CommonDbClient(config
)
44 self
.msg_bus
= MessageBusClient(config
)
47 self
, nsr_id
: str, scaling_group_name
: str, vnf_member_index
: str, action
: str
50 Sends scaling action to LCM through the message bus.
52 :param nsr_id: Network service record id
53 :param scaling_group_name: Scaling group name
54 :param vnf_member_index: VNF member index
55 :param action: Scaling action to be executed. Valid values: scale_in, scale_out
59 "scale %s %s %s %s", nsr_id
, scaling_group_name
, vnf_member_index
, action
61 nsr
= self
.db_client
.get_nsr(nsr_id
)
62 nslcmop
= self
._generate
_nslcmop
(
63 nsr_id
, scaling_group_name
, vnf_member_index
, action
, nsr
["_admin"]
65 self
.db_client
.create_nslcmop(nslcmop
)
66 log
.debug("Sending scale action message: %s", json
.dumps(nslcmop
))
67 await self
.msg_bus
.aiowrite("ns", "scale", nslcmop
)
69 def _generate_nslcmop(
72 scaling_group_name
: str,
73 vnf_member_index
: str,
78 Builds scaling nslcmop.
80 :param nsr_id: Network service record id
81 :param scaling_group_name: Scaling group name
82 :param vnf_member_index: VNF member index
83 :param action: Scaling action to be executed. Valid values: scale_in, scale_out
84 :param admin: Dict corresponding to the _admin section of the nsr. Required keys: projects_read, projects_write.
88 "_generate_nslcmop %s %s %s %s %s",
95 _id
= str(uuid
.uuid4())
98 "scaleType": "SCALE_VNF",
100 "scaleVnfType": action
.upper(),
102 "scaling-group-descriptor": scaling_group_name
,
103 "member-vnf-index": vnf_member_index
,
106 "scaleTime": "{}Z".format(datetime
.datetime
.utcnow().isoformat()),
112 "operationState": "PROCESSING",
113 "statusEnteredTime": now
,
114 "nsInstanceId": nsr_id
,
115 "lcmOperationType": "scale",
117 "isAutomaticInvocation": True,
118 "operationParams": params
,
119 "isCancelPending": False,
121 "self": "/osm/nslcm/v1/ns_lcm_op_occs/" + _id
,
122 "nsInstance": "/osm/nslcm/v1/ns_instances/" + nsr_id
,
125 "projects_read": admin
["projects_read"],
126 "projects_write": admin
["projects_write"],
137 vnf_member_index
: str,
143 Sends healing action to LCM through the message bus.
145 param nsr_id: Network service record id
146 param vdu_id: Scaling vdu id
147 param vnf_member_index: VNF member index
148 param heal_type: healing action to be executed. Valid values: restart,respawn
149 param day1: To run day1 operations
150 param cause: cause of healing
154 "heal %s %s %s %s %s %s %s %s",
164 nsr
= self
.db_client
.get_nsr(nsr_id
)
165 nslcmop
= self
._generate
_nslcmop
_heal
(
176 self
.db_client
.create_nslcmop(nslcmop
)
177 log
.debug("Sending heal action message: %s", json
.dumps(nslcmop
))
178 await self
.msg_bus
.aiowrite("ns", "heal", nslcmop
)
180 def _generate_nslcmop_heal(
186 vnf_member_index
: str,
193 Builds healing nslcmop.
194 param nsr_id: Network service record id
195 param vnf_member_index: VNF member index
196 param action: healing action to be executed. Valid values: restart, respawn
197 param admin: Dict corresponding to the _admin section of the nsr. Required keys: projects_read, projects_write.
201 "_generate_nslcmop_heal %s %s %s %s %s %s %s %s %s",
212 _id
= str(uuid
.uuid4())
215 "lcmOperationType": "heal",
216 "nsInstanceId": nsr_id
,
219 "vnfInstanceId": vnfinstance_id
,
221 "additionalParams": {
226 "count-index": count_index
,
238 "operationState": "PROCESSING",
239 "statusEnteredTime": now
,
240 "nsInstanceId": nsr_id
,
241 "member-vnf-index": vnf_member_index
,
242 "lcmOperationType": "heal",
244 "location": "default",
245 "isAutomaticInvocation": True,
246 "operationParams": params
,
247 "isCancelPending": False,
249 "self": "/osm/nslcm/v1/ns_lcm_op_occs/" + _id
,
250 "nsInstance": "/osm/nslcm/v1/ns_instances/" + nsr_id
,
253 "projects_read": admin
["projects_read"],
254 "projects_write": admin
["projects_write"],