vagrant-tart 0.0.3 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7304968aeaf2c309ef4e77a350054f83fb24d6119518e2372639ac27f51b3c73
4
- data.tar.gz: 7baed83d857caeb259d10798500493e69bbf6267234dca7789e8654576a6ad8f
3
+ metadata.gz: 216dc096ac1b18cb20713cb80c5688389f2503fe8d04954a1274406c35274fa1
4
+ data.tar.gz: 89be7ac98b4980e0b59d6ff64d0b4160abbeb1b445ee2c58b171e771eb4ad208
5
5
  SHA512:
6
- metadata.gz: 6a9a0510aa5cf86519e744de29182bfd3feccd0545314b170ec955c505414bd16d77046dbbbb085d75d004be4db60cb3377effa3ffb66ddc309f6dffb6b78f97
7
- data.tar.gz: cf738b29374eda9c4884c6c03dd58ae6fd96383ba44b9f31d19695397f71497a9fab1a4e94a7d01098f3611a3c2940cdd737326827bad115349f76c917ba74db
6
+ metadata.gz: 9057828c27f9678e9a67fa684e479cd059fc4c108c71ed3c059762f8637485dde5a177a3fc7cf0507751f5a28c83c0230ed52254a76976a190520874f5ae5ec9
7
+ data.tar.gz: 6d744163d2bdf101f0e56d6b7d806d78e3c7d7de1fb90fae1ad6e779cec94f15a563e52dd388a27ffe8664cd6c558f4485c506b29da829abe48bb462af6d04d6
@@ -32,7 +32,7 @@ module VagrantPlugins
32
32
  env[:ui].output(I18n.t("vagrant_tart.messages.instance_configured", name: name))
33
33
 
34
34
  env[:ui].output(I18n.t("vagrant_tart.messages.starting_instance", name: name))
35
- driver.run(name, config.gui, config.suspendable?, config.volumes)
35
+ driver.run(name, config)
36
36
  env[:ui].output(I18n.t("vagrant_tart.messages.instance_started", name: name))
37
37
 
38
38
  @app.call(env)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n"
4
+
5
+ module VagrantPlugins
6
+ module Tart
7
+ module Action
8
+ # Action block to connect to the VNC server exposed by the VM.
9
+ class VNCConnect
10
+ def initialize(app, _env)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ machine = env[:machine]
16
+ config = machine.provider_config
17
+ driver = machine.provider.driver
18
+ name = config.name
19
+
20
+ list = driver.list
21
+ return @app.call(env) unless list.any?(name)
22
+
23
+ instance = driver.get(name)
24
+ return @app.call(env) if instance.nil? || instance.vagrant_state != :running
25
+
26
+ # Grab the VNC info from the machine or the environment
27
+ info = env[:vnc_info]
28
+ info ||= env[:machine].ssh_info
29
+
30
+ env[:ui].output(I18n.t("vagrant_tart.messages.connecting_to_vnc", name: name))
31
+ driver.vnc_connect(info)
32
+
33
+ @app.call(env)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -21,6 +21,7 @@ module VagrantPlugins
21
21
  autoload :StartInstance, action_root.join("start_instance")
22
22
  autoload :StopInstance, action_root.join("stop_instance")
23
23
  autoload :SuspendInstance, action_root.join("suspend_instance")
24
+ autoload :VNCConnect, action_root.join("vnc_connect")
24
25
 
25
26
  # Vargrant action "destroy".
26
27
  def self.action_destroy
@@ -161,6 +162,23 @@ module VagrantPlugins
161
162
  end
162
163
  end
163
164
 
