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

Make quota compatible with new OCA libraries

This commit is contained in:
Javi Fontan 2010-07-23 17:00:08 +02:00
parent a3f5d32b3d
commit f45df6e237

View File

@ -16,16 +16,15 @@ class SimplePermissions
def get_vm_usage(data)
vm_xml=Base64::decode64(data)
vm=OpenNebula::VirtualMachine.new(
OpenNebula::XMLUtilsElement.initialize_xml(vm_xml, 'VM'),
OpenNebula::XMLElement.build_xml(vm_xml, 'TEMPLATE'),
OpenNebula::Client.new)
vm_hash=vm.to_hash
# Should set more sensible defaults or get driver configuration
cpu=vm_hash['TEMPLATE']['CPU']
cpu=vm['CPU']
cpu||=1.0
cpu=cpu.to_f
memory=vm_hash['TEMPLATE']['MEMORY']
memory=vm['MEMORY']
memory||=64
memory=memory.to_f
@ -53,6 +52,14 @@ class SimplePermissions
when 'CREATE'
auth_result=true if %w{VM NET IMAGE}.include? object
if @quota_enabled and object=='VM' and auth_result
STDERR.puts 'quota enabled'
@quota.update(uid.to_i)
if !@quota.check(uid.to_i, get_vm_usage(id))
auth_result="Quota exceeded"
end
end
when 'DELETE'
auth_result = (owner == uid)