mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-10 13:57:22 +03:00
Merge branch 'feature-411'
This commit is contained in:
commit
45abb9ce53
@ -4,4 +4,5 @@
|
||||
:enabled: false
|
||||
:defaults:
|
||||
:cpu: 10.0
|
||||
:memory: 1048576
|
||||
:memory: 1048576
|
||||
:num_vms: 10
|
@ -20,10 +20,11 @@ require 'OpenNebula'
|
||||
# total usage for a user. Variables inside are cpu and memory
|
||||
# consumption
|
||||
class VmUsage
|
||||
attr_accessor :cpu, :memory
|
||||
def initialize(cpu, memory)
|
||||
attr_accessor :cpu, :memory, :num_vms
|
||||
def initialize(cpu, memory, num_vms=0)
|
||||
@cpu=cpu
|
||||
@memory=memory
|
||||
@num_vms=num_vms
|
||||
end
|
||||
end
|
||||
|
||||
@ -76,11 +77,12 @@ class OneUsage
|
||||
|
||||
# Returns total consumption by a user into a VmUsage object
|
||||
def total(user)
|
||||
usage=VmUsage.new(0.0, 0)
|
||||
usage=VmUsage.new(0.0, 0, 0)
|
||||
|
||||
@users[user].each do |id, vm|
|
||||
usage.cpu+=vm.cpu
|
||||
usage.memory+=vm.memory
|
||||
usage.num_vms+=1
|
||||
end if @users[user]
|
||||
|
||||
usage
|
||||
|
@ -55,7 +55,7 @@ This command contains a set of utilities to manage authorization module.
|
||||
Commands:
|
||||
|
||||
* quota set (sets quota for a user)
|
||||
oneauth quota set <id> <cpu> <memory>
|
||||
oneauth quota set <id> <cpu> <memory> <num_vms>
|
||||
|
||||
* login (generates authentication proxy)
|
||||
oneauth login <username> [<expire time in seconds>]
|
||||
@ -80,10 +80,10 @@ def get_database
|
||||
db=Sequel.connect(database_url)
|
||||
end
|
||||
|
||||
def add_quota(uid, cpu, memory)
|
||||
def add_quota(uid, cpu, memory, num_vms=nil)
|
||||
db=get_database
|
||||
quota=Quota.new(db, OpenNebula::Client.new)
|
||||
quota.set(uid.to_i, cpu.to_f, memory.to_i, nil)
|
||||
quota.set(uid.to_i, cpu.to_f, memory.to_i, num_vms)
|
||||
end
|
||||
|
||||
|
||||
@ -101,7 +101,7 @@ when "quota"
|
||||
Dir.chdir VAR_LOCATION
|
||||
|
||||
begin
|
||||
add_quota(*ARGV[1..3])
|
||||
add_quota(*ARGV[1..4])
|
||||
rescue Exception => e
|
||||
puts "Error starting server: #{e}"
|
||||
exit(-1)
|
||||
|
@ -32,7 +32,8 @@ class Quota
|
||||
@conf={
|
||||
:defaults => {
|
||||
:cpu => nil,
|
||||
:memory => nil
|
||||
:memory => nil,
|
||||
:num_vms => nil
|
||||
}
|
||||
}.merge(conf)
|
||||
|
||||
@ -93,12 +94,14 @@ class Quota
|
||||
if new_vm
|
||||
usage.cpu+=new_vm.cpu.to_f
|
||||
usage.memory+=new_vm.memory.to_i
|
||||
usage.num_vms+=1
|
||||
end
|
||||
|
||||
STDERR.puts [user_quota, usage, new_vm].inspect
|
||||
|
||||
(!user_quota[:cpu] || usage.cpu<=user_quota[:cpu]) &&
|
||||
(!user_quota[:memory] || usage.memory<=user_quota[:memory])
|
||||
(!user_quota[:memory] || usage.memory<=user_quota[:memory]) &&
|
||||
(!user_quota[:num_vms] || usage.num_vms<=user_quota[:num_vms])
|
||||
end
|
||||
|
||||
# Updates user resource consuption
|
||||
|
Loading…
x
Reference in New Issue
Block a user