summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Tomasek <jtomasek@redhat.com>2013-07-23 15:30:42 +0200
committerTomas Sedovic <tomas@sedovic.cz>2013-08-01 16:18:56 +0200
commit4caba1d04f5e59e381c4c9dd2682cda72e5e5162 (patch)
tree8d38c03674e37c7da5525b977af00cf43abf4aa8
parent06bfaffa1726c6a5a76fa272a7da915bad358e68 (diff)
downloadtuskar-ui-4caba1d04f5e59e381c4c9dd2682cda72e5e5162.tar.gz
Rack detail capacities consume API, template tweaks
Change-Id: I681c71ceece68e42dbdd1cdf10a0723d65b5b2ee
-rw-r--r--openstack_dashboard/api/tuskar.py145
-rw-r--r--openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/index.html11
-rw-r--r--openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/unracked.html17
-rw-r--r--openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/racks/_detail_overview.html58
-rw-r--r--openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less4
-rw-r--r--openstack_dashboard/dashboards/infrastructure/templates/infrastructure/base_detail.html15
6 files changed, 81 insertions, 169 deletions
diff --git a/openstack_dashboard/api/tuskar.py b/openstack_dashboard/api/tuskar.py
index be4f690e..36acdf5a 100644
--- a/openstack_dashboard/api/tuskar.py
+++ b/openstack_dashboard/api/tuskar.py
@@ -22,6 +22,7 @@ from random import randint
from django.conf import settings
from django.db.models import Sum, Max
from django.utils.translation import ugettext_lazy as _
+from horizon import exceptions
from tuskarclient.v1 import client as tuskar_client
@@ -47,6 +48,24 @@ class StringIdAPIResourceWrapper(base.APIResourceWrapper):
# Because of this, ids returned from dummy api are converted to string
# (luckily django autoconverts strings to integers when passing string to
# django model id)
+
+ # FIXME
+ # this is redefined from base.APIResourceWrapper,
+ # remove this when tuskarclient returns object instead of dict
+ def __getattr__(self, attr):
+ if attr in self._attrs:
+ if issubclass(self._apiresource.__class__, dict):
+ return self._apiresource.get(attr)
+ else:
+ return self._apiresource.__getattribute__(attr)
+ else:
+ msg = ('Attempted to access unknown attribute "%s" on '
+ 'APIResource object of type "%s" wrapping resource of '
+ 'type "%s".') % (attr, self.__class__,
+ self._apiresource.__class__)
+ LOG.debug(exceptions.error_color(msg))
+ raise AttributeError(attr)
+
@property
def id(self):
return str(self._apiresource.id)
@@ -94,7 +113,7 @@ class Capacity(StringIdAPIResourceWrapper):
@property
def usage(self):
if not hasattr(self, '_usage'):
- self._usage = randint(0, self.value)
+ self._usage = randint(0, int(self.value))
return self._usage
# defines a random average of capacity - API should probably be able to
@@ -102,7 +121,7 @@ class Capacity(StringIdAPIResourceWrapper):
@property
def average(self):
if not hasattr(self, '_average'):
- self._average = randint(0, self.value)
+ self._average = randint(0, int(self.value))
return self._average
@@ -277,105 +296,6 @@ class Rack(StringIdAPIResourceWrapper):
rclass = getattr(self._apiresource, 'resource_class', None)
return rclass['id'] if rclass else None
- @property
- def capacities(self):
- if not hasattr(self, '_capacities'):
- self._capacities = [Capacity(c) for c in
- self._apiresource.capacities.all()]
- return self._capacities
-
- @property
- def cpu(self):
- if not hasattr(self, '_cpu'):
- try:
- attrs = dummymodels.Capacity.objects\
- .filter(node__rack=self._apiresource)\
- .values('name', 'unit').annotate(value=Sum('value'))\
- .filter(name='cpu')[0]
- except:
- attrs = {'name': 'cpu',
- 'value': _('Unable to retrieve '
- '(Are the nodes configured properly?)'),
- 'unit': ''}
- cpu = dummymodels.Capacity(name=attrs['name'],
- value=attrs['value'],
- unit=attrs['unit'])
- self._cpu = Capacity(cpu)
- return self._cpu
-
- @property
- def ram(self):
- if not hasattr(self, '_ram'):
- try:
- attrs = dummymodels.Capacity.objects\
- .filter(node__rack=self._apiresource)\
- .values('name', 'unit').annotate(value=Sum('value'))\
- .filter(name='ram')[0]
- except:
- attrs = {'name': 'ram',
- 'value': _('Unable to retrieve '
- '(Are the nodes configured properly?)'),
- 'unit': ''}
- ram = dummymodels.Capacity(name=attrs['name'],
- value=attrs['value'],
- unit=attrs['unit'])
- self._ram = Capacity(ram)
- return self._ram
-
- @property
- def storage(self):
- if not hasattr(self, '_storage'):
- try:
- attrs = dummymodels.Capacity.objects\
- .filter(node__rack=self._apiresource)\
- .values('name', 'unit').annotate(value=Sum('value'))\
- .filter(name='storage')[0]
- except:
- attrs = {'name': 'storage',
- 'value': _('Unable to retrieve '
- '(Are the nodes configured properly?)'),
- 'unit': ''}
- storage = dummymodels.Capacity(name=attrs['name'],
- value=attrs['value'],
- unit=attrs['unit'])
- self._storage = Capacity(storage)
- return self._storage
-
- @property
- def network(self):
- if not hasattr(self, '_network'):
- try:
- attrs = dummymodels.Capacity.objects\
- .filter(node__rack=self._apiresource)\
- .values('name', 'unit').annotate(value=Sum('value'))\
- .filter(name='network')[0]
- except:
- attrs = {'name': 'network',
- 'value': _('Unable to retrieve '
- '(Are the nodes configured properly?)'),
- 'unit': ''}
- network = dummymodels.Capacity(name=attrs['name'],
- value=attrs['value'],
- unit=attrs['unit'])
- self._network = Capacity(network)
- return self._network
-
- @property
- def vm_capacity(self):
- if not hasattr(self, '_vm_capacity'):
- try:
- value = dummymodels.ResourceClassFlavor.objects\
- .filter(resource_class__rack=self._apiresource)\
- .aggregate(Max("max_vms"))['max_vms__max']
- except:
- value = _("Unable to retrieve vm capacity")
-
- vm_capacity = dummymodels.Capacity(name=_("Max VMs"),
- value=value,
- unit=_("VMs"))
- self._vm_capacity = Capacity(vm_capacity)
- return self._vm_capacity
-
@classmethod
def delete(cls, request, rack_id):
tuskarclient(request).racks.delete(rack_id)
@@ -425,6 +345,29 @@ class Rack(StringIdAPIResourceWrapper):
self._resource_class = None
return self._resource_class
+ @property
+ def capacities(self):
+ if not hasattr(self, '_capacities'):
+ self._capacities = [Capacity(c) for c in
+ self._apiresource.capacities]
+ return self._capacities
+
+ @property
+ def vm_capacity(self):
+ if not hasattr(self, '_vm_capacity'):
+ try:
+ value = dummymodels.ResourceClassFlavor.objects\
+ .filter(resource_class__rack=self._apiresource)\
+ .aggregate(Max("max_vms"))['max_vms__max']
+ except:
+ value = _("Unable to retrieve vm capacity")
+
+ vm_capacity = dummymodels.Capacity(name=_("Max VMs"),
+ value=value,
+ unit=_("VMs"))
+ self._vm_capacity = Capacity(vm_capacity)
+ return self._vm_capacity
+
class ResourceClass(StringIdAPIResourceWrapper):
"""Wrapper for the ResourceClass object returned by the
diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/index.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/index.html
index 1f0775a0..a86727e7 100644
--- a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/index.html
+++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/index.html
@@ -7,10 +7,13 @@
{% endblock page_header %}
{% block main %}
-
-<div class="breadcrumbs">
- <a href="{% url 'horizon:infrastructure:resource_management:index' %}?tab=resource_management_tabs__resource_classes_tab" >Home</a>
- <span class="separator"></span>
+<div class="row-fluid">
+ <div class="span12">
+ <div class="breadcrumbs">
+ <a href="{% url 'horizon:infrastructure:resource_management:index' %}?tab=resource_management_tabs__resource_classes_tab" >Home</a>
+ <span class="separator"></span>
+ </div>
+ </div>
</div>
<div class="row-fluid">
diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/unracked.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/unracked.html
index 6dd105be..19a3145a 100644
--- a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/unracked.html
+++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/nodes/unracked.html
@@ -8,16 +8,19 @@
{% block main %}
+<div class="row-fluid">
+ <div class="span12">
+ <div class="breadcrumbs">
+ <a href="{% url 'horizon:infrastructure:resource_management:index' %}?tab=resource_management_tabs__resource_classes_tab" >Home</a>
+ <span class="separator"></span>
+ <a href="{% url 'horizon:infrastructure:resource_management:index' %}?tab=resource_management_tabs__racks_tab" >Racks</a>
+ <span class="separator"></span>
+ </div>
-<div class="breadcrumbs">
- <a href="{% url 'horizon:infrastructure:resource_management:index' %}?tab=resource_management_tabs__resource_classes_tab" >Home</a>
- <span class="separator"></span>
- <a href="{% url 'horizon:infrastructure:resource_management:index' %}?tab=resource_management_tabs__racks_tab" >Racks</a>
- <span class="separator"></span>
+ <h3>{% trans "Unracked Nodes" %}</h3>
+ </div>
</div>
-<h3>{% trans "Unracked Nodes" %}</h3>
-
<div class="row-fluid">
<div class="span12">
{{ table.render }}
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 4eb2af12..0d093052 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
@@ -12,7 +12,7 @@
<dd>{{ rack.switch_ips|default:_("None") }}</dd>
<dt>{% trans "Location" %}</dt>
<dd>{{ rack.location|default:_("None") }}</dd>
- <dt>{% trans "Status" %}</dt>
+ <dt>{% trans "State" %}</dt>
<dd>{{ rack.state|default:_("None") }}</dd>
</dl>
</div>
@@ -32,62 +32,22 @@
<h4>{% trans "Capacities" %}</h4>
<hr class="header_rule">
<table class="capacities">
+ {% for capacity in rack.capacities %}
<tr>
- <td class="capacity_label">{% trans "CPU" %}:</td>
+ <td class="capacity_label">{{ capacity.name }}:</td>
<td>
- <div id="cpu_capacity_usage"
+ <div id="{{ capacity.name }}_capacity_usage"
class="capacity_bar"
- data-capacity-limit="{{ rack.cpu.value }}"
- data-capacity-used="{{ rack.cpu.usage }}"
- data-average-capacity-used="{{ 12 }}">
+ data-capacity-limit="{{ capacity.value }}"
+ data-capacity-used="{{ capacity.usage }}"
+ data-average-capacity-used="{{ capacity.average }}">
</div>
</td>
<td>
- <a href="#" class="modal_chart">{{ rack.cpu.usage }}/{{ rack.cpu.value }} {{ rack.cpu.unit }}</a>
- </td>
- </tr>
- <tr>
- <td class="capacity_label">{% trans "RAM" %}:</td>
- <td>
- <div id="ram_capacity_usage"
- class="capacity_bar"
- data-capacity-limit="{{ rack.ram.value }}"
- data-capacity-used="{{ rack.ram.usage }}"
- data-average-capacity-used="{{ 12 }}">
- </div>
- </td>
- <td>
- <a href="#" class="modal_chart">{{ rack.ram.usage }}/{{ rack.ram.value }} {{ rack.ram.unit }}</a>
- </td>
- </tr>
- <tr>
- <td class="capacity_label">{% trans "Storage" %}:</td>
- <td>
- <div id="storage_capacity_usage"
- class="capacity_bar"
- data-capacity-limit="{{ rack.storage.value }}"
- data-capacity-used="{{ rack.storage.usage }}"
- data-average-capacity-used="{{ 12 }}">
- </div>
- </td>
- <td>
- <a href="#" class="modal_chart">{{ rack.storage.usage }}/{{ rack.storage.value }} {{ rack.storage.unit }}</a>
- </td>
- </tr>
- <tr>
- <td class="capacity_label">{% trans "Network" %}:</td>
- <td>
- <div id="network_capacity_usage"
- class="capacity_bar"
- data-capacity-limit="{{ rack.network.value }}"
- data-capacity-used="{{ rack.network.usage }}"
- data-average-capacity-used="{{ 12 }}">
- </div>
- </td>
- <td>
- <a href="#" class="modal_chart">{{ rack.network.usage }}/{{ rack.network.value }} {{ rack.network.unit }}</a>
+ <a href="#" class="modal_chart">{{ capacity.usage|default:_(" - ") }}/{{ capacity.value|default:_(" - ") }} {{ capacity.unit }}</a>
</td>
</tr>
+ {% endfor %}
</table>
</div>
</div>
diff --git a/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less b/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less
index ae26ee65..ec6b0a8d 100644
--- a/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less
+++ b/openstack_dashboard/dashboards/infrastructure/static/infrastructure/less/infrastructure.less
@@ -202,7 +202,7 @@ table.table {
font-size: 24px;
color: rgb(120,120,120);
margin-bottom: 3px;
- margin: 0 0 3px 30px;
+ margin: 0 0 3px 0;
}
h4 {
@@ -315,7 +315,7 @@ svg {
.breadcrumbs {
font-size: 85%;
- margin: 0 30px 20px 30px;
+ margin: 0 0 20px 0;
a {
color: rgb(180, 180, 180);
diff --git a/openstack_dashboard/dashboards/infrastructure/templates/infrastructure/base_detail.html b/openstack_dashboard/dashboards/infrastructure/templates/infrastructure/base_detail.html
index bf55df8b..5fe69021 100644
--- a/openstack_dashboard/dashboards/infrastructure/templates/infrastructure/base_detail.html
+++ b/openstack_dashboard/dashboards/infrastructure/templates/infrastructure/base_detail.html
@@ -2,14 +2,17 @@
{% block main %}
-{% block breadcrumbs %}{% endblock %}
-
-<div class="pull-right btn-toolbar">
- {% block actions %}{% endblock %}
-</div>
+<div class="row-fluid">
+ <div class="span12">
+ {% block breadcrumbs %}{% endblock %}
-<h3>{% block name %}{% endblock %}</h3>
+ <div class="pull-right btn-toolbar">
+ {% block actions %}{% endblock %}
+ </div>
+ <h3>{% block name %}{% endblock %}</h3>
+ </div>
+</div>
<div class="row-fluid">
<div class="span12">