Class: VagrantPlugins::AVF::Model::BootConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_provider_avf/model/boot_config.rb

Constant Summary collapse

GUESTS =
[:linux].freeze
FIELDS =
[:guest, :kernel_path, :initrd_path, :disk_image_path].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guest:, kernel_path:, initrd_path:, disk_image_path:) ⇒ BootConfig

Returns a new instance of BootConfig.



26
27
28
29
30
31
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 26

def initialize(guest:, kernel_path:, initrd_path:, disk_image_path:)
  @guest = normalize_guest(guest)
  @kernel_path = normalize_path(kernel_path)
  @initrd_path = normalize_path(initrd_path)
  @disk_image_path = normalize_path(disk_image_path)
end

Instance Attribute Details

#disk_image_pathObject (readonly)

Returns the value of attribute disk_image_path.



24
25
26
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 24

def disk_image_path
  @disk_image_path
end

#guestObject (readonly)

Returns the value of attribute guest.



24
25
26
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 24

def guest
  @guest
end

#initrd_pathObject (readonly)

Returns the value of attribute initrd_path.



24
25
26
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 24

def initrd_path
  @initrd_path
end

#kernel_pathObject (readonly)

Returns the value of attribute kernel_path.



24
25
26
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 24

def kernel_path
  @kernel_path
end

Class Method Details

.fetch(attributes, key) ⇒ Object



17
18
19
20
21
22
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 17

def self.fetch(attributes, key)
  return attributes[key] if attributes.key?(key)
  return attributes[key.to_sym] if attributes.key?(key.to_sym)

  nil
end

.from_h(attributes) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 8

def self.from_h(attributes)
  new(
    guest: fetch(attributes, "guest"),
    kernel_path: fetch(attributes, "kernel_path"),
    initrd_path: fetch(attributes, "initrd_path"),
    disk_image_path: fetch(attributes, "disk_image_path")
  )
end

Instance Method Details

#changed_fields(other) ⇒ Object



54
55
56
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 54

def changed_fields(other)
  FIELDS.select { |field| public_send(field) != other.public_send(field) }
end

#errorsObject



33
34
35
36
37
38
39
40
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 33

def errors
  [].tap do |result|
    validate_guest(result)
    validate_path(:kernel_path, @kernel_path, result) if @kernel_path || @initrd_path
    validate_path(:initrd_path, @initrd_path, result) if @kernel_path || @initrd_path
    validate_path(:disk_image_path, @disk_image_path, result)
  end
end

#linux?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 42

def linux?
  @guest == :linux
end

#linux_disk_boot?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 50

def linux_disk_boot?
  linux? && @kernel_path.nil? && @initrd_path.nil?
end

#linux_kernel_boot?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 46

def linux_kernel_boot?
  linux? && !@kernel_path.nil? && !@initrd_path.nil?
end

#to_hObject



58
59
60
61
62
63
64
65
# File 'lib/vagrant_provider_avf/model/boot_config.rb', line 58

def to_h
  {
    "guest" => @guest.to_s,
    "kernel_path" => @kernel_path,
    "initrd_path" => @initrd_path,
    "disk_image_path" => @disk_image_path
  }
end