function _quotaBarMB(usage, limit, default_limit){ var int_usage = parseInt(usage, 10); var int_limit = _quotaIntLimit(limit, default_limit); info_str = Humanize.size(int_usage * 1024)+' / ' + ((int_limit >= 0) ? Humanize.size(int_limit * 1024) : '-'); return ProgressBar.html(int_usage, int_limit, info_str); }
function _quotaMBInfo(usage, limit, default_limit, not_html){ var int_usage = parseInt(usage, 10); var int_limit = _quotaIntLimit(limit, default_limit); info_str = Humanize.size(int_usage * 1024)+' / ' +((int_limit >= 0) ? Humanize.size(int_limit * 1024) : '-') return _quotaBaseInfo(int_usage, int_limit, info_str, not_html); }
$( ".uinput-slider", context).on("input", function(){ $( ".uinput-slider-val",context).val(Humanize.size($( ".uinput-slider",context).val())); var cost = Humanize.sizeToMB($( ".uinput-slider",context).val())*that.diskCost; if(isNaN(cost)){ cost = 0; } document.getElementById("new_cost_resize").textContent = Locale.tr("Cost")+": "+ convertCostNumber(cost); });
/* FUNCTION DEFINITIONS */ function _html() { var cache = OpenNebulaAction.cache("CLUSTER"); if (!cache){ Sunstone.runAction("Cluster.list"); cache = OpenNebulaAction.cache("CLUSTER"); } var elementAux = Reserved.updateHostTemplate(cache, this.element); var templateTableHTML = TemplateTable.html( this.strippedTemplate, RESOURCE, Locale.tr("Attributes")); var templateTableVcenterHTML = TemplateTableVcenter.html( this.strippedTemplateVcenter, RESOURCE, Locale.tr("vCenter information"),false); var renameTrHTML = RenameTr.html(TAB_ID, RESOURCE, this.element.NAME); var clusterTrHTML = ClusterTr.html(this.element.CLUSTER); var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element); var cpuBars = CPUBars.html(elementAux); var memoryBars = MemoryBars.html(elementAux); var datastoresCapacityTableHTML = DatastoresCapacityTable.html(this.element); var realCPU = parseInt(this.element.HOST_SHARE.TOTAL_CPU); var realMEM = parseInt(this.element.HOST_SHARE.TOTAL_MEM); return TemplateInfo({ "element": this.element, "renameTrHTML": renameTrHTML, "clusterTrHTML": clusterTrHTML, "templateTableHTML": templateTableHTML, "templateTableVcenterHTML": templateTableVcenterHTML, "permissionsTableHTML": permissionsTableHTML, "cpuBars": cpuBars, "memoryBars": memoryBars, "stateStr": OpenNebulaHost.stateStr(this.element.STATE), "datastoresCapacityTableHTML": datastoresCapacityTableHTML, "maxReservedMEM": realMEM * 2, "maxReservedCPU": realCPU * 2, "realCPU": realCPU, "realMEM": Humanize.size(realMEM), "virtualMEMInput": Humanize.size(this.element.HOST_SHARE.MAX_MEM), "ec2_tr": EC2Tr.html(RESOURCE, this.element.TEMPLATE), "capacityTableHTML": CapacityTable.html() }); }
function _setup(context) { var that = this; Tips.setup(context); $( ".diskSlider", context).html(RangeSlider.html({ min: that.diskSize, max: Humanize.sizeToMB("500GB")*1024, initial: that.diskSize, name: "resize" })); $( ".uinput-slider-val",context).prop('type', 'text'); $( ".uinput-slider-val",context).val(Humanize.size($( ".uinput-slider",context).val())); $( ".uinput-slider", context).on("input", function(){ $( ".uinput-slider-val",context).val(Humanize.size($( ".uinput-slider",context).val())); var cost = Humanize.sizeToMB($( ".uinput-slider",context).val())*that.diskCost; if(isNaN(cost)){ cost = 0; } document.getElementById("new_cost_resize").textContent = Locale.tr("Cost")+": "+ convertCostNumber(cost); }); $( ".uinput-slider-val", context).on("change", function(){ $( ".uinput-slider",context).val(Humanize.sizeToMB(($( ".uinput-slider-val",context).val()).toString())*1024); var cost = Humanize.sizeToMB($( ".uinput-slider",context).val())*that.diskCost; if(isNaN(cost)){ cost = 0; } document.getElementById("new_cost_resize").textContent = Locale.tr("Cost")+": "+ convertCostNumber(cost); }); var cost = Humanize.sizeToMB($( ".uinput-slider",context).val())*this.diskCost; if(isNaN(cost)){ cost = 0; } document.getElementById("new_cost_resize").textContent = Locale.tr("Cost")+": "+ convertCostNumber(cost); $('#' + DIALOG_ID + 'Form', context).submit(function() { var new_size = $( ".uinput-slider",context).val(); new_size = Math.round(parseInt(new_size) / 1024); new_size = new_size.toString(); var obj = { "vm_id": that.element.ID, "disk_id" : that.diskId, "new_size": new_size }; Sunstone.runAction('VM.disk_resize', that.element.ID, obj); Sunstone.getDialog(DIALOG_ID).hide(); Sunstone.getDialog(DIALOG_ID).reset(); return false; }); return false; }
function _elementArray(element_json) { var element = element_json[XML_ROOT]; var state; if (element.STATE == OpenNebulaVM.STATES.ACTIVE) { state = OpenNebulaVM.shortLcmStateStr(element.LCM_STATE); } else { state = OpenNebulaVM.stateStr(element.STATE); } // VNC icon var vncIcon; if (OpenNebulaVM.isVNCSupported(element)) { vncIcon = '<a class="vnc" href="#" vm_id="' + element.ID + '"><i class="fa fa-desktop"/></a>'; } else if (OpenNebulaVM.isSPICESupported(element)) { vncIcon = '<a class="spice" href="#" vm_id="' + element.ID + '"><i class="fa fa-desktop"/></a>'; } else { vncIcon = ''; } var cpuMonitoring = 0; var memoryMonitoring = 0; if (element.MONITORING) { if (element.MONITORING.CPU) { cpuMonitoring = element.MONITORING.CPU } if (element.MONITORING.MEMORY) { memoryMonitoring = element.MONITORING.MEMORY } } return [ '<input class="check_item" '+ 'type="checkbox" '+ 'id="' + RESOURCE.toLowerCase() + '_' + element.ID + '" '+ 'name="selected_items" '+ 'value="' + element.ID + '" '+ 'state="'+element.STATE+'" lcm_state="'+element.LCM_STATE+'"/>', element.ID, element.UNAME, element.GNAME, element.NAME, state, cpuMonitoring, Humanize.size(memoryMonitoring), OpenNebulaVM.hostnameStr(element), OpenNebulaVM.ipsStr(element), Humanize.prettyTime(element.STIME), vncIcon, TemplateUtils.templateToString(element), (LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||'') ]; }
/* FUNCTION DEFINITIONS */ function _html() { var templateTableHTML = TemplateTable.html( this.strippedTemplate, RESOURCE, Locale.tr("Attributes")); var templateTableVcenterHTML = TemplateTableVcenter.html( this.strippedTemplateVcenter, RESOURCE, Locale.tr("vCenter information"),false); var renameTrHTML = RenameTr.html(TAB_ID, RESOURCE, this.element.NAME); var clusterTrHTML = ClusterTr.html(this.element.CLUSTER); var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element); var cpuBars = CPUBars.html(this.element); var memoryBars = MemoryBars.html(this.element); var datastoresCapacityTableHTML = DatastoresCapacityTable.html(this.element); var realCPU = parseInt(this.element.HOST_SHARE.TOTAL_CPU); var realMEM = parseInt(this.element.HOST_SHARE.TOTAL_MEM); return TemplateInfo({ 'element': this.element, 'renameTrHTML': renameTrHTML, 'clusterTrHTML': clusterTrHTML, 'templateTableHTML': templateTableHTML, 'templateTableVcenterHTML': templateTableVcenterHTML, 'permissionsTableHTML': permissionsTableHTML, 'cpuBars': cpuBars, 'memoryBars': memoryBars, 'stateStr': OpenNebulaHost.stateStr(this.element.STATE), 'datastoresCapacityTableHTML': datastoresCapacityTableHTML, 'maxReservedMEM': realMEM * 2, 'maxReservedCPU': realCPU * 2, 'realCPU': realCPU, 'realMEM': Humanize.size(realMEM), 'virtualMEMInput': Humanize.size(this.element.HOST_SHARE.MAX_MEM), 'ec2_tr': EC2Tr.html(RESOURCE, this.element.TEMPLATE), 'capacityTableHTML': CapacityTable.html() }); }
that.uploader.on('progress', function() { var time = new Date().getTime(); var size = this.getSize() * this.progress(); if(time - last_time > 2000){ size = size - old_size; var speed = size / ((time - last_time)); document.getElementById( 'speed' ).textContent = 'speed: ' + Humanize.size(speed) +'s'; last_time = time; old_size = size; } document.getElementById( 'percent_progress' ).textContent = 'Completed: ' + (this.progress().toFixed(3)*100).toFixed(1) +'%'; $('div.progressbar', $('div[id="' + fileName + 'progressBar"]')).html( ProgressBar.html(this.progress(), 1, fileName) ); });
var _html = function(info) { var total = parseInt(info.TOTAL_MB); var used = total - parseInt(info.FREE_MB); if (total > 0) { var ratio = Math.round((used / total) * 100); info_str = Humanize.sizeFromMB(used) + ' / ' + Humanize.sizeFromMB(total) + ' (' + ratio + '%)'; } else { if (info.TYPE == 1) { info_str = '- / -'; } else { info_str = Humanize.size(used) + ' / -'; } } return ProgressBar.html(used, total, info_str); }
var _html = function(host, hostShareFlag) { var hostShare = hostShareFlag ? host : host.HOST_SHARE; var maxMem = parseInt(hostShare.MAX_MEM); var infoStr = ""; var allocatedMemBar; if (hostShare.MEM_USAGE) { var allocatedMem = parseInt(hostShare.MEM_USAGE); if (maxMem > 0) { var ratioAllocatedMem = Math.round((allocatedMem / maxMem) * 100); infoStr = Humanize.size(allocatedMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioAllocatedMem + '%)'; } else { infoStr = Humanize.size(allocatedMem) + ' / -'; } allocatedMemBar = ProgressBar.html(allocatedMem, maxMem, infoStr); } var realMemBar; if (hostShare.USED_MEM) { var realMem = parseInt(hostShare.USED_MEM); if (maxMem > 0) { var ratioRealMem = Math.round((realMem / maxMem) * 100); infoStr = Humanize.size(realMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioRealMem + '%)'; } else { infoStr = Humanize.size(realMem) + ' / -'; } realMemBar = ProgressBar.html(realMem, maxMem, infoStr); } return { real: realMemBar, allocated: allocatedMemBar } }
function _elementArray(element_json) { var element = element_json[XML_ROOT]; var state; if (element.STATE == OpenNebulaVM.STATES.ACTIVE) { state = OpenNebulaVM.shortLcmStateStr(element.LCM_STATE); } else { state = OpenNebulaVM.stateStr(element.STATE); } // VNC icon var vncIcon; if (OpenNebulaVM.isVNCSupported(element)) { vncIcon = '<a class="vnc" href="#" vm_id="' + element.ID + '"><i class="fa fa-desktop"/></a>'; } else if (OpenNebulaVM.isSPICESupported(element)) { vncIcon = '<a class="spice" href="#" vm_id="' + element.ID + '"><i class="fa fa-desktop"/></a>'; } else { vncIcon = ''; } if (config["federation_mode"] == "SLAVE") { vncIcon = ''; } var cpuMonitoring = 0; var memoryMonitoring = 0; if (element.MONITORING) { if (element.MONITORING.CPU) { cpuMonitoring = element.MONITORING.CPU } if (element.MONITORING.MEMORY) { memoryMonitoring = element.MONITORING.MEMORY } } var hostname = OpenNebulaVM.hostnameStr(element); var type; if (element.TEMPLATE.VROUTER_ID != undefined){ type = "VR"; } else if (element.USER_TEMPLATE.SERVICE_ID != undefined){ type = "FLOW"; } else { type = "VM"; } var search = { NAME: element.NAME, UNAME: element.UNAME, GNAME: element.GNAME, STATUS: state, VM_TYPE: type, HOST: hostname, CLUSTER: OpenNebulaVM.clusterStr(element), STIME_AFTER: element.STIME, STIME_BEFORE: element.STIME } return [ '<input class="check_item" '+ 'type="checkbox" '+ 'id="' + RESOURCE.toLowerCase() + '_' + element.ID + '" '+ 'name="selected_items" '+ 'value="' + element.ID + '" '+ 'state="'+element.STATE+'" lcm_state="'+element.LCM_STATE+'"/>', element.ID, element.NAME, element.UNAME, element.GNAME, state, cpuMonitoring, Humanize.size(memoryMonitoring), hostname, OpenNebulaVM.ipsStr(element), Humanize.prettyTime(element.STIME), vncIcon, TemplateUtils.htmlEncode(TemplateUtils.templateToString(element)), (LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||''), btoa(unescape(encodeURIComponent(JSON.stringify(search)))) ]; }
function _postUpdateView() { $(".total_hosts").text(this.totalHosts); $(".on_hosts").text(this.onHosts); $(".off_hosts").text(this.offHosts); $(".error_hosts").text(this.errorHosts); var ratio_allocated_cpu = 0; if (this.maxCPU > 0) { ratio_allocated_cpu = Math.round((this.allocatedCPU / this.maxCPU) * 100); info_str = this.allocatedCPU + ' / ' + this.maxCPU ; } else { info_str = "- / -"; } //$("#dash_host_allocated_cpu").html(usageBarHtml(allocated_cpu, max_cpu, info_str, true)); $("#dashboard_host_allocated_cpu").html(quotaDashboard( "dashboard_host_allocated_cpu", Locale.tr("Allocated CPU"), "1.2rem", "1rem", {"percentage": ratio_allocated_cpu, "str": info_str}) ); var ratio_real_cpu = 0; if (this.maxCPU > 0) { ratio_real_cpu = Math.round((this.realCPU / this.maxCPU) * 100); info_str = this.realCPU + ' / ' + this.maxCPU; } else { info_str = "- / -"; } $("#dashboard_host_real_cpu").html(quotaDashboard( "dashboard_host_real_cpu", Locale.tr("Real CPU"), "1.2rem", "1rem", {"percentage": ratio_real_cpu, "str": info_str}) ); var ratio_allocated_mem = 0; if (this.maxMemory > 0) { ratio_allocated_mem = Math.round((this.allocatedMemory / this.maxMemory) * 100); info_str = Humanize.size(this.allocatedMemory) + ' / ' + Humanize.size(this.maxMemory); } else { info_str = Humanize.size(this.allocatedMemory) + ' / -'; } $("#dashboard_host_allocated_mem").html(quotaDashboard( "dashboard_host_allocated_mem", Locale.tr("Allocated Memory"), "1.2rem", "1rem", {"percentage": ratio_allocated_mem, "str": info_str}) ); var ratio_real_mem = 0; if (this.maxMemory > 0) { ratio_real_mem = Math.round((this.realMemory / this.maxMemory) * 100); info_str = Humanize.size(this.realMemory) + ' / ' + Humanize.size(this.maxMemory); } else { info_str = Humanize.size(this.realMemory) + ' / -'; } $("#dashboard_host_real_mem").html(quotaDashboard( "dashboard_host_real_mem", Locale.tr("Real Memory"), "1.2rem", "1rem", {"percentage": ratio_real_mem, "str": info_str}) ); }
function _postUpdateView() { var time = 2000; if ( !SunstoneConfig.doCountAnimation ){ time = 1; } $(".total_hosts").text(this.totalHosts); $(".on_hosts").text(this.onHosts); $(".off_hosts").text(this.offHosts); $(".error_hosts").text(this.errorHosts); var ratio_allocated_cpu = 0; if (this.maxCPU > 0) { ratio_allocated_cpu = Math.round((this.allocatedCPU / this.maxCPU) * 100); info_str = this.allocatedCPU + " / " + this.maxCPU ; } else { info_str = "- / -"; } $("#dashboard_host_allocated_cpu").html(quotaDashboard( "dashboard_host_allocated_cpu", Locale.tr("Allocated CPU"), "1.2rem", "1rem", {"percentage": ratio_allocated_cpu, "str": info_str}) ); var percentage = ratio_allocated_cpu > 100 ? 100 : ratio_allocated_cpu; $("#dashboard_host_allocated_cpu_meter").animate({ value: percentage, }, time, "swing"); var ratio_real_cpu = 0; if (this.maxCPU > 0) { ratio_real_cpu = Math.round((this.realCPU / this.maxCPU) * 100); info_str = this.realCPU + " / " + this.maxCPU; } else { info_str = "- / -"; } $("#dashboard_host_real_cpu").html(quotaDashboard( "dashboard_host_real_cpu", Locale.tr("Real CPU"), "1.2rem", "1rem", {"percentage": ratio_real_cpu, "str": info_str}) ); var percentage = ratio_real_cpu > 100 ? 100 : ratio_real_cpu; $("#dashboard_host_real_cpu_meter").animate({ value: percentage, }, time, "swing"); var ratio_allocated_mem = 0; if (this.maxMemory > 0) { ratio_allocated_mem = Math.round((this.allocatedMemory / this.maxMemory) * 100); info_str = Humanize.size(this.allocatedMemory) + " / " + Humanize.size(this.maxMemory); } else { info_str = Humanize.size(this.allocatedMemory) + " / -"; } $("#dashboard_host_allocated_mem").html(quotaDashboard( "dashboard_host_allocated_mem", Locale.tr("Allocated Memory"), "1.2rem", "1rem", {"percentage": ratio_allocated_mem, "str": info_str}) ); var percentage = ratio_allocated_mem > 100 ? 100 : ratio_allocated_mem; $("#dashboard_host_allocated_mem_meter").animate({ value: percentage, }, time, "swing"); var ratio_real_mem = 0; if (this.maxMemory > 0) { ratio_real_mem = Math.round((this.realMemory / this.maxMemory) * 100); info_str = Humanize.size(this.realMemory) + " / " + Humanize.size(this.maxMemory); } else { info_str = Humanize.size(this.realMemory) + " / -"; } $("#dashboard_host_real_mem").html(quotaDashboard( "dashboard_host_real_mem", Locale.tr("Real Memory"), "1.2rem", "1rem", {"percentage": ratio_real_mem, "str": info_str}) ); var percentage = ratio_real_mem > 100 ? 100 : ratio_real_mem; $("#dashboard_host_real_mem_meter").animate({ value: percentage, }, time, "swing"); }
document.getElementById("change_bar_mem_hosts").addEventListener("input", function(){ changeColorInputMEM(that.element.HOST_SHARE.TOTAL_MEM); document.getElementById('textInput_reserved_mem_hosts').value = Humanize.size(parseInt(document.getElementById('change_bar_mem_hosts').value)); });
/* * opts.is_float : true to parse quota_limit and default_limit as floats instead of int * opts.mb : true if the quota is in MB * opts.quota_name : string to identify the quota widget */ function _editableQuotaBar(usage, quota_limit, default_limit, opts){ if (!opts) opts = {}; if (!opts.quota_name) opts.quota_name = ""; var limit; if (opts.is_float){ usage = parseFloat(usage, 10); limit = _quotaFloatLimit(quota_limit, default_limit); } else { usage = parseInt(usage, 10); limit = _quotaIntLimit(quota_limit, default_limit); } percentage = 0; if (limit > 0){ percentage = Math.floor((usage / limit) * 100); if (percentage > 100){ percentage = 100; } } else if (limit == 0 && usage > 0){ percentage = 100; } var info_str; if (opts.mb){ info_str = Humanize.size(usage * 1024)+' / ' +((limit >= 0) ? Humanize.size(limit * 1024) : '-') } else { info_str = usage+' / '+((limit >= 0) ? limit : '-'); } html = '<div class="quotabar_container" quota_name="'+opts.quota_name+'">\ <div class="row collapse editable_quota" style="font-size: 12px; display: none">\ <div class="small-2 columns">\ <label style="font-size: 12px; margin: 0px" class="inline right">'+ usage + ' / </label>\ </div>'; if (opts.mb){ html += '<div class="small-4 columns">'; }else{ html += '<div class="small-5 columns">'; } html += '<input type="text" style="font-size: 12px; margin: 0px" quota_mode="edit" quota_limit="'+quota_limit+'" quota_default="'+default_limit+'" value="'+quota_limit+'"/>\ </div>'; if (opts.mb){ html += '<div class="small-1 columns">\ <span style="font-size: 12px; height: 2.0625rem !important; line-height: 2.0625rem !important;" class="postfix">MB</span>\ </div>'; } html += '<div class="small-5 columns">\ <div class="button-group">\ <a class="button tiny secondary quotabar_edit_btn"><span class="fa fa-pencil"></span></a>\ <a class="button tiny secondary quotabar_default_btn"><span class="fa fa-file-o"></span></a>\ <a class="button tiny secondary quotabar_unlimited_btn"><strong>∞</strong></a>\ </div>\ </div>\ </div>\ <div class="row collapse non_editable_quota">\ <div class="large-12 columns">\ <div class="progress-text right" style="font-size: 12px">\ '+info_str+'\ </div>\ <br>\ <div class="progress radius" style="height: 10px; margin-bottom:0px">\ <span class="meter" style="width: ' +percentage+'%" />\ </div>\ </div>\ </div>\ </div>'; return html; }
$("#change_bar_mem_hosts", context).on("input", function(){ changeColorInputMEM(that.element.HOST_SHARE.TOTAL_MEM); $("#textInput_reserved_mem_hosts", context).val(Humanize.size(parseInt($("#change_bar_mem_hosts").val()))); });
function changeInputMEM(maxMEM){ document.getElementById('change_bar_mem_hosts').value = Humanize.sizeToMB(document.getElementById('textInput_reserved_mem_hosts').value); document.getElementById('textInput_reserved_mem_hosts').value = Humanize.size(document.getElementById('change_bar_mem_hosts').value); changeColorInputMEM(maxMEM); }