X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=policy_module%2Fosm_policy_module%2Fcommon%2Flcm_client.py;h=be44efe361eb381909cfe2905de870bb2220119d;hb=2f1be6ba8722211068fb678bc1048283f275f0af;hp=99e3ffbd95809da8f08a8db04dc5a5e5d6246e92;hpb=62781ff00b30790610cf4cc2ef5ed5422c571e10;p=osm%2FMON.git diff --git a/policy_module/osm_policy_module/common/lcm_client.py b/policy_module/osm_policy_module/common/lcm_client.py index 99e3ffb..be44efe 100644 --- a/policy_module/osm_policy_module/common/lcm_client.py +++ b/policy_module/osm_policy_module/common/lcm_client.py @@ -1,27 +1,52 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# 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. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## import json +import logging from kafka import KafkaProducer from osm_policy_module.core.config import Config +log = logging.getLogger(__name__) + class LcmClient: def __init__(self): cfg = Config.instance() - self.kafka_server = { - 'server': '{}:{}'.format(cfg.get('policy_module', 'kafka_server_host'), - cfg.get('policy_module', 'kafka_server_port'))} + self.kafka_server = '{}:{}'.format(cfg.get('policy_module', 'kafka_server_host'), + cfg.get('policy_module', 'kafka_server_port')) self.producer = KafkaProducer(bootstrap_servers=self.kafka_server, key_serializer=str.encode, - value_serializer=lambda v: json.dumps(v).encode('utf-8')) + value_serializer=str.encode) - def scale(self, nsr_id, name, action): + def scale(self, nsr_id: str, name: str, action: str): msg = self._create_scale_action_payload(nsr_id, name, action) - self.producer.send(topic='alarm_request', key='create_alarm_request', value=msg) + log.info("Sending scale action message: %s", json.dumps(msg)) + self.producer.send(topic='lcm_pm', key='trigger_scaling', value=json.dumps(msg)) self.producer.flush() - pass - def _create_scale_action_payload(self, nsr_id, name, action): + def _create_scale_action_payload(self, nsr_id: str, name: str, action: str): msg = { "ns_id": nsr_id, "scaling_group_descriptor": {