Skip to content

Commit 4b245e3

Browse files
authored
Merge pull request #151 from Temikus/cleanup_fix
Cleanup fix
2 parents 46cce29 + 30e677c commit 4b245e3

14 files changed

+38
-46
lines changed

.ruby-version

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
2.0.0-p598
1+
2.2.3
2+
# Tracking Vagrant 1.8.5

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ group :development do
2020
# We depend on Vagrant for development, but we don't add it as a
2121
# gem dependency because we expect to be installed within the
2222
# Vagrant environment itself using `vagrant plugin`.
23-
gem 'vagrant', git: "git://github.com/mitchellh/vagrant.git"
23+
gem 'vagrant', git: "https://github.com/mitchellh/vagrant.git"
2424
gem 'vagrant-spec', git: "https://github.com/mitchellh/vagrant-spec.git"
2525
end
2626

README.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,15 @@ Service Account for API Access.
7575
## Quick Start
7676

7777
After installing the plugin (instructions above), the quickest way to get
78-
started is to actually use a dummy Google box and specify all the details
79-
manually within a `config.vm.provider` block. So first, add the Google box
80-
using any name you want:
78+
started is to actually use a dummy Google box from Atlas and specify all the
79+
details manually within a `config.vm.provider` block.
8180

82-
```sh
83-
$ vagrant box add gce https://github.com/mitchellh/vagrant-google/raw/master/google.box
84-
...
85-
```
86-
87-
And then make a Vagrantfile that looks like the following, filling in
88-
your information where necessary.
81+
So first, make a Vagrantfile that looks like the following, filling in
82+
your information where necessary:
8983

9084
```ruby
9185
Vagrant.configure("2") do |config|
92-
config.vm.box = "gce"
86+
config.vm.box = "google/gce"
9387

9488
config.vm.provider :google do |google, override|
9589
google.google_project_id = "YOUR_GOOGLE_CLOUD_PROJECT_ID"
@@ -229,7 +223,7 @@ zone you want to actually use, however. This looks like this:
229223
```ruby
230224
Vagrant.configure("2") do |config|
231225

232-
config.vm.box = "gce"
226+
config.vm.box = "google/gce"
233227

234228
config.vm.provider :google do |google|
235229
google.google_project_id = "YOUR_GOOGLE_CLOUD_PROJECT_ID"
@@ -241,7 +235,7 @@ Vagrant.configure("2") do |config|
241235

242236
google.zone_config "us-central1-f" do |zone1f|
243237
zone1f.name = "testing-vagrant"
244-
zone1f.image = "debian-8-jessie-v20160511"
238+
zone1f.image = "debian-8-jessie-v20160923"
245239
zone1f.machine_type = "n1-standard-4"
246240
zone1f.zone = "us-central1-f"
247241
zone1f.metadata = {'custom' => 'metadata', 'testing' => 'foobarbaz'}

lib/vagrant-google/action/assign_instance_groups.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class AssignInstanceGroups
2525
def initialize(app, env)
2626
@app = app
2727
@logger = Log4r::Logger.new(
28-
"vagrant_google::action::assign_instance_groups")
28+
"vagrant_google::action::assign_instance_groups"
29+
)
2930
end
3031

3132
def call(env)
@@ -58,7 +59,8 @@ def call(env)
5859
)
5960
unless response.body["status"] == "DONE"
6061
operation = env[:google_compute].operations.get(
61-
operation.body["name"], zone)
62+
operation.body["name"], zone
63+
)
6264
env[:ui].info(I18n.t("vagrant_google.waiting_for_operation",
6365
name: operation.body["name"]))
6466
operation.wait_for { ready? }

lib/vagrant-google/action/run_instance.rb

+4-13
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
111111
zone_name: zone,
112112
source_image: image
113113
)
114-
disk_created_by_vagrant = true
115114
disk.wait_for { disk.ready? }
115+
disk_created_by_vagrant = true
116116
end
117117
end
118118

