Class: VagrantPlugins::QEMU::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-qemu/config.rb

Constant Summary collapse

GEM_CONFIG_FILE =

Path to the gem-level config file

File.join(File.dirname(__FILE__), "..", "..", "config.json")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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
# File 'lib/vagrant-qemu/config.rb', line 38

def initialize
  @ssh_host = UNSET_VALUE
  @ssh_port = UNSET_VALUE
  @ssh_auto_correct = UNSET_VALUE
  @arch = UNSET_VALUE
  @machine = UNSET_VALUE
  @cpu = UNSET_VALUE
  @smp = UNSET_VALUE
  @memory = UNSET_VALUE
  @net_device = UNSET_VALUE
  @drive_interface = UNSET_VALUE
  @image_path = UNSET_VALUE
  @qemu_bin = UNSET_VALUE
  @qemu_dir = UNSET_VALUE
  @virtiofsd_bin = UNSET_VALUE
  @virtiofs_guest_uid = UNSET_VALUE
  @virtiofs_guest_gid = UNSET_VALUE
  @extra_virtiofsd_args = UNSET_VALUE
  @disk_resize = UNSET_VALUE
  @extra_qemu_args = UNSET_VALUE
  @extra_netdev_args = UNSET_VALUE
  @extra_drive_args = UNSET_VALUE
  @control_port = UNSET_VALUE
  @debug_port = UNSET_VALUE
  @no_daemonize = UNSET_VALUE
  @firmware_format = UNSET_VALUE
  @other_default = UNSET_VALUE
  @extra_image_opts = UNSET_VALUE
end

Instance Attribute Details

#archObject

Returns the value of attribute arch.



10
11
12
# File 'lib/vagrant-qemu/config.rb', line 10

def arch
  @arch
end

#control_portObject

Returns the value of attribute control_port.



28
29
30
# File 'lib/vagrant-qemu/config.rb', line 28

def control_port
  @control_port
end

#cpuObject

Returns the value of attribute cpu.



12
13
14
# File 'lib/vagrant-qemu/config.rb', line 12

def cpu
  @cpu
end

#debug_portObject

Returns the value of attribute debug_port.



29
30
31
# File 'lib/vagrant-qemu/config.rb', line 29

def debug_port
  @debug_port
end

#disk_resizeObject

Returns the value of attribute disk_resize.



24
25
26
# File 'lib/vagrant-qemu/config.rb', line 24

def disk_resize
  @disk_resize
end

#drive_interfaceObject

Returns the value of attribute drive_interface.



16
17
18
# File 'lib/vagrant-qemu/config.rb', line 16

def drive_interface
  @drive_interface
end

#extra_drive_argsObject

Returns the value of attribute extra_drive_args.



27
28
29
# File 'lib/vagrant-qemu/config.rb', line 27

def extra_drive_args
  @extra_drive_args
end

#extra_image_optsObject

Returns the value of attribute extra_image_opts.



33
34
35
# File 'lib/vagrant-qemu/config.rb', line 33

def extra_image_opts
  @extra_image_opts
end

#extra_netdev_argsObject

Returns the value of attribute extra_netdev_args.



26
27
28
# File 'lib/vagrant-qemu/config.rb', line 26

def extra_netdev_args
  @extra_netdev_args
end

#extra_qemu_argsObject

Returns the value of attribute extra_qemu_args.



25
26
27
# File 'lib/vagrant-qemu/config.rb', line 25

def extra_qemu_args
  @extra_qemu_args
end

#extra_virtiofsd_argsObject

Returns the value of attribute extra_virtiofsd_args.



23
24
25
# File 'lib/vagrant-qemu/config.rb', line 23

def extra_virtiofsd_args
  @extra_virtiofsd_args
end

#firmware_formatObject

Returns the value of attribute firmware_format.



31
32
33
# File 'lib/vagrant-qemu/config.rb', line 31

def firmware_format
  @firmware_format
end

#image_pathObject

Returns the value of attribute image_path.



17
18
19
# File 'lib/vagrant-qemu/config.rb', line 17

def image_path
  @image_path
end

#machineObject

Returns the value of attribute machine.



11
12
13
# File 'lib/vagrant-qemu/config.rb', line 11

def machine
  @machine
end

#memoryObject

Returns the value of attribute memory.



14
15
16
# File 'lib/vagrant-qemu/config.rb', line 14

def memory
  @memory
end

#net_deviceObject

Returns the value of attribute net_device.



15
16
17
# File 'lib/vagrant-qemu/config.rb', line 15

def net_device
  @net_device
end

#no_daemonizeObject

Returns the value of attribute no_daemonize.



30
31
32
# File 'lib/vagrant-qemu/config.rb', line 30

def no_daemonize
  @no_daemonize
end

#other_defaultObject

Returns the value of attribute other_default.



32
33
34
# File 'lib/vagrant-qemu/config.rb', line 32

def other_default
  @other_default
end

#qemu_binObject

Returns the value of attribute qemu_bin.



18
19
20
# File 'lib/vagrant-qemu/config.rb', line 18

def qemu_bin
  @qemu_bin
end

#qemu_dirObject

Returns the value of attribute qemu_dir.



