Feature #407: Base implementation for groups.

So far groups can be managed, but resources can't be associated to a group.
Tasks done:

  * New basic onegroup command
  * RequestManager XML-RPC methods
  * New group pool
  * New GROUP authorization symbol
  * Basic GroupPool tests
  * Ruby OCA methods
This commit is contained in:
Carlos Martín committed 2011-05-10 18:45:15 +02:00
1 parent 2fc0f5b5ca
commit ae53d43789
33 files changed
+1875 -9

No files matched your search

+4
View File
@@ -321,6 +321,10 @@ def get_template_id(name)
get_entity_id(name, OpenNebula::TemplatePool)
end
def get_group_id(name)
get_entity_id(name, OpenNebula::GroupPool)
end
def str_running_time(data)
stime=Time.at(data["STIME"].to_i)
if data["ETIME"]=="0"
+186
View File
@@ -0,0 +1,186 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# 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. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
require 'OpenNebula'
require 'client_utilities'
require 'command_parse'
ShowTableUP={
:id => {
:name => "ID",
:desc => "ONE identifier for group",
:size => 4,
:proc => lambda {|d,e|
d.id
}
},
:uid => {
:name => "OWNER",
:desc => "Owner of the group",
:size => 5,
:proc => lambda {|d,e|
d.uid
}
},
:name => {
:name => "NAME",
:desc => "Name of the group",
:size => 16,
:proc => lambda {|d,e|
d.name
}
},
:default => [:id, :uid, :name]
}
class UPShow
def initialize
@grouppool=OpenNebula::GroupPool.new(get_one_client)
@table=ShowTable.new(ShowTableUP)
end
def header_up_small
scr_bold
scr_underline
print @table.header_str
scr_restore
puts ""
end
def list_short(options=nil)
res=@grouppool.info
if options
@table.columns=options[:columns] if options[:columns]
end
if OpenNebula.is_error?(res)
result=res
else
result=res
header_up_small
puts @table.data_str(@grouppool, options)
result
end
end
end
class OneUPParse < CommandParse
COMMANDS_HELP=<<-EOT
Description:
This command enables the OpenNebula administrator to manage groups.
Commands:
* create (Creates a new group)
onegroup create groupname
* delete (Removes a group)
onegroup delete <id>
* list (Lists all the groups in the pool)
onegroup list
EOT
def text_commands
COMMANDS_HELP
end
def text_command_name
"onegroup"
end
def list_options
table=ShowTable.new(ShowTableUP)
table.print_help
end
end
oneup_opts=OneUPParse.new([:list, :xml])
oneup_opts.parse(ARGV)
ops=oneup_opts.options
result=[false, "Unknown error"]
command=ARGV.shift
case command
when "create"
check_parameters("create", 1)
group=OpenNebula::Group.new(OpenNebula::Group.build_xml, get_one_client)
result=group.allocate(ARGV[0])
if is_successful?(result)
puts "ID: " + group.id.to_s if ops[:verbose]
exit 0
end
when "delete"
check_parameters("delete", 1)
args=expand_args(ARGV)
args.each do |param|
group_id=get_group_id(param)
group=OpenNebula::Group.new(
OpenNebula::Group.build_xml(group_id), get_one_client)
result=group.delete
if !OpenNebula.is_error?(result)
puts "Group deleted" if ops[:verbose]
break
end
end
when "list"
if !ops[:xml]
uplist=UPShow.new
ops[:columns]=ops[:list] if ops[:list]
result=uplist.list_short(ops)
else
grouppool=OpenNebula::GroupPool.new(get_one_client)
grouppool.info
puts grouppool.to_xml(true)
end
else
oneup_opts.print_help
exit -1
end
if OpenNebula.is_error?(result)
puts "Error: " + result.message
exit -1
end