1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

Merge branch 'feature-4901'

This commit is contained in:
Ruben S. Montero 2016-11-16 15:06:18 +01:00
commit 08381a000b
16 changed files with 524 additions and 227 deletions

View File

@ -164,10 +164,10 @@ public:
/**
* Get the default reserved capacity for hosts in the cluster. It can be
* overridden if defined in the host template.
* @param cpu reserved cpu (in percentage)
* @param cpu reserved cpu (percentage, or absolute)
* @param mem reserved mem (in KB)
*/
void get_reserved_capacity(long long &cpu, long long& mem)
void get_reserved_capacity(string& cpu, string& mem)
{
get_template_attribute("RESERVED_CPU", cpu);

View File

@ -160,8 +160,8 @@ public:
set<int> &lost,
map<int,string> &found,
const set<int> &non_shared_ds,
long long reserved_cpu,
long long reserved_mem);
const string& reserved_cpu,
const string& reserved_mem);
/**
* Extracts the DS attributes from the given template
* @param parse_str string with values to be parsed
@ -264,97 +264,19 @@ public:
* @param cpu reserved cpu (in percentage)
* @param mem reserved mem (in KB)
*/
void get_reserved_capacity(long long &cpu, long long& mem)
void get_reserved_capacity(string& cpu, string& mem)
{
long long tcpu;
long long tmem;
if (get_template_attribute("RESERVED_CPU", tcpu))
{
cpu = tcpu;
}
else
{
replace_template_attribute("RESERVED_CPU", "");
}
if (get_template_attribute("RESERVED_MEM", tmem))
{
mem = tmem;
}
else
{
replace_template_attribute("RESERVED_MEM", "");
}
get_template_attribute("RESERVED_CPU", cpu);
get_template_attribute("RESERVED_MEM", mem);
}
// -------------------------------------------------------------------------
// Share functions. Returns the value associated with each host share
// metric
// Share functions.
// -------------------------------------------------------------------------
long long get_share_running_vms()
{
return host_share.running_vms;
}
long long get_share_disk_usage()
{
return host_share.disk_usage;
}
long long get_share_mem_usage()
{
return host_share.mem_usage;
}
long long get_share_cpu_usage()
{
return host_share.cpu_usage;
}
long long get_share_max_disk()
{
return host_share.max_disk;
}
long long get_share_max_mem()
{
return host_share.max_mem;
}
long long get_share_max_cpu()
{
return host_share.max_cpu;
}
long long get_share_free_disk()
{
return host_share.free_disk;
}
long long get_share_free_mem()
{
return host_share.free_mem;
}
long long get_share_free_cpu()
{
return host_share.free_cpu;
}
long long get_share_used_disk()
{
return host_share.used_disk;
}
long long get_share_used_mem()
{
return host_share.used_mem;
}
long long get_share_used_cpu()
{
return host_share.used_cpu;
return host_share.get_running_vms();
}
/**
@ -467,7 +389,6 @@ public:
return new HostTemplate;
}
/**
* Executed after an update operation to process the new template
* - encrypt VCENTER_PASSWORD attribute.

View File

@ -161,6 +161,8 @@ private:
map <string, PCIDevice *> pci_devices;
};
class Host;
/**
* The HostShare class. It represents a logical partition of a host...
*/
@ -175,6 +177,14 @@ public:
~HostShare(){};
/**
* Rebuilds the object from an xml node
* @param node The xml node pointer
*
* @return 0 on success, -1 otherwise
*/
int from_xml_node(const xmlNodePtr node);
/**
* Add a new VM to this share
* @param vmid of the VM
@ -303,15 +313,65 @@ public:
pci.set_monitorization(pci_att);
}
/**
* Resets capaity values of the share
*/
void reset_capacity()
{
total_cpu = 0;
total_mem = 0;
max_cpu = 0;
max_mem = 0;
free_cpu = 0;
free_mem = 0;
used_cpu = 0;
used_mem = 0;
};
/**
* Set the capacity attributes of the share. CPU and Memory may reserve some
* capacity according to RESERVED_CPU and RESERVED_MEM. These values can be
* either absolute or a percentage.
*
* Share values are read from the Host template returned by the monitoring
* probes. The values are removed from the template.
*
* @param host for this share, capacity values are removed from the template
* @para cr_cpu, reserved cpu default cluster value
* @para cluster_rmem, reserved mem default cluster value
*/
void set_capacity(Host *host, const string& crcpu, const string& crmem);
/**
* Update the capacity attributes when the RESERVED_CPU and RESERVED_MEM
* are updated.
* @param host for this share
*/
void update_capacity(Host *host);
/**
* Return the number of running VMs in this host
*/
long long get_running_vms()
{
return running_vms;
};
private:
long long disk_usage; /**< Disk allocated to VMs (in MB). */
long long mem_usage; /**< Memory allocated to VMs (in KB) */
long long cpu_usage; /**< CPU allocated to VMs (in percentage) */
long long total_mem; /**< Total memory capacity (in KB) */
long long total_cpu; /**< Total cpu capacity (in percentage) */
long long max_disk; /**< Total disk capacity (in MB) */
long long max_mem; /**< Total memory capacity (in KB) */
long long max_cpu; /**< Total cpu capacity (in percentage) */
long long max_mem; /**< Total memory capacity (in KB) +/- reserved */
long long max_cpu; /**< Total cpu capacity (in percentage) +/- reserved*/
long long free_disk; /**< Free disk from the IM monitor */
long long free_mem; /**< Free memory from the IM monitor */
@ -325,21 +385,6 @@ private:
HostShareDatastore ds;
HostSharePCI pci;
// ----------------------------------------
// Friends
// ----------------------------------------
friend class Host;
friend class HostPool;
/**
* Rebuilds the object from an xml node
* @param node The xml node pointer
*
* @return 0 on success, -1 otherwise
*/
int from_xml_node(const xmlNodePtr node);
};
#endif /*HOST_SHARE_H_*/

