diff --git a/install.sh b/install.sh index 3f3b6592db..c99f29d712 100755 --- a/install.sh +++ b/install.sh @@ -829,14 +829,15 @@ SUNSTONE_PUBLIC_JS_FILES="src/sunstone/public/js/layout.js \ src/sunstone/public/js/opennebula.js" SUNSTONE_PUBLIC_JS_PLUGINS_FILES="\ - src/sunstone/public/js/plugins/dashboard-tab.js \ - src/sunstone/public/js/plugins/hosts-tab.js \ - src/sunstone/public/js/plugins/groups-tab.js \ - src/sunstone/public/js/plugins/images-tab.js \ - src/sunstone/public/js/plugins/templates-tab.js \ - src/sunstone/public/js/plugins/users-tab.js \ - src/sunstone/public/js/plugins/vms-tab.js \ - src/sunstone/public/js/plugins/vnets-tab.js" + src/sunstone/public/js/plugins/dashboard-tab.js \ + src/sunstone/public/js/plugins/dashboard-users-tab.js \ + src/sunstone/public/js/plugins/hosts-tab.js \ + src/sunstone/public/js/plugins/groups-tab.js \ + src/sunstone/public/js/plugins/images-tab.js \ + src/sunstone/public/js/plugins/templates-tab.js \ + src/sunstone/public/js/plugins/users-tab.js \ + src/sunstone/public/js/plugins/vms-tab.js \ + src/sunstone/public/js/plugins/vnets-tab.js" SUNSTONE_PUBLIC_CSS_FILES="src/sunstone/public/css/application.css \ src/sunstone/public/css/layout.css \ diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index 0152b1c4f9..6190027c2d 100755 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -62,9 +62,17 @@ module CommandParser @args = args @options = Hash.new - set :format, :file, "" do |arg| format_file(arg) ; end - set :format, :range, "" do |arg| format_range(arg) ; end - set :format, :text, "" do |arg| format_text(arg) ; end + set :format, :file, "Path to a file" do |arg| + format_file(arg) + end + + set :format, :range, "List of id's in the form 1,8..15" do |arg| + format_range(arg) + end + + set :format, :text, "String" do |arg| + format_text(arg) + end instance_eval(&block) @@ -72,7 +80,11 @@ module CommandParser end def usage(str) - @usage = "Usage: #{str}" + @usage=<0 if objects.length>1 - return -1, "There are multiple #{ename}s with name #{name}." + return -1, + "There are multiple #{ename}s with name #{name}." else result = objects.first.id end else - return -1, "#{ename} named #{name} not found." + return -1, "#{ename} named #{name} not found." end return 0, result @@ -311,6 +330,7 @@ EOT def OpenNebulaHelper.name_to_id_desc(poolname) "OpenNebula #{poolname} name or id" end + def OpenNebulaHelper.public_to_str(str) if str.to_i == 1 public_str = "Y" @@ -369,4 +389,4 @@ EOT str = File.read(path) str end -end \ No newline at end of file +end diff --git a/src/cli/one_helper/oneacl_helper.rb b/src/cli/one_helper/oneacl_helper.rb index 3c5ef5d21f..57f8e26591 100644 --- a/src/cli/one_helper/oneacl_helper.rb +++ b/src/cli/one_helper/oneacl_helper.rb @@ -119,7 +119,8 @@ private d['STRING'].split(" ")[1].split("/")[1] end - column :OPE_CDUMIPpTW, "Operation to which the rule applies" do |d| + column :OPE_CDUMIPpTW, + "Operation to which the rule applies" do |d| OneAclHelper::right_mask d['STRING'].split(" ")[2] end diff --git a/src/cli/one_helper/onegroup_helper.rb b/src/cli/one_helper/onegroup_helper.rb index 3d3f8962ee..0710e8a920 100644 --- a/src/cli/one_helper/onegroup_helper.rb +++ b/src/cli/one_helper/onegroup_helper.rb @@ -67,9 +67,10 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper column :NAME, "Name of the Group", :left, :size=>15 do |d| d["NAME"] end - - column :USER, "Username of the Group owner", :left, :size=>8 do |d| - helper.uid_to_str(d["UID"], options) + + column :USER, "Username of the Group owner", :left, + :size=>8 do |d| + helper.user_name(d, options) end default :ID, :USER, :NAME @@ -81,4 +82,4 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper table.show(pool, options) end end -end \ No newline at end of file +end diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 57f87eb873..8808b3e345 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -51,7 +51,8 @@ class OneHostHelper < OpenNebulaHelper::OneHelper str = "%-22s: %-20s" str_h1 = "%-80s" - CLIHelper.print_header(str_h1 % "HOST #{host.id.to_s} INFORMATION", true) + CLIHelper.print_header( + str_h1 % "HOST #{host.id.to_s} INFORMATION", true) puts str % ["ID", host.id.to_s] puts str % ["NAME", host.name] @@ -97,33 +98,42 @@ class OneHostHelper < OpenNebulaHelper::OneHelper end column :FCPU, "Free CPU percentage", :size=>6 do |d| - d["HOST_SHARE"]["MAX_CPU"].to_i-d["HOST_SHARE"]["USED_CPU"].to_i + d["HOST_SHARE"]["MAX_CPU"].to_i- + d["HOST_SHARE"]["USED_CPU"].to_i end - column :ACPU, "Available cpu percentage (not reserved by VMs)", :size=>6 do |d| + column :ACPU, "Available cpu percentage (not reserved by VMs)", + :size=>6 do |d| max_cpu=d["HOST_SHARE"]["MAX_CPU"].to_i max_cpu=100 if max_cpu==0 max_cpu-d["HOST_SHARE"]["CPU_USAGE"].to_i end column :TMEM, "Total Memory", :size=>6 do |d| - OpenNebulaHelper.unit_to_str(d["HOST_SHARE"]["MAX_MEM"].to_i,options) + OpenNebulaHelper.unit_to_str( + d["HOST_SHARE"]["MAX_MEM"].to_i, + options) end column :FMEM, "Free Memory", :size=>6 do |d| - OpenNebulaHelper.unit_to_str(d["HOST_SHARE"]["FREE_MEM"].to_i,options) + OpenNebulaHelper.unit_to_str( + d["HOST_SHARE"]["FREE_MEM"].to_i, + options) end - column :AMEM, "Available Memory (not reserved by VMs)", :size=>6 do |d| - acpu=d["HOST_SHARE"]["MAX_MEM"].to_i-d["HOST_SHARE"]["MEM_USAGE"].to_i + column :AMEM, "Available Memory (not reserved by VMs)", + :size=>6 do |d| + acpu=d["HOST_SHARE"]["MAX_MEM"].to_i- + d["HOST_SHARE"]["MEM_USAGE"].to_i OpenNebulaHelper.unit_to_str(acpu,options) end - + column :STAT, "Host status", :size=>6 do |d| OneHostHelper.state_to_str(d["STATE"]) end - default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM, :AMEM, :STAT + default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM, + :AMEM, :STAT end if top @@ -132,4 +142,4 @@ class OneHostHelper < OpenNebulaHelper::OneHelper table.show(pool, options) end end -end \ No newline at end of file +end diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 228b3d6061..a446078726 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -64,9 +64,11 @@ class OneImageHelper < OpenNebulaHelper::OneHelper puts str % ["ID", image.id.to_s] puts str % ["NAME", image.name] puts str % ["TYPE", image.type_str] - puts str % ["REGISTER TIME", OpenNebulaHelper.time_to_str(image['REGTIME'])] + puts str % ["REGISTER TIME", + OpenNebulaHelper.time_to_str(image['REGTIME'])] puts str % ["PUBLIC", OpenNebulaHelper.public_to_str(image['PUBLIC'])] - puts str % ["PERSISTENT", OneImageHelper.persistent_to_str(image["PERSISTENT"])] + puts str % ["PERSISTENT", + OneImageHelper.persistent_to_str(image["PERSISTENT"])] puts str % ["SOURCE", image['SOURCE']] puts str % ["STATE", image.short_state_str] puts str % ["RUNNING_VMS", image['RUNNING_VMS']] @@ -87,27 +89,32 @@ class OneImageHelper < OpenNebulaHelper::OneHelper d["NAME"] end - column :USER, "Username of the Virtual Machine owner", :left, :size=>8 do |d| - helper.uid_to_str(d["UID"], options) + column :USER, "Username of the Virtual Machine owner", :left, + :size=>8 do |d| + helper.user_name(d, options) end - column :GROUP, "Group of the Virtual Machine", :left, :size=>8 do |d| - helper.gid_to_str(d["GID"], options) + column :GROUP, "Group of the Virtual Machine", :left, + :size=>8 do |d| + helper.group_name(d, options) end column :TYPE, "Type of the Image", :size=>4 do |d,e| OneImageHelper.type_to_str(d["TYPE"]) end - column :REGTIME, "Registration time of the Image", :size=>20 do |d| + column :REGTIME, "Registration time of the Image", + :size=>20 do |d| OpenNebulaHelper.time_to_str(d["REGTIME"]) end - column :PUBLIC, "Whether the Image is public or not", :size=>3 do |d| + column :PUBLIC, "Whether the Image is public or not", + :size=>3 do |d| OpenNebulaHelper.public_to_str(d["PUBLIC"]) end - column :PERSISTENT, "Whether the Image is persistent or not", :size=>3 do |d| + column :PERSISTENT, "Whether the Image is persistent or not", + :size=>3 do |d| OneImageHelper.persistent_to_str(d["PERSISTENT"]) end @@ -115,11 +122,13 @@ class OneImageHelper < OpenNebulaHelper::OneHelper OneImageHelper.state_to_str(d["STATE"]) end - column :RVMS, "Number of VMs currently running from this Image", :size=>5 do |d| + column :RVMS, "Number of VMs currently running from this Image", + :size=>5 do |d| d['RUNNING_VMS'] end - default :ID, :USER, :GROUP, :NAME, :TYPE, :REGTIME, :PUBLIC, :PERSISTENT , :STAT, :RVMS + default :ID, :USER, :GROUP, :NAME, :TYPE, :REGTIME, :PUBLIC, + :PERSISTENT , :STAT, :RVMS end if top @@ -128,4 +137,4 @@ class OneImageHelper < OpenNebulaHelper::OneHelper table.show(pool, options) end end -end \ No newline at end of file +end diff --git a/src/cli/one_helper/onetemplate_helper.rb b/src/cli/one_helper/onetemplate_helper.rb index 32ac96be9f..05199685c7 100644 --- a/src/cli/one_helper/onetemplate_helper.rb +++ b/src/cli/one_helper/onetemplate_helper.rb @@ -44,11 +44,14 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper str="%-15s: %-20s" str_h1="%-80s" - CLIHelper.print_header(str_h1 % "TEMPLATE #{template['ID']} INFORMATION") + CLIHelper.print_header( + str_h1 % "TEMPLATE #{template['ID']} INFORMATION") puts str % ["ID", template.id.to_s] puts str % ["NAME", template.name] - puts str % ["REGISTER TIME", OpenNebulaHelper.time_to_str(template['REGTIME'])] - puts str % ["PUBLIC", OpenNebulaHelper.public_to_str(template['PUBLIC'])] + puts str % ["REGISTER TIME", + OpenNebulaHelper.time_to_str(template['REGTIME'])] + puts str % ["PUBLIC", + OpenNebulaHelper.public_to_str(template['PUBLIC'])] puts CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false) @@ -66,19 +69,22 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper d["NAME"] end - column :USER, "Username of the Template owner", :left, :size=>8 do |d| - helper.uid_to_str(d["UID"], options) + column :USER, "Username of the Template owner", :left, + :size=>8 do |d| + helper.user_name(d, options) end column :GROUP, "Group of the Template", :left, :size=>8 do |d| - helper.gid_to_str(d["GID"], options) + helper.group_name(d, options) end - column :REGTIME, "Registration time of the Template", :size=>20 do |d| + column :REGTIME, "Registration time of the Template", + :size=>20 do |d| OpenNebulaHelper.time_to_str(d["REGTIME"]) end - column :PUBLIC, "Whether the Template is public or not", :size=>3 do |d| + column :PUBLIC, "Whether the Template is public or not", + :size=>3 do |d| OpenNebulaHelper.public_to_str(d["PUBLIC"]) end @@ -91,4 +97,4 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper table.show(pool, options) end end -end \ No newline at end of file +end diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index da05bcc672..7550d667b0 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -26,7 +26,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper end def self.password_to_str_desc - "TBD" + "User password" end def self.password_to_str(arg, options) @@ -43,7 +43,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper password = Digest::SHA1.hexdigest(arg) end end - + return 0, password end @@ -110,4 +110,4 @@ class OneUserHelper < OpenNebulaHelper::OneHelper table.show(pool, options) end end -end \ No newline at end of file +end diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 9da8c5a99e..7215a7a547 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -66,7 +66,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper str_h1="%-80s" str="%-20s: %-20s" - CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE #{vm['ID']} INFORMATION") + CLIHelper.print_header( + str_h1 % "VIRTUAL MACHINE #{vm['ID']} INFORMATION") puts str % ["ID", vm.id.to_s] puts str % ["NAME", vm.name] puts str % ["STATE", vm.state_str] @@ -104,20 +105,23 @@ class OneVMHelper < OpenNebulaHelper::OneHelper def format_pool(pool, options, top=false) config_file=self.class.table_conf table=CLIHelper::ShowTable.new(config_file, self) do - column :ID, "ONE identifier for Virtual Machine", :size=>4 do |d| + column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d| d["ID"] end - column :NAME, "Name of the Virtual Machine", :left, :size=>15 do |d| + column :NAME, "Name of the Virtual Machine", :left, + :size=>15 do |d| d["NAME"] end - column :USER, "Username of the Virtual Machine owner", :left, :size=>8 do |d| - helper.uid_to_str(d["UID"], options) + column :USER, "Username of the Virtual Machine owner", :left, + :size=>8 do |d| + helper.user_name(d, options) end - column :GROUP, "Group of the Virtual Machine", :left, :size=>8 do |d| - helper.gid_to_str(d["GID"], options) + column :GROUP, "Group of the Virtual Machine", :left, + :size=>8 do |d| + helper.group_name(d, options) end column :STAT, "Actual status", :size=>4 do |d,e| @@ -142,10 +146,15 @@ class OneVMHelper < OpenNebulaHelper::OneHelper stime = Time.at(d["STIME"].to_i) etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i) dtime = Time.at(etime-stime).getgm - "%02d %02d:%02d:%02d" % [dtime.yday-1, dtime.hour, dtime.min, dtime.sec] + "%02d %02d:%02d:%02d" % [ + dtime.yday-1, + dtime.hour, + dtime.min, + dtime.sec] end - default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME, :TIME + default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME, + :TIME end if top @@ -203,4 +212,4 @@ class OneVMHelper < OpenNebulaHelper::OneHelper table.show(history) end -end \ No newline at end of file +end diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 85eab99b8c..1afa5f1dfa 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -48,7 +48,8 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper def format_resource(vn) str_h1="%-80s" - CLIHelper.print_header(str_h1 % ["VIRTUAL NETWORK #{vn.id.to_s} INFORMATION"]) + CLIHelper.print_header(str_h1 % + ["VIRTUAL NETWORK #{vn.id.to_s} INFORMATION"]) str="%-10s: %-20s" puts str % ["ID: ", vn.id.to_s] @@ -75,16 +76,19 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper d["ID"] end - column :NAME, "Name of the Virtual Network", :left, :size=>15 do |d| + column :NAME, "Name of the Virtual Network", :left, + :size=>15 do |d| d["NAME"] end - column :USER, "Username of the Virtual Network owner", :left, :size=>8 do |d| - helper.uid_to_str(d["UID"], options) + column :USER, "Username of the Virtual Network owner", :left, + :size=>8 do |d| + helper.user_name(d, options) end - column :GROUP, "Group of the Virtual Network", :left, :size=>8 do |d| - helper.gid_to_str(d["GID"], options) + column :GROUP, "Group of the Virtual Network", :left, + :size=>8 do |d| + helper.group_name(d, options) end column :TYPE, "Type of Virtual Network", :size=>6 do |d| @@ -95,15 +99,18 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper d["SIZE"] end - column :BRIDGE, "Bridge associated to the Virtual Network", :size=>6 do |d| + column :BRIDGE, "Bridge associated to the Virtual Network", + :size=>6 do |d| d["BRIDGE"] end - column :PUBLIC, "Whether the Virtual Network is public or not", :size=>1 do |d| + column :PUBLIC, "Whether the Virtual Network is public or not", + :size=>1 do |d| OpenNebulaHelper.public_to_str(d['PUBLIC']) end - column :LEASES, "Number of this Virtual Network's given leases", :size=>7 do |d| + column :LEASES, "Number of this Virtual Network's given leases", + :size=>7 do |d| d["TOTAL_LEASES"] end diff --git a/src/cli/oneacl b/src/cli/oneacl index f34ae18240..a797eb43c4 100755 --- a/src/cli/oneacl +++ b/src/cli/oneacl @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/oneacl_helper' cmd = CommandParser::CmdParser.new(ARGV) do - usage "oneacl COMMAND [args..] [options..]" + usage "`oneacl` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneAclHelper.new @@ -56,7 +56,8 @@ cmd = CommandParser::CmdParser.new(ARGV) do Adds a new ACL rule EOT - command :create, addrule_desc, [:user,:rulestr], [:resource, nil], [:rights, nil] do + command :create, addrule_desc, [:user,:rulestr], [:resource, nil], + [:rights, nil] do case args.length when 1 new_args=Acl.parse_rule(args[0]) diff --git a/src/cli/onegroup b/src/cli/onegroup index 14622a2790..3e00268846 100755 --- a/src/cli/onegroup +++ b/src/cli/onegroup @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/onegroup_helper' cmd=CommandParser::CmdParser.new(ARGV) do - usage "onegroup COMMAND [args..] [options..]" + usage "`onegroup` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneGroupHelper.new diff --git a/src/cli/onehost b/src/cli/onehost index 8f28d75c8f..6f7b5f5c81 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/onehost_helper' cmd=CommandParser::CmdParser.new(ARGV) do - usage "onehost COMMAND [args..] [options..]" + usage "`onehost` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneHostHelper.new diff --git a/src/cli/oneimage b/src/cli/oneimage index 7459f31118..74c361d020 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/oneimage_helper' cmd=CommandParser::CmdParser.new(ARGV) do - usage "oneimage COMMAND [args..] [options..]" + usage "`oneimage` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneImageHelper.new @@ -40,7 +40,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do # Global Options ######################################################################## set :option, CommandParser::OPTIONS - + list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML list_options << OpenNebulaHelper::NUMERIC @@ -105,7 +105,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do end unpublish_desc = <<-EOT.unindent - Unpublishes the given Image. A private Image can't be used by any other + Unpublishes the given Image. A private Image can't be used by any other User EOT @@ -183,9 +183,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do Changes the Image owner and group EOT - command :chown, chown_desc, [:range, :imageid_list], :userid, [:groupid,nil] do + command :chown, chown_desc, [:range, :imageid_list], :userid, + [:groupid,nil] do gid = args[2].nil? ? -1 : args[2].to_i - helper.perform_actions(args[0],options,"Owner/Group changed") do |image| + helper.perform_actions(args[0],options, + "Owner/Group changed") do |image| image.chown(args[1].to_i, gid) end end diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 20fb6075b1..9b5d586e04 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/onetemplate_helper' cmd=CommandParser::CmdParser.new(ARGV) do - usage "onetemplate COMMAND [args..] [options..]" + usage "`onetemplate` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneTemplateHelper.new @@ -146,7 +146,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do Changes the Template owner and group EOT - command :chown, chown_desc, [:range, :templateid_list], :userid, [:groupid,nil] do + command :chown, chown_desc, [:range, :templateid_list], :userid, + [:groupid,nil] do gid = args[2].nil? ? -1 : args[2].to_id helper.perform_actions(args[0],options,"Owner/Group changed") do |t| t.chown(args[1].to_i, gid) diff --git a/src/cli/oneuser b/src/cli/oneuser index 81d7639fc4..6fba896458 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/oneuser_helper' cmd=CommandParser::CmdParser.new(ARGV) do - usage "oneuser COMMAND [args..] [options..]" + usage "`oneuser` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneUserHelper.new @@ -40,11 +40,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do # Global Options ######################################################################## set :option, CommandParser::OPTIONS - + list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML list_options << OpenNebulaHelper::NUMERIC - + READ_FILE={ :name => "read_file", :short => "-r", @@ -55,10 +55,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do PLAIN={ :name => "plain", :short => "-p", - :large => "--plain-password", + :large => "--plain", :description => "Store plain password" } - + create_options = [READ_FILE, PLAIN] ######################################################################## @@ -88,7 +88,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do Creates a new User EOT - command :create, create_desc, :username, :password, :options=>create_options do + command :create, create_desc, :username, :password, + :options=>create_options do helper.create_resource(options) do |user| user.allocate(args[0], args[1]) end diff --git a/src/cli/onevm b/src/cli/onevm index 0174edae29..7321fe3059 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/onevm_helper' cmd=CommandParser::CmdParser.new(ARGV) do - usage "onevm COMMAND [args..] [options..]" + usage "`onevm` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneVMHelper.new @@ -312,7 +312,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do Changes the Image owner and group EOT - command :chown, chown_desc, [:range, :vmid_list], :userid, [:groupid,nil] do + command :chown, chown_desc, [:range, :vmid_list], :userid, + [:groupid,nil] do gid = args[2].nil? ? -1 : args[2].to_id helper.perform_actions(args[0],options,"Owner/Group changed") do |vm| vm.chown(args[1].to_i, gid) @@ -345,4 +346,4 @@ cmd=CommandParser::CmdParser.new(ARGV) do :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do helper.list_pool(options, true, args[0]) end -end \ No newline at end of file +end diff --git a/src/cli/onevnet b/src/cli/onevnet index 2a4c30517f..f876579190 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -31,7 +31,7 @@ require 'command_parser' require 'one_helper/onevnet_helper' cmd=CommandParser::CmdParser.new(ARGV) do - usage "onevnet COMMAND [args..] [options..]" + usage "`onevnet` [] []" version OpenNebulaHelper::ONE_VERSION helper = OneVNetHelper.new @@ -93,7 +93,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do Adds a lease to the Virtual Network EOT - command :addleases, 'Adds a lease to the Virtual Network', :vnetid, :ip, [:mac, nil] do + command :addleases, 'Adds a lease to the Virtual Network', :vnetid, :ip, + [:mac, nil] do helper.perform_action(args[0],options,"lease added") do |vn| vn.addleases(args[1], args[2]) end @@ -145,7 +146,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do Changes the Virtual Network owner and group EOT - command :chown, chown_desc, [:range, :vnid_list], :userid, [:groupid,nil] do + command :chown, chown_desc, [:range, :vnid_list], :userid, + [:groupid,nil] do gid = args[2].nil? ? -1 : args[2].to_id helper.perform_actions(args[0],options,"Owner/Group changed") do |vn| vn.chown(args[1].to_i, gid) diff --git a/src/oca/java/src/org/opennebula/client/OneResponse.java b/src/oca/java/src/org/opennebula/client/OneResponse.java index d88a37da46..7b00c7aada 100644 --- a/src/oca/java/src/org/opennebula/client/OneResponse.java +++ b/src/oca/java/src/org/opennebula/client/OneResponse.java @@ -1,12 +1,12 @@ /******************************************************************************* * 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. @@ -16,14 +16,14 @@ package org.opennebula.client; /** - * This class encapsulates OpenNebula's XML-RPC responses. Each response - * carries a boolean indicating if it is an error. It can also contain a - * success message, or an error message. + * This class encapsulates OpenNebula's XML-RPC responses. Each response + * carries a boolean indicating if it is an error. It can also contain a + * success message, or an error message. */ public class OneResponse{ /** * Creates a new response. - * + * * @param success Indicates if the call was successful, and if * the message is an error or an information string. * @param message String containing the response message, or @@ -37,7 +37,7 @@ public class OneResponse{ /** * Returns true if the call resulted in error. - * + * * @return True if the call resulted in error. */ public boolean isError() @@ -48,7 +48,7 @@ public class OneResponse{ /** * Returns a string containing the error message, or null * if the response isn't an error. - * + * * @return A string containing the error message, or null * if the response isn't an error. */ @@ -61,7 +61,7 @@ public class OneResponse{ * Returns a string containing the response information, or * null if the response was an error. Note that the success * message could be also null. - * + * * @return A string containing the response information, or * null if the response was an error. Note that the success * message could be also null. @@ -71,6 +71,26 @@ public class OneResponse{ return success ? msg : null; } + /** + * Parses the string returned by getMessage + * + * @return The parsed int, or Integer.MIN_VALUE in case of error + * + * @see #getMessage + */ + public int getIntMessage() + { + int ret = Integer.MIN_VALUE; + + try + { + ret = Integer.parseInt( getMessage() ); + } + catch (NumberFormatException e) {} + + return ret; + } + // ------------------------------------------------------------------------ // PRIVATE ATTRIBUTES // ------------------------------------------------------------------------ diff --git a/src/oca/java/src/org/opennebula/client/Pool.java b/src/oca/java/src/org/opennebula/client/Pool.java index 9815f8740f..9bd7a85d8a 100644 --- a/src/oca/java/src/org/opennebula/client/Pool.java +++ b/src/oca/java/src/org/opennebula/client/Pool.java @@ -1,12 +1,12 @@ /******************************************************************************* * 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. @@ -82,7 +82,7 @@ public abstract class Pool{ new ByteArrayInputStream(info.getMessage().getBytes())); xml = doc.getDocumentElement(); - poolElements = xml.getElementsByTagName(elementName); + poolElements = xml.getElementsByTagName(elementName); } catch (ParserConfigurationException e) {} catch (SAXException e) {} @@ -92,7 +92,7 @@ public abstract class Pool{ /** * Returns the indexth element in the pool. If index is greater than or * equal to the number of elements in the pool, this returns null. - * + * * @param index Index of the element. * @return The element at the indexth position in the pool, or * null if that is not a valid index. @@ -103,7 +103,7 @@ public abstract class Pool{ if (poolElements != null) { - Node node =poolElements.item(index); + Node node = poolElements.item(index); if (node != null) { @@ -114,6 +114,26 @@ public abstract class Pool{ return theElement; } + protected PoolElement getById(int id) + { + // TODO: Use xpath to find the element //ID + + PoolElement theElement = null; + PoolElement tmpElement = null; + + for( int i = 0; i < getLength(); i++ ) + { + tmpElement = item(i); + if( tmpElement.id() == id ) + { + theElement = tmpElement; + break; + } + } + + return theElement; + } + /** * The number of elements in the pool. * @return The number of elements in the pool. diff --git a/src/oca/java/src/org/opennebula/client/acl/Acl.java b/src/oca/java/src/org/opennebula/client/acl/Acl.java new file mode 100644 index 0000000000..62d2f1d560 --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/acl/Acl.java @@ -0,0 +1,355 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ +package org.opennebula.client.acl; + + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula ACL rule. + * It also offers static XML-RPC call wrappers. + *
+ * There is not a public constructor, because the information for an individual + * ACL rule cannot be retrieved from OpenNebula. + *
+ * Instead, Acl objects should be obtained using AclPool.getById, after the + * info method has been called. + * + * @see AclPool#getById + */ +public class Acl extends PoolElement{ + + private static final String METHOD_PREFIX = "acl."; + private static final String ADDRULE = METHOD_PREFIX + "addrule"; + private static final String DELRULE = METHOD_PREFIX + "delrule"; + + private static final Map USERS; + private static final Map RESOURCES; + private static final Map RIGHTS; + + static { + HashMap tmpUsers = new HashMap(); + tmpUsers.put("#", 0x0000000100000000L); + tmpUsers.put("@", 0x0000000200000000L); + tmpUsers.put("*", 0x0000000400000000L); + + USERS = Collections.unmodifiableMap(tmpUsers); + + HashMap tmpResources = new HashMap(); + + tmpResources.put("VM" , 0x0000001000000000L); + tmpResources.put("HOST" , 0x0000002000000000L); + tmpResources.put("NET" , 0x0000004000000000L); + tmpResources.put("IMAGE" , 0x0000008000000000L); + tmpResources.put("USER" , 0x0000010000000000L); + tmpResources.put("TEMPLATE" , 0x0000020000000000L); + tmpResources.put("GROUP" , 0x0000040000000000L); + + RESOURCES = Collections.unmodifiableMap(tmpResources); + + HashMap tmpRights = new HashMap(); + + tmpRights.put("CREATE" , 0x1L); + tmpRights.put("DELETE" , 0x2L); + tmpRights.put("USE" , 0x4L); + tmpRights.put("MANAGE" , 0x8L); + tmpRights.put("INFO" , 0x10L); + tmpRights.put("INFO_POOL" , 0x20L); + tmpRights.put("INFO_POOL_MINE", 0x40L); + tmpRights.put("INSTANTIATE" , 0x80L); + tmpRights.put("CHOWN" , 0x100L); + + RIGHTS = Collections.unmodifiableMap(tmpRights); + } + + /** + * @see PoolElement + */ + protected Acl(Node xmlElement, Client client) + { + super(xmlElement, client); + } + + // ================================= + // Static XML-RPC methods + // ================================= + + /** + * Allocates a new ACl rule in OpenNebula + * + * @param client XML-RPC Client. + * @param user A string containing a hex number, e.g. 0x100000001 + * @param resource A string containing a hex number, e.g. 0x2100000001 + * @param rights A string containing a hex number, e.g. 0x10 + * @return If successful the message contains the associated + * id generated for this rule. + */ + public static OneResponse allocate(Client client, String user, + String resource, String rights) + { + return client.call(ADDRULE, user, resource, rights); + } + + /** + * Allocates a new ACl rule in OpenNebula + * + * @param client XML-RPC Client. + * @param user 64b encoded user + * @param resource 64b encoded user + * @param rights 64b encoded user + * @return If successful the message contains the associated + * id generated for this rule. + */ + public static OneResponse allocate(Client client, long user, long resource, + long rights) + { + return allocate(client, + Long.toHexString(user), + Long.toHexString(resource), + Long.toHexString(rights)); + } + + /** + * Allocates a new ACl rule in OpenNebula + * + * @param client XML-RPC Client. + * @param rule a rule string, e.g. "#5 HOST+VM/@12 INFO+CREATE+DELETE" + * @return If successful the message contains the associated + * id generated for this rule. + */ + public static OneResponse allocate(Client client, String rule) + { + String[] components = parseRule(rule); + return allocate(client, components[0], components[1], components[2]); + } + + /** + * Deletes an ACL rule from OpenNebula. + * + * @param client XML-RPC Client. + * @param id The ACL rule id. + * @return A encapsulated response. + */ + public static OneResponse delete(Client client, int id) + { + return client.call(DELRULE, id); + } + + // ================================= + // Instanced object XML-RPC methods + // ================================= + + /** + * Deletes the ACL rule from OpenNebula. + * + * @see Acl#delete(Client, int) + */ + public OneResponse delete() + { + return delete(client, id); + } + + // ================================= + // Helpers + // ================================= + + public long user() + { + long ret = 0; + + try + { + ret = Long.parseLong( xpath("USER"), 16 ); + } + catch (NumberFormatException e) + {} + + return ret; + } + + public long resource() + { + long ret = 0; + + try + { + ret = Long.parseLong( xpath("RESOURCE"), 16 ); + } + catch (NumberFormatException e) + {} + + return ret; + } + + public long rights() + { + long ret = 0; + + try + { + ret = Long.parseLong( xpath("RIGHTS"), 16 ); + } + catch (NumberFormatException e) + {} + + return ret; + } + + public String toString() + { + String st = xpath("STRING"); + + if( st == null ) + { + st = ""; + } + + return st; + } + + // ================================= + // Rule parsing + // ================================= + + /** + * Parses a rule string, e.g. "#5 HOST+VM/@12 INFO+CREATE+DELETE" + * + * @param rule an ACL rule in string format + * @return an Array containing 3 Strings (hex 64b numbers) + */ + public static String[] parseRule(String rule) + { + String [] ret = new String[3]; + + String [] components = rule.split(" "); + + if( components.length != 3 ) + { + // TODO: throw "String needs three components: User, Resource, Rights" + return ret; + } + + ret[0] = parseUsers(components[0]); + ret[1] = parseResources(components[1]); + ret[2] = parseRights(components[2]); + + return ret; + } + + /** + * Converts a string in the form [#, @, *] to a hex. number + * + * @param users Users component string + * @return A string containing a hex number + */ + private static String parseUsers(String users) + { + return Long.toHexString( calculateIds(users) ); + } + + /** + * Converts a resources string to a hex. number + * + * @param resources Resources component string + * @return A string containing a hex number + */ + private static String parseResources(String resources) + { + long ret = 0; + String[] resourcesComponents = resources.split("/"); + + if( resourcesComponents.length != 2 ) + { + // TODO: throw "Resource '#{resources}' malformed" + return ""; + } + + for( String resource : resourcesComponents[0].split("\\+") ) + { + resource = resource.toUpperCase(); + + if( !RESOURCES.containsKey(resource) ) + { + // TODO: throw "Resource '#{resource}' does not exist" + } + + ret += RESOURCES.get(resource); + } + + ret += calculateIds(resourcesComponents[1]); + + return Long.toHexString(ret); + } + + /** + * Converts a rights string to a hex. number + * + * @param rights Rights component string + * @return A string containing a hex number + */ + private static String parseRights(String rights) + { + long ret = 0; + + + for( String right : rights.split("\\+") ) + { + right = right.toUpperCase(); + + if( !RIGHTS.containsKey(right) ) + { + // TODO throw "Right '#{right}' does not exist" + return ""; + } + + ret += RIGHTS.get(right); + } + + return Long.toHexString(ret); + } + + /** + * Calculates the numeric value for a String containing an individual + * (#id), group (@id) or all (*) ID component + * + * @param id Rule Id string + * @return the numeric value for the given id_str + */ + private static long calculateIds(String id) + { + if( !id.matches("^([#@]\\d+|\\*)$") ) + { + // TODO: throw "ID string '#{id_str}' malformed" + return 0; + } + + long value = USERS.get( "" + id.charAt(0) ); + + if( id.charAt(0) != '*' ) + { + value += Long.parseLong( id.substring(1) ); + } + + return value; + } +} diff --git a/src/oca/java/src/org/opennebula/client/acl/AclPool.java b/src/oca/java/src/org/opennebula/client/acl/AclPool.java new file mode 100644 index 0000000000..22c6ddab1a --- /dev/null +++ b/src/oca/java/src/org/opennebula/client/acl/AclPool.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ +package org.opennebula.client.acl; + +import java.util.AbstractList; +import java.util.Iterator; + + +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.Pool; +import org.opennebula.client.PoolElement; +import org.w3c.dom.Node; + +/** + * This class represents an OpenNebula ACL rule pool. + * It also offers static XML-RPC call wrappers. + */ +public class AclPool extends Pool implements Iterable{ + + private static final String ELEMENT_NAME = "ACL"; + private static final String INFO_METHOD = "acl.info"; + + /** + * Creates a new ACL rule pool + * @param client XML-RPC Client. + */ + public AclPool(Client client) + { + super(ELEMENT_NAME, client); + } + + @Override + public PoolElement factory(Node node) + { + return new Acl(node, client); + } + + /** + * Retrieves all the hosts in the pool. + * + * @param client XML-RPC Client. + * @return If successful the message contains the string + * with the information returned by OpenNebula. + */ + public static OneResponse info(Client client) + { + return client.call(INFO_METHOD); + } + + /** + * Loads the xml representation of the ACL rule pool. + * + * @see AclPool#info(Client) + */ + public OneResponse info() + { + OneResponse response = info(client); + super.processInfo(response); + return response; + } + + public Iterator iterator() + { + AbstractList ab = new AbstractList() + { + public int size() + { + return getLength(); + } + + public Acl get(int index) + { + return (Acl) item(index); + } + }; + + return ab.iterator(); + } + + public Acl getById(int id) + { + return (Acl) super.getById(id); + } +} diff --git a/src/oca/java/src/org/opennebula/client/group/Group.java b/src/oca/java/src/org/opennebula/client/group/Group.java index f3f511233d..a32c5d5fb0 100644 --- a/src/oca/java/src/org/opennebula/client/group/Group.java +++ b/src/oca/java/src/org/opennebula/client/group/Group.java @@ -36,7 +36,7 @@ public class Group extends PoolElement{ /** * Creates a new Group representation. * - * @param id The group id (hid) of the machine. + * @param id The group id. * @param client XML-RPC Client. */ public Group(int id, Client client) diff --git a/src/oca/java/src/org/opennebula/client/group/GroupPool.java b/src/oca/java/src/org/opennebula/client/group/GroupPool.java index bfdc346305..74038a2d4a 100644 --- a/src/oca/java/src/org/opennebula/client/group/GroupPool.java +++ b/src/oca/java/src/org/opennebula/client/group/GroupPool.java @@ -50,7 +50,7 @@ public class GroupPool extends Pool implements Iterable{ } /** - * Retrieves all the hosts in the pool. + * Retrieves all the groups in the pool. * * @param client XML-RPC Client. * @return If successful the message contains the string diff --git a/src/oca/java/test/AclTest.java b/src/oca/java/test/AclTest.java new file mode 100644 index 0000000000..9b08558e64 --- /dev/null +++ b/src/oca/java/test/AclTest.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opennebula.client.Client; +import org.opennebula.client.OneResponse; +import org.opennebula.client.acl.*; + +public class AclTest +{ + + private static Acl acl; + private static AclPool aclPool; + + private static Client client; + + private static OneResponse res; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception + { + client = new Client(); + aclPool = new AclPool(client); + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception + { + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception + { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception + { + for(Acl rule : aclPool) + { + if( rule.id() != 0 ) + { + rule.delete(); + } + } + } + + @Test + public void defaultRules() + { + res = aclPool.info(); + assertTrue( !res.isError() ); + + assertEquals(1, aclPool.getLength()); + } + + @Test + public void hexAllocate() + { + // Allocate rule "#1 VM+HOST/@1 INFO+CREATE" + res = Acl.allocate(client, "0x100000001", "0x3200000001", "0x11"); + assertTrue( !res.isError() ); + + aclPool.info(); + acl = aclPool.getById( res.getIntMessage() ); + + assertNotNull(acl); + + assertEquals(res.getIntMessage(), acl.id()); + assertEquals(0x100000001L, acl.user()); + assertEquals(0x3200000001L, acl.resource()); + assertEquals(0x11L, acl.rights()); + assertEquals("#1 VM+HOST/@1 CREATE+INFO", acl.toString()); + } + + @Test + public void numericAllocate() + { + // Allocate rule "#1 VM+HOST/@1 INFO+CREATE" + res = Acl.allocate(client, 0x100000001L, 214748364801L, 0x11L); + assertTrue( !res.isError() ); + + aclPool.info(); + acl = aclPool.getById( res.getIntMessage() ); + + assertNotNull(acl); + + assertEquals(res.getIntMessage(), acl.id()); + assertEquals(0x100000001L, acl.user()); + assertEquals(0x3200000001L, acl.resource()); + assertEquals(0x11L, acl.rights()); + assertEquals("#1 VM+HOST/@1 CREATE+INFO", acl.toString()); + } + + @Test + public void ruleAllocate() + { + res = Acl.allocate(client, "@507 IMAGE/#456 CREATE"); + assertTrue( !res.isError() ); + + aclPool.info(); + acl = aclPool.getById( res.getIntMessage() ); + + assertNotNull(acl); + + assertEquals(res.getIntMessage(), acl.id()); + assertEquals(0x2000001fbL, acl.user()); + assertEquals(0x81000001c8L, acl.resource()); + assertEquals(0x1L, acl.rights()); + assertEquals("@507 IMAGE/#456 CREATE", acl.toString()); + } + + @Test + public void parseRules() + { + String[] rules = { + "#3 TEMPLATE/#0 INFO", + "#2 IMAGE/#0 INFO", + "@107 IMAGE+TEMPLATE/@100 INFO", + "* VM+IMAGE+TEMPLATE/@100 CREATE+INFO+INFO_POOL", + "#2345 VM+IMAGE+TEMPLATE/* CREATE+INFO+INFO_POOL+INFO_POOL_MINE+INSTANTIATE" + }; + + long[] users = { + 0x100000003L, + 0x100000002L, + 0x20000006bL, + 0x400000000L, + 0x100000929L + }; + + long[] resources = { + 0x20100000000L, + 0x8100000000L, + 0x28200000064L, + 0x29200000064L, + 0x29400000000L + }; + + long[] rights = { + 0x10L, + 0x10L, + 0x10L, + 0x31L, + 0xf1L + }; + + for( int i = 0; i < rules.length; i++ ) + { + res = Acl.allocate(client, rules[i]); + assertTrue( !res.isError() ); + + aclPool.info(); + acl = aclPool.getById( res.getIntMessage() ); + + assertNotNull(acl); + + assertEquals(res.getIntMessage(), acl.id()); + assertEquals(users[i], acl.user()); + assertEquals(resources[i], acl.resource()); + assertEquals(rights[i], acl.rights()); + } + + assertTrue( true ); + } + + @Test + public void delete() + { + res = Acl.allocate(client, "#1 HOST/@2 INFO_POOL"); + assertTrue( !res.isError() ); + + aclPool.info(); + assertTrue( aclPool.getLength() == 2 ); + + res = Acl.delete(client, res.getIntMessage()); + assertTrue( !res.isError() ); + + aclPool.info(); + assertTrue( aclPool.getLength() == 1 ); + } + +} diff --git a/src/oca/java/test/all_tests.sh b/src/oca/java/test/all_tests.sh index b6dfb55c7e..27b17915c7 100755 --- a/src/oca/java/test/all_tests.sh +++ b/src/oca/java/test/all_tests.sh @@ -1,5 +1,21 @@ #!/bin/bash +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + if [ -z $ONE_LOCATION ]; then echo "ONE_LOCATION not defined." exit -1 @@ -42,4 +58,7 @@ let RC=RC+$? ./test.sh GroupTest let RC=RC+$? +./test.sh AclTest +let RC=RC+$? + exit $RC \ No newline at end of file diff --git a/src/oca/java/test/test.sh b/src/oca/java/test/test.sh index 77754dd27f..1a2c3ba4fc 100755 --- a/src/oca/java/test/test.sh +++ b/src/oca/java/test/test.sh @@ -1,4 +1,21 @@ #!/bin/bash + +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # + # Usage: test.sh # For instance: test.sh ImageTest @@ -16,6 +33,9 @@ if [ -f $VAR_LOCATION/one.db ]; then exit -1 fi +echo "=========================================================================" +echo "Doing $1" +echo "=========================================================================" PID=$$ diff --git a/src/vnm_mad/HostManaged.rb b/src/vnm_mad/HostManaged.rb index b43c7d483a..bda6286ef1 100644 --- a/src/vnm_mad/HostManaged.rb +++ b/src/vnm_mad/HostManaged.rb @@ -33,7 +33,10 @@ class OpenNebulaHM < OpenNebulaNetwork vlan = CONF[:start_vlan] + nic[:network_id].to_i end - create_bridge bridge if !bridge_exists? bridge + if !bridge_exists? bridge + create_bridge bridge + ifup bridge + end if !device_exists?(dev, vlan) create_dev_vlan(dev, vlan) diff --git a/src/vnm_mad/test/OpenNebulaNetwork_spec.rb b/src/vnm_mad/test/OpenNebulaNetwork_spec.rb index 660baccad0..c8e7c14ccd 100644 --- a/src/vnm_mad/test/OpenNebulaNetwork_spec.rb +++ b/src/vnm_mad/test/OpenNebulaNetwork_spec.rb @@ -163,6 +163,7 @@ describe 'host-managed' do hm.activate hm_activate_rules = ["sudo /usr/sbin/brctl addbr onebr6", + "sudo /sbin/ip link set onebr6 up", "sudo /sbin/ip link show eth0.8", "sudo /sbin/vconfig add eth0 8", "sudo /sbin/ip link set eth0.8 up", @@ -174,19 +175,21 @@ describe 'host-managed' do $capture_commands = { /virsh.*dumpxml/ => OUTPUT[:virsh_dumpxml_vlan_id], /brctl show/ => OUTPUT[:brctl_show], - /brctl add/ => nil, - /vconfig/ => nil, - /ip link/ => nil + /brctl add/ => nil, + /vconfig/ => nil, + /ip link/ => nil } hm = OpenNebulaHM.new(OUTPUT[:onevm_show_vlan_id_kvm],"kvm") hm.activate hm_vlan_id = ["sudo /usr/sbin/brctl addbr onebr10", + "sudo /sbin/ip link set onebr10 up", "sudo /sbin/ip link show eth0.50", "sudo /sbin/vconfig add eth0 50", "sudo /sbin/ip link set eth0.50 up", "sudo /usr/sbin/brctl addif onebr10 eth0.50", "sudo /usr/sbin/brctl addbr specialbr", + "sudo /sbin/ip link set specialbr up", "sudo /sbin/ip link show eth0.51", "sudo /sbin/vconfig add eth0 51", "sudo /sbin/ip link set eth0.51 up",