Class: VagrantPlugins::Utm::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::Utm::Config
- Defined in:
- lib/vagrant_utm/config.rb
Overview
This is the configuration class for the UTM provider.
Instance Attribute Summary collapse
-
#check_guest_additions ⇒ Boolean
If true, will check if guest additions are installed and up to date.
-
#customizations ⇒ Array
readonly
An array of customizations to make on the VM prior to booting it.
-
#functional_9pfs ⇒ Boolean
Whether or not this VM has a functional VirtFS 9P filesystem module for VirtFS directory sharing to work.
-
#name ⇒ String
This should be set to the name of the machine in the UTM GUI.
-
#wait_time ⇒ Integer
The time to wait for the VM to be ‘running’ after ‘started’.
Instance Method Summary collapse
-
#cpus=(count) ⇒ Object
Shortcut for setting CPU count for the virtual machine.
-
#customize(*command) ⇒ Object
Customize the VM by calling ‘osascript’ with the given arguments.
-
#directory_share_mode=(mode) ⇒ Object
TODO: All warning if user sets directory_share_mode, because default implementation is ‘virtFS’ Shortcut for setting the directory share mode of the virtual machine.
-
#finalize! ⇒ Object
This is the hook that is called to finalize the object before it is put into use.
-
#icon=(icon) ⇒ Object
Shortcut for setting the icon of the virtual machine.
-
#initialize ⇒ Config
constructor
Initialize the configuration with unset values.
-
#memory=(size) ⇒ Object
Shortcut for setting memory size for the virtual machine.
-
#notes=(notes) ⇒ Object
Shortcut for setting the notes of the virtual machine.
- #to_s ⇒ Object
- #validate(_machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Initialize the configuration with unset values.
40 41 42 43 44 45 46 47 |
# File 'lib/vagrant_utm/config.rb', line 40 def initialize super @check_guest_additions = UNSET_VALUE @customizations = [] @functional_9pfs = UNSET_VALUE @name = UNSET_VALUE @wait_time = UNSET_VALUE end |
Instance Attribute Details
#check_guest_additions ⇒ Boolean
If true, will check if guest additions are installed and up to date. By default, this is true.
14 15 16 |
# File 'lib/vagrant_utm/config.rb', line 14 def check_guest_additions @check_guest_additions end |
#customizations ⇒ Array (readonly)
An array of customizations to make on the VM prior to booting it.
19 20 21 |
# File 'lib/vagrant_utm/config.rb', line 19 def customizations @customizations end |
#functional_9pfs ⇒ Boolean
Whether or not this VM has a functional VirtFS 9P filesystem module for VirtFS directory sharing to work. This defaults to true. If you set this to false, then the “utm” synced folder type won’t be valid.
27 28 29 |
# File 'lib/vagrant_utm/config.rb', line 27 def functional_9pfs @functional_9pfs end |
#name ⇒ String
This should be set to the name of the machine in the UTM GUI.
32 33 34 |
# File 'lib/vagrant_utm/config.rb', line 32 def name @name end |
#wait_time ⇒ Integer
The time to wait for the VM to be ‘running’ after ‘started’.
37 38 39 |
# File 'lib/vagrant_utm/config.rb', line 37 def wait_time @wait_time end |
Instance Method Details
#cpus=(count) ⇒ Object
Shortcut for setting CPU count for the virtual machine. Calls #customize internally.
76 77 78 |
# File 'lib/vagrant_utm/config.rb', line 76 def cpus=(count) customize("pre-boot", ["customize_vm.applescript", :id, "--cpus", count.to_i]) end |
#customize(*command) ⇒ Object
Customize the VM by calling ‘osascript’ with the given arguments.
When called multiple times, the customizations will be applied in the order given.
osascript config function.
57 58 59 60 61 62 |
# File 'lib/vagrant_utm/config.rb', line 57 def customize(*command) # Append the event and command to the customizations array event = command.first.is_a?(String) ? command.shift : "pre-boot" command = command[0] @customizations << [event, command] end |
#directory_share_mode=(mode) ⇒ Object
TODO: All warning if user sets directory_share_mode, because default implementation is ‘virtFS’ Shortcut for setting the directory share mode of the virtual machine. Calls #customize internally.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/vagrant_utm/config.rb', line 108 def directory_share_mode=(mode) # The mode can be 'none', 'webDAV', 'virtFS' # Convert the mode to the corresponding 4-byte code # and pass it to the customize_vm.applescript mode_code = case mode.to_s when "none" "SmOf" when "webDAV" "SmWv" when "virtFS" "SmVs" else raise Vagrant::Errors::ConfigInvalid, errors: "Invalid directory share mode, must be 'none', 'webDAV', or 'virtFS'" end customize("pre-boot", ["customize_vm.applescript", :id, "--directory-share-mode", mode_code]) end |
#finalize! ⇒ Object
This is the hook that is called to finalize the object before it is put into use.
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vagrant_utm/config.rb', line 128 def finalize! # By default, we check for guest additions (qemu-ga) @check_guest_additions = true if @check_guest_additions == UNSET_VALUE # Always set the directory share mode to 'virtFS' # default share folder implementation in utm plugin self.directory_share_mode = "virtFS" # By default, we assume the VM supports virtio 9p filesystems @functional_9pfs = true if @functional_9pfs == UNSET_VALUE # The default name is just nothing, and we default it @name = nil if @name == UNSET_VALUE @wait_time = 20 if @wait_time == UNSET_VALUE end |
#icon=(icon) ⇒ Object
Shortcut for setting the icon of the virtual machine. Calls #customize internally.
Available icons can be found at: github.com/utmapp/UTM/tree/main/Icons
Common icons include: linux, ubuntu, debian, fedora, archlinux, openbsd, freebsd, windows, macos, android, etc.
98 99 100 |
# File 'lib/vagrant_utm/config.rb', line 98 def icon=(icon) customize("pre-boot", ["customize_vm.applescript", :id, "--icon", icon.to_s]) end |
#memory=(size) ⇒ Object
Shortcut for setting memory size for the virtual machine. Calls #customize internally.
68 69 70 |
# File 'lib/vagrant_utm/config.rb', line 68 def memory=(size) customize("pre-boot", ["customize_vm.applescript", :id, "--memory", size.to_s]) end |
#notes=(notes) ⇒ Object
Shortcut for setting the notes of the virtual machine. Calls #customize internally.
84 85 86 |
# File 'lib/vagrant_utm/config.rb', line 84 def notes=(notes) customize("pre-boot", ["customize_vm.applescript", :id, "--notes", notes]) end |
#to_s ⇒ Object
161 162 163 |
# File 'lib/vagrant_utm/config.rb', line 161 def to_s "UTM" end |
#validate(_machine) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/vagrant_utm/config.rb', line 142 def validate(_machine) errors = _detected_errors # Add errors if config is invalid Ex: required fields are not set valid_events = %w[pre-import pre-boot post-boot post-comm] @customizations.each do |event, _| # rubocop:disable Style/HashEachMethods next if valid_events.include?(event) errors << I18n.t( "vagrant.virtualbox.config.invalid_event", event: event.to_s, valid_events: valid_events.join(", ") ) end { "UTM Provider" => errors } end |