View File

@ -353,7 +353,7 @@ public:
*/
static string local_db_version()
{
return "4.90.0";
return "5.2.0";
}
/**

View File

@ -1156,13 +1156,15 @@ ONEDB_SHARED_MIGRATOR_FILES="src/onedb/shared/2.0_to_2.9.80.rb \
src/onedb/shared/4.11.80_to_4.90.0.rb \
src/onedb/shared/4.90.0_to_5.2.0.rb"
ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/4.5.80_to_4.7.80.rb \
ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/db_schema.rb \
src/onedb/local/4.5.80_to_4.7.80.rb \
src/onedb/local/4.7.80_to_4.9.80.rb \
src/onedb/local/4.9.80_to_4.10.3.rb \
src/onedb/local/4.10.3_to_4.11.80.rb \
src/onedb/local/4.11.80_to_4.13.80.rb \
src/onedb/local/4.13.80_to_4.13.85.rb \
src/onedb/local/4.13.85_to_4.90.0.rb"
src/onedb/local/4.13.85_to_4.90.0.rb \
src/onedb/local/4.90.0_to_5.2.0.rb"
ONEDB_PATCH_FILES="src/onedb/patches/4.14_monitoring.rb \
src/onedb/patches/history_times.rb"

View File

@ -382,14 +382,19 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
puts
CLIHelper.print_header(str_h1 % "HOST SHARES", false)
puts str % ["TOTAL MEM", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM'].to_i, {})]
puts str % ["USED MEM (REAL)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM'].to_i, {})]
puts str % ["USED MEM (ALLOCATED)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE'].to_i, {})]
puts str % ["TOTAL CPU", host['HOST_SHARE/MAX_CPU']]
puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']]
puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
CLIHelper.print_header(str_h1 % "MEMORY", false)
puts str % [" TOTAL", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/TOTAL_MEM'].to_i, {})]
puts str % [" TOTAL +/- RESERVED", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM'].to_i, {})]
puts str % [" USED (REAL)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM'].to_i, {})]
puts str % [" USED (ALLOCATED)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE'].to_i, {})]
CLIHelper.print_header(str_h1 % "CPU", false)
puts str % [" TOTAL", host['HOST_SHARE/TOTAL_CPU']]
puts str % [" TOTAL +/- RESERVED", host['HOST_SHARE/MAX_CPU']]
puts str % [" USED (REAL)", host['HOST_SHARE/USED_CPU']]
puts str % [" USED (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
puts
datastores = host.to_hash['HOST']['HOST_SHARE']['DATASTORES']['DS']

View File

@ -234,8 +234,8 @@ int Host::update_info(Template &tmpl,
set<int> &lost,
map<int,string> &found,
const set<int> &non_shared_ds,
long long reserved_cpu,
long long reserved_mem)
const string &reserved_cpu,
const string &reserved_mem)
{
VectorAttribute* vatt;
vector<Attribute*>::iterator it;
@ -246,7 +246,6 @@ int Host::update_info(Template &tmpl,
int rc;
int vmid;
float val;
ostringstream zombie;
ostringstream wild;
@ -289,28 +288,7 @@ int Host::update_info(Template &tmpl,
touch(true);
get_reserved_capacity(reserved_cpu, reserved_mem);
erase_template_attribute("TOTALCPU", val);
host_share.max_cpu = val - reserved_cpu;
erase_template_attribute("TOTALMEMORY", val);
host_share.max_mem = val - reserved_mem;
erase_template_attribute("DS_LOCATION_TOTAL_MB", val);
host_share.max_disk = val;
erase_template_attribute("FREECPU", val);
host_share.free_cpu = val;
erase_template_attribute("FREEMEMORY", val);
host_share.free_mem = val;
erase_template_attribute("DS_LOCATION_FREE_MB", val);
host_share.free_disk = val;
erase_template_attribute("USEDCPU", val);
host_share.used_cpu = val;
erase_template_attribute("USEDMEMORY", val);
host_share.used_mem = val;
erase_template_attribute("DS_LOCATION_USED_MB", val);
host_share.used_disk = val;
host_share.set_capacity(this, reserved_cpu, reserved_mem);
// -------------------------------------------------------------------------
// Correlate VM information with the list of running VMs
@ -513,14 +491,7 @@ void Host::offline()
state = OFFLINE;
host_share.max_cpu = 0;
host_share.max_mem = 0;
host_share.free_cpu = 0;
host_share.free_mem = 0;
host_share.used_cpu = 0;
host_share.used_mem = 0;
host_share.reset_capacity();
remove_template_attribute("TOTALCPU");
remove_template_attribute("TOTALMEMORY");
@ -769,5 +740,7 @@ int Host::post_update_template(string& error)
replace_template_attribute("IM_MAD", im_mad_name);
replace_template_attribute("VM_MAD", vmm_mad_name);
host_share.update_capacity(this);
return 0;
};

View File

@ -22,6 +22,7 @@
#include <iomanip>
#include "HostShare.h"
#include "Host.h"
using namespace std;
@ -375,6 +376,7 @@ ostream& operator<<(ostream& os, const HostSharePCI& pci)
return os;
}
/* ************************************************************************ */
/* HostShare :: Constructor/Destructor */
/* ************************************************************************ */
@ -384,6 +386,8 @@ HostShare::HostShare(long long _max_disk,long long _max_mem,long long _max_cpu):
disk_usage(0),
mem_usage(0),
cpu_usage(0),
total_mem(_max_mem),
total_cpu(_max_cpu),
max_disk(_max_disk),
max_mem(_max_mem),
max_cpu(_max_cpu),
@ -416,6 +420,8 @@ string& HostShare::to_xml(string& xml) const
<< "<DISK_USAGE>" << disk_usage << "</DISK_USAGE>"
<< "<MEM_USAGE>" << mem_usage << "</MEM_USAGE>"
<< "<CPU_USAGE>" << cpu_usage << "</CPU_USAGE>"
<< "<TOTAL_MEM>" << total_mem << "</TOTAL_MEM>"
<< "<TOTAL_CPU>" << total_cpu << "</TOTAL_CPU>"
<< "<MAX_DISK>" << max_disk << "</MAX_DISK>"
<< "<MAX_MEM>" << max_mem << "</MAX_MEM>"
<< "<MAX_CPU>" << max_cpu << "</MAX_CPU>"
@ -450,6 +456,9 @@ int HostShare::from_xml_node(const xmlNodePtr node)
rc += xpath<long long>(mem_usage, "/HOST_SHARE/MEM_USAGE", -1);
rc += xpath<long long>(cpu_usage, "/HOST_SHARE/CPU_USAGE", -1);
rc += xpath<long long>(total_mem , "/HOST_SHARE/TOTAL_MEM", -1);
rc += xpath<long long>(total_cpu, "/HOST_SHARE/TOTAL_CPU", -1);
rc += xpath<long long>(max_disk, "/HOST_SHARE/MAX_DISK", -1);
rc += xpath<long long>(max_mem , "/HOST_SHARE/MAX_MEM", -1);
rc += xpath<long long>(max_cpu , "/HOST_SHARE/MAX_CPU", -1);
@ -523,6 +532,118 @@ void HostShare::set_ds_monitorization(const vector<VectorAttribute*> &ds_att)
}
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static void set_reserved_metric(long long& value, long long mvalue,
string& reserved)
{
bool abs = true;
if ( reserved.empty() )
{
value = mvalue;
return;
}
if (std::isspace(reserved.back()))
{
reserved = one_util::trim(reserved);
}
if (reserved.back() == '%')
{
abs = false;
reserved.erase(reserved.end()-1);
}
istringstream iss(reserved);
iss >> value;
if (iss.fail() || !iss.eof())
{
value = mvalue;
return;
}
if (abs)
{
value = mvalue - value;
}
else
{
value = mvalue * ( 1 - (value / 100.0));
}
}
/* -------------------------------------------------------------------------- */
void HostShare::set_capacity(Host *host, const string& cluster_rcpu,
const string& cluster_rmem)
{
float val;
string host_rcpu;
string host_rmem;
host->get_reserved_capacity(host_rcpu, host_rmem);
if ( host_rcpu.empty() )
{
host_rcpu = cluster_rcpu;
}
if ( host_rmem.empty() )
{
host_rmem = cluster_rmem;
}
host->erase_template_attribute("TOTALCPU", val);
total_cpu = val;
set_reserved_metric(max_cpu, val, host_rcpu);
host->erase_template_attribute("TOTALMEMORY", val);
total_mem = val;
set_reserved_metric(max_mem, val, host_rmem);
host->erase_template_attribute("DS_LOCATION_TOTAL_MB", val);
max_disk = val;
host->erase_template_attribute("FREECPU", val);
free_cpu = val;
host->erase_template_attribute("FREEMEMORY", val);
free_mem = val;
host->erase_template_attribute("DS_LOCATION_FREE_MB", val);
free_disk = val;
host->erase_template_attribute("USEDCPU", val);
used_cpu = val;
host->erase_template_attribute("USEDMEMORY", val);
used_mem = val;
host->erase_template_attribute("DS_LOCATION_USED_MB", val);
used_disk = val;
}
/* -------------------------------------------------------------------------- */
void HostShare::update_capacity(Host *host)
{
string host_rcpu;
string host_rmem;
host->get_reserved_capacity(host_rcpu, host_rmem);
set_reserved_metric(max_cpu, total_cpu, host_rcpu);
set_reserved_metric(max_mem, total_mem, host_rmem);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -133,9 +133,9 @@ void MonitorThread::do_message()
int cid = host->get_cluster_id();
long long reserved_cpu = 0;
string reserved_cpu = "";
long long reserved_mem = 0;
string reserved_mem = "";
delete hinfo;

View File

@ -0,0 +1,105 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'set'
require 'base64'
require 'zlib'
require 'pathname'
require 'opennebula'
$: << File.dirname(__FILE__)
require 'db_schema'
include OpenNebula
module Migrator
def db_version
"5.2.0"
end
def one_version
"OpenNebula 5.2.0"
end
def up
init_log_time()
feature_4901()
log_time()
return true
end
private
def xpath(doc, sxpath)
element = doc.root.at_xpath(sxpath)
if !element.nil?
element.text
else
""
end
end
############################################################################
# Feature 4921. Adds TOTAL_CPU and TOTAL_MEM to HOST/HOST_SHARE to compute
# MAX_CPU and MAX_MEM when RESERVED_CPU/MEM is updated
############################################################################
def feature_4901
@db.run "ALTER TABLE host_pool RENAME TO old_host_pool;"
@db.run host_pool_schema()
@db.transaction do
@db.fetch("SELECT * FROM old_host_pool") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c|
c.default_xml.noblanks
}
rcpu = xpath(doc, "TEMPLATE/RESERVED_CPU").to_i
rmem = xpath(doc, "TEMPLATE/RESERVED_MEM").to_i
total_cpu = xpath(doc, "HOST_SHARE/MAX_CPU").to_i + rcpu
total_mem = xpath(doc, "HOST_SHARE/MAX_MEM").to_i + rmem
total_cpu_e = doc.create_element "TOTAL_CPU", total_cpu
total_mem_e = doc.create_element "TOTAL_MEM", total_mem
host_share = doc.root.at_xpath("HOST_SHARE")
host_share.add_child(total_cpu_e)
host_share.add_child(total_mem_e)
@db[:host_pool].insert(
:oid => row[:oid],
:name => row[:name],
:body => doc.root.to_s,
:state => row[:state],
:last_mon_time => row[:last_mon_time],
:uid => row[:uid],
:gid => row[:gid],
:owner_u => row[:owner_u],
:group_u => row[:group_u],
:other_u => row[:other_u],
:cid => row[:cid])
end
end
@db.run "DROP TABLE old_host_pool;"
end
end

