1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[opennebula] added groups.get and groups.get_by_name filters

This commit is contained in:
Achim Ledermüller 2014-06-05 10:11:17 +02:00
parent f4c541d268
commit fdd6eab51f
2 changed files with 38 additions and 23 deletions

View file

@ -14,10 +14,17 @@ module Fog
end
def get(id)
# the one api does not provide any filter method and this isn't really important
# get all and filter on your own :D
#self.all({:id => id}).first
raise Fog::Errors::Error.new('get a group is not yet implemented. Contributions welcome!')
group = self.all({:id => id})
if group.length > 1
raise Fog::Errors::Error.new("groups.get should return only one group, not #{group.length}!")
end
group.first
end
def get_by_name(str)
self.all({:name => str})
end
end

View file

@ -2,32 +2,40 @@ module Fog
module Compute
class OpenNebula
class Real
def list_groups(filter = { })
def list_groups(filter = {})
groups=[]
grouppool = ::OpenNebula::GroupPool.new(client)
grouppool.info
# {
# "GROUP"=>{
# "ID"=>"0",
# "NAME"=>"oneadmin",
# "USERS"=>{"ID"=>["0", "1"]},
# "DATASTORE_QUOTA"=>{},
# "NETWORK_QUOTA"=>{},
# "VM_QUOTA"=>{},
# "IMAGE_QUOTA"=>{}
grouppool.info
# {
# "GROUP"=>{
# "ID"=>"0",
# "NAME"=>"oneadmin",
# "USERS"=>{"ID"=>["0", "1"]},
# "DATASTORE_QUOTA"=>{},
# "NETWORK_QUOTA"=>{},
# "VM_QUOTA"=>{},
# "IMAGE_QUOTA"=>{}
# }
#}
#}
grouppool.each do |group|
puts "GROUP #{group.to_hash.display}"
groups << {:id => group["ID"], :name => group["NAME"]}
end
puts "GROUPS #{groups.inspect}"
filter_missmatch = false
unless (filter.empty?)
filter.each do |k,v|
if group["#{k.to_s.upcase}"] && group["#{k.to_s.upcase}"] != v.to_s
filter_missmatch = true
break
end
end
next if filter_missmatch
end
groups << {:id => group["ID"], :name => group["NAME"]}
end
groups
end
end
class Mock