Migrate API to new signtures. Add Alarm delete.
This commit is contained in:
parent
d29fd8f48c
commit
e1a01ecf82
@ -22,9 +22,6 @@ from openstack_dashboard.api import base
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AttrStore:
|
||||
pass
|
||||
|
||||
def format_parameters(params):
|
||||
parameters = {}
|
||||
for count, p in enumerate(params, 1):
|
||||
@ -57,28 +54,19 @@ def monclient(request, password=None):
|
||||
|
||||
|
||||
def alarm_list(request, marker=None, paginate=False):
|
||||
args = AttrStore()
|
||||
args.runlocal = True
|
||||
args.os_tenant_id = "12345678"
|
||||
return monclient(request).alarms.list(args)
|
||||
return monclient(request).alarms.list()
|
||||
|
||||
|
||||
def alarm_delete(request, alarm_id):
|
||||
return monclient(request).alarms.delete(alarm_id)
|
||||
return monclient(request).alarms.delete(alarm_id=alarm_id)
|
||||
|
||||
|
||||
def alarm_get(request, alarm_id):
|
||||
args = AttrStore()
|
||||
args.runlocal = True
|
||||
args.os_tenant_id = "12345678"
|
||||
return monclient(request).alarms.get(args, alarm_id=alarm_id)
|
||||
return monclient(request).alarms.get(alarm_id=alarm_id)
|
||||
|
||||
|
||||
def alarm_create(request, password=None, **kwargs):
|
||||
args = AttrStore()
|
||||
args.runlocal = True
|
||||
args.os_tenant_id = "12345678"
|
||||
return monclient(request, password).alarms.create(args, **kwargs)
|
||||
return monclient(request, password).alarms.create(**kwargs)
|
||||
|
||||
|
||||
def alarm_update(request, alarm_id, **kwargs):
|
||||
@ -86,10 +74,7 @@ def alarm_update(request, alarm_id, **kwargs):
|
||||
|
||||
|
||||
def notification_list(request, marker=None, paginate=False):
|
||||
args = AttrStore()
|
||||
args.runlocal = True
|
||||
args.os_tenant_id = "12345678"
|
||||
return monclient(request).notifications.list(args)
|
||||
return monclient(request).notifications.list()
|
||||
|
||||
|
||||
def notification_delete(request, notification_id):
|
||||
@ -97,17 +82,11 @@ def notification_delete(request, notification_id):
|
||||
|
||||
|
||||
def notification_get(request, notification_id):
|
||||
args = AttrStore()
|
||||
args.runlocal = True
|
||||
args.os_tenant_id = "12345678"
|
||||
return monclient(request).notifications.get(args, notification_id=notification_id)
|
||||
return monclient(request).notifications.get(notification_id=notification_id)
|
||||
|
||||
|
||||
def notification_create(request, **kwargs):
|
||||
args = AttrStore()
|
||||
args.runlocal = True
|
||||
args.os_tenant_id = "12345678"
|
||||
return monclient(request).notifications.create(args, **kwargs)
|
||||
return monclient(request).notifications.create(**kwargs)
|
||||
|
||||
|
||||
def notification_update(request, notification_id, **kwargs):
|
||||
|
@ -158,6 +158,12 @@ class BaseAlarmForm(forms.SelfHandlingForm):
|
||||
self.fields['description'] = forms.CharField(label=_("Description"),
|
||||
required=False,
|
||||
widget=textAreaWidget)
|
||||
sev_choices = [("Low", _("Low")),
|
||||
("Medium", _("Medium")),
|
||||
("High", _("High"))]
|
||||
self.fields['severity'] = forms.ChoiceField(label=_("Severity"),
|
||||
choices=sev_choices,
|
||||
required=False)
|
||||
self.fields['state'] = forms.CharField(label=_("State"),
|
||||
required=False,
|
||||
widget=textWidget)
|
||||
@ -191,14 +197,12 @@ class CreateAlarmForm(BaseAlarmForm):
|
||||
self.fields.pop('state')
|
||||
self.fields['notifications'].choices = notification_choices
|
||||
|
||||
'''
|
||||
def clean_notifications(self):
|
||||
notifications = self.cleaned_data["notifications"]
|
||||
if len(notifications) == 0:
|
||||
msg = _('There must be at least one notification.')
|
||||
raise forms.ValidationError(msg)
|
||||
return notifications
|
||||
'''
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
|
@ -22,6 +22,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import tables
|
||||
|
||||
from . import constants
|
||||
from monitoring import api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -79,6 +80,19 @@ class CreateAlarm(tables.LinkAction):
|
||||
return True
|
||||
|
||||
|
||||
class DeleteAlarm(tables.DeleteAction):
|
||||
name = "delete_alarm"
|
||||
verbose_name = _("Delete Alarm")
|
||||
data_type_singular = _("Alarm")
|
||||
data_type_plural = _("Alarms")
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
|
||||
def delete(self, request, obj_id):
|
||||
api.monitor.alarm_delete(request, obj_id)
|
||||
|
||||
|
||||
class CreateNotification(tables.LinkAction):
|
||||
name = "create_notification"
|
||||
verbose_name = _("Create Notification")
|
||||
@ -124,7 +138,7 @@ class RealAlarmsTable(tables.DataTable):
|
||||
class Meta:
|
||||
name = "alarms"
|
||||
verbose_name = _("Alarms")
|
||||
row_actions = (ShowAlarmHistory, ShowAlarmMeters,)
|
||||
row_actions = (ShowAlarmHistory, ShowAlarmMeters, DeleteAlarm, )
|
||||
table_actions = (CreateNotification, CreateAlarm, )
|
||||
status_columns = ['state']
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user