View File

@ -0,0 +1,48 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'set'
require 'base64'
require 'zlib'
require 'pathname'
require 'opennebula'
include OpenNebula
module Migrator
##############################################################################
# DB schema for OpenNebula tables, each function may return the schema for
# each opennebula version
##############################################################################
def host_pool_schema
case db_version()
when "4.5.80"
when "4.7.80"
when "4.9.80"
when "4.10.3"
when "4.11.80"
when "4.13.80"
when "4.13.85"
when "4.90.0"
when "5.2.0"
'CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), '\
'body MEDIUMTEXT, state INTEGER, last_mon_time INTEGER, uid INTEGER, '\
'gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, '\
'cid INTEGER);'
end
end
end

View File

@ -24,6 +24,7 @@ define(function(require) {
var RenameTr = require('utils/panel/rename-tr');
var TemplateTable = require('utils/panel/template-table');
var Sunstone = require('sunstone');
var TemplateUtils = require('utils/template-utils');
/*
CONSTANTS
@ -47,12 +48,13 @@ define(function(require) {
this.icon = "fa-info-circle";
this.element = info[XML_ROOT];
this.percent = false;
// Hide information in the template table. Unshow values are stored
// in the unshownTemplate object to be used when the element info is updated.
that.unshownTemplate = {};
that.strippedTemplate = {};
var unshownKeys = ['RESERVED_CPU', 'RESERVED_MEM'];
var unshownKeys = ['HOST', 'RESERVED_CPU', 'RESERVED_MEM'];
$.each(that.element.TEMPLATE, function(key, value) {
if ($.inArray(key, unshownKeys) > -1) {
that.unshownTemplate[key] = value;
@ -80,14 +82,43 @@ define(function(require) {
this.strippedTemplate,
RESOURCE,
Locale.tr("Attributes"));
var reservedMem;
(this.element.TEMPLATE.RESERVED_MEM != "0%" && this.element.TEMPLATE.RESERVED_MEM != "")?reservedMem = parseInt(this.element.TEMPLATE.RESERVED_MEM): reservedMem = 0;
var reservedCPU
(this.element.TEMPLATE.RESERVED_CPU != "0%" && this.element.TEMPLATE.RESERVED_CPU != "")? reservedCPU = parseInt(this.element.TEMPLATE.RESERVED_CPU): reservedCPU = 0;
return TemplateHTML({
'element': this.element,
'renameTrHTML': renameTrHTML,
'templateTableHTML': templateTableHTML
'templateTableHTML': templateTableHTML,
'percentCPU': reservedCPU,
'percentMEM': reservedMem,
});
}
function changeBarCPU(){
if(parseInt(document.getElementById('change_bar_cpu').value) > 0)
document.getElementById('textInput_reserved_cpu').style.backgroundColor = 'rgba(111, 220, 111,0.5)';
if(parseInt(document.getElementById('change_bar_cpu').value) < 0)
document.getElementById('textInput_reserved_cpu').style.backgroundColor = 'rgba(255, 80, 80,0.5)';
document.getElementById('textInput_reserved_cpu').value = document.getElementById('change_bar_cpu').value;
}
function changeInputCPU(){
document.getElementById('change_bar_cpu').value = document.getElementById('textInput_reserved_cpu').value;
}
function changeBarMEM(){
if(parseInt(document.getElementById('change_bar_mem').value) > 0)
document.getElementById('textInput_reserved_mem').style.backgroundColor = 'rgba(111, 220, 111,0.5)';
if(parseInt(document.getElementById('change_bar_mem').value) < 0)
document.getElementById('textInput_reserved_mem').style.backgroundColor = 'rgba(255, 80, 80,0.5)';
document.getElementById('textInput_reserved_mem').value = document.getElementById('change_bar_mem').value;
}
function changeInputMEM(){
document.getElementById('change_bar_mem').value = document.getElementById('textInput_reserved_mem').value;
}
function _setup(context) {
var that = this;
@ -95,18 +126,17 @@ define(function(require) {
TemplateTable.setup(this.strippedTemplate, RESOURCE, this.element.ID, context, this.unshownTemplate);
$(".edit_reserved", context).on("click", function(){
var dialog = Sunstone.getDialog(OVERCOMMIT_DIALOG_ID);
document.getElementById("change_bar_cpu").addEventListener("change", changeBarCPU);
document.getElementById("textInput_reserved_cpu").addEventListener("change", changeInputCPU);
document.getElementById("change_bar_mem").addEventListener("change", changeBarMEM);
document.getElementById("textInput_reserved_mem").addEventListener("change", changeInputMEM);
dialog.setParams(
{ element: that.element,
action : "Cluster.append_template",
resourceName : Locale.tr("Cluster"),
tabId : TAB_ID
});
$(document).off('click', '.update_reserved').on("click", '.update_reserved', function(){
var reservedCPU = document.getElementById('change_bar_cpu').value+'%';
var reservedMem = document.getElementById('change_bar_mem').value+'%';
dialog.show();
return false;
var obj = {RESERVED_CPU: reservedCPU, RESERVED_MEM: reservedMem};
Sunstone.runAction("Cluster.append_template", that.element.ID, TemplateUtils.templateToString(obj));
});
}
});

View File

@ -31,31 +31,39 @@
{{{renameTrHTML}}}
</tbody>
</table>
<table class="dataTable">
<thead>
<tr>
<th colspan="3">{{tr "Overcommitment"}}</th>
</tr>
</thead>
<tbody>
<tr>
<td class="key_td">{{tr "Reserved CPU"}}</td>
<td class="value_td" style="width:50%;">{{valOrDefault element.TEMPLATE.RESERVED_CPU "-"}}</td>
<td>
<a class="edit_reserved edit_e" href="#"> <i class="fa fa-pencil-square-o right"/></a>
</td>
</tr>
<tr>
<td class="key_td">{{tr "Reserved Memory"}}</td>
<td class="value_td" style="width:50%;">{{humanizeSize "KB" element.TEMPLATE.RESERVED_MEM}}</td>
<td>
<a class="edit_reserved edit_e" href="#"> <i class="fa fa-pencil-square-o right"/></a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<table class="dataTable">
<thead>
<tr>
<th colspan="4">{{tr "Overcommitment"}}
<span class="right">
<button id="update_reserved" type="button" class="button small success update_reserved right radius">
{{tr "Update"}}
</button>
</span>
</th>
</tr>
</thead>
<tbody>
<tr colspan="3">
<td class="key_td">{{tr "Reserved CPU"}}</td>
<td><input type="range" name="rangeInput" id="change_bar_cpu" min="-100" value="{{percentCPU}}" max="100">
<label align="center">0%</label></td>
<td><input type="text" id="textInput_reserved_cpu" value="{{percentCPU}}" min="-100" max="100" size="1"></td>
</tr>
<tr colspan="3">
<td class="key_td">{{tr "Reserved Memory"}}</td>
<td><input type="range" name="rangeInput" id="change_bar_mem" min="-100" value="{{percentMEM}}" max="100">
<label align="center">0%</label></td>
<td><input type="text" id="textInput_reserved_mem" value="{{percentMEM}}" min="-100" max="100" size="1"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="large-9 columns">
{{{templateTableHTML}}}

View File

@ -13,12 +13,11 @@
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
define(function(require) {
/*
DEPENDENCIES
*/
require('foundation');
var Locale = require('utils/locale');
var Humanize = require('utils/humanize');
var RenameTr = require('utils/panel/rename-tr');
@ -31,6 +30,7 @@ define(function(require) {
var DatastoresCapacityTable = require('../utils/datastores-capacity-table');
var CanImportWilds = require('../utils/can-import-wilds');
var Sunstone = require('sunstone');
var TemplateUtils = require('utils/template-utils');
/*
TEMPLATES
@ -59,7 +59,6 @@ define(function(require) {
that.icon = "fa-info-circle";
that.element = info[XML_ROOT];
that.canImportWilds = CanImportWilds(that.element);
// Hide information of the Wild VMs of the Host and the ESX Hosts
@ -88,19 +87,19 @@ define(function(require) {
/*
FUNCTION DEFINITIONS
*/
function _html() {
var templateTableHTML = TemplateTable.html(
this.strippedTemplate,
RESOURCE,
Locale.tr("Attributes"));
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,
@ -111,10 +110,23 @@ define(function(require) {
'cpuBars': cpuBars,
'memoryBars': memoryBars,
'stateStr': OpenNebulaHost.stateStr(this.element.STATE),
'datastoresCapacityTableHTML': datastoresCapacityTableHTML
'datastoresCapacityTableHTML': datastoresCapacityTableHTML,
'maxReservedMEM': realMEM * 2,
'maxReservedCPU': realCPU * 2,
'realCPU': realCPU,
'realMEM': Humanize.size(realMEM),
'virtualMEMInput': Humanize.size(this.element.HOST_SHARE.MAX_MEM)
});
}
function changeInputCPU(){
document.getElementById('change_bar_cpu_hosts').value = document.getElementById('textInput_reserved_cpu_hosts').value;
}
function changeInputMEM(){
document.getElementById('change_bar_mem_hosts').value = parseInt(document.getElementById('textInput_reserved_mem_hosts').value);
}
function _setup(context) {
var that = this;
@ -123,20 +135,38 @@ define(function(require) {
TemplateTable.setup(this.strippedTemplate, RESOURCE, this.element.ID, context, this.unshownTemplate);
PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context);
$(".edit_reserved", context).on("click", function(){
var dialog = Sunstone.getDialog(OVERCOMMIT_DIALOG_ID);
//.off and .on prevent multiple clicks events
$(document).off('click', '.update_reserved_hosts').on("click", '.update_reserved', function(){
var reservedCPU = parseInt(document.getElementById('change_bar_cpu_hosts').value);
var CPU = parseInt(that.element.HOST_SHARE.FREE_CPU);
var reservedMem = parseInt(document.getElementById('change_bar_mem_hosts').value);
var MEM = parseInt(that.element.HOST_SHARE.FREE_MEM);
if(parseInt(that.element.HOST_SHARE.USED_CPU) > 0)
CPU += parseInt(that.element.HOST_SHARE.USED_CPU);
reservedCPU = CPU - reservedCPU;
if(parseInt(that.element.HOST_SHARE.USED_MEM) > 0)
MEM += parseInt(that.element.HOST_SHARE.USED_MEM);
reservedMem = MEM - reservedMem;
dialog.setParams(
{ element: that.element,
action : "Host.append_template",
resourceName : Locale.tr("Host"),
tabId : TAB_ID
});
dialog.show();
return false;
var obj = {RESERVED_CPU: reservedCPU, RESERVED_MEM: reservedMem};
Sunstone.runAction("Host.append_template", that.element.ID, TemplateUtils.templateToString(obj));
});
return false;
document.getElementById("change_bar_cpu_hosts").addEventListener("change", function(){
if(parseInt(document.getElementById('change_bar_cpu_hosts').value) > that.element.HOST_SHARE.TOTAL_CPU)
document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(111, 220, 111,0.5)';
if(parseInt(document.getElementById('change_bar_cpu_hosts').value) < that.element.HOST_SHARE.TOTAL_CPU)
document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(255, 80, 80,0.5)';
document.getElementById('textInput_reserved_cpu_hosts').value = document.getElementById('change_bar_cpu_hosts').value;
});
document.getElementById("textInput_reserved_cpu_hosts").addEventListener("change", changeInputCPU);
document.getElementById("change_bar_mem_hosts").addEventListener("change", function(){
if(parseInt(document.getElementById('change_bar_mem_hosts').value) > that.element.HOST_SHARE.TOTAL_MEM)
document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(111, 220, 111,0.5)';
if(parseInt(document.getElementById('change_bar_mem_hosts').value) < that.element.HOST_SHARE.TOTAL_MEM)
document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(255, 80, 80,0.5)';
document.getElementById('textInput_reserved_mem_hosts').value = Humanize.size(parseInt(document.getElementById('change_bar_mem_hosts').value));
});
document.getElementById("textInput_reserved_mem_hosts").addEventListener("change", changeInputMEM);
}
});

View File

@ -73,30 +73,38 @@
</tr>
</tbody>
</table>
{{{datastoresCapacityTableHTML}}}
</div>
</div>
<div class="row">
<div class="large-12 columns">
<table class="dataTable">
<thead>
<tr>
<th colspan="3">{{tr "Overcommitment"}}</th>
<th colspan="4">{{tr "Overcommitment"}}
<span class="right">
<button id="update_reserved_hosts" type="button" class="button small success update_reserved right radius">
{{tr "Update"}}
</button>
</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="key_td">{{tr "Reserved CPU"}}</td>
<td class="value_td" style="width:50%;">{{valOrDefault element.TEMPLATE.RESERVED_CPU "-"}}</td>
<td>
<a class="edit_reserved edit_e" href="#"> <i class="fa fa-pencil-square-o right"/></a>
</td>
<tr colspan="3">
<td class="key_td">{{tr "CPU"}}</td>
<td><input type="range" name="rangeInput" id="change_bar_cpu_hosts" min="0" value="{{element.HOST_SHARE.MAX_CPU}}" max="{{maxReservedCPU}}">
<label align="center">{{realCPU}}</label></td>
<td><input type="text" id="textInput_reserved_cpu_hosts" value="{{element.HOST_SHARE.MAX_CPU}}" min="0" size="1"></td>
</tr>
<tr>
<td class="key_td">{{tr "Reserved Memory"}}</td>
<td class="value_td" style="width:50%;">{{humanizeSize "KB" element.TEMPLATE.RESERVED_MEM}}</td>
<td>
<a class="edit_reserved edit_e" href="#"> <i class="fa fa-pencil-square-o right"/></a>
</td>
<tr colspan="3">
<td class="key_td">{{tr "Memory"}}</td>
<td><input type="range" name="rangeInput" id="change_bar_mem_hosts" value="{{element.HOST_SHARE.MAX_MEM}}" max="{{maxReservedMEM}}">
<label align="center">{{realMEM}}</label></td>
<td><input type="text" id="textInput_reserved_mem_hosts" value="{{virtualMEMInput}}" min="0" size="1"></td>
</tr>
</tbody>
</table>
{{{datastoresCapacityTableHTML}}}
</div>
</div>
<div class="row">

View File

@ -76,21 +76,22 @@ define(function(require) {
data: {
id: this.element.ID,
monitor: {
monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU,HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM"
monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU,HOST_SHARE/TOTAL_CPU,HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM,HOST_SHARE/TOTAL_MEM"
}
},
success: function(req, response) {
var host_graphs = [
{
monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU",
labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total"),
monitor_resources : "HOST_SHARE/CPU_USAGE,HOST_SHARE/USED_CPU,HOST_SHARE/MAX_CPU,HOST_SHARE/TOTAL_CPU",
labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total") + "," + Locale.tr("Total +/- reserved"),
humanize_figures : false,
div_graph : $("#host_cpu_graph"),
div_legend : $("#host_cpu_legend")
},
{
monitor_resources : "HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM",
labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total"),
monitor_resources : "HOST_SHARE/MEM_USAGE,HOST_SHARE/USED_MEM,HOST_SHARE/MAX_MEM,HOST_SHARE/TOTAL_MEM",
labels : Locale.tr("Allocated") + "," + Locale.tr("Real") + "," + Locale.tr("Total") + "," + Locale.tr("Total +/- reserved"),
humanize_figures : false,
humanize_figures : true,
div_graph : $("#host_mem_graph"),
div_legend : $("#host_mem_legend")