165
+ # Vagrant action "vnc_connect".
166
+ def self.action_vnc_connect
167
+ Vagrant::Action::Builder.new.tap do |b|
168
+ b.use ConfigValidate
169
+
170
+ b.use Call, IsState, :not_created do |env, b1|
171
+ raise Errors::InstanceNotCreatedError if env[:result]
172
+
173
+ b1.use Call, IsState, :running do |env2, b2|
174
+ raise Errors::InstanceNotRunningError unless env2[:result]
175
+
176
+ b2.use VNCConnect
177
+ end
178
+ end
179
+ end
180
+ end
181
+
164
182
  # Retrieves the state of the virtual machine.
165
183
  def self.action_get_state
166
184
  Vagrant::Action::Builder.new.tap do |b|
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n"
4
+ require "vagrant/util/ansi_escape_code_remover"
5
+
6
+ module VagrantPlugins
7
+ module Tart
8
+ module Command
9
+ # Command block to open a VNC connection to a virtual machine.
10
+ class VNC < Vagrant.plugin("2", :command)
11
+ def self.synopsis
12
+ "connects to machine via VNC"
13
+ end
14
+
15
+ def execute
16
+ options = {}
17
+
18
+ opts = OptionParser.new do |o|
19
+ o.banner = "Usage: vagrant vnc [options] [name|id] [-- extra args]"
20
+ o.separator ""
21
+ o.separator "Options:"
22
+ o.separator ""
23
+
24
+ o.on("-u", "--username USERNAME", "The username to use for the VNC connection.") do |u|
25
+ options[:username] = u
26
+ end
27
+
28
+ o.on("-p", "--password PASSWORD", "The password to use for the VNC connection.") do |p|
29
+ options[:password] = p
30
+ end
31
+ end
32
+
33
+ # Parse out the extra args to send to the RDP client, which
34
+ # is everything after the "--"
35
+ split_index = @argv.index("--")
36
+ if split_index
37
+ options[:extra_args] = @argv.drop(split_index + 1)
38
+ @argv = @argv.take(split_index)
39
+ end
40
+
41
+ # Parse the options and return if we don't have any target.
42
+ argv = parse_options(opts)
43
+ return unless argv
44
+
45
+ with_target_vms(argv, single_target: true) do |machine|
46
+ vnc_info = get_vnc_info(machine, options)
47
+
48
+ machine.ui.detail("Address: #{vnc_info[:host]}") if vnc_info[:host]
49
+ machine.ui.detail("Username: #{vnc_info[:username]}") if vnc_info[:username]
50
+
51
+ machine.action(:vnc_connect, vnc_info: vnc_info)
52
+ end
53
+
54
+ 0
55
+ end
56
+
57
+ def get_vnc_info(machine, options = {})
58
+ vnc_info = {}
59
+
60
+ ssh_info = machine.ssh_info
61
+ unless ssh_info.nil?
62
+ vnc_info[:host] = ssh_info[:host]
63
+ if options[:username]
64
+ vnc_info[:username] = options[:username]
65
+ vnc_info[:password] = options[:password] || nil
66
+ else
67
+ vnc_info[:username] = ssh_info[:username]
68
+ vnc_info[:password] = ssh_info[:password]
69
+ end
70
+ end
71
+ vnc_info[:extra_args] ||= options[:extra_args]
72
+
73
+ vnc_info
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -11,9 +11,9 @@ module VagrantPlugins
11
11
  class Config < Vagrant.plugin("2", :config)
12
12
  # @return [String] The image registry
13
13
  attr_accessor :registry
14
- # @return [String] The image registry username
14
+ # @return [String] The image registry username (optional)
15
15
  attr_accessor :username
16
- # @return [String] The image registry password
16
+ # @return [String] The image registry password (optional)
17
17
  attr_accessor :password
18
18
 
19
19
  # @return [String] The image source
@@ -21,18 +21,22 @@ module VagrantPlugins
21
21
  # @return [String] The name
22
22
  attr_accessor :name
23
23
 
24
+ # @return [Boolean] Show a GUI window on boot, or run headless
25
+ attr_accessor :gui
24
26
  # @return [Integer] Number of CPUs
