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

Merge branch 'feature-1612'

This commit is contained in:
Ruben S. Montero 2013-10-10 15:35:06 +02:00
commit e24fc1aae4
16 changed files with 340 additions and 57 deletions

View File

@ -22,12 +22,14 @@
/**
* VM Quotas, defined as:
* VM = [
* VMS = <Max. number of VMs>
* MEMORY = <Max. number of MB requested by VMs>
* CPU = <Max. number of CPU units requested by VMs>
* VMS_USED = Current number of VMs
* MEMORY_USED = Overall Memory requested
* CPU_USED = Overall CPU requested
* VMS = <Max. number of VMs>
* MEMORY = <Max. number of MB requested by VMs>
* CPU = <Max. number of CPU units requested by VMs>
* VOLATILE_SIZE = <Max. number of volatile disk MB>
* VMS_USED = Current number of VMs
* MEMORY_USED = Overall Memory requested
* CPU_USED = Overall CPU requested
* VOLATILE_SIZE_USED = <Max. number of volatile disk MB>
* ]
*
* 0 = unlimited, default if missing

View File

@ -1068,6 +1068,16 @@ public:
*/
void release_disk_images();
/**
* Check if the given disk is volatile
*/
static bool isVolatile(const VectorAttribute * disk);
/**
* Return the total SIZE of volatile disks
*/
static float get_volatile_disk_size(Template * tmpl);
// ------------------------------------------------------------------------
// Context related functions
// ------------------------------------------------------------------------

View File

@ -57,6 +57,8 @@
<xs:element name="MEMORY_USED" type="xs:string"/>
<xs:element name="VMS" type="xs:string"/>
<xs:element name="VMS_USED" type="xs:string"/>
<xs:element name="VOLATILE_SIZE" type="xs:string"/>
<xs:element name="VOLATILE_SIZE_USED" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View File

@ -60,6 +60,8 @@
<xs:element name="MEMORY_USED" type="xs:string"/>
<xs:element name="VMS" type="xs:string"/>
<xs:element name="VMS_USED" type="xs:string"/>
<xs:element name="VOLATILE_SIZE" type="xs:string"/>
<xs:element name="VOLATILE_SIZE_USED" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View File

@ -63,6 +63,8 @@
<xs:element name="MEMORY_USED" type="xs:string"/>
<xs:element name="VMS" type="xs:string"/>
<xs:element name="VMS_USED" type="xs:string"/>
<xs:element name="VOLATILE_SIZE" type="xs:string"/>
<xs:element name="VOLATILE_SIZE_USED" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View File

@ -67,6 +67,8 @@
<xs:element name="MEMORY_USED" type="xs:string"/>
<xs:element name="VMS" type="xs:string"/>
<xs:element name="VMS_USED" type="xs:string"/>
<xs:element name="VOLATILE_SIZE" type="xs:string"/>
<xs:element name="VOLATILE_SIZE_USED" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View File

@ -31,9 +31,10 @@ class OneQuotaHelper
# ]
#
# VM = [
# VMS = <Max. number of VMs>
# MEMORY = <Max. allocated memory (Mb)>
# CPU = <Max. allocated CPU>
# VMS = <Max. number of VMs>
# MEMORY = <Max. allocated memory (MB)>
# CPU = <Max. allocated CPU>
# VOLATILE_SIZE = <Max. allocated volatile disks (MB)>
# ]
#
# NETWORK = [
@ -180,14 +181,14 @@ class OneQuotaHelper
if !vm_quotas[0].nil?
CLIHelper::ShowTable.new(nil, self) do
column :"NUMBER OF VMS", "", :right, :size=>20 do |d|
column :"NUMBER OF VMS", "", :right, :size=>17 do |d|
if !d.nil?
elem = 'VMS'
limit = d[elem]
limit = helper.get_default_limit(
limit, "VM_QUOTA/VM/#{elem}")
"%8d / %8d" % [d["VMS_USED"], limit]
"%7d / %7d" % [d["VMS_USED"], limit]
end
end
@ -215,6 +216,20 @@ class OneQuotaHelper
"%8.2f / %8.2f" % [d["CPU_USED"], limit]
end
end
column :"VOLATILE_SIZE", "", :right, :size=>20 do |d|
if !d.nil?
elem = 'VOLATILE_SIZE'
limit = d[elem]
limit = helper.get_default_limit(
limit, "VM_QUOTA/VM/#{elem}")
"%8s / %8s" % [
OpenNebulaHelper.unit_to_str(d["VOLATILE_SIZE_USED"].to_i,{},"M"),
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
]
end
end
end.show(vm_quotas, {})
puts

