From 28a75f49c046150144f15241fc950b39501ba905 Mon Sep 17 00:00:00 2001 From: Tres Henry Date: Thu, 12 Apr 2012 11:39:21 -0700 Subject: [PATCH] Quota usage infographics now update dynamically when flavor or instance count are changed. Fixes bug 981237 Change-Id: Ia2b5905a579ddb718ea21a5f9ce2bea2ad413cd5 --- horizon/api/nova.py | 5 ++ .../nova/images_and_snapshots/images/forms.py | 1 + .../nova/images_and_snapshots/images/tests.py | 10 +++- .../nova/images_and_snapshots/images/views.py | 6 +++ .../instances_and_volumes/instances/views.py | 1 - .../images_and_snapshots/images/_launch.html | 18 +++++-- horizon/static/horizon/js/forms.js | 49 +++++++++++++++++++ .../horizon/js/underscore/underscore-min.js | 32 ++++++++++++ .../horizon/common/_progress_bar.html | 5 +- horizon/utils/memoized.py | 47 ++++++++++++++++++ .../static/dashboard/css/style.css | 19 ++++++- openstack_dashboard/templates/_scripts.html | 1 + 12 files changed, 186 insertions(+), 8 deletions(-) create mode 100644 horizon/static/horizon/js/underscore/underscore-min.js create mode 100644 horizon/utils/memoized.py diff --git a/horizon/api/nova.py b/horizon/api/nova.py index 1099f56c6..91820d9fc 100644 --- a/horizon/api/nova.py +++ b/horizon/api/nova.py @@ -30,9 +30,11 @@ from novaclient.v1_1.security_groups import SecurityGroup as NovaSecurityGroup from novaclient.v1_1.servers import REBOOT_HARD from horizon.api.base import APIResourceWrapper, APIDictWrapper, url_for +from horizon.utils.memoized import memoized from django.utils.translation import ugettext as _ + LOG = logging.getLogger(__name__) @@ -231,7 +233,9 @@ def flavor_get(request, flavor_id): return novaclient(request).flavors.get(flavor_id) +@memoized def flavor_list(request): + """Get the list of available instance sizes (flavors).""" return novaclient(request).flavors.list() @@ -399,6 +403,7 @@ def usage_list(request, start, end): return [Usage(u) for u in novaclient(request).usage.list(start, end, True)] +@memoized def tenant_quota_usages(request): """Builds a dictionary of current usage against quota for the current tenant. diff --git a/horizon/dashboards/nova/images_and_snapshots/images/forms.py b/horizon/dashboards/nova/images_and_snapshots/images/forms.py index 319ceb54b..3ae2b5f74 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/forms.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/forms.py @@ -35,6 +35,7 @@ from horizon import api from horizon import exceptions from horizon import forms + LOG = logging.getLogger(__name__) diff --git a/horizon/dashboards/nova/images_and_snapshots/images/tests.py b/horizon/dashboards/nova/images_and_snapshots/images/tests.py index 403ec9a6e..cb1df2980 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/tests.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/tests.py @@ -41,12 +41,15 @@ class ImageViewTests(test.TestCase): self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_usages') + # Two flavor_list calls, however, flavor_list is now memoized. + self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quota_usages) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) + api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) @@ -124,6 +127,7 @@ class ImageViewTests(test.TestCase): self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_usages') self.mox.StubOutWithMock(api, 'flavor_list') + self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), @@ -132,6 +136,7 @@ class ImageViewTests(test.TestCase): self.quota_usages.first()) exc = keystone_exceptions.ClientException('Failed.') api.flavor_list(IsA(http.HttpRequest)).AndRaise(exc) + api.flavor_list(IsA(http.HttpRequest)).AndRaise(exc) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) @@ -149,12 +154,14 @@ class ImageViewTests(test.TestCase): self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_usages') self.mox.StubOutWithMock(api, 'flavor_list') + self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn( self.quota_usages.first()) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) + api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) exception = keystone_exceptions.ClientException('Failed.') api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception) api.security_group_list(IsA(http.HttpRequest)) \ @@ -225,16 +232,17 @@ class ImageViewTests(test.TestCase): USER_DATA = 'user data' device_name = u'vda' volume_choice = "%s:vol" % volume.id - block_device_mapping = {device_name: u"%s::0" % volume_choice} self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'flavor_list') + self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'volume_list') self.mox.StubOutWithMock(api, 'volume_snapshot_list') self.mox.StubOutWithMock(api, 'tenant_quota_usages') + api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ diff --git a/horizon/dashboards/nova/images_and_snapshots/images/views.py b/horizon/dashboards/nova/images_and_snapshots/images/views.py index 1ec1eaef7..672afea2e 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/views.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/views.py @@ -23,6 +23,8 @@ Views for managing Nova images. """ import logging +import json + from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ @@ -64,6 +66,10 @@ class LaunchView(forms.ModalFormView): context = super(LaunchView, self).get_context_data(**kwargs) try: context['usages'] = api.tenant_quota_usages(self.request) + context['usages_json'] = json.dumps(context['usages']) + flavors = json.dumps( + [f._info for f in api.flavor_list(self.request)]) + context['flavors'] = flavors except: exceptions.handle(self.request) return context diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/views.py b/horizon/dashboards/nova/instances_and_volumes/instances/views.py index d1a564ce8..de374abd1 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/views.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/views.py @@ -26,7 +26,6 @@ import logging from django import http from django import shortcuts from django.core.urlresolvers import reverse -from django.utils.datastructures import SortedDict from django.utils.translation import ugettext_lazy as _ from horizon import api diff --git a/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_launch.html b/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_launch.html index 0b1c0f5ce..a7022c768 100644 --- a/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_launch.html +++ b/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_launch.html @@ -24,29 +24,39 @@

