Class: Veewee::Definition
- Inherits:
-
Object
- Object
- Veewee::Definition
- Includes:
- Provider::Core::Helper::Iso
- Defined in:
- lib/veewee/definition.rb
Instance Attribute Summary collapse
-
#add_shares ⇒ Object
Returns the value of attribute add_shares.
-
#boot_cmd_sequence ⇒ Object
Returns the value of attribute boot_cmd_sequence.
-
#boot_wait ⇒ Object
Returns the value of attribute boot_wait.
- #cpu_count ⇒ Object
-
#disk_count ⇒ Object
Returns the value of attribute disk_count.
-
#disk_format ⇒ Object
Returns the value of attribute disk_format.
-
#disk_size ⇒ Object
Returns the value of attribute disk_size.
-
#disk_variant ⇒ Object
Returns the value of attribute disk_variant.
-
#env ⇒ Object
Returns the value of attribute env.
-
#floppy_files ⇒ Object
Returns the value of attribute floppy_files.
-
#hostiocache ⇒ Object
Returns the value of attribute hostiocache.
-
#iso_dowload_timeout ⇒ Object
Returns the value of attribute iso_dowload_timeout.
-
#iso_download_instructions ⇒ Object
Returns the value of attribute iso_download_instructions.
-
#iso_file ⇒ Object
Returns the value of attribute iso_file.
-
#iso_md5 ⇒ Object
Returns the value of attribute iso_md5.
-
#iso_sha1 ⇒ Object
Returns the value of attribute iso_sha1.
-
#iso_src ⇒ Object
Returns the value of attribute iso_src.
-
#kickstart_file ⇒ Object
Returns the value of attribute kickstart_file.
-
#kickstart_ip ⇒ Object
Returns the value of attribute kickstart_ip.
-
#kickstart_port ⇒ Object
Returns the value of attribute kickstart_port.
-
#kickstart_timeout ⇒ Object
Returns the value of attribute kickstart_timeout.
-
#kvm ⇒ Object
Returns the value of attribute kvm.
- #memory_size ⇒ Object
-
#name ⇒ Object
Returns the value of attribute name.
-
#os_type_id ⇒ Object
Returns the value of attribute os_type_id.
-
#path ⇒ Object
Returns the value of attribute path.
-
#postinstall_files ⇒ Object
Returns the value of attribute postinstall_files.
-
#postinstall_timeout ⇒ Object
Returns the value of attribute postinstall_timeout.
-
#pre_postinstall_file ⇒ Object
Returns the value of attribute pre_postinstall_file.
-
#shutdown_cmd ⇒ Object
Returns the value of attribute shutdown_cmd.
-
#skip_iso_transfer ⇒ Object
Returns the value of attribute skip_iso_transfer.
-
#skip_nat_mapping ⇒ Object
Returns the value of attribute skip_nat_mapping.
-
#ssh_guest_port ⇒ Object
Returns the value of attribute ssh_guest_port.
-
#ssh_host_port ⇒ Object
Returns the value of attribute ssh_host_port.
-
#ssh_key ⇒ Object
Returns the value of attribute ssh_key.
-
#ssh_login_timeout ⇒ Object
Returns the value of attribute ssh_login_timeout.
-
#ssh_password ⇒ Object
Returns the value of attribute ssh_password.
-
#ssh_user ⇒ Object
Returns the value of attribute ssh_user.
-
#sudo_cmd ⇒ Object
Returns the value of attribute sudo_cmd.
-
#use_hw_virt_ext ⇒ Object
Returns the value of attribute use_hw_virt_ext.
-
#use_pae ⇒ Object
Returns the value of attribute use_pae.
-
#use_sata ⇒ Object
Returns the value of attribute use_sata.
-
#video_memory_size ⇒ Object
Returns the value of attribute video_memory_size.
-
#virtualbox ⇒ Object
Returns the value of attribute virtualbox.
-
#vmdk_file ⇒ Object
Returns the value of attribute vmdk_file.
-
#vmfusion ⇒ Object
Returns the value of attribute vmfusion.
-
#winrm_guest_port ⇒ Object
Returns the value of attribute winrm_guest_port.
-
#winrm_host_port ⇒ Object
Returns the value of attribute winrm_host_port.
-
#winrm_login_timeout ⇒ Object
Returns the value of attribute winrm_login_timeout.
-
#winrm_password ⇒ Object
Returns the value of attribute winrm_password.
-
#winrm_user ⇒ Object
Returns the value of attribute winrm_user.
Class Method Summary collapse
-
.load(name, env) ⇒ Object
Class method to loading a definition.
Instance Method Summary collapse
-
#declare(options) ⇒ Object
This function takes a hash of options and injects them into the definition.
- #exists? ⇒ Boolean
-
#initialize(name, path, env) ⇒ Definition
constructor
A new instance of Definition.
- #ui ⇒ Object
- #valid? ⇒ Boolean
Methods included from Provider::Core::Helper::Iso
#download_iso, #download_progress, #hashsum, #verify_iso, #verify_sum
Constructor Details
#initialize(name, path, env) ⇒ Definition
Returns a new instance of Definition.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/veewee/definition.rb', line 57 def initialize(name, path, env) @name = name @env = env if path.nil? @path = File.join(env.definition_dir, name) else @path = path end # Default is 1 CPU + 256 Mem of memory + 8 Mem of video memory @cpu_count = '1' ; @memory_size = '256'; @video_memory_size = '8' # Default there is no ISO file mounted @iso_file = nil, @iso_src = nil ; @iso_md5 = nil ; @iso_sha1; @iso_download_timeout = 1000 ; @iso_download_instructions = nil # Shares to add @add_shares = [] # Default is no floppy mounted @floppy_files = nil # Default there are no post install files @pre_postinstall_file = nil @postinstall_files = [] ; @postinstall_timeout = 10000 ; @iso_file = "" @disk_size = '10240' ; @disk_format = 'VDI' ; @disk_variant = 'Standard' ; @disk_count = 1 @use_sata = true # :hostiocache => 'off' , # :os_type_id => 'Ubuntu', # :boot_wait => "10", :boot_cmd_sequence => [ "boot"], # :kickstart_port => "7122", :kickstart_ip => "127.0.0.1", :kickstart_timeout => 10000,# # :ssh_login_timeout => "10000", :ssh_user => "vagrant", :ssh_password => "vagrant",:ssh_key => "", @ssh_host_port = "2222" ; @ssh_guest_port = "22" # :ssh_host_port => "2222", :ssh_guest_port => "22", :sudo_cmd => "echo '%p'|sudo -S sh '%f'", # :shutdown_cmd => "shutdown -h now", # :kickstart_file => nil, @winrm_host_port = "5985" ; @winrm_guest_port = "5985" @winrm_login_timeout = "10000" @boot_cmd_sequence = [] # Empty list by default @virtualbox = { :vm_options => {} } @vmfusion = { :vm_options => {} } @kvm = { :vm_options => {} } @skip_iso_transfer = false @skip_nat_mapping = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object (private)
226 227 228 |
# File 'lib/veewee/definition.rb', line 226 def method_missing(m, *args, &block) env.logger.info "There's no attribute #{m} defined for definition #{@name}-- ignoring it" end |
Instance Attribute Details
#add_shares ⇒ Object
Returns the value of attribute add_shares.
44 45 46 |
# File 'lib/veewee/definition.rb', line 44 def add_shares @add_shares end |
#boot_cmd_sequence ⇒ Object
Returns the value of attribute boot_cmd_sequence.
20 21 22 |
# File 'lib/veewee/definition.rb', line 20 def boot_cmd_sequence @boot_cmd_sequence end |
#boot_wait ⇒ Object
Returns the value of attribute boot_wait.
20 21 22 |
# File 'lib/veewee/definition.rb', line 20 def boot_wait @boot_wait end |
#cpu_count ⇒ Object
207 208 209 210 211 212 213 |
# File 'lib/veewee/definition.rb', line 207 def cpu_count if ENV['VEEWEE_CPU_COUNT'].nil? return @cpu_count else return ENV['VEEWEE_CPU_COUNT'].to_i end end |
#disk_count ⇒ Object
Returns the value of attribute disk_count.
16 17 18 |
# File 'lib/veewee/definition.rb', line 16 def disk_count @disk_count end |
#disk_format ⇒ Object
Returns the value of attribute disk_format.
16 17 18 |
# File 'lib/veewee/definition.rb', line 16 def disk_format @disk_format end |
#disk_size ⇒ Object
Returns the value of attribute disk_size.
16 17 18 |
# File 'lib/veewee/definition.rb', line 16 def disk_size @disk_size end |
#disk_variant ⇒ Object
Returns the value of attribute disk_variant.
16 17 18 |
# File 'lib/veewee/definition.rb', line 16 def disk_variant @disk_variant end |
#env ⇒ Object
Returns the value of attribute env.
10 11 12 |
# File 'lib/veewee/definition.rb', line 10 def env @env end |
#floppy_files ⇒ Object
Returns the value of attribute floppy_files.
35 36 37 |
# File 'lib/veewee/definition.rb', line 35 def floppy_files @floppy_files end |
#hostiocache ⇒ Object
Returns the value of attribute hostiocache.
37 38 39 |
# File 'lib/veewee/definition.rb', line 37 def hostiocache @hostiocache end |
#iso_dowload_timeout ⇒ Object
Returns the value of attribute iso_dowload_timeout.
39 40 41 |
# File 'lib/veewee/definition.rb', line 39 def iso_dowload_timeout @iso_dowload_timeout end |
#iso_download_instructions ⇒ Object
Returns the value of attribute iso_download_instructions.
39 40 41 |
# File 'lib/veewee/definition.rb', line 39 def iso_download_instructions @iso_download_instructions end |
#iso_file ⇒ Object
Returns the value of attribute iso_file.
15 16 17 |
# File 'lib/veewee/definition.rb', line 15 def iso_file @iso_file end |
#iso_md5 ⇒ Object
Returns the value of attribute iso_md5.
39 40 41 |
# File 'lib/veewee/definition.rb', line 39 def iso_md5 @iso_md5 end |
#iso_sha1 ⇒ Object
Returns the value of attribute iso_sha1.
39 40 41 |
# File 'lib/veewee/definition.rb', line 39 def iso_sha1 @iso_sha1 end |
#iso_src ⇒ Object
Returns the value of attribute iso_src.
39 40 41 |
# File 'lib/veewee/definition.rb', line 39 def iso_src @iso_src end |
#kickstart_file ⇒ Object
Returns the value of attribute kickstart_file.
22 23 24 |
# File 'lib/veewee/definition.rb', line 22 def kickstart_file @kickstart_file end |
#kickstart_ip ⇒ Object
Returns the value of attribute kickstart_ip.
22 23 24 |
# File 'lib/veewee/definition.rb', line 22 def kickstart_ip @kickstart_ip end |
#kickstart_port ⇒ Object
Returns the value of attribute kickstart_port.
22 23 24 |
# File 'lib/veewee/definition.rb', line 22 def kickstart_port @kickstart_port end |
#kickstart_timeout ⇒ Object
Returns the value of attribute kickstart_timeout.
22 23 24 |
# File 'lib/veewee/definition.rb', line 22 def kickstart_timeout @kickstart_timeout end |
#kvm ⇒ Object
Returns the value of attribute kvm.
43 44 45 |
# File 'lib/veewee/definition.rb', line 43 def kvm @kvm end |
#memory_size ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/veewee/definition.rb', line 199 def memory_size if ENV['VEEWEE_MEMORY_SIZE'].nil? return @memory_size else return ENV['VEEWEE_MEMORY_SIZE'].to_i end end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/veewee/definition.rb', line 9 def name @name end |
#os_type_id ⇒ Object
Returns the value of attribute os_type_id.
18 19 20 |
# File 'lib/veewee/definition.rb', line 18 def os_type_id @os_type_id end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/veewee/definition.rb', line 11 def path @path end |
#postinstall_files ⇒ Object
Returns the value of attribute postinstall_files.
33 34 35 |
# File 'lib/veewee/definition.rb', line 33 def postinstall_files @postinstall_files end |
#postinstall_timeout ⇒ Object
Returns the value of attribute postinstall_timeout.
33 34 35 |
# File 'lib/veewee/definition.rb', line 33 def postinstall_timeout @postinstall_timeout end |
#pre_postinstall_file ⇒ Object
Returns the value of attribute pre_postinstall_file.
31 32 33 |
# File 'lib/veewee/definition.rb', line 31 def pre_postinstall_file @pre_postinstall_file end |
#shutdown_cmd ⇒ Object
Returns the value of attribute shutdown_cmd.
29 30 31 |
# File 'lib/veewee/definition.rb', line 29 def shutdown_cmd @shutdown_cmd end |
#skip_iso_transfer ⇒ Object
Returns the value of attribute skip_iso_transfer.
47 48 49 |
# File 'lib/veewee/definition.rb', line 47 def skip_iso_transfer @skip_iso_transfer end |
#skip_nat_mapping ⇒ Object
Returns the value of attribute skip_nat_mapping.
48 49 50 |
# File 'lib/veewee/definition.rb', line 48 def skip_nat_mapping @skip_nat_mapping end |
#ssh_guest_port ⇒ Object
Returns the value of attribute ssh_guest_port.
24 25 26 |
# File 'lib/veewee/definition.rb', line 24 def ssh_guest_port @ssh_guest_port end |
#ssh_host_port ⇒ Object
Returns the value of attribute ssh_host_port.
24 25 26 |
# File 'lib/veewee/definition.rb', line 24 def ssh_host_port @ssh_host_port end |
#ssh_key ⇒ Object
Returns the value of attribute ssh_key.
24 25 26 |
# File 'lib/veewee/definition.rb', line 24 def ssh_key @ssh_key end |
#ssh_login_timeout ⇒ Object
Returns the value of attribute ssh_login_timeout.
24 25 26 |
# File 'lib/veewee/definition.rb', line 24 def ssh_login_timeout @ssh_login_timeout end |
#ssh_password ⇒ Object
Returns the value of attribute ssh_password.
24 25 26 |
# File 'lib/veewee/definition.rb', line 24 def ssh_password @ssh_password end |
#ssh_user ⇒ Object
Returns the value of attribute ssh_user.
24 25 26 |
# File 'lib/veewee/definition.rb', line 24 def ssh_user @ssh_user end |
#sudo_cmd ⇒ Object
Returns the value of attribute sudo_cmd.
28 29 30 |
# File 'lib/veewee/definition.rb', line 28 def sudo_cmd @sudo_cmd end |
#use_hw_virt_ext ⇒ Object
Returns the value of attribute use_hw_virt_ext.
37 38 39 |
# File 'lib/veewee/definition.rb', line 37 def use_hw_virt_ext @use_hw_virt_ext end |
#use_pae ⇒ Object
Returns the value of attribute use_pae.
37 38 39 |
# File 'lib/veewee/definition.rb', line 37 def use_pae @use_pae end |
#use_sata ⇒ Object
Returns the value of attribute use_sata.
37 38 39 |
# File 'lib/veewee/definition.rb', line 37 def use_sata @use_sata end |
#video_memory_size ⇒ Object
Returns the value of attribute video_memory_size.
15 16 17 |
# File 'lib/veewee/definition.rb', line 15 def video_memory_size @video_memory_size end |
#virtualbox ⇒ Object
Returns the value of attribute virtualbox.
41 42 43 |
# File 'lib/veewee/definition.rb', line 41 def virtualbox @virtualbox end |
#vmdk_file ⇒ Object
Returns the value of attribute vmdk_file.
45 46 47 |
# File 'lib/veewee/definition.rb', line 45 def vmdk_file @vmdk_file end |
#vmfusion ⇒ Object
Returns the value of attribute vmfusion.
42 43 44 |
# File 'lib/veewee/definition.rb', line 42 def vmfusion @vmfusion end |
#winrm_guest_port ⇒ Object
Returns the value of attribute winrm_guest_port.
26 27 28 |
# File 'lib/veewee/definition.rb', line 26 def winrm_guest_port @winrm_guest_port end |
#winrm_host_port ⇒ Object
Returns the value of attribute winrm_host_port.
26 27 28 |
# File 'lib/veewee/definition.rb', line 26 def winrm_host_port @winrm_host_port end |
#winrm_login_timeout ⇒ Object
Returns the value of attribute winrm_login_timeout.
26 27 28 |
# File 'lib/veewee/definition.rb', line 26 def winrm_login_timeout @winrm_login_timeout end |
#winrm_password ⇒ Object
Returns the value of attribute winrm_password.
26 27 28 |
# File 'lib/veewee/definition.rb', line 26 def winrm_password @winrm_password end |
#winrm_user ⇒ Object
Returns the value of attribute winrm_user.
26 27 28 |
# File 'lib/veewee/definition.rb', line 26 def winrm_user @winrm_user end |
Class Method Details
.load(name, env) ⇒ Object
Class method to loading a definition
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/veewee/definition.rb', line 121 def self.load(name, env) # Construct the path to the definition path = File.join(env.definition_dir, name) definition = Veewee::Definition.new(name, path, env) env.logger.info "Loading definition directory #{definition.path}" unless definition.exists? raise Veewee::DefinitionNotExist, "Error: Definition #{name} does not seem to exist" end # We create this longer name to avoid clashes veewee_definition = definition if definition.exists? definition_file = File.join(definition.path, "definition.rb") content = File.read(definition_file) content.gsub!("Veewee::Session.declare", "veewee_definition.declare") content.gsub!("Veewee::Definition.declare", "veewee_definition.declare") env.logger.info(content) begin cwd = FileUtils.pwd env.logger.info("Entering path #{definition.path}") FileUtils.cd(definition.path) self.instance_eval(content) env.logger.info("Returning to path #{cwd}") FileUtils.cd(cwd) rescue NameError => ex raise Veewee::DefinitionError, "NameError reading definition from file #{definition_file} #{ex}" rescue Exception => ex raise Veewee::DefinitionError, "Error in the definition from file #{definition_file}\n#{ex}" end else env.logger.fatal("#{definition_file} not found") raise Veewee::DefinitionNotExist, "#{definition_file} not found" end if definition.valid? return definition else env.logger.fatal("Invalid Definition") raise Veewee::DefinitionError, "Invalid Definition" end end |
Instance Method Details
#declare(options) ⇒ Object
This function takes a hash of options and injects them into the definition
112 113 114 115 116 117 118 |
# File 'lib/veewee/definition.rb', line 112 def declare() .each do |key, value| instance_variable_set("@#{key}".to_sym, [key]) env.logger.info("definition") { " - #{key} : #{[key]}" } end end |
#exists? ⇒ Boolean
169 170 171 172 173 174 175 176 |
# File 'lib/veewee/definition.rb', line 169 def exists? filename = File.join(path, "definition.rb") unless File.exists?(filename) return false end return true end |
#ui ⇒ Object
50 51 52 53 54 55 |
# File 'lib/veewee/definition.rb', line 50 def ui return @_ui if defined?(@_ui) @_ui = @env.ui.dup @_ui.resource = @name @_ui end |
#valid? ⇒ Boolean
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/veewee/definition.rb', line 178 def valid? # Check if the definition exists? unless exists? return false end # Check ostype to be valid unless ostype_valid? return false end # Postinstall files require a valid user and password unless self.postinstall_files.nil? if (self.ssh_user.nil? || self.ssh_password.nil?) && (self.winrm_user.nil? || self.winrm_password.nil?) return false end end return true end |