vagrant-digitalocean 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.2.7'
3
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.4.0'
4
4
  gem 'vagrant-omnibus'
5
5
  gem 'rake'
6
6
  gemspec
@@ -17,9 +17,14 @@ module VagrantPlugins
17
17
  # submit destroy droplet request
18
18
  result = @client.request("/droplets/#{@machine.id}/destroy")
19
19
 
20
- # wait for request to complete
21
- env[:ui].info I18n.t('vagrant_digital_ocean.info.destroying')
22
- @client.wait_for_event(env, result['event_id'])
20
+ env[:ui].info I18n.t('vagrant_digital_ocean.info.destroying')
21
+
22
+ # wait for destroy request to make progress before exiting
23
+ @client.wait_for_event(env, result['event_id']) do |response|
24
+ if response['event']['percentage'] != nil
25
+ return
26
+ end
27
+ end
23
28
 
24
29
  # set the machine id to nil to cleanup local vagrant state
25
30
  @machine.id = nil
@@ -5,6 +5,7 @@ module VagrantPlugins
5
5
  module Actions
6
6
  class Rebuild
7
7
  include Helpers::Client
8
+ include Vagrant::Util::Retryable
8
9
 
9
10
  def initialize(app, env)
10
11
  @app = app
@@ -31,6 +32,18 @@ module VagrantPlugins
31
32
  # refresh droplet state with provider
32
33
  Provider.droplet(@machine, :refresh => true)
33
34
 
35
+ # wait for ssh to be ready
36
+ switch_user = @machine.provider_config.setup?
37
+ user = @machine.config.ssh.username
38
+ @machine.config.ssh.username = 'root' if switch_user
39
+
40
+ retryable(:tries => 120, :sleep => 10) do
41
+ next if env[:interrupted]
42
+ raise 'not ready' if !@machine.communicate.ready?
43
+ end
44
+
45
+ @machine.config.ssh.username = user
46
+
34
47
  @app.call(env)
35
48
  end
36
49
  end
@@ -38,6 +38,7 @@ module VagrantPlugins
38
38
  def create_ssh_key(name, env)
39
39
  # assumes public key exists on the same path as private key with .pub ext
40
40
  path = @machine.config.ssh.private_key_path
41
+ path = path[0] if path.is_a?(Array)
41
42
  path = File.expand_path(path, @machine.env.root_path)
42
43
  pub_key = DigitalOcean.public_key(path)
43
44
 
@@ -25,7 +25,7 @@ module VagrantPlugins
25
25
 
26
26
  # create user account
27
27
  @machine.communicate.execute(<<-BASH)
28
- if ! (grep #{user} /etc/passwd); then
28
+ if ! (grep ^#{user}: /etc/passwd); then
29
29
  useradd -m -s /bin/bash #{user};
30
30
  fi
31
31
  BASH
@@ -34,6 +34,8 @@ module VagrantPlugins
34
34
  @machine.communicate.execute(<<-BASH)
35
35
  if ! (grep #{user} /etc/sudoers); then
36
36
  echo "#{user} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers;
37
+ else
38
+ sed -i -e "/#{user}/ s/=.*/=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers;
37
39
  fi
38
40
  BASH
39
41
 
@@ -42,6 +44,7 @@ module VagrantPlugins
42
44
 
43
45
  # add the specified key to the authorized keys file
44
46
  path = @machine.config.ssh.private_key_path
47
+ path = path[0] if path.is_a?(Array)
45
48
  path = File.expand_path(path, @machine.env.root_path)
46
49
  pub_key = DigitalOcean.public_key(path)
47
50
  @machine.communicate.execute(<<-BASH)
@@ -44,10 +44,13 @@ module VagrantPlugins
44
44
  @machine.communicate.sudo(
45
45
  "chown -R #{ssh_info[:username]} #{guestpath}")
46
46
 
47
+ key = ssh_info[:private_key_path]
48
+ key = key[0] if key.is_a?(Array)
49
+
47
50
  # rsync over to the guest path using the ssh info
48
51
  command = [
49
52
  "rsync", "--verbose", "--archive", "-z", "--delete",
50
- "-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i '#{ssh_info[:private_key_path]}'",
53
+ "-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i '#{key}'",
51
54
  hostpath,
52
55
  "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
53
56
 
@@ -43,6 +43,7 @@ module VagrantPlugins
43
43
  errors << I18n.t('vagrant_digital_ocean.config.api_key') if !@api_key
44
44
 
45
45
  key = machine.config.ssh.private_key_path
46
+ key = key[0] if key.is_a?(Array)
46
47
  if !key
47
48
  errors << I18n.t('vagrant_digital_ocean.config.private_key')
48
49
  elsif !File.file?(File.expand_path("#{key}.pub", machine.env.root_path))
@@ -15,6 +15,7 @@ module VagrantPlugins
15
15
  include Vagrant::Util::Retryable
16
16
 
17
17
  def initialize(machine)
18
+ @logger = Log4r::Logger.new('vagrant::digitalocean::apiclient')
18
19
  @config = machine.provider_config
19
20
  @client = Faraday.new({
20
21
  :url => 'https://api.digitalocean.com/',
@@ -26,6 +27,7 @@ module VagrantPlugins
26
27
 
27
28
  def request(path, params = {})
28
29
  begin
30
+ @logger.info "Request: #{path}"
29
31
  result = @client.get(path, params = params.merge({
30
32
  :client_id => @config.client_id,
31
33
  :api_key => @config.api_key
@@ -46,6 +48,7 @@ module VagrantPlugins
46
48
 
47
49
  begin
48
50
  body = JSON.parse(result.body)
51
+ @logger.info "Response: #{body}"
49
52
  rescue JSON::ParserError => e
50
53
  raise(Errors::JSONError, {
51
54
  :message => e.message,
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module DigitalOcean
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-digitalocean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-06 00:00:00.000000000 Z
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -115,12 +115,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -3657554704749346690
118
121
  required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  none: false
120
123
  requirements:
121
124
  - - ! '>='
122
125
  - !ruby/object:Gem::Version
123
126
  version: '0'
127
+ segments:
128
+ - 0
129
+ hash: -3657554704749346690
124
130
  requirements: []
125
131
  rubyforge_project:
126
132
  rubygems_version: 1.8.23