Class: PackerFiles::Virtual::KVMConverter
- Inherits:
-
Object
- Object
- PackerFiles::Virtual::KVMConverter
- Defined in:
- lib/PackerFiles/Virtual/KVMConverter.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Hash Value.
Instance Method Summary collapse
-
#convert(os, gen) ⇒ Object
Convert OS object into a hash.
-
#initialize(os, gen) ⇒ KVMConverter
constructor
Constructor.
Constructor Details
#initialize(os, gen) ⇒ KVMConverter
Constructor
14 15 16 |
# File 'lib/PackerFiles/Virtual/KVMConverter.rb', line 14 def initialize(os, gen) @value = convert(os, gen).to_hash end |
Instance Attribute Details
#value ⇒ Object (readonly)
Hash Value
11 12 13 |
# File 'lib/PackerFiles/Virtual/KVMConverter.rb', line 11 def value @value end |
Instance Method Details
#convert(os, gen) ⇒ Object
Convert OS object into a hash
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/PackerFiles/Virtual/KVMConverter.rb', line 19 def convert(os, gen) KVM.new do |kvm| # Fill in output directory rel = os.CDImage.release arch = os.CDImage.arch name = os.name.gsub('::', '-') kvm.output_directory = "output-#{name}-#{rel}-#{arch}-#{kvm.type}" kvm.name = "#{name}-#{rel}-#{arch}-#{kvm.type}" # Fill in image details, Some amount of url handling # is really required to handle various corner cases. # thus making the code a bit harder to understand kvm.iso_checksum_type = os.CDImage.check_sum_type kvm.iso_checksum = os.CDImage.check_sum # The code below creates a user variable called mirror # whose base value is the URL fragment w/o the file-name. url = URI::parse(os.CDImage.iso_url) file = File.basename(url.path) url.path = File.dirname(url.path) gen.variables['mirror'] = url.to_s kvm.iso_url = "{{user `mirror`}}/#{file}" # Fill in SSH specifics kvm.ssh_username = os.User.login kvm.ssh_password = os.User.password kvm.ssh_wait_timeout = '10000s' # Fill in other specifics kvm.disk_size = os.Disk.size kvm.http_directory = File.basename(os.http_dir) # Fill in boot command and boot_wait command gen.variables['host'] = '' gen.variables['port'] = '' user_var_name = name + "-#{kvm.type}-boot-wait" gen.variables[user_var_name] = "10s" kvm.boot_command = os.boot_command kvm.boot_wait = "{{user `#{user_var_name}`}}" # Fill in shutdown command kvm.shutdown_command = os.shutdown_command # If the guest OS type contains 64 bit OS, then we need to enable # a 64 bit CPU. if os.guest_os_type.match("64") kvm.Hypervisor(os.Hypervisors.KVM, true) else kvm.Hypervisor(os.Hypervisors.KVM, false) end # Merge with Custom attributes kvm.merge_hs(os.Hypervisors.KVM.custom) end end |