View File

@ -28,7 +28,7 @@ module Migrator
def up
########################################################################
# Feature #1742
# Feature #1742 & #1612
########################################################################
@db.run "ALTER TABLE user_pool RENAME TO old_user_pool;"
@ -39,6 +39,11 @@ module Migrator
doc.root.add_element("GROUPS").add_element("ID").text = row[:gid].to_s
# oneadmin does not have quotas
if row[:oid] != 0
redo_vm_quotas(doc, "uid=#{row[:oid]}")
end
@db[:user_pool].insert(
:oid => row[:oid],
:name => row[:name],
@ -52,6 +57,44 @@ module Migrator
@db.run "DROP TABLE old_user_pool;"
########################################################################
# Feature #1612
########################################################################
@db.run "ALTER TABLE group_pool RENAME TO old_group_pool;"
@db.run "CREATE TABLE group_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));"
# oneadmin group does not have quotas
@db.fetch("SELECT * FROM old_group_pool WHERE oid=0") do |row|
@db[:group_pool].insert(
:oid => row[:oid],
:name => row[:name],
:body => row[:body],
:uid => row[:oid],
:gid => row[:gid],
:owner_u => row[:owner_u],
:group_u => row[:group_u],
:other_u => row[:other_u])
end
@db.fetch("SELECT * FROM old_group_pool WHERE oid>0") do |row|
doc = REXML::Document.new(row[:body])
redo_vm_quotas(doc, "gid=#{row[:oid]}")
@db[:group_pool].insert(
:oid => row[:oid],
:name => row[:name],
:body => doc.root.to_s,
:uid => row[:oid],
:gid => row[:gid],
:owner_u => row[:owner_u],
:group_u => row[:group_u],
:other_u => row[:other_u])
end
@db.run "DROP TABLE old_group_pool;"
########################################################################
# Bug #2330
########################################################################
@ -82,4 +125,81 @@ module Migrator
return true
end
def redo_vm_quotas(doc, where_filter)
cpu_limit = "-1"
mem_limit = "-1"
vms_limit = "-1"
vol_limit = "-1"
doc.root.each_element("VM_QUOTA/VM/CPU") { |e|
cpu_limit = e.text
}
doc.root.each_element("VM_QUOTA/VM/MEMORY") { |e|
mem_limit = e.text
}
doc.root.each_element("VM_QUOTA/VM/VMS") { |e|
vms_limit = e.text
}
doc.root.delete_element("VM_QUOTA")
vm_quota = doc.root.add_element("VM_QUOTA")
# VM quotas
cpu_used = 0
mem_used = 0
vms_used = 0
vol_used = 0
@db.fetch("SELECT body FROM vm_pool WHERE #{where_filter} AND state<>6") do |vm_row|
vmdoc = REXML::Document.new(vm_row[:body])
# VM quotas
vmdoc.root.each_element("TEMPLATE/CPU") { |e|
cpu_used += e.text.to_f
}
vmdoc.root.each_element("TEMPLATE/MEMORY") { |e|
mem_used += e.text.to_i
}
vmdoc.root.each_element("TEMPLATE/DISK") { |e|
type = ""
e.each_element("TYPE") { |t_elem|
type = t_elem.text.upcase
}
if ( type == "SWAP" || type == "FS")
e.each_element("SIZE") { |size_elem|
vol_used += size_elem.text.to_f
}
end
}
vms_used += 1
end
if (vms_used != 0 ||
cpu_limit != "-1" || mem_limit != "-1" || vms_limit != "-1" || vol_limit != "-1" )
# VM quotas
vm_elem = vm_quota.add_element("VM")
vm_elem.add_element("CPU").text = cpu_limit
vm_elem.add_element("CPU_USED").text = sprintf('%.2f', cpu_used)
vm_elem.add_element("MEMORY").text = mem_limit
vm_elem.add_element("MEMORY_USED").text = mem_used.to_s
vm_elem.add_element("VMS").text = vms_limit
vm_elem.add_element("VMS_USED").text = vms_used.to_s
vm_elem.add_element("VOLATILE_SIZE").text = vol_limit
vm_elem.add_element("VOLATILE_SIZE_USED").text = sprintf('%.2f', vol_used)
end
end
end

View File

@ -1286,6 +1286,7 @@ module OneDBFsck
cpu_used = 0.0
mem_used = 0
vms_used = 0
vol_used = 0.0
# VNet quotas
vnet_usage = {}
@ -1301,12 +1302,28 @@ module OneDBFsck
# truncate to 2 decimals
cpu = (e.text.to_f * 100).to_i / 100.0
cpu_used += cpu
cpu_used = (cpu_used * 100).to_i / 100.0
}
vmdoc.root.each_element("TEMPLATE/MEMORY") { |e|
mem_used += e.text.to_i
}
vmdoc.root.each_element("TEMPLATE/DISK") { |e|
type = ""
e.each_element("TYPE") { |t_elem|
type = t_elem.text.upcase
}
if ( type == "SWAP" || type == "FS")
e.each_element("SIZE") { |size_elem|
vol_used += size_elem.text.to_f
vol_used = (vol_used * 100).to_i / 100.0
}
end
}
vms_used += 1
# VNet quotas
@ -1342,6 +1359,9 @@ module OneDBFsck
vm_elem.add_element("VMS").text = "-1"
vm_elem.add_element("VMS_USED").text = "0"
vm_elem.add_element("VOLATILE_SIZE").text = "-1"
vm_elem.add_element("VOLATILE_SIZE_USED").text = "0"
end
@ -1378,6 +1398,20 @@ module OneDBFsck
end
}
vm_elem.each_element("VOLATILE_SIZE_USED") { |e|
# Check if the float value or the string representation mismatch,
# but ignoring the precision
different = ( e.text.to_f != vol_used ||
![sprintf('%.2f', vol_used), sprintf('%.1f', vol_used), sprintf('%.0f', vol_used)].include?(e.text) )
vol_used_str = sprintf('%.2f', vol_used)
if different
log_error("#{resource} #{oid} quotas: VOLATILE_SIZE_USED has #{e.text} \tis\t#{vol_used_str}")
e.text = vol_used_str
end
}
# VNet quotas

