Class: VagrantPlugins::Utm::Driver::Version_4_6
- Inherits:
-
Version_4_5
- Object
- Base
- Version_4_5
- VagrantPlugins::Utm::Driver::Version_4_6
- Defined in:
- lib/vagrant_utm/driver/version_4_6.rb
Overview
Driver for UTM 4.6.x
Direct Known Subclasses
Instance Method Summary collapse
-
#clear_shared_folders ⇒ Object
Implement clear_shared_folders.
- #export(path) ⇒ Object
- #import(utm) ⇒ Object
-
#initialize(uuid) ⇒ Version_4_6
constructor
rubocop:disable Naming/ClassAndModuleCamelCase.
- #read_shared_folders ⇒ Object
- #share_folders(folders) ⇒ Object
- #unshare_folders(folders) ⇒ Object
Methods inherited from Version_4_5
#check_qemu_guest_agent, #clear_forwarded_ports, #create_snapshot, #delete, #delete_snapshot, #execute_osa_script, #forward_ports, #get_vm_file, #halt, #last_uuid, #list, #list_snapshots, #read_forwarded_ports, #read_guest_ip, #read_network_interfaces, #read_state, #read_used_ports, #read_vms, #restore_snapshot, #set_mac_address, #set_name, #ssh_port, #start, #start_disposable, #suspend, #verify!, #vm_exists?
Methods inherited from Base
#check_qemu_guest_agent, #clear_forwarded_ports, #delete, #execute, #execute_osa_script, #execute_shell, #forward_ports, #halt, #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) ⇒ Version_4_6
rubocop:disable Naming/ClassAndModuleCamelCase
10 11 12 13 14 |
# File 'lib/vagrant_utm/driver/version_4_6.rb', line 10 def initialize(uuid) super @logger = Log4r::Logger.new("vagrant::provider::utm::version_4_6") end |
Instance Method Details
#clear_shared_folders ⇒ Object
Implement clear_shared_folders
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant_utm/driver/version_4_6.rb', line 17 def clear_shared_folders # Get the list of shared folders shared_folders = read_shared_folders # Get the args to remove the shared folders script_path = @script_path.join("read_shared_folders_args.js") cmd = ["osascript", script_path.to_s, @uuid, "--ids", shared_folders.join(",")] output = execute_shell(*cmd) result = JSON.parse(output) return unless result["status"] # Flatten the list of args and build the command sf_args = result["result"].flatten return unless sf_args.any? command = ["remove_qemu_additional_args.applescript", @uuid, "--args", *sf_args] execute_osa_script(command) end |
#export(path) ⇒ Object
53 54 55 56 57 |
# File 'lib/vagrant_utm/driver/version_4_6.rb', line 53 def export(path) @logger.debug("Exporting UTM file to: #{path}") command = ["export_vm.applescript", @uuid, path] execute_osa_script(command) end |
#import(utm) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vagrant_utm/driver/version_4_6.rb', line 35 def import(utm) utm = Vagrant::Util::Platform.windows_path(utm) vm_id = nil command = ["import_vm.applescript", utm] output = execute_osa_script(command) @logger.debug("Import output: #{output}") # Check if we got the VM ID if output =~ /virtual machine id ([A-F0-9-]+)/ vm_id = ::Regexp.last_match(1) # Capture the VM ID end vm_id end |
#read_shared_folders ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vagrant_utm/driver/version_4_6.rb', line 59 def read_shared_folders @logger.debug("Reading shared folders") script_path = @script_path.join("read_shared_folders.js") cmd = ["osascript", script_path.to_s, @uuid] output = execute_shell(*cmd) result = JSON.parse(output) return unless result["status"] # Return the list of shared folders names(id) result["result"] end |
#share_folders(folders) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vagrant_utm/driver/version_4_6.rb', line 71 def share_folders(folders) # sync folder cleanup will call clear_shared_folders # This is just a precaution, to make sure we don't # have duplicate shared folders shared_folders = read_shared_folders @logger.debug("Shared folders: #{shared_folders}") @logger.debug("Sharing folders: #{folders}") folders.each do |folder| # Skip if the folder is already shared next if shared_folders.include?(folder[:name]) args = ["--id", folder[:name], "--dir", folder[:hostpath]] command = ["add_folder_share.applescript", @uuid, *args] execute_osa_script(command) end end |
#unshare_folders(folders) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/vagrant_utm/driver/version_4_6.rb', line 90 def unshare_folders(folders) @logger.debug("Unsharing folder: #{folder[:name]}") # Get the args to remove the shared folders script_path = @script_path.join("read_shared_folders_args.js") cmd = ["osascript", script_path.to_s, @uuid, "--ids", folders.join(",")] output = execute_shell(*cmd) result = JSON.parse(output) return unless result["status"] # Flatten the list of args and build the command sf_args = result["result"].flatten return unless sf_args.any? command = ["remove_qemu_additional_args.applescript", @uuid, "--args", *sf_args] execute_osa_script(command) end |