Files
deb-python-fuelclient/fuelclient/objects/notifications.py
Przemyslaw Kaminski 3355e188ee Add 'notifications' argument
This can be used for displaying and sending notifications to Fuel.

Send an error message:
fuel notify -m This is wrong --topic error
fuel notifications --send Hello world

List all unread notifications:
fuel notifications

List all notifications:
fuel notifications -a

Mark messages as read:
fuel notifications -r 1 2

Mark all messages as read:
fuel notifications -r '*'

DocImpact
Related-Bug: #1371757
Change-Id: I6a5f05febf8f5a01a7b9415546ef56c11aedefce
2015-02-02 15:51:26 +01:00

68 lines
2.0 KiB
Python

# Copyright 2015 Mirantis, Inc.
#
# 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.
from fuelclient.cli import error
from fuelclient.objects import base
class Notifications(base.BaseObject):
class_api_path = "notifications/"
instance_api_path = "notifications/{0}"
default_topic = 'done'
@classmethod
def mark_as_read(cls, ids=None):
if not ids:
raise error.BadDataException('Message id not specified.')
if '*' in ids:
data = Notifications.get_all_data()
else:
try:
ids = map(int, ids)
except ValueError:
raise error.BadDataException(
"Numerical ids expected or the '*' symbol.")
notifications = Notifications.get_by_ids(ids)
data = [notification.get_fresh_data()
for notification in notifications]
for notification in data:
notification['status'] = 'read'
resp = cls.connection.put_request(
cls.class_api_path, data)
return resp
@classmethod
def send(cls, message, topic=default_topic):
if not topic:
topic = cls.default_topic
if not message:
raise error.BadDataException('Message not specified.')
resp = cls.connection.post_request(
cls.class_api_path, {
'message': message,
'topic': topic,
})
return resp