From 42bf46e21aee5d1240edbb3814740808180f016a Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 30 Jul 2010 17:57:52 +0200 Subject: [PATCH 1/7] feature #297: ImageRepository for managing images --- share/hooks/image.rb | 12 +- src/cli/oneimage | 77 ++------- src/cloud/common/CloudServer.rb | 35 +--- src/cloud/occi/lib/OCCIServer.rb | 2 +- src/oca/ruby/OpenNebula.rb | 1 + src/oca/ruby/OpenNebula/Image.rb | 95 +---------- src/oca/ruby/OpenNebula/ImageRepository.rb | 188 +++++++++++++++++++++ 7 files changed, 216 insertions(+), 194 deletions(-) create mode 100644 src/oca/ruby/OpenNebula/ImageRepository.rb diff --git a/share/hooks/image.rb b/share/hooks/image.rb index 2d42ea53ca..8709a7d65f 100755 --- a/share/hooks/image.rb +++ b/share/hooks/image.rb @@ -37,6 +37,7 @@ end client = Client.new() +img_repo = ImageRepository.new vm = VirtualMachine.new( VirtualMachine.build_xml(vm_id), @@ -52,17 +53,8 @@ vm.each('TEMPLATE/DISK') do |disk| Image.build_xml(image_id), client) - result = image.info - exit -1 if OpenNebula.is_error?(result) - - # Disable the Image for a safe overwriting - # image.disable - - # Save the image file - result = image.move(source_path, image['SOURCE']) + result = img_repo.update_source(image, source_path) exit -1 if OpenNebula.is_error?(result) - - # image.enable end end diff --git a/src/cli/oneimage b/src/cli/oneimage index 41a17186a4..dfa43d4b26 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -251,6 +251,11 @@ EOT table.print_help end + def special_options(opts, options) + opts.on_tail("-n", "--no-cp", "Do not copy the source") do |o| + options[:no_cp]=true + end + end end @@ -300,58 +305,18 @@ result=[false, "Unknown error"] command=ARGV.shift +img_repo = OpenNebula::ImageRepository.new + case command -when "register", "create", "add" - # ---------- Get the Template ------------ - +when "register", "create", "add" check_parameters("register", 1) template = get_template(ARGV[0]) - - # ---------- Allocate the Image file ------------ - image = OpenNebula::Image.new( - OpenNebula::Image.build_xml, - get_one_client) - - result = image.allocate(template) - - if !is_successful?(result) - puts result.message - exit -1 - end + image = OpenNebula::Image.new(OpenNebula::Image.build_xml, get_one_client) - # ---------- Copy the Image file ------------ - - image.info - - if image['TEMPLATE/PATH'] - file_path = image['TEMPLATE/PATH'] - - if !File.exists?(file_path) - error_msg = "Image file could not be found, aborting." - result = OpenNebula::Error.new(error_msg) - end - - result = image.copy(file_path, image['SOURCE']) - elsif image['TEMPLATE/SIZE'] and - image['TEMPLATE/FSTYPE'] and - image['TEMPLATE/TYPE'] == 'DATABLOCK' - result = image.mk_datablock( - image['TEMPLATE/SIZE'], - image['TEMPLATE/FSTYPE'], - image['SOURCE']) - else - error_msg = "Image not present, aborting." - result = OpenNebula::Error.new(error_msg) - end - - - if is_successful?(result) - image.enable + result = img_repo.create(image, template, !ops[:no_cp]) + if is_successful?(result) puts "ID: " + image.id.to_s if ops[:verbose] - exit 0 - else - image.delete end @@ -494,22 +459,14 @@ when "delete" args=expand_args(ARGV) args.each do |param| - image_id=get_image_id(param) - - image=OpenNebula::Image.new_with_id(image_id, get_one_client) - - result = image.info + image_id = get_image_id(param) + image = OpenNebula::Image.new( + OpenNebula::Image.build_xml(image_id), + get_one_client) + result = img_repo.delete(image) if is_successful?(result) - - file_path = image['SOURCE'] - - result=image.delete - - if is_successful?(result) - FileUtils.rm(file_path) if File.exists?(file_path) - puts "Image correctly deleted" if ops[:verbose] - end + puts "Image correctly deleted" if ops[:verbose] end end diff --git a/src/cloud/common/CloudServer.rb b/src/cloud/common/CloudServer.rb index f15acad711..157da9366c 100755 --- a/src/cloud/common/CloudServer.rb +++ b/src/cloud/common/CloudServer.rb @@ -58,6 +58,7 @@ class CloudServer @one_client = Client.new() @user_pool = UserPool.new(@one_client) + @img_repo = OpenNebula::ImageRepository.new end # @@ -110,47 +111,23 @@ class CloudServer if file if file[:tempfile] file_path = file[:tempfile].path + template = image.to_one_template + template << "\nPATH = #{file_path}" else error_msg = "Image not present, aborting." error = OpenNebula::Error.new(error_msg) return error end - - if !File.exists?(file_path) - error_msg = "Image file could not be found, aborting." - error = OpenNebula::Error.new(error_msg) - return error - end end - # ---------- Allocate the Image file ------------ + rc = @img_repo.create(image, template) - rc = image.allocate(image.to_one_template) + file[:tempfile].unlink + if OpenNebula.is_error?(rc) return rc end - # ---------- Copy the Image file ------------ - - image.info - - if file_path - rc = image.copy(file_path, image['SOURCE']) - file[:tempfile].unlink - elsif image['TEMPLATE/SIZE'] and - image['TEMPLATE/FSTYPE'] and - image['TEMPLATE/TYPE'] == 'DATABLOCK' - rc = image.mk_datablock( - image['TEMPLATE/SIZE'], - image['TEMPLATE/FSTYPE'], - image['SOURCE']) - end - - if OpenNebula.is_error?(rc) - image.delete - return rc - end - return nil end diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index a5b3abf2aa..0422213b9d 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -355,7 +355,7 @@ class OCCIServer < CloudServer get_client(request.env)) # --- Delete the Image --- - rc = image.delete + rc = @img_repo.delete(image) return rc, 500 if OpenNebula::is_error?(rc) return "", 204 diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/OpenNebula.rb index 1e8412b8be..975e4f6002 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/OpenNebula.rb @@ -15,6 +15,7 @@ require 'OpenNebula/VirtualNetwork' require 'OpenNebula/VirtualNetworkPool' require 'OpenNebula/Image' require 'OpenNebula/ImagePool' +require 'OpenNebula/ImageRepository' require 'OpenNebula/User' require 'OpenNebula/UserPool' require 'OpenNebula/Host' diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index 74840da8ab..65ab9cda64 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -55,7 +55,6 @@ module OpenNebula super(xml,client) @client = client - @immanager = ImageManager.new end ####################################################################### @@ -114,22 +113,7 @@ module OpenNebula def delete() super(IMAGE_METHODS[:delete]) end - - def copy(path, source) - @immanager.copy(path, source) - end - - def move(path, source) - @immanager.move(path, source) - end - - def mk_datablock(size, fstype, source) - rc = @immanager.dd(size, source) - - return rc if OpenNebula.is_error?(rc) - - @immanager.mkfs(fstype, source) - end + ####################################################################### # Helpers to get Image information @@ -195,81 +179,4 @@ module OpenNebula end end - - class ImageManager - # --------------------------------------------------------------------- - # Constants and Class Methods - # --------------------------------------------------------------------- - FS_UTILS = { - :dd => "env dd", - :mkfs => "env mkfs" - } - - def copy(path, source) - if source.nil? or path.nil? - return OpenNebula::Error.new("copy Image: missing parameters.") - end - - begin - FileUtils.copy(path, source) - FileUtils.chmod(0660, source) - rescue Exception => e - return OpenNebula::Error.new(e.message) - end - - return nil - end - - def move(path, source) - if source.nil? or path.nil? - return OpenNebula::Error.new("copy Image: missing parameters.") - end - - begin - FileUtils.move(path, source) - FileUtils.chmod(0660, source) - rescue Exception => e - return OpenNebula::Error.new(e.message) - end - - return nil - end - - def dd(size, source) - if source.nil? or size.nil? - return OpenNebula::Error.new("dd Image: missing parameters.") - end - - command = "" - command << FS_UTILS[:dd] - command << " if=/dev/zero of=#{source} ibs=1 count=1" - command << " obs=1048576 seek=#{size}" - - local_command=LocalCommand.run(command) - - if local_command.code!=0 - return OpenNebula::Error.new("dd Image: in dd command.") - end - - return nil - end - - def mkfs(fstype, source) - if source.nil? or fstype.nil? - return OpenNebula::Error.new("mkfs Image: missing parameters.") - end - - command = "" - command << FS_UTILS[:mkfs] - command << " -t #{fstype} -F #{source}" - - local_command=LocalCommand.run(command) - - if local_command.code!=0 - return OpenNebula::Error.new("mkfs Image: in mkfs command.") - end - - return nil - end - end end diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb new file mode 100644 index 0000000000..ff1caba42a --- /dev/null +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -0,0 +1,188 @@ +require 'OpenNebula/Image' +require 'fileutils' + +module OpenNebula + class ImageRepository + + def create(image, template, copy=true) + if image.nil? + error_msg = "Image could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + # ------ Allocate the Image ------ + result = image.allocate(template) + + if OpenNebula.is_error?(result) + puts result.message + exit -1 + end + + + # ------ Copy the Image file ------ + image.info + + if image['TEMPLATE/PATH'] + if copy + # --- CDROM, DATABLOCK or OS based on a PATH --- + file_path = image['TEMPLATE/PATH'] + + if !File.exists?(file_path) + error_msg = "Image file could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + result = copy(file_path, image['SOURCE']) + end + elsif image['TEMPLATE/SIZE'] and image['TEMPLATE/FSTYPE'] and \ + image['TEMPLATE/TYPE'] == 'DATABLOCK' + # --- Empty DATABLOCK --- + result = dd(image['TEMPLATE/SIZE'], image['SOURCE']) + + if !OpenNebula.is_error?(result) + result = mkfs(image['TEMPLATE/FSTYPE'], image['SOURCE']) + end + else + error_msg = "Image not present, aborting." + result = OpenNebula::Error.new(error_msg) + end + + + # ------ Enable the Image ------ + if !OpenNebula.is_error?(result) + image.enable + else + image.delete + end + + return result + end + + def delete(image) + if image.nil? + error_msg = "Image could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + result = image.info + + if !OpenNebula.is_error?(result) + file_path = image['SOURCE'] + + result = image.delete + + if !OpenNebula.is_error?(result) + result = remove(file_path) + end + end + + return result + end + + def update_source(image, source) + if image.nil? + error_msg = "Image could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + result = image.info + + if !OpenNebula.is_error?(result) + # Disable the Image for a safe overwriting + # image.disable + + result = move(source, image['SOURCE']) + + # image.enable + end + + return result + end + + private + + FS_UTILS = { + :dd => "env dd", + :mkfs => "env mkfs" + } + + def copy(path, source) + if source.nil? or path.nil? + return OpenNebula::Error.new("copy Image: missing parameters.") + end + + begin + FileUtils.copy(path, source) + FileUtils.chmod(0660, source) + rescue Exception => e + return OpenNebula::Error.new(e.message) + end + + return nil + end + + def move(path, source) + if source.nil? or path.nil? + return OpenNebula::Error.new("copy Image: missing parameters.") + end + + begin + FileUtils.move(path, source) + FileUtils.chmod(0660, source) + rescue Exception => e + return OpenNebula::Error.new(e.message) + end + + return nil + end + + def dd(size, source) + if source.nil? or size.nil? + return OpenNebula::Error.new("dd Image: missing parameters.") + end + + command = "" + command << FS_UTILS[:dd] + command << " if=/dev/zero of=#{source} ibs=1 count=1" + command << " obs=1048576 seek=#{size}" + + local_command=LocalCommand.run(command) + + if local_command.code!=0 + return OpenNebula::Error.new("dd Image: in dd command.") + end + + return nil + end + + def mkfs(fstype, source) + if source.nil? or fstype.nil? + return OpenNebula::Error.new("mkfs Image: missing parameters.") + end + + command = "" + command << FS_UTILS[:mkfs] + command << " -t #{fstype} -F #{source}" + + local_command=LocalCommand.run(command) + + if local_command.code!=0 + return OpenNebula::Error.new("mkfs Image: in mkfs command.") + end + + return nil + end + + def remove(source) + if File.exists?(source) + begin + FileUtils.rm(source) + rescue Exception => e + return OpenNebula::Error.new(e.message) + end + end + + return nil + end + end +end \ No newline at end of file From 971031f32676e10a8e527df60e9cd8089559adf6 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 1 Aug 2010 17:44:58 +0200 Subject: [PATCH 2/7] bug #295: Images are disabled if have to be written in the repo --- src/oca/ruby/OpenNebula/ImageRepository.rb | 46 +++++++++++----------- src/vm/VirtualMachine.cc | 43 +++++++++++++++++++- 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb index ff1caba42a..d731c79ef6 100644 --- a/src/oca/ruby/OpenNebula/ImageRepository.rb +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -3,21 +3,21 @@ require 'fileutils' module OpenNebula class ImageRepository - + def create(image, template, copy=true) if image.nil? error_msg = "Image could not be found, aborting." result = OpenNebula::Error.new(error_msg) end - + # ------ Allocate the Image ------ result = image.allocate(template) - if OpenNebula.is_error?(result) + if OpenNebula.is_error?(result) puts result.message exit -1 end - + # ------ Copy the Image file ------ image.info @@ -38,7 +38,7 @@ module OpenNebula image['TEMPLATE/TYPE'] == 'DATABLOCK' # --- Empty DATABLOCK --- result = dd(image['TEMPLATE/SIZE'], image['SOURCE']) - + if !OpenNebula.is_error?(result) result = mkfs(image['TEMPLATE/FSTYPE'], image['SOURCE']) end @@ -49,21 +49,21 @@ module OpenNebula # ------ Enable the Image ------ - if !OpenNebula.is_error?(result) + if !OpenNebula.is_error?(result) image.enable else image.delete end - + return result end - + def delete(image) if image.nil? error_msg = "Image could not be found, aborting." result = OpenNebula::Error.new(error_msg) end - + result = image.info if !OpenNebula.is_error?(result) @@ -75,32 +75,32 @@ module OpenNebula result = remove(file_path) end end - + return result - end - + end + def update_source(image, source) if image.nil? error_msg = "Image could not be found, aborting." result = OpenNebula::Error.new(error_msg) end - + result = image.info - + if !OpenNebula.is_error?(result) # Disable the Image for a safe overwriting - # image.disable + image.disable result = move(source, image['SOURCE']) - - # image.enable + + image.enable end - + return result end - + private - + FS_UTILS = { :dd => "env dd", :mkfs => "env mkfs" @@ -120,7 +120,7 @@ module OpenNebula return nil end - + def move(path, source) if source.nil? or path.nil? return OpenNebula::Error.new("copy Image: missing parameters.") @@ -172,7 +172,7 @@ module OpenNebula return nil end - + def remove(source) if File.exists?(source) begin @@ -181,7 +181,7 @@ module OpenNebula return OpenNebula::Error.new(e.message) end end - + return nil end end diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 71ef6f7623..f9e8e88153 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -904,6 +904,8 @@ error_common: void VirtualMachine::release_disk_images() { string iid; + string saveas; + int saveas_id; int num_disks; vector disks; @@ -939,12 +941,49 @@ void VirtualMachine::release_disk_images() continue; } - if (img->release_image() == true) + img->release_image(); + + + // -------------- DISABLE THIS IMAGE IF OVERWRITTEN -------------------- + saveas = disk->vector_value("SAVE_AS"); + saveas_id = -1; + + if ( !saveas.empty() ) { - ipool->update(img); + if (saveas == id) + { + img->enable(false); + } + else + { + saveas_id = atoi(saveas.c_str()) + } } + // ----------------------- UPDATE IMAGE -------------------------------- + + ipool->update(img); + img->unlock(); + + // ------------------- DISABLE IMAGE TO BE SAVED ----------------------- + + if (saveas_id != -1) + { + img = ipool->get(saveas_id,true); + + if ( img == 0 ) + { + continue; + } + + img->enable(false); + + ipool->update(img); + + img->unlock(); + } + } } From 84e51477e4a5df6a1e5fa3572fd3643d5f0b0930 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 1 Aug 2010 17:54:46 +0200 Subject: [PATCH 3/7] feature #295: Only overwritten images are disabled --- src/oca/ruby/OpenNebula/ImageRepository.rb | 3 -- src/vm/VirtualMachine.cc | 38 ++-------------------- 2 files changed, 3 insertions(+), 38 deletions(-) diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb index d731c79ef6..f80638cc83 100644 --- a/src/oca/ruby/OpenNebula/ImageRepository.rb +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -88,9 +88,6 @@ module OpenNebula result = image.info if !OpenNebula.is_error?(result) - # Disable the Image for a safe overwriting - image.disable - result = move(source, image['SOURCE']) image.enable diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index f9e8e88153..72cc62a610 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -905,7 +905,6 @@ void VirtualMachine::release_disk_images() { string iid; string saveas; - int saveas_id; int num_disks; vector disks; @@ -943,47 +942,16 @@ void VirtualMachine::release_disk_images() img->release_image(); + saveas = disk->vector_value("SAVE_AS"); - // -------------- DISABLE THIS IMAGE IF OVERWRITTEN -------------------- - saveas = disk->vector_value("SAVE_AS"); - saveas_id = -1; - - if ( !saveas.empty() ) + if ( !saveas.empty() && saveas == iid ) { - if (saveas == id) - { - img->enable(false); - } - else - { - saveas_id = atoi(saveas.c_str()) - } + img->enable(false); } - // ----------------------- UPDATE IMAGE -------------------------------- - ipool->update(img); img->unlock(); - - // ------------------- DISABLE IMAGE TO BE SAVED ----------------------- - - if (saveas_id != -1) - { - img = ipool->get(saveas_id,true); - - if ( img == 0 ) - { - continue; - } - - img->enable(false); - - ipool->update(img); - - img->unlock(); - } - } } From c176cf75ab3c0d9e0391b1cda9eec4ca95f83184 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 1 Aug 2010 18:10:50 +0200 Subject: [PATCH 4/7] feature #300: TARGET can be used with ImageRepository --- src/image/Image.cc | 59 ++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/image/Image.cc b/src/image/Image.cc index fbe3bd6b5d..a90beefd8b 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -540,17 +540,21 @@ int Image::disk_attribute( VectorAttribute * disk, ImageType* img_type) { string bus; + string target; ostringstream iid; *img_type = type; bus = disk->vector_value("BUS"); + target = disk->vector_value("TARGET"); iid << oid; string template_bus; + string template_target; string prefix; get_template_attribute("BUS", template_bus); + get_template_attribute("TARGET", template_target); get_template_attribute("DEV_PREFIX", prefix); //-------------------------------------------------------------------------- @@ -572,17 +576,14 @@ int Image::disk_attribute( VectorAttribute * disk, new_disk.insert(make_pair("IMAGE_ID", iid.str())); new_disk.insert(make_pair("SOURCE", source)); - if (bus.empty()) - { - if (!template_bus.empty()) - { - new_disk.insert(make_pair("BUS",template_bus)); - } - } - else + if (!bus.empty()) { new_disk.insert(make_pair("BUS",bus)); } + else if (!template_bus.empty()) + { + new_disk.insert(make_pair("BUS",template_bus)); + } //--------------------------------------------------------------------------- // TYPE, READONLY, CLONE, and SAVE attributes @@ -609,23 +610,35 @@ int Image::disk_attribute( VectorAttribute * disk, // TARGET attribute //--------------------------------------------------------------------------- - switch(type) + if (!target.empty()) { - case OS: - prefix += "a"; - break; - - case CDROM: - prefix += "c"; // b is for context - break; - - case DATABLOCK: - prefix += static_cast(('e'+ *index)); - *index = *index + 1; - break; - + new_disk.insert(make_pair("TARGET", target)); + } + else if (!template_target.empty()) + { + new_disk.insert(make_pair("TARGET", template_target)); + } + else + { + switch(type) + { + case OS: + prefix += "a"; + break; + + case CDROM: + prefix += "c"; // b is for context + break; + + case DATABLOCK: + prefix += static_cast(('e'+ *index)); + *index = *index + 1; + break; + + } + + new_disk.insert(make_pair("TARGET", prefix)); } - new_disk.insert(make_pair("TARGET", prefix)); disk->replace(new_disk); From 13de50389fbf6ae2e81797f8a6400c9414543ab9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 1 Aug 2010 18:28:03 +0200 Subject: [PATCH 5/7] bug #295: installs ImageRepository.rb --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index a9172bdba4..6618c3cad1 100755 --- a/install.sh +++ b/install.sh @@ -306,6 +306,7 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \ src/oca/ruby/OpenNebula/VirtualNetworkPool.rb \ src/oca/ruby/OpenNebula/Image.rb \ src/oca/ruby/OpenNebula/ImagePool.rb \ + src/oca/ruby/OpenNebula/ImageRepository.rb \ src/oca/ruby/OpenNebula/Cluster.rb \ src/oca/ruby/OpenNebula/ClusterPool.rb \ src/oca/ruby/OpenNebula/XMLUtils.rb" From 04874dbf7a2b8247a497e59a9d9e10e34af0dfe0 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 2 Aug 2010 11:24:01 +0200 Subject: [PATCH 6/7] bug #295: Hooks can be specified without absolute path. Adjusted share location for system-wide installations --- include/Nebula.h | 3 +++ include/PoolSQL.h | 2 +- include/VirtualMachinePool.h | 4 +++- install.sh | 2 +- src/nebula/Nebula.cc | 2 +- src/vm/VirtualMachinePool.cc | 8 +++++++- src/vm/test/VirtualMachinePoolTest.cc | 2 +- 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/Nebula.h b/include/Nebula.h index e44038cef8..44e41f503f 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -236,6 +236,7 @@ private: etc_location = "/etc/one/"; log_location = "/var/log/one/"; var_location = "/var/lib/one/"; + hook_location= "/usr/share/one/hooks/"; } else { @@ -250,6 +251,7 @@ private: etc_location = nebula_location + "etc/"; log_location = nebula_location + "var/"; var_location = nebula_location + "var/"; + hook_location= nebula_location + "share/hooks/"; } }; @@ -345,6 +347,7 @@ private: string etc_location; string log_location; string var_location; + string hook_location; string hostname; // --------------------------------------------------------------- diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 74ffb85fe5..a7f57685aa 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -46,7 +46,7 @@ public: * @param table the name of the table supporting the pool (to set the oid * counter). If null the OID counter is not updated. */ - PoolSQL(SqlDB * _db, const char * table=0); + PoolSQL(SqlDB * _db, const char * table); virtual ~PoolSQL(); diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index fe8ca25bae..711008cfde 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -32,7 +32,9 @@ class VirtualMachinePool : public PoolSQL { public: - VirtualMachinePool(SqlDB * db, vector hook_mads); + VirtualMachinePool(SqlDB * db, + vector hook_mads, + const string& hook_location); ~VirtualMachinePool(){}; diff --git a/install.sh b/install.sh index 6618c3cad1..92d6416afc 100755 --- a/install.sh +++ b/install.sh @@ -99,7 +99,7 @@ if [ -z "$ROOT" ] ; then RUN_LOCATION="/var/run/one" LOCK_LOCATION="/var/lock/one" INCLUDE_LOCATION="/usr/include" - SHARE_LOCATION="/usr/share/doc/opennebula" + SHARE_LOCATION="/usr/share/one" if [ "$CLIENT" = "no" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \ diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index d6ab6b64d3..d03a9da6d8 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -224,7 +224,7 @@ void Nebula::start() nebula_configuration->get("VM_HOOK", vm_hooks); - vmpool = new VirtualMachinePool(db, vm_hooks); + vmpool = new VirtualMachinePool(db, vm_hooks,hook_location); hpool = new HostPool(db); nebula_configuration->get("MAC_PREFIX", mac_prefix); diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index bc1a744c24..6d542ce0f3 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -25,7 +25,8 @@ /* -------------------------------------------------------------------------- */ VirtualMachinePool::VirtualMachinePool(SqlDB * db, - vector hook_mads) + vector hook_mads, + const string& hook_location) : PoolSQL(db,VirtualMachine::table) { const VectorAttribute * vattr; @@ -79,6 +80,11 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db, } } + if (cmd[0] != '/') + { + cmd = hook_location + cmd; + } + if ( on == "CREATE" ) { VirtualMachineAllocateHook * hook; diff --git a/src/vm/test/VirtualMachinePoolTest.cc b/src/vm/test/VirtualMachinePoolTest.cc index 04ce70247e..f116bc90dd 100644 --- a/src/vm/test/VirtualMachinePoolTest.cc +++ b/src/vm/test/VirtualMachinePoolTest.cc @@ -87,7 +87,7 @@ class VirtualMachinePoolFriend : public VirtualMachinePool { public: VirtualMachinePoolFriend(SqlDB * db, vector hook_mads): - VirtualMachinePool(db, hook_mads) + VirtualMachinePool(db, hook_mads, "./") {}; From b3857b1d224b09cb023ab23e4af57af6861e721c Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 30 Jul 2010 18:24:54 +0200 Subject: [PATCH 7/7] bug #284: Default location for the image repository (cherry picked from commit 8b9313699d9f07ff4198caddc9095f1bb3734899) (cherry picked from commit 4f93062accb94032eb80febc48706a586d5db7b6) --- share/etc/oned.conf.template | 2 +- src/nebula/Nebula.cc | 6 -- src/nebula/NebulaTemplate.cc | 148 ++++++++++++++++++++++++----------- 3 files changed, 102 insertions(+), 54 deletions(-) diff --git a/share/etc/oned.conf.template b/share/etc/oned.conf.template index 439c01053c..31d68da491 100644 --- a/share/etc/oned.conf.template +++ b/share/etc/oned.conf.template @@ -82,7 +82,7 @@ MAC_PREFIX = "02:00" # vd KVM virtual disk #******************************************************************************* -IMAGE_REPOSITORY_PATH = [IMAGES_LOCATION] +#IMAGE_REPOSITORY_PATH = /srv/cloud/var/images DEFAULT_IMAGE_TYPE = "OS" DEFAULT_DEVICE_PREFIX = "hd" diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index d03a9da6d8..771bbd6ed6 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -235,12 +235,6 @@ void Nebula::start() upool = new UserPool(db); nebula_configuration->get("IMAGE_REPOSITORY_PATH", repository_path); - - if (repository_path.empty()) // Defaults to ONE_LOCATION/var - { - repository_path = var_location; - } - nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type); nebula_configuration->get("DEFAULT_DEVICE_PREFIX", default_device_prefix); diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 0e94046082..a38f592fd2 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -31,60 +31,114 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location) { ostringstream os; SingleAttribute * attribute; + VectorAttribute * vattribute; string value; conf_file = etc_location + conf_name; + // MANAGER_TIMER + value = "15"; + + attribute = new SingleAttribute("MANAGER_TIMER",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + +/* +#******************************************************************************* +# Daemon configuration attributes +#------------------------------------------------------------------------------- +# HOST_MONITORING_INTERVAL +# VM_POLLING_INTERVAL +# VM_DIR +# PORT +# DB +# VNC_BASE_PORT +#******************************************************************************* +*/ + // MONITOR_INTERVAL + value = "600"; + + attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + // POLL_INTERVAL - value = "300"; - + value = "600"; + attribute = new SingleAttribute("VM_POLLING_INTERVAL",value); conf_default.insert(make_pair(attribute->name(),attribute)); - // MANAGER_TIMER - value = "30"; - - attribute = new SingleAttribute("MANAGER_TIMER",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - // MONITOR_INTERVAL - value = "300"; - - attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - //XML-RPC Server PORT - value = "2633"; - - attribute = new SingleAttribute("PORT",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - //VM_DIR + //VM_DIR attribute = new SingleAttribute("VM_DIR",var_location); conf_default.insert(make_pair(attribute->name(),attribute)); - - //MAC_PREFIX - value = "00:01"; - - attribute = new SingleAttribute("MAC_PREFIX",value); + + //XML-RPC Server PORT + value = "2633"; + + attribute = new SingleAttribute("PORT",value); conf_default.insert(make_pair(attribute->name(),attribute)); - //NETWORK_SIZE - value = "254"; - - attribute = new SingleAttribute("NETWORK_SIZE",value); - conf_default.insert(make_pair(attribute->name(),attribute)); + //DB CONFIGURATION + map vvalue; + vvalue.insert(make_pair("BACKEND","sqlite")); - //NETWORK_SIZE + vattribute = new VectorAttribute("DB",vvalue); + conf_default.insert(make_pair(attribute->name(),vattribute)); + + //VNC_BASE_PORT value = "5900"; attribute = new SingleAttribute("VNC_BASE_PORT",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - //DEBUG_LEVEL - value = Log::WARNING; - - attribute = new SingleAttribute("DEBUG_LEVEL",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //XML-RPC Server PORT + value = "2633"; + + attribute = new SingleAttribute("PORT",value); + conf_default.insert(make_pair(attribute->name(),attribute)); +/* +#******************************************************************************* +# Physical Networks configuration +#******************************************************************************* +# NETWORK_SIZE +# MAC_PREFIX +#******************************************************************************* +*/ + //MAC_PREFIX + value = "02:00"; + + attribute = new SingleAttribute("MAC_PREFIX",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //NETWORK_SIZE + value = "254"; + + attribute = new SingleAttribute("NETWORK_SIZE",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + +/* +#******************************************************************************* +# Image Repository Configuration +#******************************************************************************* +# IMAGE_REPOSITORY_PATH +# DEFAULT_IMAGE_TYPE +# DEFAULT_DEVICE_PREFIX +#******************************************************************************* +*/ + //IMAGE_REPOSITORY_PATH + value = var_location + "/images"; + + attribute = new SingleAttribute("IMAGE_REPOSITORY_PATH",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //DEFAULT_IMAGE_TYPE + value = "OS"; + + attribute = new SingleAttribute("DEFAULT_IMAGE_TYPE",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //DEFAULT_DEVICE_PREFIX + value = "hd"; + + attribute = new SingleAttribute("DEFAULT_DEVICE_PREFIX",value); conf_default.insert(make_pair(attribute->name(),attribute)); } @@ -95,31 +149,31 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location) int NebulaTemplate::load_configuration() { char * error = 0; - map::iterator iter, j; + map::iterator iter, j; int rc; - + string aname; Attribute * attr; - + rc = parse(conf_file.c_str(), &error); - + if ( rc != 0 && error != 0) { cout << "\nError while parsing configuration file:\n" << error << endl; free(error); - + return -1; } - + for(iter=conf_default.begin();iter!=conf_default.end();) { aname = iter->first; attr = iter->second; - + j = attributes.find(aname); - + if ( j == attributes.end() ) { attributes.insert(make_pair(aname,attr)); @@ -131,7 +185,7 @@ int NebulaTemplate::load_configuration() conf_default.erase(iter++); } } - + return 0; }