From 5d62091db1bdfebb296b669c710cfdcb5d62834c Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Mon, 15 Jul 2013 14:48:38 +0200 Subject: Added alerts Alerts data are now mocked in local db. There are precreated 3 alerts for rack and node - it expects that there will exist rack with id 1 and nodes with ids 1 and 2. This is for demo purpose. Currently nodes alerts are not displayed because nodes-related API logic is not there yet (we return empty array of nodes for each rack). Change-Id: Ic8a16db2f13909dceb700f2c99269960253da88b --- openstack_dashboard/api/tuskar.py | 45 ++++++++++++++++++++++ .../infrastructure/fixtures/initial_data.json | 5 ++- .../dashboards/infrastructure/models.py | 10 +++++ .../nodes/_detail_overview.html | 6 ++- .../racks/_detail_overview.html | 24 ++++++++++++ .../resource_classes/_detail_overview.html | 18 +++++---- .../static/infrastructure/less/infrastructure.less | 4 ++ 7 files changed, 102 insertions(+), 10 deletions(-) diff --git a/openstack_dashboard/api/tuskar.py b/openstack_dashboard/api/tuskar.py index 12b4c393..0f86cadf 100644 --- a/openstack_dashboard/api/tuskar.py +++ b/openstack_dashboard/api/tuskar.py @@ -82,6 +82,13 @@ class StringIdAPIResourceWrapper(base.APIResourceWrapper): setattr(self, '_request', value) +class Alert(StringIdAPIResourceWrapper): + """Wrapper for the Alert object returned by the + dummy model. + """ + _attrs = ['message', 'time'] + + class Capacity(StringIdAPIResourceWrapper): """Wrapper for the Capacity object returned by the dummy model. @@ -246,6 +253,15 @@ class Node(StringIdAPIResourceWrapper): def is_provisioned(self): return False + @property + def alerts(self): + if not hasattr(self, '_alerts'): + self._alerts = [Alert(a) for a in + dummymodels.Alert.objects + .filter(object_type='node') + .filter(object_id=int(self.id))] + return self._alerts + class Rack(StringIdAPIResourceWrapper): """Wrapper for the Rack object returned by the @@ -304,6 +320,13 @@ class Rack(StringIdAPIResourceWrapper): def delete(cls, request, rack_id): tuskarclient(request).racks.delete(rack_id) + @property + def node_ids(self): + """ List of unicode ids of nodes added to rack""" + return [ + unicode(node['id']) for node in ( + self._apiresource.nodes)] + ## FIXME: this will have to be rewritten to ultimately ## fetch nodes from nova baremetal @property @@ -372,6 +395,21 @@ class Rack(StringIdAPIResourceWrapper): self._vm_capacity = Capacity(vm_capacity) return self._vm_capacity + @property + def alerts(self): + if not hasattr(self, '_alerts'): + self._alerts = [Alert(a) for a in + dummymodels.Alert.objects + .filter(object_type='rack') + .filter(object_id=int(self.id))] + return self._alerts + + @property + def aggregated_alerts(self): + # FIXME: for now return only list of nodes (particular alerts are not + # used) + return [node for node in self.list_nodes if node.alerts] + class ResourceClass(StringIdAPIResourceWrapper): """Wrapper for the ResourceClass object returned by the @@ -626,6 +664,13 @@ class ResourceClass(StringIdAPIResourceWrapper): racks = [{'id': rid} for rid in racks_ids] tuskarclient(request).resource_classes.update(self.id, racks=racks) + @property + def aggregated_alerts(self): + # FIXME: for now return only list of racks (particular alerts are not + # used) + return [rack for rack in self.list_racks if (rack.alerts + + rack.aggregated_alerts)] + class FlavorTemplate(StringIdAPIResourceWrapper): """Wrapper for the Flavor object returned by the diff --git a/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json b/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json index 870f3dc5..5cbd8e2c 100644 --- a/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json +++ b/openstack_dashboard/dashboards/infrastructure/fixtures/initial_data.json @@ -87,5 +87,8 @@ {"pk": 52, "model": "infrastructure.capacity", "fields": {"value": 16384, "unit": "MB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "memory"}}, {"pk": 53, "model": "infrastructure.capacity", "fields": {"value": 160, "unit": "GB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "storage"}}, {"pk": 54, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "GB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "ephemeral_disk"}}, - {"pk": 55, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}} + {"pk": 55, "model": "infrastructure.capacity", "fields": {"value": 0, "unit": "MB", "object_id": 7, "content_type": ["infrastructure", "flavortemplate"], "name": "swap_disk"}}, + {"pk": 1, "model": "infrastructure.alert", "fields": {"message": "Switch is not accessible.", "object_id": 1, "object_type": "rack", "time": "2011-09-01T13:20:30+03:00"}}, + {"pk": 2, "model": "infrastructure.alert", "fields": {"message": "Nova service is not running.", "object_id": 1, "object_type": "node", "time": "2011-09-01T13:20:30+03:00"}}, + {"pk": 3, "model": "infrastructure.alert", "fields": {"message": "Disk usage is over 90%.", "object_id": 1, "object_type": "node", "time": "2011-09-01T13:20:30+03:00"}} ] diff --git a/openstack_dashboard/dashboards/infrastructure/models.py b/openstack_dashboard/dashboards/infrastructure/models.py index f552ce9a..513e463d 100644 --- a/openstack_dashboard/dashboards/infrastructure/models.py +++ b/openstack_dashboard/dashboards/infrastructure/models.py @@ -30,6 +30,16 @@ class Capacity(models.Model): unit = models.CharField(max_length=10) +class Alert(models.Model): + class Meta: + db_table = 'infrastructure_alerts' + + object_id = models.PositiveIntegerField() + object_type = models.CharField(max_length=20) + message = models.CharField(max_length=250) + time = models.DateTimeField() + + class FlavorTemplate(models.Model): class Meta: db_table = 'infrastructure_flavortemplate' diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/_detail_overview.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/_detail_overview.html index 22510e53..e6823ed0 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/_detail_overview.html +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/_detail_overview.html @@ -159,7 +159,11 @@

{% trans "Active alerts" %}


{% if node.is_provisioned %} - + {% else %}

{% trans "No data available yet." %}

{% endif %} diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/racks/_detail_overview.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/racks/_detail_overview.html index 78e8ea11..9f3aebe2 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/racks/_detail_overview.html +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/racks/_detail_overview.html @@ -53,6 +53,30 @@ +
+
+

{% trans "Summary of instances and Usage" %}

+
+ TODO +
+ +
+

{% trans "Active Alerts" %}

+
+
    + {% for alert in rack.alerts %} +
  • {{ alert.message }}
  • + {% endfor %} + {% for node in rack.aggregated_alerts %} +
  • + + Node {{ node.name }} has some problems +
  • + {% endfor %} +
+
+
+
diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html index 0c8fbb2e..9921ace8 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_detail_overview.html @@ -103,15 +103,17 @@
-
-

{% trans "Virtual Capacity" %}

+
+

{% trans "Active Alerts" %}


-
- {% for flavor_count in resource_class.list_flavors %} -
{{ flavor_count.flavor.name }}
-
{{ flavor_count.max_vms }}
- {% endfor %} -
+
    + {% for rack in resource_class.aggregated_alerts %} +
  • + + Rack {{ rack.name }} has some problems +
  • + {% endfor %} +
diff --git a/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less b/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less index 7fe8cba5..cc4c9204 100644 --- a/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less +++ b/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less @@ -370,3 +370,7 @@ svg { input { border-radius: 2px; } + +.alerts .icon-warning-sign { + padding-right: 5px; +} -- cgit v1.2.1