25
27
  attr_accessor :cpus
26
28
  # @return [Integer] Memory size in MB
27
29
  attr_accessor :memory
28
30
  # @return [Integer] Disk storage size in GB
29
31
  attr_accessor :disk
30
- # @return [Boolean] Show a GUI window on boot, or run headless
31
- attr_accessor :gui
32
32
  # @return [String] Display screen resolution
33
33
  attr_accessor :display
34
34
  # @return [Boolean] Whether the machine is suspendable
35
35
  attr_accessor :suspendable
36
+ # @return [Boolean] Whether the machine expose a VNC server (screen sharing)
37
+ attr_accessor :vnc
38
+ # @return [Boolean] Whether the machine expose a VNC server (virtualization framework)
39
+ attr_accessor :vnc_experimental
36
40
 
37
41
  # @return [Array<String>] List of volumes to mount
38
42
  attr_accessor :volumes
@@ -48,12 +52,14 @@ module VagrantPlugins
48
52
  @image = UNSET_VALUE
49
53
  @name = UNSET_VALUE
50
54
 
55
+ @gui = UNSET_VALUE
51
56
  @cpus = UNSET_VALUE
52
57
  @memory = UNSET_VALUE
53
58
  @disk = UNSET_VALUE
54
- @gui = UNSET_VALUE
55
59
  @display = UNSET_VALUE
56
60
  @suspendable = UNSET_VALUE
61
+ @vnc = UNSET_VALUE
62
+ @vnc_experimental = UNSET_VALUE
57
63
 
58
64
  @volumes = []
59
65
  end
@@ -67,24 +73,20 @@ module VagrantPlugins
67
73
  @image = nil if @image == UNSET_VALUE
68
74
  @name = nil if @name == UNSET_VALUE
69
75
 
76
+ @gui = false if @gui == UNSET_VALUE
70
77
  @cpus = 1 if @cpus == UNSET_VALUE
71
78
  @memory = 1024 if @memory == UNSET_VALUE
72
79
  @disk = 10 if @disk == UNSET_VALUE
73
- @gui = false if @gui == UNSET_VALUE
74
80
  @display = "1024x768" if @display == UNSET_VALUE
75
81
  @suspendable = false if @suspendable == UNSET_VALUE
82
+ @vnc = false if @vnc == UNSET_VALUE
83
+ @vnc_experimental = false if @vnc_experimental == UNSET_VALUE
76
84
  end
77
85
 
78
86
  # Validate the configuration
79
87
  def validate(_machine)
80
88
  errors = _detected_errors
81
89
 
82
- # Sanity checks for the registry
83
- unless @registry.nil?
84
- errors << I18n.t("vagrant_tart.config.username_required") if @username.nil? || @username.empty?
85
- errors << I18n.t("vagrant_tart.config.password_required") if @password.nil? || @password.empty?
86
- end
87
-
88
90
  # Sanity checks for the image and the name
89
91
  errors << I18n.t("vagrant_tart.config.image_required") if @image.nil? || @image.empty?
90
92
  errors << I18n.t("vagrant_tart.config.name_required") if @name.nil? || @name.empty?
@@ -110,6 +112,20 @@ module VagrantPlugins
110
112
  # Check that the display resolution is a valid string conforming to the format "WIDTHxHEIGHT"
111
113
  errors << I18n.t("vagrant_tart.config.display_invalid") unless @display.match?(/^\d+x\d+$/)
112
114
 
115
+ # Check that the suspendable flag is a valid boolean
116
+ errors << I18n.t("vagrant_tart.config.suspendable_invalid") unless @suspendable == true || @suspendable == false
117
+
118
+ # Check that the VNC flag is a valid boolean
119
+ errors << I18n.t("vagrant_tart.config.vnc_invalid") unless @vnc == true || @vnc == false
120
+
121
+ # Check that the VNC experimental flag is a valid boolean
122
+ unless @vnc_experimental == true || @vnc_experimental == false
123
+ errors << I18n.t("vagrant_tart.config.vnc_experimental_invalid")
124
+ end
125
+
126
+ # Check that the VNC and VNC experimental flags are not both true
127
+ errors << I18n.t("vagrant_tart.config.vnc_exclusive") if @vnc == true && @vnc_experimental == true
128
+
113
129
  { "Tart Provider" => errors }
