tcr-vagrant-google 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/CHANGELOG.md +20 -0
- data/CONTRIB.md +64 -0
- data/Gemfile +24 -0
- data/LICENSE +201 -0
- data/README.md +237 -0
- data/Rakefile +35 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/google.box +0 -0
- data/lib/vagrant-google.rb +31 -0
- data/lib/vagrant-google/action.rb +140 -0
- data/lib/vagrant-google/action/connect_google.rb +49 -0
- data/lib/vagrant-google/action/is_created.rb +31 -0
- data/lib/vagrant-google/action/message_already_created.rb +29 -0
- data/lib/vagrant-google/action/message_not_created.rb +29 -0
- data/lib/vagrant-google/action/message_will_not_destroy.rb +29 -0
- data/lib/vagrant-google/action/read_ssh_info.rb +54 -0
- data/lib/vagrant-google/action/read_state.rb +59 -0
- data/lib/vagrant-google/action/run_instance.rb +145 -0
- data/lib/vagrant-google/action/sync_folders.rb +87 -0
- data/lib/vagrant-google/action/terminate_instance.rb +40 -0
- data/lib/vagrant-google/action/timed_provision.rb +34 -0
- data/lib/vagrant-google/action/warn_networks.rb +32 -0
- data/lib/vagrant-google/config.rb +265 -0
- data/lib/vagrant-google/errors.rb +32 -0
- data/lib/vagrant-google/plugin.rb +86 -0
- data/lib/vagrant-google/provider.rb +63 -0
- data/lib/vagrant-google/util/timer.rb +30 -0
- data/lib/vagrant-google/version.rb +18 -0
- data/locales/en.yml +105 -0
- data/spec/vagrant-google/config_spec.rb +202 -0
- data/tcr-vagrant-google.gemspec +75 -0
- metadata +173 -0
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'bundler/setup'
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
|
19
|
+
# Immediately sync all stdout so that tools like buildbot can
|
20
|
+
# immediately load in the output.
|
21
|
+
$stdout.sync = true
|
22
|
+
$stderr.sync = true
|
23
|
+
|
24
|
+
# Change to the directory of this file.
|
25
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
26
|
+
|
27
|
+
# This installs the tasks that help with gem creation and
|
28
|
+
# publishing.
|
29
|
+
Bundler::GemHelper.install_tasks
|
30
|
+
|
31
|
+
# Install the `spec` task so that we can run tests.
|
32
|
+
RSpec::Core::RakeTask.new
|
33
|
+
|
34
|
+
# Default task is to run the unit tests
|
35
|
+
task :default => "spec"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Vagrant Google Example Box
|
2
|
+
|
3
|
+
Vagrant providers each require a custom provider-specific box format.
|
4
|
+
This folder shows the example contents of a box for the `google` provider.
|
5
|
+
To turn this into a box:
|
6
|
+
|
7
|
+
```
|
8
|
+
$ tar cvzf ../google.box ./metadata.json ./Vagrantfile
|
9
|
+
```
|
10
|
+
|
11
|
+
This box works by using Vagrant's built-in Vagrantfile merging to setup
|
12
|
+
defaults for Google. These defaults can easily be overwritten by higher-level
|
13
|
+
Vagrantfiles (such as project root Vagrantfiles).
|
data/google.box
ADDED
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "pathname"
|
16
|
+
require "vagrant-google/plugin"
|
17
|
+
|
18
|
+
module VagrantPlugins
|
19
|
+
module Google
|
20
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-google", __FILE__))
|
21
|
+
autoload :Action, lib_path.join("action")
|
22
|
+
autoload :Errors, lib_path.join("errors")
|
23
|
+
|
24
|
+
# This returns the path to the source of this plugin.
|
25
|
+
#
|
26
|
+
# @return [Pathname]
|
27
|
+
def self.source_root
|
28
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require "vagrant/action/builder"
|
15
|
+
|
16
|
+
module VagrantPlugins
|
17
|
+
module Google
|
18
|
+
module Action
|
19
|
+
# Include the built-in modules so we can use them as top-level things.
|
20
|
+
include Vagrant::Action::Builtin
|
21
|
+
|
22
|
+
# This action is called to terminate the remote machine.
|
23
|
+
def self.action_destroy
|
24
|
+
Vagrant::Action::Builder.new.tap do |b|
|
25
|
+
b.use Call, DestroyConfirm do |env, b2|
|
26
|
+
if env[:result]
|
27
|
+
b2.use ConfigValidate
|
28
|
+
b2.use ConnectGoogle
|
29
|
+
b2.use TerminateInstance
|
30
|
+
else
|
31
|
+
b2.use MessageWillNotDestroy
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# This action is called when `vagrant provision` is called.
|
38
|
+
def self.action_provision
|
39
|
+
Vagrant::Action::Builder.new.tap do |b|
|
40
|
+
b.use ConfigValidate
|
41
|
+
b.use Call, IsCreated do |env, b2|
|
42
|
+
if !env[:result]
|
43
|
+
b2.use MessageNotCreated
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
b2.use Provision
|
48
|
+
b2.use SyncFolders
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# This action is called to read the SSH info of the machine. The
|
54
|
+
# resulting state is expected to be put into the `:machine_ssh_info`
|
55
|
+
# key.
|
56
|
+
def self.action_read_ssh_info
|
57
|
+
Vagrant::Action::Builder.new.tap do |b|
|
58
|
+
b.use ConfigValidate
|
59
|
+
b.use ConnectGoogle
|
60
|
+
b.use ReadSSHInfo
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# This action is called to read the state of the machine. The
|
65
|
+
# resulting state is expected to be put into the `:machine_state_id`
|
66
|
+
# key.
|
67
|
+
def self.action_read_state
|
68
|
+
Vagrant::Action::Builder.new.tap do |b|
|
69
|
+
b.use ConfigValidate
|
70
|
+
b.use ConnectGoogle
|
71
|
+
b.use ReadState
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# This action is called to SSH into the machine.
|
76
|
+
def self.action_ssh
|
77
|
+
Vagrant::Action::Builder.new.tap do |b|
|
78
|
+
b.use ConfigValidate
|
79
|
+
b.use Call, IsCreated do |env, b2|
|
80
|
+
if !env[:result]
|
81
|
+
b2.use MessageNotCreated
|
82
|
+
next
|
83
|
+
end
|
84
|
+
|
85
|
+
b2.use SSHExec
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.action_ssh_run
|
91
|
+
Vagrant::Action::Builder.new.tap do |b|
|
92
|
+
b.use ConfigValidate
|
93
|
+
b.use Call, IsCreated do |env, b2|
|
94
|
+
if !env[:result]
|
95
|
+
b2.use MessageNotCreated
|
96
|
+
next
|
97
|
+
end
|
98
|
+
|
99
|
+
b2.use SSHRun
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# This action is called to bring the box up from nothing.
|
105
|
+
def self.action_up
|
106
|
+
Vagrant::Action::Builder.new.tap do |b|
|
107
|
+
b.use HandleBox
|
108
|
+
b.use ConfigValidate
|
109
|
+
b.use ConnectGoogle
|
110
|
+
b.use Call, IsCreated do |env, b2|
|
111
|
+
if env[:result]
|
112
|
+
b2.use MessageAlreadyCreated
|
113
|
+
next
|
114
|
+
end
|
115
|
+
|
116
|
+
b2.use Provision
|
117
|
+
b2.use SyncFolders
|
118
|
+
b2.use WarnNetworks
|
119
|
+
b2.use RunInstance
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# The autoload farm
|
125
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
126
|
+
autoload :ConnectGoogle, action_root.join("connect_google")
|
127
|
+
autoload :IsCreated, action_root.join("is_created")
|
128
|
+
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
|
129
|
+
autoload :MessageNotCreated, action_root.join("message_not_created")
|
130
|
+
autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
|
131
|
+
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
132
|
+
autoload :ReadState, action_root.join("read_state")
|
133
|
+
autoload :RunInstance, action_root.join("run_instance")
|
134
|
+
autoload :SyncFolders, action_root.join("sync_folders")
|
135
|
+
autoload :TimedProvision, action_root.join("timed_provision")
|
136
|
+
autoload :WarnNetworks, action_root.join("warn_networks")
|
137
|
+
autoload :TerminateInstance, action_root.join("terminate_instance")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require "fog"
|
15
|
+
require "log4r"
|
16
|
+
|
17
|
+
module VagrantPlugins
|
18
|
+
module Google
|
19
|
+
module Action
|
20
|
+
# This action connects to Google, verifies credentials work, and
|
21
|
+
# puts the Google connection object into the `:google_compute` key
|
22
|
+
# in the environment.
|
23
|
+
class ConnectGoogle
|
24
|
+
def initialize(app, env)
|
25
|
+
@app = app
|
26
|
+
@logger = Log4r::Logger.new("vagrant_google::action::connect_google")
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(env)
|
30
|
+
provider_config = env[:machine].provider_config
|
31
|
+
|
32
|
+
# Build the fog config
|
33
|
+
fog_config = {
|
34
|
+
:provider => :google,
|
35
|
+
:google_project => provider_config.google_project_id,
|
36
|
+
:google_client_email => provider_config.google_client_email,
|
37
|
+
:google_key_location => provider_config.google_key_location
|
38
|
+
}
|
39
|
+
|
40
|
+
@logger.info("Connecting to Google...")
|
41
|
+
env[:google_compute] = Fog::Compute.new(fog_config)
|
42
|
+
|
43
|
+
@app.call(env)
|
44
|
+
@logger.info("...Connected!")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
module VagrantPlugins
|
15
|
+
module Google
|
16
|
+
module Action
|
17
|
+
# This can be used with "Call" built-in to check if the machine
|
18
|
+
# is created and branch in the middleware.
|
19
|
+
class IsCreated
|
20
|
+
def initialize(app, env)
|
21
|
+
@app = app
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
env[:result] = env[:machine].state.id != :not_created
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
module VagrantPlugins
|
15
|
+
module Google
|
16
|
+
module Action
|
17
|
+
class MessageAlreadyCreated
|
18
|
+
def initialize(app, env)
|
19
|
+
@app = app
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
env[:ui].info(I18n.t("vagrant_google.already_created"))
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
module VagrantPlugins
|
15
|
+
module Google
|
16
|
+
module Action
|
17
|
+
class MessageNotCreated
|
18
|
+
def initialize(app, env)
|
19
|
+
@app = app
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
env[:ui].info(I18n.t("vagrant_google.not_created"))
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
module VagrantPlugins
|
15
|
+
module Google
|
16
|
+
module Action
|
17
|
+
class MessageWillNotDestroy
|
18
|
+
def initialize(app, env)
|
19
|
+
@app = app
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
env[:ui].info(I18n.t("vagrant_google.will_not_destroy", name: env[:machine].name))
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require "log4r"
|
15
|
+
|
16
|
+
module VagrantPlugins
|
17
|
+
module Google
|
18
|
+
module Action
|
19
|
+
# This action reads the SSH info for the machine and puts it into the
|
20
|
+
# `:machine_ssh_info` key in the environment.
|
21
|
+
class ReadSSHInfo
|
22
|
+
def initialize(app, env)
|
23
|
+
@app = app
|
24
|
+
@logger = Log4r::Logger.new("vagrant_google::action::read_ssh_info")
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(env)
|
28
|
+
env[:machine_ssh_info] = read_ssh_info(env[:google_compute], env[:machine])
|
29
|
+
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_ssh_info(google, machine)
|
34
|
+
return nil if machine.id.nil?
|
35
|
+
# Find the machine
|
36
|
+
zone = machine.provider_config.zone
|
37
|
+
server = google.servers.get(machine.id, zone)
|
38
|
+
if server.nil?
|
39
|
+
# The machine can't be found
|
40
|
+
@logger.info("Machine '#{zone}:#{machine.id}'couldn't be found, assuming it got destroyed.")
|
41
|
+
machine.id = nil
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# Read SSH network info
|
46
|
+
return {
|
47
|
+
:host => server.public_ip_address,
|
48
|
+
:port => 22
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|