mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Merge branch 'master' of git.opennebula.org:one
This commit is contained in:
commit
d71f41e5fa
17
install.sh
17
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 \
|
||||
|
@ -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=<<EOT
|
||||
## SYNOPSIS
|
||||
|
||||
#{str}
|
||||
EOT
|
||||
end
|
||||
|
||||
def version(str)
|
||||
@ -185,7 +197,7 @@ module CommandParser
|
||||
print_formatters
|
||||
puts
|
||||
if @version
|
||||
puts "== LICENSE"
|
||||
puts "## LICENSE"
|
||||
puts @version
|
||||
end
|
||||
end
|
||||
@ -193,7 +205,7 @@ module CommandParser
|
||||
private
|
||||
|
||||
def print_options
|
||||
puts "== Options"
|
||||
puts "## OPTIONS"
|
||||
|
||||
shown_opts = Array.new
|
||||
opt_format = "#{' '*5}%-25s %s"
|
||||
@ -217,7 +229,7 @@ module CommandParser
|
||||
end
|
||||
|
||||
def print_commands
|
||||
puts "== Commands"
|
||||
puts "## COMMANDS"
|
||||
|
||||
cmd_format5 = "#{' '*3}%s"
|
||||
cmd_format10 = "#{' '*8}%s"
|
||||
@ -243,7 +255,7 @@ module CommandParser
|
||||
opts_str=value[:options].flatten.collect{|o|
|
||||
o[:name]
|
||||
}.join(', ')
|
||||
printf cmd_format10, "options: #{opts_str}"
|
||||
printf cmd_format10, "valid options: #{opts_str}"
|
||||
puts
|
||||
end
|
||||
puts
|
||||
@ -251,7 +263,7 @@ module CommandParser
|
||||
end
|
||||
|
||||
def print_formatters
|
||||
puts "== Argument formats"
|
||||
puts "## ARGUMENT FORMATS"
|
||||
|
||||
cmd_format5 = "#{' '*3}%s"
|
||||
cmd_format10 = "#{' '*8}%s"
|
||||
|
@ -1,7 +1,7 @@
|
||||
---
|
||||
:ID:
|
||||
:desc: ONE identifier for Virtual Machine
|
||||
:size: 4
|
||||
:size: 6
|
||||
|
||||
:NAME:
|
||||
:desc: Name of the Virtual Machine
|
||||
|
@ -76,7 +76,7 @@ EOT
|
||||
if OpenNebula.is_error?(rc)
|
||||
return -1, rc.message
|
||||
else
|
||||
puts "ID: #{resource.id.to_s}" if options[:verbose]
|
||||
puts "ID: #{resource.id.to_s}"
|
||||
return 0
|
||||
end
|
||||
end
|
||||
@ -95,7 +95,8 @@ EOT
|
||||
phash = pool.to_hash
|
||||
rname = self.class.rname
|
||||
|
||||
if phash["#{rname}_POOL"] && phash["#{rname}_POOL"]["#{rname}"]
|
||||
if phash["#{rname}_POOL"] &&
|
||||
phash["#{rname}_POOL"]["#{rname}"]
|
||||
if phash["#{rname}_POOL"]["#{rname}"].instance_of?(Array)
|
||||
phash = phash["#{rname}_POOL"]["#{rname}"]
|
||||
else
|
||||
@ -130,7 +131,9 @@ EOT
|
||||
if OpenNebula.is_error?(rc)
|
||||
return -1, rc.message
|
||||
else
|
||||
puts "#{self.class.rname} #{id}: #{verbose}" if options[:verbose]
|
||||
if options[:verbose]
|
||||
puts "#{self.class.rname} #{id}: #{verbose}"
|
||||
end
|
||||
return 0
|
||||
end
|
||||
end
|
||||
@ -160,6 +163,21 @@ EOT
|
||||
rid_to_str(:groups, gid, options)
|
||||
end
|
||||
|
||||
def user_name(resource, options={})
|
||||
if options[:numeric]
|
||||
resource['UID']
|
||||
else
|
||||
resource['UNAME']
|
||||
end
|
||||
end
|
||||
|
||||
def group_name(resource, options={})
|
||||
if options[:numeric]
|
||||
resource['GID']
|
||||
else
|
||||
resource['GNAME']
|
||||
end
|
||||
end
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
@ -245,12 +263,13 @@ EOT
|
||||
|
||||
if objects.length>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
|
||||
end
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
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])
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneGroupHelper.new
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneHostHelper.new
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
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
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
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)
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
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
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
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
|
||||
end
|
||||
|
@ -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` <command> [<args>] [<options>]"
|
||||
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)
|
||||
|
@ -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
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -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 /<elementName>/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.
|
||||
|
355
src/oca/java/src/org/opennebula/client/acl/Acl.java
Normal file
355
src/oca/java/src/org/opennebula/client/acl/Acl.java
Normal file
@ -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.
|
||||
* <br/>
|
||||
* There is not a public constructor, because the information for an individual
|
||||
* ACL rule cannot be retrieved from OpenNebula.
|
||||
* <br/>
|
||||
* 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<String, Long> USERS;
|
||||
private static final Map<String, Long> RESOURCES;
|
||||
private static final Map<String, Long> RIGHTS;
|
||||
|
||||
static {
|
||||
HashMap<String, Long> tmpUsers = new HashMap<String, Long>();
|
||||
tmpUsers.put("#", 0x0000000100000000L);
|
||||
tmpUsers.put("@", 0x0000000200000000L);
|
||||
tmpUsers.put("*", 0x0000000400000000L);
|
||||
|
||||
USERS = Collections.unmodifiableMap(tmpUsers);
|
||||
|
||||
HashMap<String, Long> tmpResources = new HashMap<String, Long>();
|
||||
|
||||
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<String, Long> tmpRights = new HashMap<String, Long>();
|
||||
|
||||
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 [#<id>, @<id>, *] 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;
|
||||
}
|
||||
}
|
98
src/oca/java/src/org/opennebula/client/acl/AclPool.java
Normal file
98
src/oca/java/src/org/opennebula/client/acl/AclPool.java
Normal file
@ -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<Acl>{
|
||||
|
||||
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<Acl> iterator()
|
||||
{
|
||||
AbstractList<Acl> ab = new AbstractList<Acl>()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -50,7 +50,7 @@ public class GroupPool extends Pool implements Iterable<Group>{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
213
src/oca/java/test/AclTest.java
Normal file
213
src/oca/java/test/AclTest.java
Normal file
@ -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 );
|
||||
}
|
||||
|
||||
}
|
@ -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
|
@ -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 <Test_name>
|
||||
# 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=$$
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user