114
130
  end
115
131
 
@@ -117,8 +133,10 @@ module VagrantPlugins
117
133
  @suspendable
118
134
  end
119
135
 
136
+ # Check if the configuration uses a registry.
137
+ # @return [Boolean] True if the configuration uses a registry, false otherwise
120
138
  def use_registry?
121
- !@registry.nil? && !@username.nil? && !@password.nil?
139
+ !@registry.nil?
122
140
  end
123
141
  end
124
142
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -36,6 +36,12 @@ module VagrantPlugins
36
36
  SyncedFolder
37
37
  end
38
38
 
39
+ # Register the custom VNC command.
40
+ command("vnc", primary: false) do
41
+ require_relative "command/vnc"
42
+ Command::VNC
43
+ end
44
+
39
45
  # Load the translation files
40
46
  def self.setup_i18n
41
47
  I18n.load_path << File.expand_path("locales/en.yml", Tart.source_root)
@@ -5,5 +5,10 @@ HOST="$1"
5
5
  USERNAME="$2"
6
6
  PASSWORD="$3"
7
7
 
8
- # Login to the registry with the provided credentials
9
- echo "$PASSWORD" | tart login "$HOST" --username "$USERNAME" --password-stdin
8
+ if [[ -z "$USERNAME" ]] || [[ -z "$PASSWORD" ]]; then
9
+ # Assumes that the credentials are provided in another way (e.g. environment variables)
10
+ tart login "$HOST"
11
+ else
12
+ # Login to the registry with the provided credentials
13
+ echo "$PASSWORD" | tart login "$HOST" --username "$USERNAME" --password-stdin
14
+ fi
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env zsh
2
+ set -eo pipefail
3
+
4
+ # Open a VNC connection to the virtual machine
5
+ nohup open $1 &
@@ -26,6 +26,27 @@ module VagrantPlugins
26
26
  execute(*cmd, &block)
27
27
  end
28
28
 
29
+ # Trigger a VNC connection to the machine.
30
+ # @param info [Hash] The information to connect to the machine
31
+ def vnc_connect(info)
32
+ machine_ip = info[:host]
33
+ username = info[:username]
34
+ password = info[:password]
35
+
36
+ auth = if username && password
37
+ "#{username}:#{password}@"
38
+ elsif username
39
+ "#{username}@"
40
+ else
41
+ ""
42
+ end
43
+ target = "vnc://#{auth}#{machine_ip}"
44
+
45
+ script_path = @script_path.join("open.sh")
46
+ cmd = [script_path.to_s, target]
47
+ execute(*cmd)
48
+ end
49
+
29
50
  # Execute the 'create' command.
30
51
  # @param name [String] The name of the machine
31
52
  def delete(name)
@@ -88,13 +109,20 @@ module VagrantPlugins
88
109
 
89
110
  # Execute the 'run' command by calling an accessory script.
90
111
  # @param name [String] The name of the machine
91
- def run(name, use_gui, suspend, volumes)
112
+ # @param options [Hash] The options to pass to the command
113
+ # @param options.use_gui [Boolean] Whether to use the GUI
114
+ # @param options.suspend [Boolean] Whether the machine is suspendable
115
+ # @param options.volumes [Array<String>] The volumes to mount
116
+ def run(name, config)
92
117
  script_path = @script_path.join("run.sh")
93
118
 
94
119
  cmd = [script_path.to_s, name]
