vagrant-shell 0.2.13 → 0.2.14

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWJjNjBkNTU5OTZmNTA1OGI2MzNmNTU0YmVhMzc0Y2ZhZWEwZGJkMA==
5
+ data.tar.gz: !binary |-
6
+ ZmI4MDk2MmY0MjcyZmUyNjU4Mjk4ZGFhZmQ4NDE4YmExZGE4NjYyZg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzM5NmI5MjU0YzI0ODk5ZGQ4N2ViNzA3NTNjYTI0NjEzN2Q3ZmRjMjNmNThh
10
+ ZTc5YTgyZjUzMDA3NmYxZGJhYzU2YzYyZjVjODYzOGQzZTE5YjIxOTU5Zjdh
11
+ MDZlMGZhY2ExZDJmZGNjN2MxNzQ4OWE5MjI3YjdkMmNjOGExZDE=
12
+ data.tar.gz: !binary |-
13
+ NjE1MzRjYzRhNzFkMDNiYzI1NTM2MzQ0OTk4Mzc5M2EwMDI1ZDFmZTk5ZGE5
14
+ NmNjZTFhOWY1MzVhMTgzOTc3NTMxMWVkNDAxNjAxZDliMGFhMGE5MmFjOTVi
15
+ YTdiZGY3NDk1YTAyMGE1Y2QxNzExMTliY2ZmMWMzOGVmMTY0ZDM=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.13
1
+ 0.2.14
@@ -11,8 +11,15 @@ module VagrantPlugins
11
11
  # This action is called to terminate the remote machine.
12
12
  def self.action_destroy
13
13
  Vagrant::Action::Builder.new.tap do |b|
14
- b.use ConfigValidate
15
- b.use TerminateInstance
14
+ b.use Call, DestroyConfirm do |env, b2|
15
+ if env[:result]
16
+ b2.use ConfigValidate
17
+ b2.use ConnectShell
18
+ b2.use TerminateInstance
19
+ else
20
+ b2.use MessageWillNotDestroy
21
+ end
22
+ end
16
23
  end
17
24
  end
18
25
 
@@ -37,6 +44,7 @@ module VagrantPlugins
37
44
  def self.action_read_ssh_info
38
45
  Vagrant::Action::Builder.new.tap do |b|
39
46
  b.use ConfigValidate
47
+ b.use ConnectShell
40
48
  b.use ReadSSHInfo
41
49
  end
42
50
  end
@@ -47,6 +55,7 @@ module VagrantPlugins
47
55
  def self.action_read_state
48
56
  Vagrant::Action::Builder.new.tap do |b|
49
57
  b.use ConfigValidate
58
+ b.use ConnectShell
50
59
  b.use ReadState
51
60
  end
52
61
  end
@@ -83,7 +92,9 @@ module VagrantPlugins
83
92
  # This action is called to bring the box up from nothing.
84
93
  def self.action_up
85
94
  Vagrant::Action::Builder.new.tap do |b|
95
+ b.use HandleBoxUrl
86
96
  b.use ConfigValidate
97
+ b.use ConnectShell
87
98
  b.use Call, IsCreated do |env, b2|
88
99
  if env[:result]
89
100
  b2.use MessageAlreadyCreated
@@ -98,9 +109,11 @@ module VagrantPlugins
98
109
 
99
110
  # The autoload farm
100
111
  action_root = Pathname.new(File.expand_path("../action", __FILE__))
112
+ autoload :ConnectShell, action_root.join("connect_shell")
101
113
  autoload :IsCreated, action_root.join("is_created")
102
114
  autoload :MessageAlreadyCreated, action_root.join("message_already_created")
103
115
  autoload :MessageNotCreated, action_root.join("message_not_created")
116
+ autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
104
117
  autoload :ReadSSHInfo, action_root.join("read_ssh_info")
105
118
  autoload :ReadState, action_root.join("read_state")
106
119
  autoload :RunInstance, action_root.join("run_instance")
@@ -0,0 +1,30 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module Shell
5
+ module Action
6
+ # This action connects to Shell, verifies credentials work, and
7
+ # puts the Shell script object into the `:script` key
8
+ # in the environment.
9
+ class ConnectShell
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_shell::action::connect_shell")
13
+ end
14
+
15
+ def call(env)
16
+ # Get the region we're going to booting up in
17
+ region = env[:machine].provider_config.region
18
+
19
+ # Get the configs
20
+ region_config = env[:machine].provider_config.get_region_config(region)
21
+
22
+ @logger.info("Connecting to Shell...")
23
+ env[:script] = nil
24
+
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module Shell
3
+ module Action
4
+ class MessageWillNotDestroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_shell.will_not_destroy", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -12,24 +12,27 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  def call(env)
15
- env[:machine_ssh_info] = read_ssh_info(env[:machine])
15
+ env[:machine_ssh_info] = read_ssh_info(env[:script], env[:machine])
16
16
 
