vagrant_utm 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +12 -0
- data/docs/.gitignore +15 -0
- data/docs/Gemfile +10 -0
- data/docs/Gemfile.lock +276 -0
- data/docs/README.md +174 -0
- data/docs/_config.yml +76 -0
- data/docs/_includes/footer_custom.html +3 -0
- data/docs/_sass/gallery.scss +64 -0
- data/docs/_virtual_machines/archlinux-arm.md +13 -0
- data/docs/assets/images/favicon.ico +0 -0
- data/docs/assets/images/logo.png +0 -0
- data/docs/assets/images/screens/archlinux-logo.png +0 -0
- data/docs/assets/images/screens/debian-11-xfce-arm64.png +0 -0
- data/docs/boxes/creating_utm_box.md +70 -0
- data/docs/boxes/index.md +6 -0
- data/docs/boxes/utm_box_gallery.md +117 -0
- data/docs/commands.md +156 -0
- data/docs/configuration.md +51 -0
- data/docs/features/index.md +5 -0
- data/docs/features/synced_folders.md +28 -0
- data/docs/index.md +103 -0
- data/docs/internals/actions.md +20 -0
- data/docs/internals/index.md +5 -0
- data/docs/internals/status.md +25 -0
- data/docs/internals/utm_api.md +31 -0
- data/docs/known_issues.md +24 -0
- data/lib/vagrant_utm/action/boot.rb +22 -0
- data/lib/vagrant_utm/action/boot_disposable.rb +22 -0
- data/lib/vagrant_utm/action/check_accessible.rb +33 -0
- data/lib/vagrant_utm/action/check_created.rb +24 -0
- data/lib/vagrant_utm/action/check_guest_additions.rb +37 -0
- data/lib/vagrant_utm/action/check_qemu_img.rb +21 -0
- data/lib/vagrant_utm/action/check_running.rb +25 -0
- data/lib/vagrant_utm/action/check_utm.rb +30 -0
- data/lib/vagrant_utm/action/clear_forwarded_ports.rb +26 -0
- data/lib/vagrant_utm/action/created.rb +26 -0
- data/lib/vagrant_utm/action/customize.rb +50 -0
- data/lib/vagrant_utm/action/destroy.rb +25 -0
- data/lib/vagrant_utm/action/download_confirm.rb +19 -0
- data/lib/vagrant_utm/action/export.rb +22 -0
- data/lib/vagrant_utm/action/forced_halt.rb +28 -0
- data/lib/vagrant_utm/action/forward_ports.rb +90 -0
- data/lib/vagrant_utm/action/import.rb +63 -0
- data/lib/vagrant_utm/action/is_paused.rb +26 -0
- data/lib/vagrant_utm/action/is_running.rb +26 -0
- data/lib/vagrant_utm/action/is_stopped.rb +26 -0
- data/lib/vagrant_utm/action/message_already_running.rb +22 -0
- data/lib/vagrant_utm/action/message_not_created.rb +22 -0
- data/lib/vagrant_utm/action/message_not_running.rb +22 -0
- data/lib/vagrant_utm/action/message_not_stopped.rb +22 -0
- data/lib/vagrant_utm/action/message_will_not_create.rb +23 -0
- data/lib/vagrant_utm/action/message_will_not_destroy.rb +23 -0
- data/lib/vagrant_utm/action/prepare_forwarded_port_collision_params.rb +43 -0
- data/lib/vagrant_utm/action/resume.rb +24 -0
- data/lib/vagrant_utm/action/set_id.rb +20 -0
- data/lib/vagrant_utm/action/set_name.rb +62 -0
- data/lib/vagrant_utm/action/snapshot_delete.rb +34 -0
- data/lib/vagrant_utm/action/snapshot_restore.rb +28 -0
- data/lib/vagrant_utm/action/snapshot_save.rb +34 -0
- data/lib/vagrant_utm/action/suspend.rb +23 -0
- data/lib/vagrant_utm/action/wait_for_running.rb +28 -0
- data/lib/vagrant_utm/action.rb +413 -0
- data/lib/vagrant_utm/cap.rb +40 -0
- data/lib/vagrant_utm/config.rb +141 -0
- data/lib/vagrant_utm/disposable.rb +16 -0
- data/lib/vagrant_utm/driver/base.rb +358 -0
- data/lib/vagrant_utm/driver/meta.rb +132 -0
- data/lib/vagrant_utm/driver/version_4_5.rb +307 -0
- data/lib/vagrant_utm/errors.rb +77 -0
- data/lib/vagrant_utm/model/forwarded_port.rb +75 -0
- data/lib/vagrant_utm/model/list_result.rb +77 -0
- data/lib/vagrant_utm/plugin.rb +65 -0
- data/lib/vagrant_utm/provider.rb +139 -0
- data/lib/vagrant_utm/scripts/add_port_forwards.applescript +72 -0
- data/lib/vagrant_utm/scripts/clear_port_forwards.applescript +56 -0
- data/lib/vagrant_utm/scripts/customize_vm.applescript +59 -0
- data/lib/vagrant_utm/scripts/downloadVM.sh +1 -0
- data/lib/vagrant_utm/scripts/list_vm.js +32 -0
- data/lib/vagrant_utm/scripts/open_with_utm.js +30 -0
- data/lib/vagrant_utm/scripts/read_forwarded_ports.applescript +27 -0
- data/lib/vagrant_utm/scripts/read_guest_ip.applescript +9 -0
- data/lib/vagrant_utm/scripts/read_network_interfaces.applescript +12 -0
- data/lib/vagrant_utm/util/compile_forwarded_ports.rb +43 -0
- data/lib/vagrant_utm/version.rb +9 -0
- data/lib/vagrant_utm.rb +40 -0
- data/locales/en.yml +154 -0
- data/sig/vagrant_utm.rbs +4 -0
- data/vagrantfile_examples/Vagrantfile +27 -0
- metadata +140 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "log4r"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Utm
|
7
|
+
# Provider that is responsible for managing the virtual machine and exposing it to Vagrant.
|
8
|
+
class Provider < Vagrant.plugin("2", :provider)
|
9
|
+
# The driver for this provider.
|
10
|
+
attr_reader :driver
|
11
|
+
|
12
|
+
def self.installed?
|
13
|
+
Driver::Meta.new
|
14
|
+
true
|
15
|
+
rescue Errors::UtmInvalidVersion,
|
16
|
+
Errors::UtmNotDetected
|
17
|
+
raise if raise_error
|
18
|
+
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
# Check if the provider is usable.
|
23
|
+
# rubocop:disable Style/OptionalBooleanParameter
|
24
|
+
def self.usable?(raise_error = false)
|
25
|
+
raise Errors::MacOSRequired unless Vagrant::Util::Platform.darwin?
|
26
|
+
|
27
|
+
# Instantiate the driver, which will determine the UTM
|
28
|
+
# version and all that, which checks for UTM being present.
|
29
|
+
Driver::Meta.new
|
30
|
+
true
|
31
|
+
rescue Errors::MacOSRequired,
|
32
|
+
Errors::UtmInvalidVersion,
|
33
|
+
Errors::UtmNotDetected
|
34
|
+
raise if raise_error
|
35
|
+
|
36
|
+
false
|
37
|
+
end
|
38
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
39
|
+
|
40
|
+
# Initialize the provider with given machine.
|
41
|
+
def initialize(machine)
|
42
|
+
super
|
43
|
+
@logger = Log4r::Logger.new("vagrant::provider::utm")
|
44
|
+
@machine = machine
|
45
|
+
|
46
|
+
# This method will load in our driver, so we call it now to
|
47
|
+
# initialize it.
|
48
|
+
machine_id_changed
|
49
|
+
end
|
50
|
+
|
51
|
+
# @see Vagrant::Plugin::V1::Provider#action
|
52
|
+
def action(name)
|
53
|
+
# Attempt to get the action method from the Action class if it
|
54
|
+
# exists, otherwise return nil to show that we don't support the
|
55
|
+
# given action.
|
56
|
+
action_method = "action_#{name}"
|
57
|
+
return Action.send(action_method) if Action.respond_to?(action_method)
|
58
|
+
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# If the machine ID changed, then we need to rebuild our underlying
|
63
|
+
# driver.
|
64
|
+
def machine_id_changed
|
65
|
+
id = @machine.id
|
66
|
+
|
67
|
+
begin
|
68
|
+
@logger.debug("Instantiating the driver for machine ID: #{@machine.id.inspect}")
|
69
|
+
@driver = Driver::Meta.new(id)
|
70
|
+
rescue Driver::Meta::VMNotFound
|
71
|
+
# The virtual machine doesn't exist, so we probably have a stale
|
72
|
+
# ID. Just clear the id out of the machine and reload it.
|
73
|
+
@logger.debug("VM not found! Clearing saved machine ID and reloading.")
|
74
|
+
id = nil
|
75
|
+
retry
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns the SSH info for accessing the UTM VM.
|
80
|
+
def ssh_info
|
81
|
+
# If the VM is not running (utm, started) then we can't possibly SSH into it
|
82
|
+
# TODO: We should use the state 'running', rather than 'started'
|
83
|
+
# UTM provider, which does not expose 'running' state. So we use 'started' state
|
84
|
+
return nil if state.id != :started
|
85
|
+
|
86
|
+
# Return what we know
|
87
|
+
# host = IP address of the VM
|
88
|
+
# port = the SSH port
|
89
|
+
# username = vagrant, the default vagrant user
|
90
|
+
# private_key_path = get the private key of the VM (default ~/.vagrant.d/insecure_private_key)
|
91
|
+
|
92
|
+
# Return ssh info for connector to connect to the VM
|
93
|
+
# If VM has shared network adapter in UTM, then we can use the IP address of the VM
|
94
|
+
# If we have multiple network adapters, we need to pick the right one, read_guest_ip returns just first IP
|
95
|
+
# Also, since Vagrant by default adds port forwarding for ssh port 22,
|
96
|
+
# we might aswell use the forwarded ports to connect to the VM using the localhost.
|
97
|
+
{
|
98
|
+
host: "127.0.0.1",
|
99
|
+
port: @driver.ssh_port(@machine.config.ssh.guest_port)
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
# Return the state of UTM virtual machine by actually
|
104
|
+
# querying utmctl.
|
105
|
+
#
|
106
|
+
# @return [Symbol]
|
107
|
+
def state
|
108
|
+
@logger.info("Getting state of '#{@machine.id}'")
|
109
|
+
|
110
|
+
# Determine the ID of the state here.
|
111
|
+
state_id = nil
|
112
|
+
state_id = :not_created unless @driver.uuid
|
113
|
+
state_id ||= @driver.read_state
|
114
|
+
state_id ||= :unknown
|
115
|
+
|
116
|
+
# Translate into short/long descriptions
|
117
|
+
short = state_id.to_s.gsub("_", " ")
|
118
|
+
long = I18n.t("vagrant_utm.commands.status.#{state_id}")
|
119
|
+
|
120
|
+
# If we're not created, then specify the special ID flag
|
121
|
+
state_id = Vagrant::MachineState::NOT_CREATED_ID if state_id == :not_created
|
122
|
+
|
123
|
+
# Return the state
|
124
|
+
Vagrant::MachineState.new(state_id, short, long)
|
125
|
+
end
|
126
|
+
|
127
|
+
# TODO: Get UUID of the VM from UTM
|
128
|
+
# Returns a human-friendly string version of this provider which
|
129
|
+
# includes the machine's ID that this provider represents, if it
|
130
|
+
# has one.
|
131
|
+
#
|
132
|
+
# @return [String]
|
133
|
+
def to_s
|
134
|
+
id = @machine.id || "new VM"
|
135
|
+
"UTM (#{id})"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Usage: osascript add_port_forwards.applescript UUID --index 2 "protocol,guestIp,guestPort,hostIp,hostPort" --index 1 "UdPp,100,100,100,100"
|
2
|
+
# index is the index of the network interface
|
3
|
+
on run argv
|
4
|
+
-- VM id is assumed to be the first argument
|
5
|
+
set vmID to item 1 of argv
|
6
|
+
-- Initialize an empty list to store port forwarding rules
|
7
|
+
set portForwardRules to {}
|
8
|
+
|
9
|
+
-- Parse the arguments
|
10
|
+
repeat with i from 2 to count of argv by 3
|
11
|
+
set indexArg to item i of argv
|
12
|
+
set indexNumber to item (i + 1) of argv
|
13
|
+
set ruleArg to item (i + 2) of argv
|
14
|
+
|
15
|
+
-- Index number is assume to point to 'emulated' network interface
|
16
|
+
-- port forwarding does not work with other network interfaces
|
17
|
+
-- even though the UTM API allows it
|
18
|
+
set indexNumber to indexNumber as integer
|
19
|
+
|
20
|
+
-- Port forwarding rules are assumed to be in the format
|
21
|
+
-- "protocol,guestAddress,guestPort,hostAddress,hostPort"
|
22
|
+
set AppleScript's text item delimiters to ","
|
23
|
+
|
24
|
+
-- Split the rule argument into its components
|
25
|
+
set ruleComponents to text items of ruleArg
|
26
|
+
|
27
|
+
-- Create a port forwarding rule record
|
28
|
+
set portForwardRule to { �
|
29
|
+
indexVal:indexNumber, protocolVal:item 1 of ruleComponents, �
|
30
|
+
guestAddress:item 2 of ruleComponents, guestPort:item 3 of ruleComponents, �
|
31
|
+
hostAddress:item 4 of ruleComponents, hostPort:item 5 of ruleComponents �
|
32
|
+
}
|
33
|
+
|
34
|
+
-- Add the rule to the list
|
35
|
+
set end of portForwardRules to portForwardRule
|
36
|
+
end repeat
|
37
|
+
|
38
|
+
-- Add port forwarding rules to the corresponding network interfaces
|
39
|
+
tell application "UTM"
|
40
|
+
set vm to virtual machine id vmID
|
41
|
+
set config to configuration of vm
|
42
|
+
|
43
|
+
set networkInterfaces to network interfaces of config
|
44
|
+
repeat with anInterface in networkInterfaces
|
45
|
+
set netIfIndex to index of anInterface
|
46
|
+
repeat with portForwardRule in portForwardRules
|
47
|
+
if (indexVal of portForwardRule) as integer is netIfIndex then
|
48
|
+
-- Existing port forwards
|
49
|
+
set portForwards to port forwards of anInterface
|
50
|
+
|
51
|
+
-- Create a new port forward configuration
|
52
|
+
set newPortForward to { �
|
53
|
+
protocol:(protocolVal of portForwardRule), �
|
54
|
+
guest address:(guestAddress of portForwardRule), �
|
55
|
+
guest port:(guestPort of portForwardRule), �
|
56
|
+
host address:(hostAddress of portForwardRule), �
|
57
|
+
host port:(hostPort of portForwardRule) �
|
58
|
+
}
|
59
|
+
|
60
|
+
-- Add new port forward to the list
|
61
|
+
copy newPortForward to the end of portForwards
|
62
|
+
|
63
|
+
-- Update the port forwards for the current interface
|
64
|
+
set port forwards of anInterface to portForwards
|
65
|
+
end if
|
66
|
+
end repeat
|
67
|
+
end repeat
|
68
|
+
|
69
|
+
-- Update the VM configuration
|
70
|
+
update configuration of vm with config
|
71
|
+
end tell
|
72
|
+
end run
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Usage: osascript clear_port_forwards.applescript <vmID> --index <index> <hostPort> --index <index> <hostPort> ...
|
2
|
+
# index is the index of the network interface
|
3
|
+
# hostPort is the host port to remove from the port forwards
|
4
|
+
on run argv
|
5
|
+
-- VM id is assumed to be the first argument
|
6
|
+
set vmID to item 1 of argv
|
7
|
+
-- Initialize an empty list to store port forwarding rules to be deleted
|
8
|
+
set portForwardRules to {}
|
9
|
+
|
10
|
+
-- Parse the arguments
|
11
|
+
repeat with i from 2 to count of argv by 3
|
12
|
+
set indexArg to item i of argv
|
13
|
+
set indexNumber to item (i + 1) of argv
|
14
|
+
set hostPortArg to item (i + 2) of argv
|
15
|
+
|
16
|
+
-- Assumed the index to be 'emulated' network interface
|
17
|
+
set indexNumber to indexNumber as integer
|
18
|
+
|
19
|
+
-- Create record of index and host port to remove
|
20
|
+
set portForwardRule to {indexVal:indexNumber, hostPort:hostPortArg}
|
21
|
+
|
22
|
+
-- Add the rule to the list
|
23
|
+
set end of portForwardRules to portForwardRule
|
24
|
+
end repeat
|
25
|
+
|
26
|
+
-- Add port forwarding rules to the corresponding network interfaces
|
27
|
+
tell application "UTM"
|
28
|
+
set vm to virtual machine id vmID
|
29
|
+
set config to configuration of vm
|
30
|
+
|
31
|
+
set networkInterfaces to network interfaces of config
|
32
|
+
repeat with anInterface in networkInterfaces
|
33
|
+
repeat with portForwardRule in portForwardRules
|
34
|
+
if (index of anInterface) is (indexVal of portForwardRule as integer) then
|
35
|
+
-- Existing port forwards
|
36
|
+
set portForwards to port forwards of anInterface
|
37
|
+
|
38
|
+
-- Find and remove the port forward with the specified host port
|
39
|
+
set updatedPortForwards to {}
|
40
|
+
repeat with aPortForward in portForwards
|
41
|
+
# Dont add the port forward if the host port matches the specified host port
|
42
|
+
if (host port of aPortForward) is not (hostPort of portForwardRule as integer) then
|
43
|
+
set end of updatedPortForwards to aPortForward
|
44
|
+
end if
|
45
|
+
end repeat
|
46
|
+
|
47
|
+
-- Update the port forwards for the current interface
|
48
|
+
set port forwards of anInterface to updatedPortForwards
|
49
|
+
end if
|
50
|
+
end repeat
|
51
|
+
end repeat
|
52
|
+
|
53
|
+
-- Update the VM configuration
|
54
|
+
update configuration of vm with config
|
55
|
+
end tell
|
56
|
+
end run
|
@@ -0,0 +1,59 @@
|
|
1
|
+
on run argv
|
2
|
+
tell application "UTM"
|
3
|
+
set vmID to item 1 of argv -- VM id is given as the first argument
|
4
|
+
set vmName to ""
|
5
|
+
set cpuCount to 0
|
6
|
+
set memorySize to 0
|
7
|
+
set vmNotes to ""
|
8
|
+
set directoryShareMode to null
|
9
|
+
|
10
|
+
-- Parse arguments
|
11
|
+
repeat with i from 2 to (count argv)
|
12
|
+
set currentArg to item i of argv
|
13
|
+
if currentArg is "--name" then
|
14
|
+
set vmName to item (i + 1) of argv
|
15
|
+
else if currentArg is "--cpus" then
|
16
|
+
set cpuCount to item (i + 1) of argv
|
17
|
+
else if currentArg is "--memory" then
|
18
|
+
set memorySize to item (i + 1) of argv
|
19
|
+
else if currentArg is "--notes" then
|
20
|
+
set vmNotes to item (i + 1) of argv
|
21
|
+
else if currentArg is "--directory-share-mode" then
|
22
|
+
set directoryShareMode to item (i + 1) of argv
|
23
|
+
end if
|
24
|
+
end repeat
|
25
|
+
|
26
|
+
-- Get the VM and its configuration
|
27
|
+
set vm to virtual machine id vmID -- ID is assumed to be valid
|
28
|
+
set config to configuration of vm
|
29
|
+
|
30
|
+
-- Set VM name if provided
|
31
|
+
if vmName is not "" then
|
32
|
+
set name of config to vmName
|
33
|
+
end if
|
34
|
+
|
35
|
+
-- Set CPU count if provided
|
36
|
+
if cpuCount is not 0 then
|
37
|
+
set cpu cores of config to cpuCount
|
38
|
+
end if
|
39
|
+
|
40
|
+
-- Set memory size if provided
|
41
|
+
if memorySize is not 0 then
|
42
|
+
set memory of config to memorySize
|
43
|
+
end if
|
44
|
+
|
45
|
+
-- Set the notes if --notes is provided (existing notes will be overwritten)
|
46
|
+
if vmNotes is not "" then
|
47
|
+
set notes of config to vmNotes
|
48
|
+
end if
|
49
|
+
|
50
|
+
-- Set Directory Sharing mode if provided
|
51
|
+
if directoryShareMode is not null then
|
52
|
+
set directory share mode of config to directoryShareMode -- mode is assumed to be enum value
|
53
|
+
end if
|
54
|
+
|
55
|
+
-- Save the configuration
|
56
|
+
update configuration of vm with config
|
57
|
+
|
58
|
+
end tell
|
59
|
+
end run
|
@@ -0,0 +1 @@
|
|
1
|
+
open -g "utm://downloadVM?url=$1"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Lists all virtual machines managed by UTM and returns their details in JSON format.
|
3
|
+
*
|
4
|
+
* Mimics the `utmctl list` command.
|
5
|
+
* UUID, Name, and Status
|
6
|
+
*
|
7
|
+
* @returns {string} A JSON string representing an array of objects, each object containing
|
8
|
+
* the UUID, Name, and Status of a virtual machine.
|
9
|
+
*/
|
10
|
+
function utmctlListVMs() {
|
11
|
+
const utm = Application('UTM');
|
12
|
+
utm.includeStandardAdditions = true;
|
13
|
+
|
14
|
+
// Listing virtual machines
|
15
|
+
const vms = utm.virtualMachines();
|
16
|
+
const vmList = [];
|
17
|
+
|
18
|
+
// Loop through all virtual machines
|
19
|
+
for (const vm of vms) {
|
20
|
+
const vmID = vm.id();
|
21
|
+
const vmName = vm.name();
|
22
|
+
const vmStatus = vm.status();
|
23
|
+
const vmDict = { UUID: vmID, Name: vmName, Status: vmStatus };
|
24
|
+
vmList.push(vmDict);
|
25
|
+
}
|
26
|
+
|
27
|
+
// Convert list to JSON
|
28
|
+
const jsonString = JSON.stringify(vmList);
|
29
|
+
return jsonString;
|
30
|
+
}
|
31
|
+
|
32
|
+
utmctlListVMs();
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/**
|
2
|
+
* Opens a specified UTM file.
|
3
|
+
*
|
4
|
+
* This function uses the UTM application to open a UTM file located at the given file path.
|
5
|
+
* It mimics the action of opening a Open with UTM.
|
6
|
+
*
|
7
|
+
* @param {string} filePath - The file path of the UTM file to be opened.
|
8
|
+
* @returns {string} A JSON string indicating the success or failure of the operation.
|
9
|
+
*/
|
10
|
+
function run(argv) {
|
11
|
+
// Check if a file path is provided
|
12
|
+
if (argv.length === 0) {
|
13
|
+
console.log("Usage: osascript -l JavaScript open_with_utm.js <path_to_utm_file>");
|
14
|
+
return JSON.stringify({ status: "error", message: "No file path provided." });
|
15
|
+
}
|
16
|
+
|
17
|
+
const filePath = argv[0];
|
18
|
+
const utm = Application('UTM');
|
19
|
+
utm.includeStandardAdditions = true;
|
20
|
+
|
21
|
+
try {
|
22
|
+
// Attempt to open the UTM file
|
23
|
+
utm.open(Path(filePath));
|
24
|
+
// Return a success message
|
25
|
+
return JSON.stringify({ status: "success", message: "UTM file opened successfully." });
|
26
|
+
} catch (error) {
|
27
|
+
// Return an error message if the operation fails
|
28
|
+
return JSON.stringify({ status: "error", message: error.toString() });
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Usage: osascript read_port_forwards.applescript <vmID>
|
2
|
+
# vmID is the id of the virtual machine
|
3
|
+
# This script reads the port forwards of the 'emulated' network interface
|
4
|
+
# 'Forwarding(nicIndex)(ruleIndex)="protocol,guestAddress,guestPort,hostAddress,hostPort"'
|
5
|
+
on run argv
|
6
|
+
set vmID to item 1 of argv
|
7
|
+
tell application "UTM"
|
8
|
+
set vm to virtual machine id vmID
|
9
|
+
set config to configuration of vm
|
10
|
+
|
11
|
+
set networkInterfaces to network interfaces of config
|
12
|
+
repeat with anInterface in networkInterfaces
|
13
|
+
if (mode of anInterface as string) is "emulated" then
|
14
|
+
set portForwards to port forwards of anInterface
|
15
|
+
set i to -1
|
16
|
+
repeat with aPortForward in portForwards
|
17
|
+
set i to i + 1
|
18
|
+
# Log the port forward details Virtualbox style
|
19
|
+
# 'Forwarding(nicIndex)(ruleIndex)="protocol,guestAddress,guestPort,hostAddress,hostPort"'
|
20
|
+
log "Forwarding(" & index of anInterface & ")(" & i & ")=\"" & protocol of aPortForward & "," �
|
21
|
+
& guest address of aPortForward & "," & guest port of aPortForward & "," �
|
22
|
+
& host address of aPortForward & "," & host port of aPortForward & "\""
|
23
|
+
end repeat
|
24
|
+
end if
|
25
|
+
end repeat
|
26
|
+
end tell
|
27
|
+
end run
|
@@ -0,0 +1,12 @@
|
|
1
|
+
on run argv
|
2
|
+
set vmID to item 1 of argv
|
3
|
+
tell application "UTM"
|
4
|
+
set vm to virtual machine id vmID
|
5
|
+
set config to configuration of vm
|
6
|
+
set networkInterfaces to network interfaces of config
|
7
|
+
repeat with anInterface in networkInterfaces
|
8
|
+
# if you start log with variable you'll get "," at the end of the log if '&' is used to concatenate
|
9
|
+
log "nic" & index of anInterface & "," & mode of anInterface
|
10
|
+
end repeat
|
11
|
+
end tell
|
12
|
+
end run
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) HashiCorp, Inc.
|
4
|
+
# SPDX-License-Identifier: BUSL-1.1
|
5
|
+
|
6
|
+
require "vagrant/util/scoped_hash_override"
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module Utm
|
10
|
+
module Util
|
11
|
+
# This module contains the code to compile the forwarded ports from config.
|
12
|
+
module CompileForwardedPorts
|
13
|
+
include Vagrant::Util::ScopedHashOverride
|
14
|
+
|
15
|
+
# This method compiles the forwarded ports into {ForwardedPort}
|
16
|
+
# models.
|
17
|
+
def compile_forwarded_ports(config) # rubocop:disable Metrics/AbcSize
|
18
|
+
mappings = {}
|
19
|
+
|
20
|
+
config.vm.networks.each do |type, options|
|
21
|
+
next unless type == :forwarded_port
|
22
|
+
|
23
|
+
guest_port = options[:guest]
|
24
|
+
host_port = options[:host]
|
25
|
+
host_ip = options[:host_ip]
|
26
|
+
protocol = options[:protocol] || "tcp"
|
27
|
+
options = scoped_hash_override(options, :utm)
|
28
|
+
id = options[:id]
|
29
|
+
|
30
|
+
# If the forwarded port was marked as disabled, ignore.
|
31
|
+
next if options[:disabled]
|
32
|
+
|
33
|
+
key = "#{host_ip}#{protocol}#{host_port}"
|
34
|
+
mappings[key] =
|
35
|
+
Model::ForwardedPort.new(id, host_port, guest_port, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
mappings.values
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/vagrant_utm.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require "vagrant_utm/plugin"
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
# Top level module for the UTM provider plugin.
|
8
|
+
module Utm
|
9
|
+
lib_path = Pathname.new(File.expand_path("vagrant_utm", __dir__))
|
10
|
+
autoload :Action, lib_path.join("action")
|
11
|
+
autoload :Errors, lib_path.join("errors")
|
12
|
+
|
13
|
+
# Drop some autoloads in here to optimize the performance of loading
|
14
|
+
# our drivers only when they are needed.
|
15
|
+
module Driver
|
16
|
+
lib_path = Pathname.new(File.expand_path("vagrant_utm/driver", __dir__))
|
17
|
+
autoload :Meta, lib_path.join("meta")
|
18
|
+
autoload :Version_4_5, lib_path.join("version_4_5") # rubocop:disable Naming/VariableNumber
|
19
|
+
end
|
20
|
+
|
21
|
+
# Drop some autoloads for the model classes
|
22
|
+
module Model
|
23
|
+
lib_path = Pathname.new(File.expand_path("vagrant_utm/model", __dir__))
|
24
|
+
autoload :ForwardedPort, lib_path.join("forwarded_port")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Drop some autoloads for the util classes
|
28
|
+
module Util
|
29
|
+
lib_path = Pathname.new(File.expand_path("vagrant_utm/util", __dir__))
|
30
|
+
autoload :CompileForwardedPorts, lib_path.join("compile_forwarded_ports")
|
31
|
+
end
|
32
|
+
|
33
|
+
# This returns the path to the source of this plugin.
|
34
|
+
#
|
35
|
+
# @return [Pathname]
|
36
|
+
def self.source_root
|
37
|
+
@source_root ||= Pathname.new(File.expand_path("..", __dir__))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|