{{ usages.instances.available|quota }}

-
{% horizon_progress_bar usages.instances.used usages.instances.quota %}
+
{% horizon_progress_bar usages.instances.used usages.instances.quota %}
{% trans "VCPUs" %} ({{ usages.cores.used }})

{{ usages.cores.available|quota }}

-
{% horizon_progress_bar usages.cores.used usages.cores.quota %}
+
{% horizon_progress_bar usages.cores.used usages.cores.quota %}
{% trans "Disk" %} ({{ usages.gigabytes.used }} {% trans "GB" %})

{{ usages.gigabytes.available|quota:"GB" }}

-
{% horizon_progress_bar usages.gigabytes.used usages.gigabytes.quota %}
+
{% horizon_progress_bar usages.gigabytes.used usages.gigabytes.quota %}
{% trans "Memory" %} ({{ usages.ram.used }} {% trans "MB" %})

{{ usages.ram.available|quota:"MB" }}

-
{% horizon_progress_bar usages.ram.used usages.ram.quota %}
+
{% horizon_progress_bar usages.ram.used usages.ram.quota %}
+ {% endblock %} {% block modal-footer %} diff --git a/horizon/static/horizon/js/forms.js b/horizon/static/horizon/js/forms.js index 5602a2e1e..af3e45eb3 100644 --- a/horizon/static/horizon/js/forms.js +++ b/horizon/static/horizon/js/forms.js @@ -80,3 +80,52 @@ horizon.addInitFunction(function () { // Hide the text for js-capable browsers $('span.help-block').hide(); }); + +/* Update quota usage infographics when a flavor is selected to show the usage + * that will be consumed by the selected flavor. */ +horizon.updateQuotaUsages = function(flavors, usages) { + var selectedFlavor = _.find(flavors, function(flavor) { + return flavor.id == $("#id_flavor").children(":selected").val(); + }); + + var selectedCount = parseInt($("#id_count").val()); + if(isNaN(selectedCount)) { + selectedCount = 1; + } + + // Map usage data fields to their corresponding html elements + var flavorUsageMapping = [ + {'usage': 'instances', 'element': 'quota_instances'}, + {'usage': 'cores', 'element': 'quota_cores'}, + {'usage': 'gigabytes', 'element': 'quota_disk'}, + {'usage': 'ram', 'element': 'quota_ram'} + ]; + + var el, used, usage, width; + _.each(flavorUsageMapping, function(mapping) { + el = $('#' + mapping.element + " .progress_bar_selected"); + used = 0; + usage = usages[mapping.usage]; + + if(mapping.usage == "instances") { + used = selectedCount; + } else { + _.each(usage.flavor_fields, function(flavorField) { + used += (selectedFlavor[flavorField] * selectedCount); + }); + } + + available = 100 - $('#' + mapping.element + " .progress_bar_fill").attr("data-width"); + if(used + usage.used <= usage.quota) { + width = Math.round((used / usage.quota) * 100); + el.removeClass('progress_bar_over'); + } else { + width = available; + if(!el.hasClass('progress_bar_over')) { + el.addClass('progress_bar_over'); + } + } + + el.animate({width: width + "%"}, 300); + }); +}; diff --git a/horizon/static/horizon/js/underscore/underscore-min.js b/horizon/static/horizon/js/underscore/underscore-min.js new file mode 100644 index 000000000..5a0cb3b00 --- /dev/null +++ b/horizon/static/horizon/js/underscore/underscore-min.js @@ -0,0 +1,32 @@ +// Underscore.js 1.3.3 +// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore is freely distributable under the MIT license. +// Portions of Underscore are inspired or borrowed from Prototype, +// Oliver Steele's Functional, and John Resig's Micro-Templating. +// For all details and documentation: +// http://documentcloud.github.com/underscore +(function(){function r(a,c,d){if(a===c)return 0!==a||1/a==1/c;if(null==a||null==c)return a===c;a._chain&&(a=a._wrapped);c._chain&&(c=c._wrapped);if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return!1;switch(e){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:0==a?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== +c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if("object"!=typeof a||"object"!=typeof c)return!1;for(var f=d.length;f--;)if(d[f]==a)return!0;d.push(a);var f=0,g=!0;if("[object Array]"==e){if(f=a.length,g=f==c.length)for(;f--&&(g=f in a==f in c&&r(a[f],c[f],d)););}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return!1;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c,h)&&!f--)break; +g=!f}}d.pop();return g}var s=this,I=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,J=k.unshift,l=p.toString,K=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,q=k.indexOf,F=k.lastIndexOf,p=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){return new m(a)};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a, +c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a==null&&(a=[]);if(A&& +a.reduce===A){e&&(c=b.bind(c,e));return f?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,i){if(f)d=c.call(e,d,a,b,i);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return f?a.reduceRight(c,d):a.reduceRight(c)}var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a, +c,b){var e;G(a,function(a,g,h){if(c.call(b,a,g,h)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,b);j(a,function(a,g,h){if(!(e=e&&c.call(b, +a,g,h)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= +function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]}; +j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1),true);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a= +i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&& +c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var c={};j(b.flatten(i.call(arguments,1)),function(b){b in a&&(c[b]=a[b])});return c};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty= +function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=function(a){return l.call(a)=="[object Arguments]"};b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFunction=function(a){return l.call(a)=="[object Function]"}; +b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a, +b){return K.call(a,b)};b.noConflict=function(){s._=I;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){M(c,b[c]=a[c])})};var N=0;b.uniqueId= +function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var u=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},v;for(v in n)n[n[v]]=v;var O=/\\|'|\r|\n|\t|\u2028|\u2029/g,P=/\\(\\|'|r|n|t|u2028|u2029)/g,w=function(a){return a.replace(P,function(a,b){return n[b]})};b.template=function(a,c,d){d=b.defaults(d||{},b.templateSettings);a="__p+='"+a.replace(O,function(a){return"\\"+n[a]}).replace(d.escape|| +u,function(a,b){return"'+\n_.escape("+w(b)+")+\n'"}).replace(d.interpolate||u,function(a,b){return"'+\n("+w(b)+")+\n'"}).replace(d.evaluate||u,function(a,b){return"';\n"+w(b)+"\n;__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");var a="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n"+a+"return __p;\n",e=new Function(d.variable||"obj","_",a);if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c}; +b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var x=function(a,c){return c?b(a).chain():a},M=function(a,c){m.prototype[a]=function(){var a=i.call(arguments);J.call(a,this._wrapped);return x(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return x(d, +this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return x(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); diff --git a/horizon/templates/horizon/common/_progress_bar.html b/horizon/templates/horizon/common/_progress_bar.html index 580bc7ba8..8e7883d1b 100644 --- a/horizon/templates/horizon/common/_progress_bar.html +++ b/horizon/templates/horizon/common/_progress_bar.html @@ -1 +1,4 @@ -
+
+
+
+
diff --git a/horizon/utils/memoized.py b/horizon/utils/memoized.py new file mode 100644 index 000000000..0c260ddc2 --- /dev/null +++ b/horizon/utils/memoized.py @@ -0,0 +1,47 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2012 Nebula, 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. + +import functools + + +class memoized(object): + '''Decorator. Caches a function's return value each time it is called. + If called later with the same arguments, the cached value is returned + (not reevaluated). + ''' + def __init__(self, func): + self.func = func + self.cache = {} + + def __call__(self, *args): + try: + return self.cache[args] + except KeyError: + value = self.func(*args) + self.cache[args] = value + return value + except TypeError: + # uncachable -- for instance, passing a list as an argument. + # Better to not cache than to blow up entirely. + return self.func(*args) + + def __repr__(self): + '''Return the function's docstring.''' + return self.func.__doc__ + + def __get__(self, obj, objtype): + '''Support instance methods.''' + return functools.partial(self.__call__, obj) diff --git a/openstack_dashboard/static/dashboard/css/style.css b/openstack_dashboard/static/dashboard/css/style.css index e57c6dd39..15cf2cb3e 100644 --- a/openstack_dashboard/static/dashboard/css/style.css +++ b/openstack_dashboard/static/dashboard/css/style.css @@ -951,13 +951,29 @@ iframe { background-color: #CCC; } -.progress_bar_fill { +.progress_bar_fill, +.progress_bar_selected { height: 100%; + float: left; +} + +.progress_bar_fill { background-color: #666; } +.progress_bar_selected { + background-color: #4790AE; + width: 0; +} + +.progress_bar_over { + background-color: red; +} + .quota_title { color: #999; + padding-bottom: 0; + margin-bottom: 8px; } .quota_title strong { @@ -970,6 +986,7 @@ iframe { .quota_title p { float: right; + margin-bottom: 0; } .quota_bar { diff --git a/openstack_dashboard/templates/_scripts.html b/openstack_dashboard/templates/_scripts.html index 3e144e8f3..5f5f2df4a 100644 --- a/openstack_dashboard/templates/_scripts.html +++ b/openstack_dashboard/templates/_scripts.html @@ -5,6 +5,7 @@ + {% comment %} Bootstrap {% endcomment %}