From 5020b24fc7c20451f74e734ed4fe6047d5e91a12 Mon Sep 17 00:00:00 2001 From: bbuczynski Date: Mon, 22 Feb 2016 13:46:00 -0500 Subject: [PATCH] Version 0.4.0 - 7/12/2015 1. Added http_port to one_image resource so that port other than 8066 (default) can be used to upload images. 2. Replaced :credentials and :secret_file driver options with profiles. 3. Fixed ssh timeout; :timeout will be applied to each ssh command and overall timeout to establish a ssh session is 5 min. 4. one_image now takes 'download_url' as an optional attribute; 'image_file' still takes precedence over 'download_url'. If 'download_url' is specified then that location is used for image and it will not try to start HTTP server locally. 5. Changed default port for HTTP server in one_image to be 8066 instead of previously used port 80. 6. Added :mode attribute to one_image, one_template and one_vnet resources. 7. Added bootstrap_options[:mode] so that machines can be created with different permissions. --- .rubocop.yml | 5 +- CHANGELOG.md | 26 +++-- README.md | 45 ++++---- lib/chef/provider/one_image.rb | 100 +++++++++++------- lib/chef/provider/one_template.rb | 1 + lib/chef/provider/one_vnet.rb | 1 + .../opennebula_driver/credentials.rb | 8 +- .../provisioning/opennebula_driver/driver.rb | 20 ++-- .../provisioning/opennebula_driver/one_lib.rb | 77 ++++++++------ .../provisioning/opennebula_driver/version.rb | 2 +- lib/chef/resource/one_image.rb | 5 +- lib/chef/resource/one_template.rb | 1 + lib/chef/resource/one_vnet.rb | 1 + 13 files changed, 171 insertions(+), 121 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cb17ab2..1d98ab5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -30,7 +30,7 @@ ClassLength: Max: 1000 AbcSize: - Max: 40 + Max: 62 ParameterLists: Max: 15 @@ -39,6 +39,9 @@ ParameterLists: StringLiterals: Enabled: false +Style/SpecialGlobalVars: + Enabled: false + Style/SignalException: Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 6732faa..64ca5b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 0.4.0 (7/12/2015) +- Added http_port to one_image resource so that port other than 8066 (default) can be used to upload images. +- Fixed error message in one_image resource +- Removed :credentials and :secret_file support as driver options. It uses profiles now. +- Fixed ssh timeout. Now the :timeout will be applied to each ssh command and overall timeout to establish + a ssh session is 5 min. +- one_image now takes 'download_url' as an optional attribute. 'image_file' still takes precedence over + 'download_url'. If 'download_url' is specified then that location is used for image and it will not try + to start HTTP server locally. +- Changed default port for HTTP server in one_image to be 8066 instead of previously used port 80. This is to + avoid collision with existing web servers running on the host. +- Added :mode attribute to one_image, one_template and one_vnet resources. +- Added bootstrap_options[:mode] so that machines can be created with different permissions + ## 0.3.4 (10/29/2015) - Yanked version 0.3.3 from rubygems due to internal homepage link in gemspec - Need to release version 0.3.4 to reupload to rubygems.org @@ -8,7 +22,7 @@ - Changed driver_url to include profiles. Without profiles machine_file was unable to recreate the driver and subsequently failed. The new driver_url format is: opennebula:: - where profile is stored in ~/.one/one_config or ENV['ONE_CONFIG'] or /var/lig/one/.one/one_config file + where profile is stored in ~/.one/one_config or ENV['ONE_CONFIG'] or /var/lib/one/.one/one_config file - Added check for machine :destroy to verify that the VM is in DONE state. If not successful after 20 seconds it will fail. - opennebula 4.14 is not backwards compatible so there is a new gem dependency 'opennebula <4.14'. @@ -24,12 +38,12 @@ ## 0.3.0 (9/23/2015) - Added one_user resource - Added support for machine shutdown. Before 'machine :stop' would call the stop method on the VM, - now this behaviour can be changed to call vm.shutdown by specifying :bootstrap_options[:is_shutdown] = true + now this behavior can be changed to call vm.shutdown by specifying :bootstrap_options[:is_shutdown] = true - Added optional bootstrap_option flag [:unique_name] for validation of unique machine names in OpenNebula - Removed :instantiate from one_template resource, because it is a duplicate or 'machine :template' - Fixed warnings in providers regarding resource_names - Removed support for :ssh_execute_options => { :prefix => 'sudo '} in favour of :sudo => true -- Added licencse headers +- Added license headers - Modified permissions for downloaded qcow images to be 777 - Added error message when :bootstrap_options are not defined - Added missing :cache attribute to one_image resource @@ -42,7 +56,7 @@ ```json :ssh_username => 'local', - :ssh_options => { + :ssh_options => { :keys_only => false, :forward_agent => true, :use_agent => true, @@ -66,8 +80,8 @@ ## 0.2.1 (7/11/2015) -- Added upload/downlod functionality to one_image +- Added upload/download functionality to one_image ## 0.1.0 (4/30/2015) -- Initial submission of chef-provisioning-opennebula gem +- Initial submission of chef-provisioning-opennebula gem \ No newline at end of file diff --git a/README.md b/README.md index 7e5099d..1af99f3 100644 --- a/README.md +++ b/README.md @@ -45,27 +45,6 @@ A sample one_config file would look like this: } ``` -If no profile is specified the driver will attempt to read and use the ```ENV['ONE_AUTH']``` file or ```~/.one/one_auth``` or ```/var/lib/one/.one/one_auth```. -The driver is still backward compatible with previous format and passing ```:secret_file``` or ```:credentials``` in```:driver_options```. - -Additional options to OpenNebual client can be passed vi ```:one_options```. - -```ruby -with_driver "opennebula:http://1.2.3.4/endpoint:port", - :credentials => ":", - :one_options => { :timeout => 3 } -``` - -or - -```ruby -with_driver "opennebula:http://1.2.3.4/endpoint:port", - :secret_file => "", - :one_options => { :timeout => 3 } -``` - -If additional OpenNebula client options need to be passed they can be specified as a hash ```:one_options => {}```. - In context of OpenNebula ```machine``` resource will take the following additional options: ```ruby @@ -79,6 +58,7 @@ machine_options { :enforce_chef_fqdn => [TrueClass, FalseClass] flag indicating if fqdn names should be used for machine names :is_shutdown => [TrueClass, FalseClass] call vm.shutodwn instead of vm.stop during :stop action :shutdown_hard => [TrueClass, FalseClass] flag indicating hard or soft shutdown + :mode => String octed to set permissions to the machine }, :sudo => true, :ssh_username => 'local', @@ -109,6 +89,7 @@ This resource will allow to create and delete OpenNebula templates. ```ruby :template => Hash defining OpenNebula template :template_file => String location of the VM template file + :mode => String octet to set permissions ``` ### Actions @@ -201,6 +182,8 @@ This resource will manage images within OpenNebula. :driver => String Image driver eq. 'qcow2' :machine_id => [String, Integer] id of the machine (VM) for disk attach :disk_id => [String, Integer] id or name of the disk to attach/snapshot + :mode => String octet to set permissions + :http_port => Integer port number to start local HTTP server at, for :image_file uploads. Default: 8066 ``` ### Actions @@ -272,20 +255,31 @@ one_image "snapshot-img" do end ``` -#### 6. Upload a local qcow2 image file to OpenNebula +#### 6. Upload a local qcow2 image file to OpenNebula, starting HTTP server on port 4567 ```ruby -one_image "snapshot-img" do +one_image "upload-img" do datastore_id 103 image_file "/local/path/to/qcow/image/file" img_driver "qcow2" type "OS" + http_port 4567 description "This is my cool qcow image" action :upload end ``` -#### 7. Download a 'boggi-test-img' and store it in /home/local/my-image.qcow2. Download URL read from ENV[ONE_DOWNLOAD] variable. It will be stored locally in Chef::Config[:file_cache_path]/boggi-test-img.qcow2. +#### 7. Upload a qcow2 image file residing on a different host to OpenNebula + +```ruby +one_image "upload-img" do + datastore_id 103 + download_url "http://my.image.host/path/to/qcow/image/file" + action :upload +end +``` + +#### 8. Download a 'boggi-test-img' and store it in /home/local/my-image.qcow2. Download URL is read from ENV[ONE_DOWNLOAD] variable. It will be stored locally in Chef::Config[:file_cache_path]/boggi-test-img.qcow2. ```ruby one_image "boggi-test-img" do @@ -293,7 +287,7 @@ one_image "boggi-test-img" do end ``` -#### 8. Download image ID 12345 and store it in /tmp/image.qcow2. +#### 9. Download image ID 12345 and store it in /tmp/image.qcow2. ```ruby one_image "boggi-test-img" do @@ -319,6 +313,7 @@ This resource will allow to create and delete OpenNebula vnets. :mac_ip => String ip or mac address :template_file => String local file containing the template of a new vnet :cluster_id => Integer cluster in which to create a vnet + :mode => String octet to set permissions ``` ### Actions diff --git a/lib/chef/provider/one_image.rb b/lib/chef/provider/one_image.rb index f838f00..cf6b950 100644 --- a/lib/chef/provider/one_image.rb +++ b/lib/chef/provider/one_image.rb @@ -43,7 +43,7 @@ def action_handler def exists? new_driver = driver - @image = new_driver.one.get_resource('img', :name => new_resource.name) + @image = new_driver.one.get_resource('img', :name => @new_resource.name) !@image.nil? end @@ -56,14 +56,15 @@ def exists? action_handler.perform_action "allocated image '#{new_resource.name}'" do @image = new_driver.one.allocate_img( - new_resource.name, - new_resource.size, - new_resource.datastore_id, - new_resource.type || 'OS', - new_resource.fs_type || 'ext2', - new_resource.img_driver || 'qcow2', - new_resource.prefix || 'vd', - new_resource.persistent || false) + :name => new_resource.name, + :size => new_resource.size, + :datastore_id => new_resource.datastore_id, + :type => new_resource.type || 'OS', + :fs_type => new_resource.fs_type || 'ext2', + :driver => new_resource.img_driver || 'qcow2', + :prefix => new_resource.prefix || 'vd', + :persistent => new_resource.persistent || false) + new_driver.one.chmod_resource(@image, new_resource.mode) Chef::Log.info("Image '#{new_resource.name}' allocate in initial state #{@image.state_str}") @new_resource.updated_by_last_action(true) end @@ -143,6 +144,7 @@ def exists? fail "Failed to create snapshot '#{new_resource.name}': #{@image.message}" if OpenNebula.is_error?(@image) @image = new_driver.one.wait_for_img(new_resource.name, @image) + new_driver.one.chmod_resource(image, new_resource.mode) if new_resource.persistent action_handler.report_progress "make image '#{new_resource.name}' persistent" @image.persistent @@ -153,47 +155,63 @@ def exists? action :upload do fail "'datastore_id' is required" unless new_resource.datastore_id - fail "'image_file' is required" unless new_resource.image_file - fail "image_file #{new_resource.image_file} does not exist" unless ::File.exist? new_resource.image_file + fail "'image_file' or 'download_url' attribute is required" unless new_resource.image_file || new_resource.download_url - file_url = "http://#{node['ipaddress']}/#{::File.basename(@new_resource.image_file)}" - description = @new_resource.description || "#{@new_resource.name} image" - image_driver = @new_resource.img_driver || 'qcow2' + file_url = nil + if new_resource.image_file + fail "image_file #{new_resource.image_file} does not exist" unless ::File.exist? new_resource.image_file + file_url = "http://#{node['ipaddress']}:#{@new_resource.http_port}/#{::File.basename(@new_resource.image_file)}" + else + file_url = new_resource.download_url + end + image_config = { + :name => @new_resource.name, + :datastore_id => @new_resource.datastore_id.to_s, + :path => file_url, + :driver => @new_resource.img_driver || 'qcow2', + :description => @new_resource.description || "#{@new_resource.name} image", + :type => @new_resource.type, + :mode => @new_resource.mode, + :prefix => @new_resource.prefix, + :persistent => @new_resource.persistent, + :public => @new_resource.public, + :target => @new_resource.target, + :disk_type => @new_resource.disk_type, + :source => @new_resource.source, + :size => @new_resource.size, + :fs_type => @new_resource.fs_type + } if exists? - if @image.name == @new_resource.name && - @image['PATH'] == file_url && - @image['TEMPLATE/DRIVER'] == image_driver && - @image['TEMPLATE/DESCRIPTION'] == description && - @image['DATASTORE_ID'] == @new_resource.datastore_id.to_s + if @image.name == image_config[:name] && + @image['PATH'] == image_config[:path] && + @image['TEMPLATE/DRIVER'] == image_config[:driver] && + @image['TEMPLATE/DESCRIPTION'] == image_config[:description] && + @image['DATASTORE_ID'] == image_config[:datastore_id] action_handler.report_progress("image '#{@new_resource.name}' (ID: #{@image.id}) already exists - nothing to do") else fail "image '#{new_resource.name}' already exists, but it is not the same image" end else - action_handler.perform_action "upload image '#{@new_resource.image_file}'" do - begin - pid = Process.spawn("sudo python -m SimpleHTTPServer 80", :chdir => ::File.dirname(@new_resource.image_file), STDOUT => "/dev/null", STDERR => "/dev/null", :pgroup => true) - fail "Failed to start 'SimpleHTTPServer'" if pid.nil? - new_driver.one.upload_img( - @new_resource.name, - @new_resource.datastore_id, - file_url, - image_driver, - description, - @new_resource.type, - @new_resource.prefix, - @new_resource.persistent, - @new_resource.public, - @new_resource.target, - @new_resource.disk_type, - @new_resource.source, - @new_resource.size, - @new_resource.fs_type) - + action_handler.perform_action "upload image '#{@new_resource.name}'" do + if @new_resource.image_file + begin + success = false + pid = nil + trap("CLD") do + cpid = Process.wait + fail "Could not start HTTP server on port #{@new_resource.http_port}" if cpid == pid && !success + end + pid = Process.spawn("python -m SimpleHTTPServer #{@new_resource.http_port}", :chdir => ::File.dirname(@new_resource.image_file), STDOUT => "/dev/null", STDERR => "/dev/null", :pgroup => true) + new_driver.one.upload_img(image_config) + success = true + @new_resource.updated_by_last_action(true) + ensure + system("sudo kill -9 -#{pid}") + end + else + new_driver.one.upload_img(image_config) @new_resource.updated_by_last_action(true) - ensure - system("sudo kill -9 -#{pid}") end end end diff --git a/lib/chef/provider/one_template.rb b/lib/chef/provider/one_template.rb index a995039..5361175 100644 --- a/lib/chef/provider/one_template.rb +++ b/lib/chef/provider/one_template.rb @@ -57,6 +57,7 @@ def exists? template_str = new_driver.one.create_template(new_resource.template) if new_resource.template template_str << "\nNAME=\"#{new_resource.name}\"" @template = new_driver.one.allocate_template(template_str) + new_driver.one.chmod_resource(@template, new_resource.mode) @new_resource.updated_by_last_action(true) end end diff --git a/lib/chef/provider/one_vnet.rb b/lib/chef/provider/one_vnet.rb index d1ec32c..a6dc5f8 100644 --- a/lib/chef/provider/one_vnet.rb +++ b/lib/chef/provider/one_vnet.rb @@ -53,6 +53,7 @@ def exists?(filter) vnet = new_driver.one.allocate_vnet(template_str, @new_resource.cluster_id) Chef::Log.debug(template_str) fail "failed to create vnet '#{@new_resource.name}': #{vnet.message}" if OpenNebula.is_error?(vnet) + new_driver.one.chmod_resource(vnet, new_resource.mode) @new_resource.updated_by_last_action(true) end end diff --git a/lib/chef/provisioning/opennebula_driver/credentials.rb b/lib/chef/provisioning/opennebula_driver/credentials.rb index 9f5a9ce..d3b6bbe 100644 --- a/lib/chef/provisioning/opennebula_driver/credentials.rb +++ b/lib/chef/provisioning/opennebula_driver/credentials.rb @@ -69,8 +69,12 @@ def load_profiles begin content_hash = JSON.parse(File.read(file), :symbolize_names => true) content_hash.each { |k, v| json[k.to_s] = v } - rescue Exception => e - Chef::Log.warn("Failed to read and parse config file #{file}: #{e.message}") + rescue StandardError => e_file + Chef::Log.warn("Failed to read config file #{file}: #{e_file.message}") + rescue JSON::ParserError => e_json + Chef::Log.warn("Failed to parse config file #{file}: #{e_json.message}") + rescue + Chef::Log.warn("Failed to read or parse config file #{file}: #{$!}") end @credentials.merge!(json) end diff --git a/lib/chef/provisioning/opennebula_driver/driver.rb b/lib/chef/provisioning/opennebula_driver/driver.rb index 7017831..23ae674 100644 --- a/lib/chef/provisioning/opennebula_driver/driver.rb +++ b/lib/chef/provisioning/opennebula_driver/driver.rb @@ -84,14 +84,7 @@ class Driver < Chef::Provisioning::Driver # def initialize(driver_url, config) super - scan = driver_url.match(%r/(opennebula):(https?:\/\/[^:\/]+ (?::[0-9]{2,5})? (?:\/[^:\s]+) ) :?([^:\s]+)?/x) - endpoint = scan[2] - profile_name = scan[3] - fail "OpenNebula endpoint must be specified in 'driver_url': #{driver_url}" if endpoint.nil? - - profile = profile_name ? one_credentials[profile_name] : one_credentials.default - Chef::Log.warn("':credentials' and ':secret_file' will be deprecated in next version in favour of 'opennebula::'") if profile_name.nil? - @one = OneLib.new(profile[:credentials], endpoint, profile[:options] || {}) + @one = OneLib.new(:driver_url => driver_url) end def self.from_url(driver_url, config) @@ -143,6 +136,7 @@ def allocate_machine(action_handler, machine_spec, machine_options) tpl = @one.get_template(machine_spec.name, machine_options.bootstrap_options) vm = @one.allocate_vm(tpl) populate_node_object(machine_spec, machine_options, vm) + @one.chmod_resource(vm, machine_options.bootstrap_options[:mode]) end Chef::Log.debug(machine_spec.reference) else @@ -241,7 +235,7 @@ def stop_machine(action_handler, machine_spec, machine_options) instance = instance_for(machine_spec) if !instance.nil? action_handler.perform_action "powered off machine #{machine_spec.name} (#{machine_spec.reference['instance_id']})" do - if machine_spec.reference[:is_shutdown] || machine_options.bootstrap_options[:is_shutdown] + if machine_spec.reference[:is_shutdown] || (machine_options.bootstrap_options && machine_options.bootstrap_options[:is_shutdown]) hard = machine_spec.reference[:shutdown_hard] || machine_options.bootstrap_options[:shutdown_hard] || false instance.shutdown(hard) else @@ -516,12 +510,12 @@ def get_ssh_user(machine_spec, machine_options) end def transport_for(machine_spec, machine_options, _instance) - # TODO: Store ssh_options in machine_spec.reference ??? ssh_options = { :keys_only => false, :forward_agent => true, :use_agent => true, - :user_known_hosts_file => '/dev/null' + :user_known_hosts_file => '/dev/null', + :timeout => 10 }.merge(machine_options[:ssh_options] || {}) username = get_ssh_user(machine_spec, machine_options) conf = machine_options[:ssh_config] || config @@ -537,9 +531,9 @@ def transport_for(machine_spec, machine_options, _instance) transport = Chef::Provisioning::Transport::SSH.new(machine_spec.reference['ip'], username, ssh_options, options, conf) # wait up to 5 min to establish SSH connection - 100.times do + val = 300 / ssh_options[:timeout].to_i + val.times do break if transport.available? - sleep 3 Chef::Log.debug("Waiting for SSH server ...") end fail "Failed to establish SSH connection to '#{machine_spec.name}'" unless transport.available? diff --git a/lib/chef/provisioning/opennebula_driver/one_lib.rb b/lib/chef/provisioning/opennebula_driver/one_lib.rb index 7291a51..bdda22e 100644 --- a/lib/chef/provisioning/opennebula_driver/one_lib.rb +++ b/lib/chef/provisioning/opennebula_driver/one_lib.rb @@ -52,7 +52,19 @@ class OpenNebulaException < Exception class OneLib attr_accessor :client - def initialize(credentials, endpoint, options = {}) + def initialize(args) + credentials = args[:credentials] + endpoint = args[:endpoint] + options = args[:options] || {} + if args[:driver_url] + scan = args[:driver_url].match(%r/(opennebula):(https?:\/\/[^:\/]+ (?::[0-9]{2,5})? (?:\/[^:\s]+) ) :?([^:\s]+)?/x) + endpoint = scan[2] + profile = scan[3] + fail "'driver_url' option has invalid format: #{args[:driver_url]}" if endpoint.nil? || profile.nil? + one_profile = Chef::Provisioning::OpenNebulaDriver::Credentials.new[profile] + credentials = one_profile[:credentials] + options = one_profile[:options] || {} + end @client = OpenNebula::Client.new(credentials, endpoint, options) rc = @client.get_version raise OpenNebulaException, rc.message if OpenNebula.is_error?(rc) @@ -144,53 +156,58 @@ def wait_for_vm(id, end_state = nil) vm end - def upload_img(name, ds_id, path, driver, description, type, prefix, persistent, pub, target, disk_type, source, size, fstype) + def upload_img(img_config) template = <<-EOTPL -NAME = #{name} -PATH = \"#{path}\" -DRIVER = #{driver} -DESCRIPTION = \"#{description}\" +NAME = #{img_config[:name]} +PATH = \"#{img_config[:path]}\" +DRIVER = #{img_config[:driver]} +DESCRIPTION = \"#{img_config[:description]}\" EOTPL - template << "TYPE = #{type}\n" unless type.nil? - template << "PERSISTENT = YES\n" if !persistent.nil? && persistent - template << "DEV_PREFIX = #{prefix}\n" unless prefix.nil? - template << "PUBLIC = YES\n" if !pub.nil? && pub - template << "TARGET = #{target}\n" unless target.nil? - template << "DISK_TYPE = #{disk_type}\n" unless disk_type.nil? - template << "SOURCE = #{source}\n" unless source.nil? - template << "SIZE = #{size}" unless size.nil? - template << "FSTYPE = #{fstype}\n" unless fstype.nil? + template << "TYPE = #{img_config[:type]}\n" unless img_config[:type].nil? + template << "DEV_PREFIX = #{img_config[:prefix]}\n" unless img_config[:prefix].nil? + template << "TARGET = #{img_config[:target]}\n" unless img_config[:target].nil? + template << "DISK_STYPE = #{img_config[:disk_type]}\n" unless img_config[:disk_type].nil? + template << "SOURCE = #{img_config[:source]}\n" unless img_config[:source].nil? + template << "SIZE = #{img_config[:size]}\n" unless img_config[:size].nil? + template << "FSTYPE = #{img_config[:fs_type]}\n" unless img_config[:fs_type].nil? + template << "PUBLIC = #{img_config[:public] ? 'YES' : 'NO'}\n" unless img_config[:public].nil? + template << "PERSISTENT = #{img_config[:persistent] ? 'YES' : 'NO'}\n" unless img_config[:persistent].nil? Chef::Log.debug("\n#{template}") - image = OpenNebula::Image.new(OpenNebula::Image.build_xml, @client) raise OpenNebulaException, image.message if OpenNebula.is_error?(image) - rc = image.allocate(template, ds_id) + rc = image.allocate(template, img_config[:datastore_id].to_i) + raise OpenNebulaException, rc.message if OpenNebula.is_error?(rc) + Chef::Log.debug("Waiting for image '#{img_config[:name]}' (#{image.id}) to be ready") + wait_for_img(img_config[:name], image.id) + chmod_resource(image, img_config[:mode]) + end + + def chmod_resource(res = nil, octet = nil) + rc = res.chmod_octet(octet) unless res.nil? || octet.nil? raise OpenNebulaException, rc.message if OpenNebula.is_error?(rc) - Chef::Log.debug("Waiting for image '#{name}' (#{image.id}) to be ready") - wait_for_img(name, image.id) end - def allocate_img(name, size, ds_id, type, fstype, driver, prefix, persistent) + def allocate_img(img_config) template = <<-EOT -NAME = #{name} -TYPE = #{type} -FSTYPE = #{fstype} -SIZE = #{size} -PERSISTENT = #{persistent ? 'YES' : 'NO'} - -DRIVER = #{driver} -DEV_PREFIX = #{prefix} +NAME = #{img_config[:name]} +TYPE = #{img_config[:type]} +FSTYPE = #{img_config[:fstype]} +SIZE = #{img_config[:size]} +PERSISTENT = #{img_config[:persistent] ? 'YES' : 'NO'} + +DRIVER = #{img_config[:driver]} +DEV_PREFIX = #{img_config[:prefix]} EOT img = OpenNebula::Image.new(OpenNebula::Image.build_xml, @client) raise OpenNebulaException, img.message if OpenNebula.is_error?(img) - rc = img.allocate(template, ds_id) + rc = img.allocate(template, img_config[:datastore_id]) raise OpenNebulaException, rc.message if OpenNebula.is_error?(rc) - Chef::Log.debug("Allocated disk image #{name} (#{img.id})") + Chef::Log.debug("Allocated disk image #{img_config[:name]} (#{img.id})") img end diff --git a/lib/chef/provisioning/opennebula_driver/version.rb b/lib/chef/provisioning/opennebula_driver/version.rb index 01351a4..388d783 100644 --- a/lib/chef/provisioning/opennebula_driver/version.rb +++ b/lib/chef/provisioning/opennebula_driver/version.rb @@ -24,7 +24,7 @@ module Provisioning # Extending module. # module OpenNebulaDriver - VERSION = '0.3.4' + VERSION = '0.4.0' end end end diff --git a/lib/chef/resource/one_image.rb b/lib/chef/resource/one_image.rb index c13e9c7..62ef198 100644 --- a/lib/chef/resource/one_image.rb +++ b/lib/chef/resource/one_image.rb @@ -42,6 +42,7 @@ class OneImage < Chef::Resource::LWRPBase attribute :prefix, :kind_of => String, :equal_to => %w(vd xvd sd hd) attribute :persistent, :kind_of => [TrueClass, FalseClass] attribute :public, :kind_of => [TrueClass, FalseClass] + attribute :mode, :regex => [/^\d\d\d$/] attribute :disk_type, :kind_of => String attribute :source, :kind_of => String attribute :target, :kind_of => String @@ -49,10 +50,10 @@ class OneImage < Chef::Resource::LWRPBase attribute :disk_id, :kind_of => [String, Integer] attribute :image_file, :kind_of => String attribute :cache, :kind_of => String - attribute :driver - attribute :download_url, :kind_of => String attribute :image_id, :kind_of => Integer + attribute :http_port, :kind_of => Integer, :default => 8066 + attribute :driver def initialize(*args) super diff --git a/lib/chef/resource/one_template.rb b/lib/chef/resource/one_template.rb index 23f2ed5..19b23eb 100644 --- a/lib/chef/resource/one_template.rb +++ b/lib/chef/resource/one_template.rb @@ -30,6 +30,7 @@ class OneTemplate < Chef::Resource::LWRPBase attribute :template, :kind_of => Hash attribute :template_file, :kind_of => String + attribute :mode, :regex => [/^\d\d\d$/] attribute :driver actions :create, :delete diff --git a/lib/chef/resource/one_vnet.rb b/lib/chef/resource/one_vnet.rb index a1b10c2..78c6d65 100644 --- a/lib/chef/resource/one_vnet.rb +++ b/lib/chef/resource/one_vnet.rb @@ -36,6 +36,7 @@ class OneVnet < Chef::Resource::LWRPBase attribute :ar_id, :kind_of => Integer attribute :template_file, :kind_of => String attribute :cluster_id, :kind_of => Integer + attribute :mode, :regex => [/^\d\d\d$/] attribute :driver