17
17
  @app.call(env)
18
18
  end
19
19
 
20
- def read_ssh_info(machine)
20
+ def read_ssh_info(script, machine)
21
21
  return nil if machine.id.nil?
22
22
 
23
- # Read the DNS info
24
- output = %x{ #{machine.provider_config.script} ssh-info #{machine.id} }
25
- if $?.to_i > 0
26
- raise Errors::ShellError, :message => "Failure: #{env[:machine].provider_config.script} ssh-info #{machine.id}"
23
+ # Find the machine
24
+ server = script.servers.get(machine.id)
25
+ if server.nil?
26
+ # The machine can't be found
27
+ @logger.info("Machine couldn't be found, assuming it got destroyed.")
28
+ machine.id = nil
29
+ return nil
27
30
  end
28
31
 
29
- host,port = output.split(/\s+/)[0,2] # TODO check formatting
32
+ # Read the DNS info
30
33
  return {
31
- :host => host,
32
- :port => port
34
+ :host => server.public_ip_address || server.dns_name || server.private_ip_address,
35
+ :port => server.public_port || server.private_port
33
36
  }
34
37
  end
35
38
  end
@@ -12,20 +12,25 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  def call(env)
15
- env[:machine_state_id] = read_state(env[:machine])
15
+ env[:machine_state_id] = read_state(env[:script], env[:machine])
16
16
 
17
17
  @app.call(env)
18
18
  end
19
19
 
20
- def read_state(machine)
20
+ def read_state(script, machine)
21
21
  return :not_created if machine.id.nil?
22
22
 
23
- # Return the state
24
- output = %x{ #{machine.provider_config.script} read-state #{machine.id} }
25
- if $?.to_i > 0
26
- raise Errors::ShellError, :message => "Failure: #{env[:machine].provider_config.script} read-state #{machine.id}"
23
+ # Find the machine
24
+ server = aws.servers.get(machine.id)
25
+ if server.nil? || [:"shutting-down", :terminated].include?(server.state.to_sym)
26
+ # The machine can't be found
27
+ @logger.info("Machine not found or terminated, assuming it got destroyed.")
28
+ machine.id = nil
29
+ return :not_created
27
30
  end
28
- output.strip
31
+
32
+ # Return the state
33
+ return server.state.to_sym
29
34
  end
30
35
  end
31
36
  end
@@ -1,5 +1,5 @@
1
1
  require "log4r"
2
- require "pp"
2
+ require 'json'
3
3
 
4
4
  require 'vagrant/util/retryable'
5
5
 
@@ -21,27 +21,35 @@ module VagrantPlugins
21
21
  # Initialize metrics if they haven't been
22
22
  env[:metrics] ||= {}
23
23
 
24
+ # Get the region we're going to booting up in
25
+ region = env[:machine].provider_config.region
26
+
24
27
  # Get the configs
25
- provider_config = env[:machine].provider_config
26
- image = provider_config.image
27
- user_data = provider_config.user_data
28
- run_args = provider_config.run_args
28
+ region_config = env[:machine].provider_config.get_region_config(region)
29
+ image = region_config.image
30
+ user_data = region_config.user_data
31
+ run_args = region_config.run_args
29
32
 
30
33
  # Launch!
31
34
  env[:ui].info(I18n.t("vagrant_shell.launching_instance"))
32
35
  env[:ui].info(" -- Image: #{image}")
33
36
 
34
- # Immediately save the ID since it is created at this point.
35
- output = %x{ #{env[:machine].provider_config.script} run-instance #{image} #{run_args.join(" ")} }
36
- if $?.to_i > 0
37
- raise Errors::ShellError, :message => "Failure: #{env[:machine].provider_config.script} run-instance #{image} ..."
37
+ begin
38
+ options = {
39
+ :image => image,
40
+ :user_data => user_data,
41
+ :run_args => run_args
42
+ }
43
+
44
+ server = env[:script].servers.create(options)
38
45
  end
39
46
 
40
- env[:machine].id = output.split(/\s+/)[0]
47
+ # Immediately save the ID since it is created at this point.
48
+ env[:machine].id = server.id
41
49
 
42
50
  # Wait for the instance to be ready first
43
51
  env[:metrics]["instance_ready_time"] = Util::Timer.time do
44
- tries = provider_config.instance_ready_timeout / 2
52
+ tries = region_config.instance_ready_timeout / 2
45
53
 
46
54
  env[:ui].info(I18n.t("vagrant_shell.waiting_for_ready"))
47
55
  begin
@@ -50,7 +58,7 @@ module VagrantPlugins
50
58
  next if env[:interrupted]
51
59
 
52
60
  # Wait for the server to be ready
53
- true
61
+ server.wait_for(2) { ready? }
54
62
  end
55
63
  rescue Shell::Errors::TimeoutError
56
64
  # Delete the instance
@@ -58,7 +66,7 @@ module VagrantPlugins
58
66
 
59
67
  # Notify the user
60
68
  raise Errors::InstanceReadyTimeout,
61
- timeout: provider_config.instance_ready_timeout
69
+ timeout: region_config.instance_ready_timeout
62
70
  end
63
71
  end
64
72
 
@@ -11,15 +11,11 @@ module VagrantPlugins
11
11
  end
12
12
 
13
13
  def call(env)
14
+ server = env[:script].servers.get(env[:machine].id)
15
+
14
16
  # Destroy the server and remove the tracking ID
15
17
  env[:ui].info(I18n.t("vagrant_shell.terminating"))
16
- output = %x{ #{env[:machine].provider_config.script} terminate-instance #{env[:machine].id}}
17
- if $?.to_i > 0
18
- raise Errors::ShellError, :message => "Failure: #{env[:machine].provider_config.script} terminate-instance #{env[:machine].id}"
19
- end
20
-
21
- puts output
22
-
18
+ server.destroy
23
19
  env[:machine].id = nil
24
20
 
25
21
  @app.call(env)
@@ -3,41 +3,71 @@ require "vagrant"
3
3
  module VagrantPlugins
4
4
  module Shell
5
5
  class Config < Vagrant.plugin("2", :config)
6
- # The ID of the Image to use.
7
- #
8
- # @return [String]
9
- attr_accessor :image
10
6
 
11
7
  # The timeout to wait for an instance to become ready.
12
8
  #
13
9
  # @return [Fixnum]
14
10
  attr_accessor :instance_ready_timeout
15
11
 
12
+
16
13
  # The user data string
17
14
  #
18
15
  # @return [String]
19
16
  attr_accessor :user_data
20
17
 
18
+ # The ID of the Image to use.
19
+ attr_accessor :image
20
+
21
21
  # The shell script implementing some tech
22
- #
23
- # @return [String]
24
22
  attr_accessor :script
25
23
 
26
24
  # The shell script run-instance args
27
- #
28
- # @return [String]
29
25
  attr_accessor :run_args
30
26
 
31
- def initialize
32
- @image = UNSET_VALUE
27
+ def initialize(region_specific=false)
33
28
  @instance_ready_timeout = UNSET_VALUE
34
29
  @user_data = UNSET_VALUE
30
+ @image = UNSET_VALUE
35
31
  @script = UNSET_VALUE
36
32
  @run_args = UNSET_VALUE
37
33
 
38
34
  # Internal state (prefix with __ so they aren't automatically
39
35
  # merged)
36
+ @__compiled_region_configs = {}
40
37
  @__finalized = false
38
+ @__region_config = {}
39
+ @__region_specific = region_specific
40
+ end
41
+
42
+ # Allows region-specific overrides of any of the settings on this
43
+ # configuration object. This allows the user to override things like
44
+ # AMI and keypair name for regions. Example:
45
+ #
46
+ # aws.region_config "us-east-1" do |region|
47
+ # region.ami = "ami-12345678"
48
+ # region.keypair_name = "company-east"
49
+ # end
50
+ #
51
+ # @param [String] region The region name to configure.
52
+ # @param [Hash] attributes Direct attributes to set on the configuration
53
+ # as a shortcut instead of specifying a full block.
54
+ # @yield [config] Yields a new Shell configuration.
55
+ def region_config(region, attributes=nil, &block)
56
+ # Append the block to the list of region configs for that region.
57
+ # We'll evaluate these upon finalization.
58
+ @__region_config[region] ||= []
59
+
60
+ # Append a block that sets attributes if we got one
61
+ if attributes
62
+ attr_block = lambda do |config|
63
+ config.set_options(attributes)
64
+ end
65
+
66
+ @__region_config[region] << attr_block
67
+ end
68
+
69
+ # Append a block if we got one
70
+ @__region_config[region] << block if block_given?
41
71
  end
42
72
 
43
73
  #-------------------------------------------------------------------
@@ -46,31 +76,102 @@ module VagrantPlugins
46
76
 
47
77
  def merge(other)
48
78
  super.tap do |result|
79
+ # Copy over the region specific flag. "True" is retained if either
80
+ # has it.
81
+ new_region_specific = other.instance_variable_get(:@__region_specific)
82
+ result.instance_variable_set(
83
+ :@__region_specific, new_region_specific || @__region_specific)
84
+
85
+ # Go through all the region configs and prepend ours onto
86
+ # theirs.
87
+ new_region_config = other.instance_variable_get(:@__region_config)
88
+ @__region_config.each do |key, value|
89
+ new_region_config[key] ||= []
90
+ new_region_config[key] = value + new_region_config[key]
91
+ end
92
+
93
+ # Set it
94
+ result.instance_variable_set(:@__region_config, new_region_config)
95
+
96
+ # Merge in the tags
97
+ result.tags.merge!(self.tags)
98
+ result.tags.merge!(other.tags)
49
99
  end
50
100
  end
51
101
 
52
102
  def finalize!
53
- # Image must be nil, since we can't default that
54
- @image = nil if @image == UNSET_VALUE
55
-
56
103
  # Set the default timeout for waiting for an instance to be ready
57
104
  @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE
58
105
 
59
106
  # User Data is nil by default
60
107
  @user_data = nil if @user_data == UNSET_VALUE
61
108
 
109
+ # Image must be nil, since we can't default that
110
+ @image = nil if @image == UNSET_VALUE
111
+
62
112
  # No default shell script
63
113
  @script = nil if @script == UNSET_VALUE
64
114
 
65
- # No rub args by default
115
+ # No run args by default
66
116
  @run_args = [] if @run_args == UNSET_VALUE
67
117
 
118
+ # Compile our region specific configurations only within
119
+ # NON-REGION-SPECIFIC configurations.
120
+ if !@__region_specific
121
+ @__region_config.each do |region, blocks|
122
+ config = self.class.new(true).merge(self)
123
+
124
+ # Execute the configuration for each block
125
+ blocks.each { |b| b.call(config) }
126
+
127
+ # The region name of the configuration always equals the
128
+ # region config name:
129
+ config.region = region
130
+
131
+ # Finalize the configuration
132
+ config.finalize!
133
+
134
+ # Store it for retrieval
135
+ @__compiled_region_configs[region] = config
136
+ end
137
+ end
138
+
68
139
  # Mark that we finalized
69
140
  @__finalized = true
70
141
  end
71
142
 
72
143
  def validate(machine)
73
- { "Shell Provider" => [ ] }
144
+ errors = _detected_errors
145
+
146
+ errors << I18n.t("vagrant_shell.config.region_required") if @region.nil?
147
+
148
+ if @region
149
+ # Get the configuration for the region we're using and validate only
150
+ # that region.
151
+ config = get_region_config(@region)
152
+
153
+ if !config.use_iam_profile
154
+ errors << I18n.t("vagrant_shell.config.access_key_id_required") if \
155
+ config.access_key_id.nil?
156
+ errors << I18n.t("vagrant_shell.config.secret_access_key_required") if \
157
+ config.secret_access_key.nil?
158
+ end
159
+
160
+ errors << I18n.t("vagrant_shell.config.ami_required") if config.ami.nil?
161
+ end
162
+
163
+ { "Shell Provider" => errors }
164
+ end
165
+
166
+ # This gets the configuration for a specific region. It shouldn't
167
+ # be called by the general public and is only used internally.
168
+ def get_region_config(name)
169
+ if !@__finalized
170
+ raise "Configuration must be finalized before calling this method."
171
+ end
172
+
173
+ # Return the compiled region config
174
+ @__compiled_region_configs[name] || self
74
175
  end
75
176
 
76
177
  # utilities
@@ -89,7 +190,6 @@ module VagrantPlugins
89
190
  return try_load
90
191
  end
91
192
  end
92
-
93
193
  end
94
194
  end
95
195
  end
@@ -11,16 +11,20 @@ module VagrantPlugins
11
11
  error_key(:shell_error)
12
12
  end
13
13
 
14
- class TimeoutError < VagrantShellError
15
- error_key(:instance_ready_timeout)
14
+ class InternalShellError < VagrantShellError
15
+ error_key(:internal_shell_error)
16
16
  end
17
17
 
18
- class ComputeError < VagrantShellError
18
+ class InstanceReadyTimeout < VagrantShellError
19
19
  error_key(:instance_ready_timeout)
20
20
  end
21
21
 
22
- class InstanceReadyTimeout < VagrantShellError
23
- error_key(:instance_ready_timeout)
22
+ class RsyncError < VagrantShellError
23
+ error_key(:rsync_error)
24
+ end
25
+
26
+ class MkdirError < VagrantShellError
27
+ error_key(:mkdir_error)
24
28
  end
25
29
  end
26
30
  end
@@ -18,14 +18,13 @@ module VagrantPlugins
18
18
  This plugin installs a provider that allows Vagrant to manage
19
19
  machines with shell scripts.
20
20
  DESC
21
-
22
21
  def self.make_provider nm_provider
23
22
  config(nm_provider, :provider) do
24
23
  require_relative "config"
25
24
  Config
26
25
  end
27
26
 
28
- provider(nm_provider) do
27
+ provider(nm_provider, parallel: true) do
29
28
  # Setup logging and i18n
30
29
  setup_logging
31
30
  setup_i18n
@@ -36,8 +35,6 @@ module VagrantPlugins
36
35
  end
37
36
  end
38
37
 
39
- make_provider(:shell)
40
-
41
38
  # This initializes the internationalization strings.
42
39
  def self.setup_i18n
43
40
  I18n.load_path << File.expand_path("locales/en.yml", Shell.source_root)
data/libexec/shell-docker CHANGED
@@ -20,11 +20,18 @@ case "$cmd" in
20
20
  ;;
21
21
  ssh-info)
22
22
  instance="$1"; shift
23
- echo "$(docker inspect $instance | awk '$1 ~ /IPAddress/ { split($2,ip,"\""); print ip[2] }')" 22
23
+ echo "$(docker inspect -format '{{.NetworkSettings.IPAddress}}' $instance)" 22
24
24
  ;;
25
25
  read-state)
