1 # Copyright 2017 Intel Research and Development Ireland Limited
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Intel Corporation
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: helena.mcgough@intel.com or adrian.hoban@intel.com
22 """Generate valid responses to send back to the SO."""
26 log
= logging
.getLogger(__name__
)
28 schema_version
= "1.1"
31 class ResponseBuilder(object):
32 """Generates responses for OpenStack plugin."""
35 """Initialize OpenStack Response instance."""
37 def generate_response(self
, key
, **kwargs
) -> dict:
38 """Make call to appropriate response function."""
39 if key
== "create_alarm_response":
40 message
= self
.create_alarm_response(**kwargs
)
41 elif key
== "delete_alarm_response":
42 message
= self
.delete_alarm_response(**kwargs
)
43 elif key
== "notify_alarm":
44 message
= self
.notify_alarm(**kwargs
)
46 log
.warning("Failed to generate a valid response message.")
51 def create_alarm_response(self
, **kwargs
) -> dict:
52 """Generate a response for a create alarm request."""
54 "schema_version": schema_version
,
55 "schema_type": "create_alarm_response",
56 "alarm_create_response": {
57 "correlation_id": kwargs
["cor_id"],
58 "alarm_uuid": kwargs
["alarm_id"],
59 "status": kwargs
["status"],
62 return create_alarm_resp
64 def delete_alarm_response(self
, **kwargs
) -> dict:
65 """Generate a response for a delete alarm request."""
67 "schema_version": schema_version
,
68 "schema_type": "alarm_delete_response",
69 "alarm_delete_response": {
70 "correlation_id": kwargs
["cor_id"],
71 "alarm_uuid": kwargs
["alarm_id"],
72 "status": kwargs
["status"],
75 return delete_alarm_resp
77 def notify_alarm(self
, **kwargs
) -> dict:
78 """Generate a response to send alarm notifications."""
80 "schema_version": schema_version
,
81 "schema_type": "notify_alarm",
83 "alarm_uuid": kwargs
["alarm_id"],
84 "metric_name": kwargs
["metric_name"],
85 "threshold_value": kwargs
["threshold_value"],
86 "operation": kwargs
["operation"],
87 "severity": kwargs
["sev"],
88 "status": kwargs
["status"],
89 "start_date": kwargs
["date"],
90 "tags": kwargs
["tags"],
93 return notify_alarm_resp