19
20
21
# File 'lib/vagrant-qemu/config.rb', line 19

def qemu_dir
  @qemu_dir
end

#smpObject

Returns the value of attribute smp.



13
14
15
# File 'lib/vagrant-qemu/config.rb', line 13

def smp
  @smp
end

#ssh_auto_correctObject

Returns the value of attribute ssh_auto_correct.



9
10
11
# File 'lib/vagrant-qemu/config.rb', line 9

def ssh_auto_correct
  @ssh_auto_correct
end

#ssh_hostObject

Returns the value of attribute ssh_host.



7
8
9
# File 'lib/vagrant-qemu/config.rb', line 7

def ssh_host
  @ssh_host
end

#ssh_portObject

Returns the value of attribute ssh_port.



8
9
10
# File 'lib/vagrant-qemu/config.rb', line 8

def ssh_port
  @ssh_port
end

#virtiofs_guest_gidObject

Returns the value of attribute virtiofs_guest_gid.



22
23
24
# File 'lib/vagrant-qemu/config.rb', line 22

def virtiofs_guest_gid
  @virtiofs_guest_gid
end

#virtiofs_guest_uidObject

Returns the value of attribute virtiofs_guest_uid.



21
22
23
# File 'lib/vagrant-qemu/config.rb', line 21

def virtiofs_guest_uid
  @virtiofs_guest_uid
end

#virtiofsd_binObject

Returns the value of attribute virtiofsd_bin.



20
21
22
# File 'lib/vagrant-qemu/config.rb', line 20

def virtiofsd_bin
  @virtiofsd_bin
end

Instance Method Details

#finalize!Object



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
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vagrant-qemu/config.rb', line 81

def finalize!
  # Load gem-level config file defaults
  gem_config = load_gem_config

  @ssh_host = "127.0.0.1" if @ssh_host == UNSET_VALUE
  @ssh_port = 50022 if @ssh_port == UNSET_VALUE
  @ssh_auto_correct = false if @ssh_auto_correct == UNSET_VALUE
  @arch = "aarch64" if @arch == UNSET_VALUE
  @machine = "virt,accel=hvf,highmem=on" if @machine == UNSET_VALUE
  @cpu = "host" if @cpu == UNSET_VALUE
  @smp = "2" if @smp == UNSET_VALUE
  @memory = "4G" if @memory == UNSET_VALUE
  @net_device = "virtio-net-device" if @net_device == UNSET_VALUE
  @drive_interface = "virtio" if @drive_interface == UNSET_VALUE
  @image_path = nil if @image_path == UNSET_VALUE
  @qemu_bin = resolve_binary(gem_config["qemu_bin"], "qemu") if @qemu_bin == UNSET_VALUE
  # TODO: I am not happy that we hardcode this qemu_dir fallback value, I think maybe there is a better option
  if @qemu_dir == UNSET_VALUE
    default_qemu_dir = RUBY_PLATFORM.include?("darwin") ? "/opt/homebrew/share/qemu" : "/usr/share/qemu"
    @qemu_dir = resolve_directory(gem_config["qemu_dir"], default_qemu_dir)
  end
  @virtiofsd_bin = resolve_binary(gem_config["virtiofsd_bin"], "virtiofsd") if @virtiofsd_bin == UNSET_VALUE
  @virtiofs_guest_uid = 1000 if @virtiofs_guest_uid == UNSET_VALUE
  @virtiofs_guest_gid = 1000 if @virtiofs_guest_gid == UNSET_VALUE
  @extra_virtiofsd_args = [] if @extra_virtiofsd_args == UNSET_VALUE
  @disk_resize = nil if @disk_resize == UNSET_VALUE
  @extra_qemu_args = [] if @extra_qemu_args == UNSET_VALUE
  @extra_netdev_args = nil if @extra_netdev_args == UNSET_VALUE
  @extra_drive_args = nil if @extra_drive_args == UNSET_VALUE
  @control_port = nil if @control_port == UNSET_VALUE
  @debug_port = nil if @debug_port == UNSET_VALUE
  @no_daemonize = false if @no_daemonize == UNSET_VALUE
  @firmware_format = "raw" if @firmware_format == UNSET_VALUE
  @other_default = %W(-parallel null -monitor none -display none -vga none) if @other_default == UNSET_VALUE
  @extra_image_opts = nil if @extra_image_opts == UNSET_VALUE

  # TODO better error msg
  @ssh_port = Integer(@ssh_port)
end

#merge(other) ⇒ Object


Internal methods.




72
73
74
75
76
77
78
79
# File 'lib/vagrant-qemu/config.rb', line 72

def merge(other)
  super.tap do |result|
    # Merge extra_qemu_args from both configs instead of overwriting
    if other.extra_qemu_args != UNSET_VALUE && @extra_qemu_args != UNSET_VALUE
      result.extra_qemu_args = @extra_qemu_args + other.extra_qemu_args
    end
  end
end

#validate(machine) ⇒ Object



121
122
123
124
125
# File 'lib/vagrant-qemu/config.rb', line 121

def validate(machine)
  # errors = _detected_errors
  errors = []
  { "QEMU Provider" => errors }
end