vagrant-tart 0.0.4 → 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: 3e9661a2803897b09b1601b13b608e24ea19a5f95db89c760f3c04e6a1b18c41
4
- data.tar.gz: fd5723f36984a597846413d9fe14438dd8386116357faff32d212ba6ca265c8e
3
+ metadata.gz: 216dc096ac1b18cb20713cb80c5688389f2503fe8d04954a1274406c35274fa1
4
+ data.tar.gz: 89be7ac98b4980e0b59d6ff64d0b4160abbeb1b445ee2c58b171e771eb4ad208
5
5
  SHA512:
6
- metadata.gz: 942cb301b228455fac8369be172bd5c9be38cf4b4ed91fe7eac0b0af46a15ff9235ecb3e9601de039aafb0836ec493b4e417c46748da4b79058fb8957f762d53
7
- data.tar.gz: 53d7dba4e76a42d9ea51f76cfacb5306db38397e13102ab18123c2b1bc129d65775f09cafa030981d21f2fb16b21c42ef445e5eb8f07feddb433a81605938f75
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
@@ -33,6 +33,10 @@ module VagrantPlugins
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
@@ -54,6 +58,8 @@ module VagrantPlugins
54
58
  @disk = 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
@@ -73,6 +79,8 @@ module VagrantPlugins
73
79
  @disk = 10 if @disk == 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
@@ -107,6 +115,17 @@ module VagrantPlugins
107
115
  # Check that the suspendable flag is a valid boolean
108
116
  errors << I18n.t("vagrant_tart.config.suspendable_invalid") unless @suspendable == true || @suspendable == false
109
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
+
110
129
  { "Tart Provider" => errors }
111
130
  end
112
131
 
@@ -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)
@@ -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.4"
7
+ VERSION = "0.0.5"
8
8
  end
9
9
  end
data/locales/en.yml CHANGED
@@ -17,6 +17,12 @@ en:
17
17
  Configuration must specify a virtual machine name
18
18
  suspendable_invalid: |-
19
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)
20
26
 
21
27
  errors:
22
28
  command_error: |-
@@ -39,6 +45,8 @@ en:
39
45
  Cloning instance %{name}...
40
46
  configuring_instance: |-
41
47
  Configuring instance %{name}...
48
+ connecting_to_vnc: |-
49
+ Opening VNC connection to %{name}...
42
50
  deleting_instance: |-
43
51
  Deleting instance %{name}...
44
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.4
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-22 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