@@ -137,11 +137,9 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
137137
server = env[:google_compute].servers.create(defaults)
138138
@logger.info("Machine '#{zone}:#{name}' created.")
139139
rescue *FOG_ERRORS => e
140-
# there is a chance Google responded with error but actually created
141-
# instance, so we need to remove it
142-
cleanup_instance(env)
143-
# there is a chance Google has failed to create instance, so we need
144-
# to remove created disk
140+
# TODO: Cleanup the Fog catch-all once Fog implements better exceptions
141+
# There is a chance Google has failed to create an instance, so we need
142+
# to clean up the created disk.
145143
cleanup_disk(disk.name, env) if disk && disk_created_by_vagrant
146144
raise Errors::FogError, :message => e.message
147145
end
@@ -223,13 +221,6 @@ def get_external_ip(env, external_ip)
223221
address.address
224222
end
225223

226-
def cleanup_instance(env)
227-
zone = env[:machine].provider_config.zone
228-
zone_config = env[:machine].provider_config.get_zone_config(zone)
229-
server = env[:google_compute].servers.get(zone_config.name, zone)
230-
server.destroy(false) if server
231-
end
232-
233224
def cleanup_disk(disk_name, env)
234225
zone = env[:machine].provider_config.zone
235226
autodelete_disk = env[:machine].provider_config.get_zone_config(zone).autodelete_disk

lib/vagrant-google/action/sync_folders.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def call(env) # rubocop:disable Metrics/MethodLength
6464
# Create the guest path
6565
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
6666
env[:machine].communicate.sudo(
67-
"chown #{ssh_info[:username]} '#{guestpath}'")
67+
"chown #{ssh_info[:username]} '#{guestpath}'"
68+
)
6869

6970
# patch from https://github.com/tmatilai/vagrant-aws/commit/4a043a96076c332220ec4ec19470c4af5597dd51
7071
def ssh_key_options(ssh_info)
@@ -81,7 +82,8 @@ def ssh_key_options(ssh_info)
8182
*excludes.map{|e| ['--exclude', e]}.flatten,
8283
"-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}",
8384
hostpath,
84-
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
85+
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"
86+
]
8587

8688
# we need to fix permissions when using rsync.exe on windows, see
8789
# http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
@@ -90,7 +92,7 @@ def ssh_key_options(ssh_info)
9092
end
9193

9294
r = Vagrant::Util::Subprocess.execute(*command)
93-
if r.exit_code != 0
95+
if r.exit_code.nonzero?
9496
raise Errors::RsyncError,
9597
:guestpath => guestpath,
9698
:hostpath => hostpath,

lib/vagrant-google/config.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def merge(other)
214214
# has it.
215215
new_zone_specific = other.instance_variable_get(:@__zone_specific)
216216
result.instance_variable_set(
217-
:@__zone_specific, new_zone_specific || @__zone_specific)
217+
:@__zone_specific, new_zone_specific || @__zone_specific
218+
)
218219

219220
# Go through all the zone configs and prepend ours onto
220221
# theirs.

lib/vagrant-google/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
# limitations under the License.
1414
module VagrantPlugins
1515
module Google
16-
VERSION = "0.2.4".freeze
16+
VERSION = "0.2.5".freeze
1717
end
1818
end

tasks/acceptance.rake

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ namespace :acceptance do
4949
if File.read(ENV["GOOGLE_SSH_KEY_LOCATION"]).include?('ENCRYPTED')
5050
unless `ssh-add -L`.include?(ENV["GOOGLE_SSH_KEY_LOCATION"])
5151
yellow "WARNING: It looks like ssh key is encrypted and ssh-agent doesn't contain any identities."
52-
yellow "This will likely cause the connection to the machine to fail."
52+
puts "Trying to add identity, executing ssh-add..."
53+
system("ssh-add #{ENV["GOOGLE_SSH_KEY_LOCATION"]}")
5354
end
5455
end
5556
end

test/acceptance/skeletons/scopes/Vagrantfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ Vagrant.configure("2") do |config|
99
zone1d.name = "vagrant-acceptance-scopes-#{('a'..'z').to_a.sample(8).join}"
1010
zone1d.scopes = ['sql-admin',
1111
'bigquery',
12-
'https://www.googleapis.com/auth/compute'
13-
]
12+
'https://www.googleapis.com/auth/compute']
1413
zone1d.disk_type = "pd-ssd"
1514
end
1615
end

