1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Merge branch 'master' of opennebula.org:one

This commit is contained in:
Jaime Melis 2010-07-26 15:30:31 +02:00
commit 0f0bb611bb
5 changed files with 88 additions and 70 deletions

View File

@ -35,53 +35,25 @@ OpenNebula 1.5.0
Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
EOT
def initialize
def initialize(standard_options=nil)
@options=Hash.new
if standard_options
@standard_options=standard_options
else
@standard_options=[:list, :top, :xml]
end
@cmdparse=OptionParser.new do |opts|
opts.banner=text_banner
opts.on("-l x,y,z", "--list x,y,z", Array,
"Selects columns to display with list", "command") do |o|
@options[:list]=o.collect {|c| c.to_sym }
end
execute_standard_options(opts, @options)
special_options(opts, @options)
opts.on("--list-columns", "Information about the columns available",
"to display, order or filter") do |o|
puts list_options
exit
end
opts.on("-o x,y,z", "--order x,y,z", Array,
"Order by these columns, column starting",
"with - means decreasing order") do |o|
@options[:order]=o
end
opts.on("-f x,y,z", "--filter x,y,z", Array,
"Filter data. An array is specified", "with column=value pairs.") do |o|
@options[:filter]=Hash.new
o.each {|i|
k,v=i.split('=')
@options[:filter][k]=v
}
end
opts.on("-d seconds", "--delay seconds", Integer,
"Sets the delay in seconds for top", "command") do |o|
@options[:delay]=o
end
opts.on("-v", "--verbose",
opts.on("-v", "--verbose",
"Tells more information if the command",
"is successful") do |o|
@options[:verbose]=true
end
opts.on("-x", "--xml",
"Returns xml instead of human readable text") do |o|
@options[:xml]=true
end
opts.on_tail("-h", "--help", "Shows this help message") do |o|
print_help
@ -105,6 +77,62 @@ EOT
end
end
def opts_list(opts, options)
opts.on("-l x,y,z", "--list x,y,z", Array,
"Selects columns to display with list", "command") do |o|
options[:list]=o.collect {|c| c.to_sym }
end
opts.on("--list-columns", "Information about the columns available",
"to display, order or filter") do |o|
puts list_options
exit
end
opts.on("-o x,y,z", "--order x,y,z", Array,
"Order by these columns, column starting",
"with - means decreasing order") do |o|
options[:order]=o
end
opts.on("-f x,y,z", "--filter x,y,z", Array,
"Filter data. An array is specified", "with column=value pairs.") do |o|
options[:filter]=Hash.new
o.each {|i|
k,v=i.split('=')
options[:filter][k]=v
}
end
end
def opts_top(opts, options)
opts.on("-d seconds", "--delay seconds", Integer,
"Sets the delay in seconds for top", "command") do |o|
options[:delay]=o
end
end
def opts_xml(opts, options)
opts.on("-x", "--xml",
"Returns xml instead of human readable text") do |o|
options[:xml]=true
end
end
def set_standard_options(options)
@standard_options=options
end
def execute_standard_options(opts, options)
@standard_options.each do |op|
sym="opts_#{op}".to_sym
self.send(sym, opts, options) if self.respond_to?(sym)
end
end
def special_options(opts, options)
end
def options
@options
end

View File

@ -122,7 +122,7 @@ EOT
end
oneup_opts=OneUPParse.new
oneup_opts=OneUPParse.new([:list, :xml])
oneup_opts.parse(ARGV)
ops=oneup_opts.options

View File

@ -120,10 +120,16 @@ EOT
table=ShowTable.new(ShowTableUP)
table.print_help
end
def special_options(opts, options)
opts.on_tail("-n", "--no-hash", "Store plain password "<<
"into the database") do |o|
options[:no_hash]=true
end
end
end
oneup_opts=OneUPParse.new
oneup_opts=OneUPParse.new([:list])
oneup_opts.parse(ARGV)
ops=oneup_opts.options
@ -136,8 +142,12 @@ when "create"
check_parameters("create", 2)
user=OpenNebula::User.new(
OpenNebula::User.build_xml, get_one_client)
sha_password = Digest::SHA1.hexdigest(ARGV[1])
result=user.allocate(ARGV[0],sha_password)
if ops[:no_hash]
password = ARGV[1]
else
password = Digest::SHA1.hexdigest(ARGV[1])
end
result=user.allocate(ARGV[0], password)
if !OpenNebula.is_error?(result)
puts "ID: " + user.id.to_s if ops[:verbose]
exit 0
@ -192,8 +202,12 @@ when "passwd"
user=OpenNebula::User.new_with_id(user_id, get_one_client)
sha_password = Digest::SHA1.hexdigest(ARGV[1])
result=user.passwd(sha_password)
if ops[:no_hash]
password = ARGV[1]
else
password = Digest::SHA1.hexdigest(ARGV[1])
end
result=user.passwd(password)
if !OpenNebula.is_error?(result)
puts "Password changed" if ops[:verbose]

View File

@ -347,10 +347,6 @@ Commands:
when the vm shutdowns)
onevm saveas <vm_id> <disk_id> <image_name>
* save (Set the specified vm's disk to be saved, overwriting the original image
when the vm shutdowns)
onevm save <vm_id> <disk_id>
* delete (Deletes a VM from the pool and DB)
onevm delete <vm_id>
@ -733,26 +729,6 @@ when "saveas"
result = vm.save_as(disk_id.to_i, image.id)
when "save"
check_parameters("save", 2)
vm_id = get_vm_id(ARGV[0])
disk_id = ARGV[1]
# Get the Image ID for this disk
vm = OpenNebula::VirtualMachine.new(
OpenNebula::VirtualMachine.build_xml(vm_id),
get_one_client)
result = vm.info
if !is_successful?(result)
puts result.message
exit -1
end
image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"]
result = vm.save_as(disk_id.to_i, image_id.to_i)
when "show"
check_parameters("get_info", 1)
args=expand_args(ARGV)

View File

@ -180,7 +180,7 @@ EOT
end
onevn_opts=OneVNParse.new
onevn_opts=OneVNParse.new([:list, :xml])
onevn_opts.parse(ARGV)
ops=onevn_opts.options