95
- cmd << "--no-graphics" unless use_gui
96
- cmd << "--suspendable" if suspend
97
- volumes.each do |volume|
120
+ cmd << "--no-graphics" unless config.gui
121
+ cmd << "--suspendable" if config.suspendable?
122
+ cmd << "--vnc" if config.vnc
123
+ cmd << "--vnc-experimental" if config.vnc_experimental
124
+
125
+ config.volumes.each do |volume|
98
126
  cmd << "--dir=#{volume}"
99
127
  end
100
128
 
@@ -4,6 +4,6 @@ module VagrantPlugins
4
4
  # Top level module for the Tart provider plugin.
5
5
  module Tart
6
6
  # Current version of the Tart provider plugin.
7
- VERSION = "0.0.3"
7
+ VERSION = "0.0.5"
8
8
  end
9
9
  end
data/locales/en.yml CHANGED
@@ -1,21 +1,28 @@
1
1
  en:
2
2
  vagrant_tart:
3
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
4
  cpus_invalid: |-
12
5
  Configuration must specify a valid CPUs count (between 1 and %{max_cpus})
13
- memory_invalid: |-
14
- Configuration must specify a valid memory size (between 1 and %{max_memory} MB)
15
6
  disk_invalid: |-
16
7
  Configuration must specify a valid disk size (greater than 1 GB)
17
8
  display_invalid: |-
18
9
  Configuration must specify a valid display size (WIDTHxHEIGHT pixels)
10
+ gui_invalid: |-
11
+ Configuration must specify a valid GUI setting (true or false)
12
+ image_required: |-
13
+ Configuration must specify an image
14
+ memory_invalid: |-
15
+ Configuration must specify a valid memory size (between 1 and %{max_memory} MB)
16
+ name_required: |-
17
+ Configuration must specify a virtual machine name
18
+ suspendable_invalid: |-
19
+ Configuration must specify a valid suspendable setting (true or false)
20
+ vnc_invalid: |-
21
+ Configuration must specify a valid VNC setting (true or false)
22
+ vnc_exclusive: |-
23
+ Configuration must specify either vnc or vnc_experimental setting
24
+ vnc_experimental_invalid: |-
25
+ Configuration must specify a valid VNC experimental setting (true or false)
19
26
 
20
27
  errors:
21
28
  command_error: |-
@@ -38,6 +45,8 @@ en:
38
45
  Cloning instance %{name}...
39
46
  configuring_instance: |-
40
47
  Configuring instance %{name}...
48
+ connecting_to_vnc: |-
49
+ Opening VNC connection to %{name}...
41
50
  deleting_instance: |-
42
51
  Deleting instance %{name}...
43
52
  image_pulled: |-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-tart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Etiemble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-08 00:00:00.000000000 Z
11
+ date: 2024-11-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Allows Vagrant to manage Tart virtual machines.
14
14
  email:
@@ -30,6 +30,8 @@ files:
30
30
  - lib/vagrant-tart/action/start_instance.rb
31
31
  - lib/vagrant-tart/action/stop_instance.rb
32
32
  - lib/vagrant-tart/action/suspend_instance.rb
33
+ - lib/vagrant-tart/action/vnc_connect.rb
34
+ - lib/vagrant-tart/command/vnc.rb
33
35
  - lib/vagrant-tart/config.rb
34
36
  - lib/vagrant-tart/errors.rb
35
37
  - lib/vagrant-tart/model/get_result.rb
@@ -38,6 +40,7 @@ files:
38
40
  - lib/vagrant-tart/plugin.rb
39
41
  - lib/vagrant-tart/provider.rb
40
42
  - lib/vagrant-tart/scripts/login.sh
43
+ - lib/vagrant-tart/scripts/open.sh
41
44
  - lib/vagrant-tart/scripts/run.sh
42
45
  - lib/vagrant-tart/synced_folder.rb
43
46
  - lib/vagrant-tart/util/driver.rb