5f1529a91671d6d4c033668eff49ab575d5383a1
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."""
27 log
= logging
.getLogger(__name__
)
29 schema_version
= "1.0"
32 class OpenStack_Response(object):
33 """Generates responses for OpenStack plugin."""
36 """Initialize OpenStack Response instance."""
38 def generate_response(self
, key
, **kwargs
):
39 """Make call to appropriate response function."""
40 if key
== "list_alarm_response":
41 message
= self
.alarm_list_response(**kwargs
)
42 elif key
== "create_alarm_response":
43 message
= self
.create_alarm_response(**kwargs
)
44 elif key
== "delete_alarm_response":
45 message
= self
.delete_alarm_response(**kwargs
)
46 elif key
== "update_alarm_response":
47 message
= self
.update_alarm_response(**kwargs
)
48 elif key
== "create_metric_response":
49 message
= self
.metric_create_response(**kwargs
)
50 elif key
== "read_metric_data_response":
51 message
= self
.read_metric_data_response(**kwargs
)
52 elif key
== "delete_metric_response":
53 message
= self
.delete_metric_response(**kwargs
)
54 elif key
== "update_metric_response":
55 message
= self
.update_metric_response(**kwargs
)
56 elif key
== "list_metric_response":
57 message
= self
.list_metric_response(**kwargs
)
58 elif key
== "notify_alarm":
59 message
= self
.notify_alarm(**kwargs
)
61 log
.warning("Failed to generate a valid response message.")
66 def alarm_list_response(self
, **kwargs
):
67 """Generate the response for an alarm list request."""
68 alarm_list_resp
= {"schema_version": schema_version
,
69 "schema_type": "list_alarm_response",
70 "correlation_id": kwargs
['cor_id'],
71 "list_alarm_response": kwargs
['alarm_list']}
72 return json
.dumps(alarm_list_resp
)
74 def create_alarm_response(self
, **kwargs
):
75 """Generate a response for a create alarm request."""
76 create_alarm_resp
= {"schema_version": schema_version
,
77 "schema_type": "create_alarm_response",
78 "alarm_create_response": {
79 "correlation_id": kwargs
['cor_id'],
80 "alarm_uuid": kwargs
['alarm_id'],
81 "status": kwargs
['status']}}
82 return json
.dumps(create_alarm_resp
)
84 def delete_alarm_response(self
, **kwargs
):
85 """Generate a response for a delete alarm request."""
86 delete_alarm_resp
= {"schema_version": schema_version
,
87 "schema_type": "alarm_deletion_response",
88 "alarm_deletion_response": {
89 "correlation_id": kwargs
['cor_id'],
90 "alarm_uuid": kwargs
['alarm_id'],
91 "status": kwargs
['status']}}
92 return json
.dumps(delete_alarm_resp
)
94 def update_alarm_response(self
, **kwargs
):
95 """Generate a response for an update alarm request."""
96 update_alarm_resp
= {"schema_version": schema_version
,
97 "schema_type": "update_alarm_response",
98 "alarm_update_response": {
99 "correlation_id": kwargs
['cor_id'],
100 "alarm_uuid": kwargs
['alarm_id'],
101 "status": kwargs
['status']}}
102 return json
.dumps(update_alarm_resp
)
104 def metric_create_response(self
, **kwargs
):
105 """Generate a response for a create metric request."""
106 create_metric_resp
= {"schema_version": schema_version
,
107 "schema_type": "create_metric_response",
108 "correlation_id": kwargs
['cor_id'],
109 "metric_create_response": {
110 "metric_uuid": kwargs
['metric_id'],
111 "resource_uuid": kwargs
['resource_id'],
112 "status": kwargs
['status']}}
113 return json
.dumps(create_metric_resp
)
115 def read_metric_data_response(self
, **kwargs
):
116 """Generate a response for a read metric data request."""
117 read_metric_data_resp
= {"schema_version": schema_version
,
118 "schema_type": "read_metric_data_response",
119 "metric_name": kwargs
['metric_name'],
120 "metric_uuid": kwargs
['metric_id'],
121 "resource_uuid": kwargs
['resource_id'],
122 "correlation_id": kwargs
['cor_id'],
123 "status": kwargs
['status'],
125 "time_series": kwargs
['times'],
126 "metrics_series": kwargs
['metrics']}}
127 return json
.dumps(read_metric_data_resp
)
129 def delete_metric_response(self
, **kwargs
):
130 """Generate a response for a delete metric request."""
131 delete_metric_resp
= {"schema_version": schema_version
,
132 "schema_type": "delete_metric_response",
133 "metric_name": kwargs
['metric_name'],
134 "metric_uuid": kwargs
['metric_id'],
135 "resource_uuid": kwargs
['resource_id'],
136 "correlation_id": kwargs
['cor_id'],
137 "status": kwargs
['status']}
138 return json
.dumps(delete_metric_resp
)
140 def update_metric_response(self
, **kwargs
):
141 """Generate a repsonse for an update metric request."""
142 update_metric_resp
= {"schema_version": schema_version
,
143 "schema_type": "update_metric_response",
144 "correlation_id": kwargs
['cor_id'],
145 "metric_update_response": {
146 "metric_uuid": kwargs
['metric_id'],
147 "status": kwargs
['status'],
148 "resource_uuid": kwargs
['resource_id']}}
149 return json
.dumps(update_metric_resp
)
151 def list_metric_response(self
, **kwargs
):
152 """Generate a response for a list metric request."""
153 list_metric_resp
= {"schema_version": schema_version
,
154 "schema_type": "list_metric_response",
155 "correlation_id": kwargs
['cor_id'],
156 "status": kwargs
['status'],
157 "metrics_list": kwargs
['metric_list']}
158 return json
.dumps(list_metric_resp
)
160 def notify_alarm(self
, **kwargs
):
161 """Generate a response to send alarm notifications."""
162 notify_alarm_resp
= {"schema_version": schema_version
,
163 "schema_type": "notify_alarm",
165 "alarm_uuid": kwargs
['alarm_id'],
166 "vdu_name": kwargs
['vdu_name'],
167 "vnf_member_index": kwargs
['vnf_member_index'],
168 "ns_id": kwargs
['ns_id'],
169 "metric_name": kwargs
['metric_name'],
170 "threshold_value": kwargs
['threshold_value'],
171 "operation": kwargs
['operation'],
172 "severity": kwargs
['sev'],
173 "status": kwargs
['state'],
174 "start_date": kwargs
['date']}}
175 return json
.dumps(notify_alarm_resp
)