From 5ee7d871e8ead432afd48a0f5c662876ada23f5a Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 26 Jul 2010 14:49:12 +0200 Subject: [PATCH 01/13] Disable image enable and disable in hook while bug #295 is fixed --- share/hooks/image.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/hooks/image.rb b/share/hooks/image.rb index e04d337920..22c92f6279 100755 --- a/share/hooks/image.rb +++ b/share/hooks/image.rb @@ -61,13 +61,13 @@ vm.each('TEMPLATE/DISK') do |disk| exit -1 if OpenNebula.is_error?(result) # Disable the Image for a safe overwriting - image.disable + # image.disable # Save the image file result = image.move(source_path, image['SOURCE']) exit -1 if OpenNebula.is_error?(result) - image.enable + # image.enable end end From 83fe5ba1bfa0ec24a6c9d933dee83dd76a4e666a Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 26 Jul 2010 14:49:33 +0200 Subject: [PATCH 02/13] Bug regarding quotes in onevm --- src/cli/onevm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/onevm b/src/cli/onevm index 65d3062ec8..73b49d3efe 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -716,7 +716,7 @@ when "saveas" end # Build the template and allocate the new Image - template = "NAME=#{image_name}\n" + template = "NAME=\"#{image_name}\"\n" template << "TYPE=#{image_type}\n" if image_type From fb58d090d080503c6677425456691f7b2a71b427 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 26 Jul 2010 15:00:25 +0200 Subject: [PATCH 03/13] made CLI option parsing more modular --- src/cli/command_parse.rb | 104 +++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 38 deletions(-) diff --git a/src/cli/command_parse.rb b/src/cli/command_parse.rb index b86f5a1685..f3f55ee4cd 100644 --- a/src/cli/command_parse.rb +++ b/src/cli/command_parse.rb @@ -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 From 239ed2493c3393dd205df574be77289e5577426e Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 26 Jul 2010 15:02:36 +0200 Subject: [PATCH 04/13] cleaned options and added --no-hash to oneuser --- src/cli/oneuser | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cli/oneuser b/src/cli/oneuser index 576a5ee918..5802dac6b6 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -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] + sha_password = ARGV[1] + else + sha_password = Digest::SHA1.hexdigest(ARGV[1]) + end + result=user.allocate(ARGV[0], sha_password) if !OpenNebula.is_error?(result) puts "ID: " + user.id.to_s if ops[:verbose] exit 0 From e62649ade4615b94c1d2409b39ed5566fb2aac99 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 26 Jul 2010 15:05:18 +0200 Subject: [PATCH 05/13] Removed save command in onevm --- src/cli/onevm | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index 73b49d3efe..fe65eb59f9 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -347,10 +347,6 @@ Commands: when the vm shutdowns) onevm saveas -* save (Set the specified vm's disk to be saved, overwriting the original image - when the vm shutdowns) - onevm save - * delete (Deletes a VM from the pool and DB) onevm delete @@ -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) From fa440daec269c70543183de3b6b5e29ba4ef67ec Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 26 Jul 2010 15:12:36 +0200 Subject: [PATCH 06/13] clean options for onecluster and onevnet --- src/cli/onecluster | 2 +- src/cli/onevnet | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/onecluster b/src/cli/onecluster index ac829ab454..933073bb4f 100755 --- a/src/cli/onecluster +++ b/src/cli/onecluster @@ -122,7 +122,7 @@ EOT end -oneup_opts=OneUPParse.new +oneup_opts=OneUPParse.new([:list, :xml]) oneup_opts.parse(ARGV) ops=oneup_opts.options diff --git a/src/cli/onevnet b/src/cli/onevnet index 8dcdf17d54..403db47135 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -180,7 +180,7 @@ EOT end -onevn_opts=OneVNParse.new +onevn_opts=OneVNParse.new([:list, :xml]) onevn_opts.parse(ARGV) ops=onevn_opts.options From 947bcd74750e73ca0ef5af6bc466c474061d1400 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 26 Jul 2010 15:27:23 +0200 Subject: [PATCH 07/13] oneuser passwd should also be aware of --no-hash --- src/cli/oneuser | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cli/oneuser b/src/cli/oneuser index 5802dac6b6..292016b99f 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -143,11 +143,11 @@ when "create" user=OpenNebula::User.new( OpenNebula::User.build_xml, get_one_client) if ops[:no_hash] - sha_password = ARGV[1] + password = ARGV[1] else - sha_password = Digest::SHA1.hexdigest(ARGV[1]) + password = Digest::SHA1.hexdigest(ARGV[1]) end - result=user.allocate(ARGV[0], sha_password) + result=user.allocate(ARGV[0], password) if !OpenNebula.is_error?(result) puts "ID: " + user.id.to_s if ops[:verbose] exit 0 @@ -202,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] From 64fd4dbea68a50fa8334cb4c9218cdb75ad0e9ec Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 26 Jul 2010 15:22:54 +0200 Subject: [PATCH 08/13] Minor changes in OCCI and added onevm saveas --type --- src/cli/onevm | 8 ++++++++ src/cloud/occi/lib/VirtualMachineOCCI.rb | 3 --- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index fe65eb59f9..39ca4bc5d8 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -346,6 +346,9 @@ Commands: * saveas (Set the specified vm's disk to be saved in a new image (image_name) when the vm shutdowns) onevm saveas + + (Set a different type for the new Image) + onevm saveas -t/--type * delete (Deletes a VM from the pool and DB) onevm delete @@ -387,6 +390,11 @@ EOT table.print_help end + def special_options(opts, options) + opts.on_tail("-t", "--type", "Image type") do |o| + options[:type]=o + end + end end diff --git a/src/cloud/occi/lib/VirtualMachineOCCI.rb b/src/cloud/occi/lib/VirtualMachineOCCI.rb index 3990bdee47..1568f9ea7c 100755 --- a/src/cloud/occi/lib/VirtualMachineOCCI.rb +++ b/src/cloud/occi/lib/VirtualMachineOCCI.rb @@ -33,9 +33,6 @@ class VirtualMachineOCCI < VirtualMachine <%= disk['TYPE'] %> <%= disk['TARGET'] %> - <% if disk['SAVE_AS'] %> - <%= disk['SAVE_AS'] %> - <% end %> <% end %> <% end %> From 6a8d2f5e23297aed4b5913e9a6a6bc3fdbb41a88 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 26 Jul 2010 15:34:29 +0200 Subject: [PATCH 09/13] saveas support for old disk version --- src/cli/onevm | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/cli/onevm b/src/cli/onevm index 39ca4bc5d8..9f89fdbc96 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -695,27 +695,27 @@ when "saveas" get_one_client) result = vm.info - if !is_successful?(result) + if !is_successful?(result) puts result.message exit -1 end - - image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"] - - # Get the image type - image = OpenNebula::Image.new( - OpenNebula::Image.build_xml(image_id), - get_one_client) - - result = image.info - if !is_successful?(result) - puts result.message - exit -1 - end - + if ops[:type] image_type = ops[:type] else + image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"] + + # Get the image type + image = OpenNebula::Image.new( + OpenNebula::Image.build_xml(image_id), + get_one_client) + + result = image.info + if !is_successful?(result) + puts result.message + exit -1 + end + image_type = image.type_str end @@ -725,12 +725,12 @@ when "saveas" image = OpenNebula::Image.new( - OpenNebula::Image.build_xml, + OpenNebula::Image.build_xml, get_one_client) result = image.allocate(template) - if !is_successful?(result) + if !is_successful?(result) puts result.message exit -1 end From 0069caca43ef4319c836eaa9d51d0d75fdd2ffe8 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 26 Jul 2010 15:39:19 +0200 Subject: [PATCH 10/13] Set default authorization mad in oned.conf --- share/etc/oned.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 7834e187d4..6a1d7aa6fa 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -309,5 +309,5 @@ VM_HOOK = [ #------------------------------------------------------------------------------- #AUTH_MAD = [ -# executable = "" ] +# executable = "one_auth_mad" ] From 4e1e9e5fc2cf9d3b772850831bc389b86673383d Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 26 Jul 2010 15:45:18 +0200 Subject: [PATCH 11/13] Fixed --type for onevm saveas --- src/cli/onevm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/onevm b/src/cli/onevm index 9f89fdbc96..bce3ccb5fa 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -391,7 +391,8 @@ EOT end def special_options(opts, options) - opts.on_tail("-t", "--type", "Image type") do |o| + opts.on("-t type", "--type type", String, + "Image type") do |o| options[:type]=o end end From f334cdf71efd8e5989b310b9e4a76882fe448d65 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 26 Jul 2010 15:56:16 +0200 Subject: [PATCH 12/13] bug in authorization policies --- src/authm_mad/simple_permissions.rb | 2 +- src/authm_mad/spec/simple_permissions_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/authm_mad/simple_permissions.rb b/src/authm_mad/simple_permissions.rb index 28ee76af14..81862e302f 100644 --- a/src/authm_mad/simple_permissions.rb +++ b/src/authm_mad/simple_permissions.rb @@ -65,7 +65,7 @@ class SimplePermissions when 'USE' if %w{VM NET IMAGE}.include? object - auth_result = ((owner == uid) | pub=='1') + auth_result = ((owner == uid) | (pub=='1')) elsif object == 'HOST' auth_result=true end diff --git a/src/authm_mad/spec/simple_permissions_spec.rb b/src/authm_mad/spec/simple_permissions_spec.rb index 68c49621e2..55c62f9275 100644 --- a/src/authm_mad/spec/simple_permissions_spec.rb +++ b/src/authm_mad/spec/simple_permissions_spec.rb @@ -92,7 +92,7 @@ describe SimplePermissions do @perm.auth(1, gen_tokens(1, :create, :host => false)).should == true @perm.auth(1, gen_tokens(1, :delete, :host => false)).should == true @perm.auth(1, gen_tokens(1, :manage, :host => false)).should == true - @perm.auth(1, gen_tokens(1, :use)).should == true + @perm.auth(1, gen_tokens(1, :use)).should == true end end From 5d84f82e650d70e0bf2b55fe20f53ac48bafbafe Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 26 Jul 2010 16:58:09 +0200 Subject: [PATCH 13/13] occi-storage now shows size info --- src/cloud/occi/lib/ImageOCCI.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cloud/occi/lib/ImageOCCI.rb b/src/cloud/occi/lib/ImageOCCI.rb index 478f868ff4..7366713255 100755 --- a/src/cloud/occi/lib/ImageOCCI.rb +++ b/src/cloud/occi/lib/ImageOCCI.rb @@ -68,8 +68,8 @@ class ImageOCCI < Image size = nil begin - if self['TEMPLATE/SOURCE'] != nil - size = File.stat(self['TEMPLATE/SOURCE']).size + if self['SOURCE'] != nil and File.exists?(self['SOURCE']) + size = File.stat(self['SOURCE']).size end rescue Exception => e error = OpenNebula::Error.new(e.message)