View File

@ -360,6 +360,7 @@ function updateUserConfigInfo(request,user_json) {
var quotas_tab_html = Quotas.vms(info, default_user_quotas);
quotas_tab_html += Quotas.cpu(info, default_user_quotas);
quotas_tab_html += Quotas.memory(info, default_user_quotas);
quotas_tab_html += Quotas.volatile_size(info, default_user_quotas);
quotas_tab_html += Quotas.image(info, default_user_quotas);
quotas_tab_html += Quotas.network(info, default_user_quotas);
quotas_tab_html += Quotas.datastore(info, default_user_quotas);
@ -456,6 +457,7 @@ function fillGroupQuotas(group_id){
var quotas_tab_html = Quotas.vms(info, default_group_quotas);
quotas_tab_html += Quotas.cpu(info, default_group_quotas);
quotas_tab_html += Quotas.memory(info, default_group_quotas);
quotas_tab_html += Quotas.volatile_size(info, default_group_quotas);
quotas_tab_html += Quotas.image(info, default_group_quotas);
quotas_tab_html += Quotas.network(info, default_group_quotas);
quotas_tab_html += Quotas.datastore(info, default_group_quotas);

View File

@ -133,10 +133,10 @@ var group_quotas_tmpl = '<div class="panel">\
<hr>\
<div id="vm_quota">\
<div class="row">\
<div class="four columns">\
<div class="six columns">\
<label class="inline right" >'+tr("Max VMs")+':</label>\
</div>\
<div class="seven columns">\
<div class="five columns">\
<input type="text" name="VMS"></input>\
</div>\
<div class="one columns">\
@ -144,10 +144,10 @@ var group_quotas_tmpl = '<div class="panel">\
</div>\
</div>\
<div class="row">\
<div class="four columns">\
<div class="six columns">\
<label class="inline right" >'+tr("Max Memory (MB)")+':</label>\
</div>\
<div class="seven columns">\
<div class="five columns">\
<input type="text" name="MEMORY"></input>\
</div>\
<div class="one columns">\
@ -155,16 +155,27 @@ var group_quotas_tmpl = '<div class="panel">\
</div>\
</div>\
<div class="row">\
<div class="four columns">\
<div class="six columns">\
<label class="inline right" >'+tr("Max CPU")+':</label>\
</div>\
<div class="seven columns">\
<div class="five columns">\
<input type="text" name="CPU"></input>\
</div>\
<div class="one columns">\
<div class=""></div>\
</div>\
</div>\
<div class="row">\
<div class="six columns">\
<label class="inline right" >'+tr("Max Volatile Storage (MB)")+':</label>\
</div>\
<div class="five columns">\
<input type="text" name="VOLATILE_SIZE"></input>\
</div>\
<div class="one columns">\
<div class=""></div>\
</div>\
</div>\
</div>\
<div id="datastore_quota">\
<div class="row">\
@ -528,9 +539,10 @@ function updateGroupInfo(request,group){
var info = group.GROUP;
var default_group_quotas = Quotas.default_quotas(info.DEFAULT_GROUP_QUOTAS);
var quotas_tab_html = '<div class="four columns">' + Quotas.vms(info, default_group_quotas) + '</div>';
quotas_tab_html += '<div class="four columns">' + Quotas.cpu(info, default_group_quotas) + '</div>';
quotas_tab_html += '<div class="four columns">' + Quotas.memory(info, default_group_quotas) + '</div>';
var quotas_tab_html = '<div class="three columns">' + Quotas.vms(info, default_group_quotas) + '</div>';
quotas_tab_html += '<div class="three columns">' + Quotas.cpu(info, default_group_quotas) + '</div>';
quotas_tab_html += '<div class="three columns">' + Quotas.memory(info, default_group_quotas) + '</div>';
quotas_tab_html += '<div class="three columns">' + Quotas.volatile_size(info, default_group_quotas) + '</div>';
quotas_tab_html += '<br><br>';
quotas_tab_html += '<div class="six columns">' + Quotas.image(info, default_group_quotas) + '</div>';
quotas_tab_html += '<div class="six columns">' + Quotas.network(info, default_group_quotas) + '</div>';

View File

@ -219,10 +219,10 @@ var user_quotas_tmpl = '<div class="panel">\
<hr>\
<div id="vm_quota">\
<div class="row">\
<div class="four columns">\
<div class="six columns">\
<label class="inline right" >'+tr("Max VMs")+':</label>\
</div>\
<div class="seven columns">\
<div class="five columns">\
<input type="text" name="VMS"></input>\
</div>\
<div class="one columns">\
@ -230,10 +230,10 @@ var user_quotas_tmpl = '<div class="panel">\
</div>\
</div>\
<div class="row">\
<div class="four columns">\
<div class="six columns">\
<label class="inline right" >'+tr("Max Memory (MB)")+':</label>\
</div>\
<div class="seven columns">\
<div class="five columns">\
<input type="text" name="MEMORY"></input>\
</div>\
<div class="one columns">\
@ -241,16 +241,27 @@ var user_quotas_tmpl = '<div class="panel">\
</div>\
</div>\
<div class="row">\
<div class="four columns">\
<div class="six columns">\
<label class="inline right" >'+tr("Max CPU")+':</label>\
</div>\
<div class="seven columns">\
<div class="five columns">\
<input type="text" name="CPU"></input>\
</div>\
<div class="one columns">\
<div class=""></div>\
</div>\
</div>\
<div class="row">\
<div class="six columns">\
<label class="inline right" >'+tr("Max Volatile Storage (MB)")+':</label>\
</div>\
<div class="five columns">\
<input type="text" name="VOLATILE_SIZE"></input>\
</div>\
<div class="one columns">\
<div class=""></div>\
</div>\
</div>\
</div>\
<div id="datastore_quota">\
<div class="row">\
@ -780,9 +791,10 @@ function updateUserInfo(request,user){
};
var default_user_quotas = Quotas.default_quotas(info.DEFAULT_USER_QUOTAS)
var quotas_tab_html = '<div class="four columns">' + Quotas.vms(info, default_user_quotas) + '</div>';
quotas_tab_html += '<div class="four columns">' + Quotas.cpu(info, default_user_quotas) + '</div>';
quotas_tab_html += '<div class="four columns">' + Quotas.memory(info, default_user_quotas) + '</div>';
var quotas_tab_html = '<div class="three columns">' + Quotas.vms(info, default_user_quotas) + '</div>';
quotas_tab_html += '<div class="three columns">' + Quotas.cpu(info, default_user_quotas) + '</div>';
quotas_tab_html += '<div class="three columns">' + Quotas.memory(info, default_user_quotas) + '</div>';
quotas_tab_html += '<div class="three columns">' + Quotas.volatile_size(info, default_user_quotas) + '</div>';
quotas_tab_html += '<br><br>';
quotas_tab_html += '<div class="six columns">' + Quotas.image(info, default_user_quotas) + '</div>';
quotas_tab_html += '<div class="six columns">' + Quotas.network(info, default_user_quotas) + '</div>';

View File

@ -1238,6 +1238,21 @@ var Quotas = {
return '';
}
},
"volatile_size" : function(info, default_quotas){
if (!$.isEmptyObject(info.VM_QUOTA)){
var volatile_bar = quotaBarMB(
info.VM_QUOTA.VM.VOLATILE_SIZE_USED,
info.VM_QUOTA.VM.VOLATILE_SIZE,
default_quotas.VM_QUOTA.VM.VOLATILE_SIZE);
var quotas_tab_html =
'<fieldset><legend>' + tr("Volatile disks") + '</legend><div>'+volatile_bar+'</div><br></fieldset>'
return quotas_tab_html;
} else {
return '';
}
},
"datastore" : function(info, default_quotas) {
if (!$.isEmptyObject(info.DATASTORE_QUOTA)){
var quotas_tab_html =
@ -1410,9 +1425,10 @@ var Quotas = {
if ($.isEmptyObject(default_quotas.VM_QUOTA)){
default_quotas.VM_QUOTA = {
"VM" : {
"VMS" : "0",
"MEMORY" : "0",
"CPU" : "0"
"VMS" : "0",
"MEMORY" : "0",
"CPU" : "0",
"VOLATILE_SIZE" : "0"
}
}
}
@ -1581,6 +1597,7 @@ function setupQuotaIcons(){
$('div#vm_quota input[name="VMS"]',dialog).val(quota.VMS);
$('div#vm_quota input[name="MEMORY"]',dialog).val(quota.MEMORY);
$('div#vm_quota input[name="CPU"]',dialog).val(quota.CPU);
$('div#vm_quota input[name="VOLATILE_SIZE"]',dialog).val(quota.VOLATILE_SIZE);
break;
case "DATASTORE":
$('div#datastore_quota select[name="ID"]',dialog).val(quota.ID);
@ -1675,7 +1692,8 @@ function quotaListItem(quota_json){
case "VM":
str += 'VMs: ' + quota_json.VMS + (quota_json.VMS_USED ? ' (' + quota_json.VMS_USED + '). ' : ". ") + '<br>' +
'Memory: ' + quota_json.MEMORY + (quota_json.MEMORY_USED ? ' MB (' + quota_json.MEMORY_USED + ' MB). ' : " MB. ") + '<br>' +
'CPU: ' + quota_json.CPU + (quota_json.CPU_USED ? ' (' + quota_json.CPU_USED + '). ' : ". ");
'CPU: ' + quota_json.CPU + (quota_json.CPU_USED ? ' (' + quota_json.CPU_USED + '). ' : ". ") + '<br>' +
'Volatile disks: ' + quota_json.VOLATILE_SIZE + (quota_json.VOLATILE_SIZE_USED ? ' MB (' + quota_json.VOLATILE_SIZE_USED + ' MB). ' : " MB. ");
break;
case "DATASTORE":
str += 'ID/Name: ' + getDatastoreName(quota_json.ID) + '. ' + '<br>' +

View File

@ -733,19 +733,6 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static bool isVolatile(const VectorAttribute * disk)
{
string type;
type = disk->vector_value("TYPE");
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
return ( type == "SWAP" || type == "FS");
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void TransferManager::prolog_migr_action(int vid)
{
ofstream xfr;
@ -816,7 +803,7 @@ void TransferManager::prolog_migr_action(int vid)
disk->vector_value_str("DISK_ID", disk_id);
if ( isVolatile(disk) == true )
if ( VirtualMachine::isVolatile(disk) == true )
{
tm_mad = vm_tm_mad;
ds_id = vm_ds_id;
@ -955,7 +942,7 @@ void TransferManager::prolog_resume_action(int vid)
disk->vector_value_str("DISK_ID", disk_id);
if ( isVolatile(disk) == true )
if ( VirtualMachine::isVolatile(disk) == true )
{
tm_mad = vm_tm_mad;
ds_id = vm_ds_id;
@ -1079,7 +1066,7 @@ void TransferManager::epilog_transfer_command(
}
else //No saving disk
{
if ( isVolatile(disk) == true )
if ( VirtualMachine::isVolatile(disk) == true )
{
tm_mad = vm->get_tm_mad();
ds_id = vm->get_ds_id();
@ -1285,7 +1272,7 @@ void TransferManager::epilog_stop_action(int vid)
disk->vector_value_str("DISK_ID", disk_id);
if ( isVolatile(disk) == true )
if ( VirtualMachine::isVolatile(disk) == true )
{
tm_mad = vm_tm_mad;
ds_id = vm_ds_id;
@ -1437,7 +1424,7 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm,
disk->vector_value_str("DISK_ID", disk_id);
if ( isVolatile(disk) == true )
if ( VirtualMachine::isVolatile(disk) == true )
{
tm_mad = vm_tm_mad;
ds_id = vm_ds_id;

View File

@ -16,13 +16,15 @@
#include "QuotaVirtualMachine.h"
#include "Quotas.h"
#include "VirtualMachine.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
const char * QuotaVirtualMachine::VM_METRICS[] = {"VMS", "CPU", "MEMORY"};
const char * QuotaVirtualMachine::VM_METRICS[] =
{"VMS", "CPU", "MEMORY", "VOLATILE_SIZE"};
const int QuotaVirtualMachine::NUM_VM_METRICS = 3;
const int QuotaVirtualMachine::NUM_VM_METRICS = 4;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -56,7 +58,7 @@ bool QuotaVirtualMachine::check(Template * tmpl,
map<string, float> vm_request;
int memory;
float cpu;
float cpu, size;
if ( tmpl->get("MEMORY", memory) == false || memory <= 0 )
{
@ -70,9 +72,12 @@ bool QuotaVirtualMachine::check(Template * tmpl,
return false;
}
size = VirtualMachine::get_volatile_disk_size(tmpl);
vm_request.insert(make_pair("VMS",1));
vm_request.insert(make_pair("MEMORY", memory));
vm_request.insert(make_pair("CPU", cpu));
vm_request.insert(make_pair("VOLATILE_SIZE", size));
return check_quota("", vm_request, default_quotas, error);
}
@ -85,7 +90,7 @@ void QuotaVirtualMachine::del(Template * tmpl)
map<string, float> vm_request;
int memory, vms;
float cpu;
float cpu, size;
if ( tmpl->get("MEMORY", memory) == false )
{
@ -102,9 +107,12 @@ void QuotaVirtualMachine::del(Template * tmpl)
vms = 1;
}
size = VirtualMachine::get_volatile_disk_size(tmpl);
vm_request.insert(make_pair("VMS", vms));
vm_request.insert(make_pair("MEMORY", memory));
vm_request.insert(make_pair("CPU", cpu));
vm_request.insert(make_pair("VOLATILE_SIZE", size));
del_quota("", vm_request);
}
@ -130,7 +138,7 @@ bool QuotaVirtualMachine::update(Template * tmpl,
map<string, float> vm_request;
int delta_memory;
float delta_cpu;
float delta_cpu, delta_size;
if ( tmpl->get("MEMORY", delta_memory) == true )
{
@ -142,5 +150,10 @@ bool QuotaVirtualMachine::update(Template * tmpl,
vm_request.insert(make_pair("CPU", delta_cpu));
}
if ( tmpl->get("VOLATILE_SIZE", delta_size) == true )
{
vm_request.insert(make_pair("VOLATILE_SIZE", delta_size));
}
return check_quota("", vm_request, default_quotas, error);
}

View File

@ -2018,6 +2018,56 @@ VectorAttribute * VirtualMachine::delete_attach_disk()
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool VirtualMachine::isVolatile(const VectorAttribute * disk)
{
string type = disk->vector_value("TYPE");
one_util::toupper(type);
return ( type == "SWAP" || type == "FS");
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
float VirtualMachine::get_volatile_disk_size(Template * tmpl)
{
float size = 0;
vector<const Attribute*> disks;
int num_disks = tmpl->get("DISK", disks);
if (num_disks == 0)
{
return size;
}
for (int i = 0 ; i < num_disks ; i++)
{
float disk_size;
const VectorAttribute * disk = dynamic_cast<const VectorAttribute*>(disks[i]);
if (disk == 0)
{
continue;
}
if (!VirtualMachine::isVolatile(disk))
{
continue;
}
if (disk->vector_value("SIZE", disk_size) == 0)
{
size += disk_size;
}
}
return size;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */