vagrant-tart 0.0.2

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.
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "vagrant/util/busy"
5
+ require "vagrant/util/subprocess"
6
+ require_relative "../model/get_result"
7
+ require_relative "../model/list_result"
8
+
9
+ module VagrantPlugins
10
+ module Tart
11
+ module Util
12
+ # Executes commands on the host machine through the Tart command line interface.
13
+ # rubocop:disable Metrics/ClassLength
14
+ class Driver
15
+ # Initialize the driver with the path to the scripts directory.
16
+ def initialize
17
+ @script_path = Pathname.new(File.expand_path("../scripts", __dir__))
18
+ end
19
+
20
+ # Execute the 'clone' command.
21
+ # @param source [String] The source image
22
+ # @param name [String] The name of the machine
23
+ # @yield [(String, String)] The output of the command
24
+ def clone(source, name, &block)
25
+ cmd = ["tart", "clone", source, name]
26
+ execute(*cmd, &block)
27
+ end
28
+
29
+ # Execute the 'create' command.
30
+ # @param name [String] The name of the machine
31
+ def delete(name)
32
+ cmd = ["tart", "delete", name]
33
+ execute(*cmd)
34
+ end
35
+
36
+ # Execute the 'get' command and returns the machine detailed information.
37
+ # @param name [String] The name of the machine
38
+ # @return [VagrantPlugins::Tart::Model::GetResult] The result of the command
39
+ def get(name)
40
+ cmd = ["tart", "get", name, "--format", "json"]
41
+ result = execute(*cmd)
42
+ data = JSON.parse(result)
43
+ Model::GetResult.new(data)
44
+ end
45
+
46
+ # Execute the 'ip' commanda and returns the IP address of the machine.
47
+ # @param name [String] The name of the machine
48
+ # @return [String] The IP address of the machine
49
+ def ip(name)
50
+ cmd = ["tart", "ip", name]
51
+ result = execute(*cmd)
52
+ result.strip
53
+ end
54
+
55
+ # Execute the 'list' command and returns the list of machines.
56
+ # @return [VagrantPlugins::Tart::Model::ListResult] The result of the command
57
+ def list
58
+ cmd = ["tart", "list", "--format", "json"]
59
+ result = execute(*cmd)
60
+ data = JSON.parse(result)
61
+ Model::ListResult.new(data)
62
+ end
63
+
64
+ # Execute the 'login' command by calling an accessory script.
65
+ # @param host [String] The registry host name
66
+ # @param username [String] The username
67
+ # @param password [String] The password
68
+ def login(host, username, password)
69
+ script_path = @script_path.join("login.sh")
70
+ cmd = [script_path.to_s, host, username, password]
71
+ execute(*cmd)
72
+ end
73
+
74
+ # Execute the 'logout' command.
75
+ # @param host [String] The registry host name
76
+ def logout(host)
77
+ cmd = ["tart", "logout", host]
78
+ execute(*cmd)
79
+ end
80
+
81
+ # Execute the 'pull' command.
82
+ # @param image [String] The image to pull
83
+ # @yield [(String, String)] The output of the command
84
+ def pull(image, &block)
85
+ cmd = ["tart", "pull", image]
86
+ execute(*cmd, &block)
87
+ end
88
+
89
+ # Execute the 'run' command by calling an accessory script.
90
+ # @param name [String] The name of the machine
91
+ def run(name, use_gui, suspend, volumes)
92
+ script_path = @script_path.join("run.sh")
93
+
94
+ cmd = [script_path.to_s, name]
95
+ cmd << "--no-graphics" unless use_gui
96
+ cmd << "--suspendable" if suspend
97
+ volumes.each do |volume|
98
+ cmd << "--dir=#{volume}"
99
+ end
100
+
101
+ execute(*cmd)
102
+ end
103
+
104
+ # Execute the 'stop' command.
105
+ # @param name [String] The name of the machine
106
+ # @param timeout [Integer] The timeout in seconds
107
+ def stop(name, timeout = nil)
108
+ cmd = ["tart", "stop", name]
109
+ cmd << ["--timeout", timeout.to_s] if timeout&.positive?
110
+ execute(*cmd)
111
+ end
112
+
113
+ # Execute the 'suspend' command.
114
+ # @param name [String] The name of the machine
115
+ def suspend(name)
116
+ cmd = ["tart", "suspend", name]
117
+ execute(*cmd)
118
+ end
119
+
120
+ # Execute the 'set' command.
121
+ # @param name [String] The name of the machine
122
+ # @param key [String] The key to set
123
+ # @param value [String] The value to set
124
+ def set(name, key, value)
125
+ return if value == Config::UNSET_VALUE
126
+
127
+ # Map the key to the correct switch
128
+ switch = nil
129
+ case key
130
+ when "cpu"
131
+ switch = "--cpu"
132
+ when "memory"
133
+ switch = "--memory"
134
+ when "display"
135
+ switch = "--display"
136
+ when "disk"
137
+ switch = "--disk-size"
138
+ end
139
+ return unless switch
140
+
141
+ cmd = ["tart", "set", name, switch, value.to_s]
142
+ execute(*cmd)
143
+ end
144
+
145
+ # Execute the 'version' command and returns the version of Tart.
146
+ # @return [String] The version of Tart
147
+ def version
148
+ cmd = ["tart", "--version"]
149
+ result = execute(*cmd)
150
+ result.strip
151
+ end
152
+
153
+ private
154
+
155
+ # Execute a command on the host machine.
156
+ # Heavily inspired from https://github.com/hashicorp/vagrant/blob/main/plugins/providers/docker/executor/local.rb.
157
+ def execute(*cmd, &block)
158
+ # Append in the options for subprocess
159
+ cmd << { notify: %i[stdout stderr] }
160
+
161
+ interrupted = false
162
+ int_callback = -> { interrupted = true }
163
+ result = ::Vagrant::Util::Busy.busy(int_callback) do
164
+ ::Vagrant::Util::Subprocess.execute(*cmd, &block)
165
+ end
166
+
167
+ # Trim the outputs
168
+ result.stderr.gsub!("\r\n", "\n")
169
+ result.stdout.gsub!("\r\n", "\n")
170
+
171
+ if result.exit_code != 0 && !interrupted
172
+ raise VagrantPlugins::Tart::Errors::CommandError,
173
+ command: cmd.inspect,
174
+ stderr: result.stderr,
175
+ stdout: result.stdout
176
+ end
177
+
178
+ # Return the outputs of the command
179
+ "#{result.stdout} #{result.stderr}"
180
+ end
181
+ end
182
+ # rubocop:enable Metrics/ClassLength
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ # Top level module for the Tart provider plugin.
5
+ module Tart
6
+ # Current version of the Tart provider plugin.
7
+ VERSION = "0.0.2"
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "vagrant-tart/plugin"
5
+
6
+ module VagrantPlugins
7
+ # Top level module for the Tart provider plugin.
8
+ module Tart
9
+ lib_path = Pathname.new(File.expand_path("vagrant-tart", __dir__))
10
+ autoload :Action, lib_path.join("action")
11
+ autoload :Errors, lib_path.join("errors")
12
+
13
+ # This returns the path to the source of this plugin.
14
+ #
15
+ # @return [Pathname]
16
+ def self.source_root
17
+ @source_root ||= Pathname.new(File.expand_path("..", __dir__))
18
+ end
19
+ end
20
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,74 @@
1
+ en:
2
+ vagrant_tart:
3
+ config:
4
+ image_required: |-
5
+ Configuration must specify an image
6
+ name_required: |-
7
+ Configuration must specify a virtual machine name
8
+
9
+ gui_invalid: |-
10
+ Configuration must specify a valid GUI setting (true or false)
11
+ cpu_invalid: |-
12
+ Configuration must specify a valid CPU count (between 1 and %{max_cpus})
13
+ memory_invalid: |-
14
+ Configuration must specify a valid memory size (between 1 and %{max_memory} MB)
15
+ disk_invalid: |-
16
+ Configuration must specify a valid disk size (greater than 1 GB)
17
+ display_invalid: |-
18
+ Configuration must specify a valid display size (WIDTHxHEIGHT pixels)
19
+
20
+ errors:
21
+ command_error: |-
22
+ Command failed with error: %{stderr}
23
+ instance_not_created: |-
24
+ The virtual machine has not been created yet.
25
+ instance_not_running: |-
26
+ The virtual machine is not running.
27
+ macos_required: |-
28
+ MacOS is required to run this provider
29
+ synced_folder_not_tart: |-
30
+ The "tart" synced folder type can't be used because the provider
31
+ in use is not Tart. This synced folder type only works with the
32
+ Tart provider. The provider this machine is using is: %{provider}
33
+ tart_required: |-
34
+ tart CLI is required to run this provider
35
+
36
+ messages:
37
+ cloning_instance: |-
38
+ Cloning instance %{name}...
39
+ configuring_instance: |-
40
+ Configuring instance %{name}...
41
+ deleting_instance: |-
42
+ Deleting instance %{name}...
43
+ image_pulled: |-
44
+ Image %{image} pulled
45
+ instance_cloned: |-
46
+ Instance %{name} cloned
47
+ instance_configured: |-
48
+ Instance %{name} configured
49
+ instance_deleted: |-
50
+ Instance %{name} deleted
51
+ instance_started: |-
52
+ Instance %{name} started
53
+ instance_stopped: |-
54
+ Instance %{name} stopped
55
+ instance_suspended: |-
56
+ Instance %{name} suspended
57
+ logged_in: |-
58
+ Logged in to registry
59
+ logged_out: |-
60
+ Logged out of registry
61
+ logging_in: |-
62
+ Logging in to registry...
63
+ logging_out: |-
64
+ Logging out of registry...
65
+ not_created: |-
66
+ Virtual machine not created. Moving on...
67
+ pulling_image: |-
68
+ Pulling image %{image}...
69
+ starting_instance: |-
70
+ Starting instance %{name}...
71
+ stopping_instance: |-
72
+ Stopping instance %{name}...
73
+ suspending_instance: |-
74
+ Suspending instance %{name}...
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-tart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Laurent Etiemble
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows Vagrant to manage Tart virtual machines.
14
+ email:
15
+ - laurent.etiemble@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - lib/vagrant-tart.rb
23
+ - lib/vagrant-tart/action.rb
24
+ - lib/vagrant-tart/action/create_instance.rb
25
+ - lib/vagrant-tart/action/delete_instance.rb
26
+ - lib/vagrant-tart/action/forward_ports.rb
27
+ - lib/vagrant-tart/action/get_state.rb
28
+ - lib/vagrant-tart/action/login.rb
29
+ - lib/vagrant-tart/action/pull_image.rb
30
+ - lib/vagrant-tart/action/start_instance.rb
31
+ - lib/vagrant-tart/action/stop_instance.rb
32
+ - lib/vagrant-tart/action/suspend_instance.rb
33
+ - lib/vagrant-tart/config.rb
34
+ - lib/vagrant-tart/errors.rb
35
+ - lib/vagrant-tart/model/get_result.rb
36
+ - lib/vagrant-tart/model/list_result.rb
37
+ - lib/vagrant-tart/model/tart_disk.rb
38
+ - lib/vagrant-tart/plugin.rb
39
+ - lib/vagrant-tart/provider.rb
40
+ - lib/vagrant-tart/scripts/login.sh
41
+ - lib/vagrant-tart/scripts/run.sh
42
+ - lib/vagrant-tart/synced_folder.rb
43
+ - lib/vagrant-tart/util/driver.rb
44
+ - lib/vagrant-tart/version.rb
45
+ - locales/en.yml
46
+ homepage: https://github.com/letiemble/vagrant-tart
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ allowed_push_host: https://rubygems.org
51
+ homepage_uri: https://letiemble.github.io/vagrant-tart
52
+ source_code_uri: https://github.com/letiemble/vagrant-tart
53
+ changelog_uri: https://github.com/letiemble/vagrant-tart/blob/main/CHANGELOG.md
54
+ rubygems_mfa_required: 'true'
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.0.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.3.27
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Vagrant Tart provider
74
+ test_files: []