Class: VagrantPlugins::Utm::Driver::Meta

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant_utm/driver/meta.rb

Overview

This driver uses the AppleScript bridge interface to interact with UTM.

Defined Under Namespace

Classes: VMNotFound

Constant Summary collapse

@@version_lock =

rubocop:disable Style/ClassVars

Mutex.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#check_qemu_guest_agent, #clear_forwarded_ports, #delete, #execute, #execute_osa_script, #execute_shell, #forward_ports, #halt, #import, #last_uuid, #list, #random_mac_address, #raw, #raw_shell, #read_forwarded_ports, #read_guest_ip, #read_network_interfaces, #read_state, #read_used_ports, #read_vms, #set_mac_address, #set_name, #ssh_port, #start, #start_disposable, #suspend, #verify!, #vm_exists?

Constructor Details

#initialize(uuid = nil) ⇒ Meta

rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/AbcSize,Metrics/PerceivedComplexity

Raises:



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/vagrant_utm/driver/meta.rb', line 36

def initialize(uuid = nil) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/AbcSize,Metrics/PerceivedComplexity
  # Setup the base
  super()

  @logger = Log4r::Logger.new("vagrant::provider::utm::meta")
  @uuid = uuid

  @@version_lock.synchronize do
    unless @version
      begin
        @version = read_version
      rescue Errors::CommandError
        # This means that UTM was not found, so we raise this
        # error here.
        raise Errors::UtmNotDetected
      end
    end
  end

  # Instantiate the proper version driver for UTM
  @logger.debug("Finding driver for UTM version: #{@version}")
  driver_map = {
    "4.6" => Version_4_6,
    "4.7" => Version_4_7
  }

  # UTM version < 4.6.5  doesn't have
  # import support to work with Vagrant box (< 4.6.1)
  # registry support to work with synced folders (< 4.6.5)
  # Restrict to UTM versions >= 4.6.5
  unless Gem::Version.new(@version) >= Gem::Version.new("4.6.5")
    raise Errors::UtmInvalidVersion,
          supported_versions: "4.6.5 or later"
  end

  driver_klass = nil
  driver_map.each do |key, klass|
    if @version.start_with?(key)
      driver_klass = klass
      break
    end
  end

  unless driver_klass
    supported_versions = driver_map.keys.sort.join(", ")
    raise Errors::UtmInvalidVersion,
          supported_versions: supported_versions
  end

  @logger.info("Using UTM driver: #{driver_klass}")
  @driver = driver_klass.new(@uuid)

  return unless @uuid
  # Verify the VM exists, and if it doesn't, then don't worry
  # about it (mark the UUID as nil)
  raise VMNotFound unless @driver.vm_exists?(@uuid)
end

Instance Attribute Details

#uuidObject (readonly)

The UUID of the virtual machine we represent (Name in UTM).



29
30
31
# File 'lib/vagrant_utm/driver/meta.rb', line 29

def uuid
  @uuid
end

#versionObject (readonly)

The version of UTM that is running.



32
33
34
# File 'lib/vagrant_utm/driver/meta.rb', line 32

def version
  @version
end