vagrant-google.gemspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ Gem::Specification.new do |s|
2828
s.required_rubygems_version = ">= 1.3.6"
2929
s.rubyforge_project = "vagrant-google"
3030

31-
s.add_runtime_dependency "fog-google", "~> 0.2.0"
31+
s.add_runtime_dependency "fog-google", "~> 0.4.0"
3232
s.add_runtime_dependency "google-api-client", "< 0.9", ">= 0.6.2"
3333

3434
s.add_development_dependency "pry"
3535
s.add_development_dependency "pry-byebug"
3636
s.add_development_dependency "rake"
3737
s.add_development_dependency "rspec", "~> 2.14"
3838
s.add_development_dependency "rubocop", "~> 0.35"
39+
s.add_development_dependency "highline"
3940

4041
# The following block of code determines the files that should be included
4142
# in the gem. It does this by reading all the files in the directory where

vagrantfile_examples/Vagrantfile.multiple_machines

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cat /etc/motd
4848
SCRIPT
4949

5050
Vagrant.configure("2") do |config|
51-
config.vm.box = "gce"
51+
config.vm.box = "google/gce"
5252
config.vm.provision :shell, :inline => $PROVISION_DEBIAN
5353

5454
config.vm.define :z1c do |z1c|
@@ -63,7 +63,7 @@ Vagrant.configure("2") do |config|
6363

6464
google.zone_config "us-central1-c" do |z1c_zone|
6565
z1c_zone.name = "z1c"
66-
z1c_zone.image = "debian-8-jessie-v20160511"
66+
z1c_zone.image = "debian-8-jessie-v20160923"
6767
z1c_zone.machine_type = "n1-standard-1"
6868
z1c_zone.zone = "us-central1-c"
6969
z1c_zone.metadata = {"zone" => "US Central 1c"}
@@ -83,7 +83,7 @@ Vagrant.configure("2") do |config|
8383

8484
google.zone_config "us-central1-f" do |z1f_zone|
8585
z1f_zone.name = "z1f"
86-
z1f_zone.image = "debian-8-jessie-v20160511"
86+
z1f_zone.image = "debian-8-jessie-v20160923"
8787
z1f_zone.machine_type = "n1-standard-2"
8888
z1f_zone.zone = "us-central1-f"
8989
z1f_zone.metadata = {"zone" => "US Central 1f"}

vagrantfile_examples/Vagrantfile.provision_single

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $LOCAL_SSH_KEY = "~/.ssh/id_rsa"
2727

2828
Vagrant.configure("2") do |config|
2929

30-
config.vm.box = "gce"
30+
config.vm.box = "google/gce"
3131

3232
config.vm.provider :google do |google, override|
3333
google.google_project_id = $GOOGLE_PROJECT_ID
@@ -36,7 +36,7 @@ Vagrant.configure("2") do |config|
3636

3737
# Override provider defaults
3838
google.name = "testing-vagrant"
39-
google.image = "debian-8-jessie-v20160511"
39+
google.image = "debian-8-jessie-v20160923"
4040
google.machine_type = "n1-standard-1"
4141
google.zone = "us-central1-f"
4242
google.metadata = {'custom' => 'metadata', 'testing' => 'foobarbaz'}

vagrantfile_examples/Vagrantfile.zone_config

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
Vagrant.configure("2") do |config|
18-
config.vm.box = "gce"
18+
config.vm.box = "google/gce"
1919

2020
config.vm.provider :google do |google, override|
2121
google.google_project_id = "YOUR_GOOGLE_CLOUD_PROJECT_ID"
@@ -30,7 +30,7 @@ Vagrant.configure("2") do |config|
3030

3131
google.zone_config "us-central1-f" do |zone1a|
3232
zone1a.name = "testing-vagrant"
33-
zone1a.image = "debian-8-jessie-v20160511"
33+
zone1a.image = "debian-8-jessie-v20160923"
3434
zone1a.machine_type = "n1-standard-4"
3535
zone1a.zone = "us-central1-f"
3636
zone1a.scopes = ['bigquery', 'monitoring', 'https://www.googleapis.com/auth/compute']

0 commit comments

Comments
 (0)