1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-10 01:17:40 +03:00

F #1546: Display quotas in Cloud View (#1590)

* F #1511: Improved quotas widget in Cloud View

* F #1546: Display quotas in Cloud View
This commit is contained in:
Abel Coronado 2017-12-19 12:37:25 +01:00 committed by Ruben S. Montero
parent 771d476a9c
commit 4962b608eb
5 changed files with 82 additions and 11 deletions

View File

@ -200,6 +200,31 @@ define(function(require) {
CapacityInputs.html() +
'</fieldset>');
if (Config.provision.dashboard.isEnabled("quotas")) {
$("#quotas-mem", context).show();
$("#quotas-cpu", context).show();
var quotaMem = false;
var quotaCpu = false;
var user = this.user;
if (!$.isEmptyObject(user.VM_QUOTA)){
var memUsed = parseFloat(user.VM_QUOTA.VM.MEMORY_USED);
var cpuUsed = parseFloat(user.VM_QUOTA.VM.CPU_USED);
if (user.VM_QUOTA.VM.MEMORY === "-1" || user.VM_QUOTA.VM.MEMORY === "-2"){
$("#quotas-mem", context).text(Humanize.size(memUsed * 1024) + " / ∞");
} else {
quotaMem = true;
$("#quotas-mem", context).text(Humanize.size(memUsed * 1024) + " / " + Humanize.size(user.VM_QUOTA.VM.MEMORY * 1024));
}
if (user.VM_QUOTA.VM.CPU === "-1" || user.VM_QUOTA.VM.CPU === "-2"){
$("#quotas-cpu", context).text(cpuUsed + " / ∞");
} else {
quotaCpu = true;
$("#quotas-cpu", context).text(cpuUsed + " / " + user.VM_QUOTA.VM.CPU);
}
}
}
CapacityInputs.setup(context);
CapacityInputs.fill(context, element);
@ -219,6 +244,23 @@ define(function(require) {
$(".memory_value", context).html(memory_value);
$(".memory_unit", context).html(memory_unit);
if (!values.MEMORY){
values.MEMORY = 0;
}
if (!values.CPU){
values.CPU = 0;
}
if (quotaMem){
$("#quotas-mem", context).text( Humanize.size((parseFloat(user.VM_QUOTA.VM.MEMORY_USED) + parseFloat(values.MEMORY)) * 1024) + " / " + Humanize.size(user.VM_QUOTA.VM.MEMORY * 1024));
} else {
$("#quotas-mem", context).text( Humanize.size((parseFloat(user.VM_QUOTA.VM.MEMORY_USED) + parseFloat(values.MEMORY)) * 1024) + " / ∞");
}
if (quotaCpu){
$("#quotas-cpu", context).text(((parseFloat(user.VM_QUOTA.VM.CPU_USED) + parseFloat(values.CPU))).toFixed(2) + " / " + user.VM_QUOTA.VM.CPU);
} else {
$("#quotas-cpu", context).text(((parseFloat(user.VM_QUOTA.VM.CPU_USED) + parseFloat(values.CPU))).toFixed(2) + " / ∞");
}
});
var cost = 0;
@ -276,6 +318,17 @@ define(function(require) {
$(".total_cost_div .cost_value", context).text( (total).toFixed(2) );
}
if (Config.provision.dashboard.isEnabled("quotas")) {
if (!$("#quotas-disks").text().includes("/")){
var totalSize = parseFloat($("#quotas-disks").text());
if (this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE === "-1" || this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE === "-2"){
$("#quotas-disks").text(Humanize.size((parseFloat(this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE_USED) + totalSize) * 1024) + " / ∞");
} else {
$("#quotas-disks").text(Humanize.size((parseFloat(this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE_USED) + totalSize) * 1024) + " / " + Humanize.size(parseFloat(this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE) * 1024));
}
}
}
}
function _calculateFlowCost(){
@ -441,13 +494,14 @@ define(function(require) {
if (Config.provision.dashboard.isEnabled("quotas")) {
$("#provision_dashboard").append(TemplateDashboardQuotas());
var that = this;
OpenNebula.User.show({
data : {
id: "-1"
},
success: function(request,user_json){
var user = user_json.USER;
that.user = user;
QuotaWidgets.initEmptyQuotas(user);
@ -974,6 +1028,15 @@ define(function(require) {
cost_callback: _calculateCost,
uinput_mb: true
});
if (Config.provision.dashboard.isEnabled("quotas")) {
$("#quotas-disks").show();
if (this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE === "-1" || this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE === "-2"){
$("#quotas-disks").text(Humanize.size(parseFloat(this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE_USED) * 1024) + " / " + "∞");
} else {
$("#quotas-disks").text(Humanize.size(parseFloat(this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE_USED) * 1024) + " / " + Humanize.size(parseFloat(this.user.VM_QUOTA.VM.SYSTEM_DISK_SIZE) * 1024));
}
$("input", disksContext).change();
}
} else {
disksContext.html("");
}

View File

@ -13,10 +13,12 @@
{{! See the License for the specific language governing permissions and }}
{{! limitations under the License. }}
{{! -------------------------------------------------------------------------- }}
<div id="provision_quotas_dashboard" hidden>
<fieldset class="large-12 columns dashboard-fieldset" id="provision_quotas_dashboard" hidden>
<div class="row">
<div class="large-12 columns">
<h4>{{tr "Quotas"}}</h2>
<div class="large-12 columns dashboard-div-titles">
<div class="small-6 medium-8 columns">
<h5>{{tr "Quotas"}}</h5>
</div>
</div>
</div>
<div class="row">
@ -61,4 +63,4 @@
</div>
</div>
</div>
</div>
</fieldset>

View File

@ -16,21 +16,25 @@
<div class="row">
<div class="memory_input_wrapper small-12 columns">
<label class="" for="MEMORY">
<div class="memory_input_wrapper large-8 small-12 columns">
<label style="padding: 0; text-align: left" class="small-5 columns" for="MEMORY">
{{tr "Memory"}}
{{{tip (tr "Amount of RAM required for the VM, in Megabytes.")}}}
</label>
<label style="padding: 0; text-align: right; font-size: 95%" class="small-7 columns" id="quotas-mem" hidden>
</label>
<div class="memory_input">
</div>
</div>
</div>
<div class="row">
<div class="cpu_input_wrapper small-12 columns">
<label class="" for="CPU">
<label style="padding: 0; text-align: left" class="small-5 columns" for="CPU">
{{tr "CPU"}}
{{{tip (tr "Percentage of CPU divided by 100 required for the Virtual Machine. Half a processor is written 0.5.")}}}
</label>
<label style="padding: 0; text-align: right" class="small-7 columns" id="quotas-cpu" hidden>
</label>
<div class="cpu_input">
</div>
</div>

View File

@ -31,6 +31,7 @@ define(function(require){
function _calculateCost(context, disk_cost, callback){
var cost = 0;
var totalSize = 0;
$(".diskContainer", context).each(function(){
var size = 0;
@ -46,12 +47,13 @@ define(function(require){
size = disk['SIZE'];
}
}
totalSize += parseFloat(size);
cost += size * disk_cost;
cost += $(this).data('disk_snapshot_total_cost');
});
$(".cost_value", context).text(cost.toFixed(6));
$("#quotas-disks", context).text(totalSize.toFixed(2));
if(callback != undefined){
callback();
@ -113,8 +115,6 @@ define(function(require){
var diskContext;
$(".disksContainer", disksContext).html("");
$.each(disks, function(disk_id, disk) {
diskContext = $(
'<div class="row diskContainer">'+

View File

@ -22,6 +22,8 @@
<small>{{tr "COST"}} / {{tr "HOUR"}}</small>
</span>
</legend>
<label class="" id="quotas-disks" style="margin-top: -20px; text-align: right" hidden>
</label>
<div class="disksContainer">
</div>
</fieldset>