26
26
  instance="$1"; shift
27
- echo "$(docker inspect $instance | awk '$1 ~ /Running/ { split($2,state,","); print(state[1] == "true" ? "running" : "not_created") }')"
27
+ case "$(docker inspect -tformat '{{.State.Running}}' $instance)" in
28
+ true)
29
+ echo running
30
+ ;;
31
+ *)
32
+ echo not_created
33
+ ;;
34
+ esac
28
35
  ;;
29
36
  *)
30
37
  exit 1
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
5
- prerelease:
4
+ version: 0.2.14
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tom Bombadil
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-07-22 00:00:00.000000000 Z
12
+ date: 2014-01-17 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Enables Vagrant to manage machines using shell scripts
16
15
  email:
@@ -20,9 +19,11 @@ executables: []
20
19
  extensions: []
21
20
  extra_rdoc_files: []
22
21
  files:
22
+ - lib/vagrant-shell/action/connect_shell.rb
23
23
  - lib/vagrant-shell/action/is_created.rb
24
24
  - lib/vagrant-shell/action/message_already_created.rb
25
25
  - lib/vagrant-shell/action/message_not_created.rb
26
+ - lib/vagrant-shell/action/message_will_not_destroy.rb
26
27
  - lib/vagrant-shell/action/read_ssh_info.rb
27
28
  - lib/vagrant-shell/action/read_state.rb
28
29
  - lib/vagrant-shell/action/run_instance.rb
@@ -47,26 +48,25 @@ files:
47
48
  - VERSION
48
49
  homepage: http://destructuring.org/vagrant-shell
49
50
  licenses: []
51
+ metadata: {}
50
52
  post_install_message:
51
53
  rdoc_options: []
52
54
  require_paths:
53
55
  - lib
54
56
  required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
57
  requirements:
57
58
  - - ! '>='
58
59
  - !ruby/object:Gem::Version
59
60
  version: '0'
60
61
  required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
62
  requirements:
63
63
  - - ! '>='
64
64
  - !ruby/object:Gem::Version
65
65
  version: 1.3.6
66
66
  requirements: []
67
67
  rubyforge_project: vagrant-shell
68
- rubygems_version: 1.8.25
68
+ rubygems_version: 2.1.11
69
69
  signing_key:
70
- specification_version: 3
70
+ specification_version: 4
71
71
  summary: Enables Vagrant to manage machines using shell scripts
72
72
  test_files: []