vagrant-google 0.1.5 → 0.2.0.rc1
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 +4 -4
- data/.gitignore +4 -3
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +201 -0
- data/CHANGELOG.md +14 -0
- data/README.md +45 -22
- data/example_boxes/gce/Vagrantfile +23 -0
- data/example_boxes/gce-test/Vagrantfile +30 -0
- data/lib/vagrant-google/action/connect_google.rb +10 -14
- data/lib/vagrant-google/action/is_terminated.rb +31 -0
- data/lib/vagrant-google/action/run_instance.rb +58 -35
- data/lib/vagrant-google/action/start_instance.rb +90 -0
- data/lib/vagrant-google/action/stop_instance.rb +48 -0
- data/lib/vagrant-google/action/warn_networks.rb +2 -1
- data/lib/vagrant-google/action.rb +62 -12
- data/lib/vagrant-google/config.rb +56 -11
- data/lib/vagrant-google/errors.rb +13 -5
- data/lib/vagrant-google/version.rb +1 -1
- data/lib/vagrant-google.rb +3 -3
- data/locales/en.yml +33 -4
- data/tasks/acceptance.rake +20 -1
- data/tasks/lint.rake +3 -0
- data/tasks/test.rake +1 -0
- data/test/acceptance/provider/multi_instance_spec.rb +31 -0
- data/test/acceptance/provider/preemptible_spec.rb +26 -0
- data/test/acceptance/provider/scopes_spec.rb +29 -0
- data/test/acceptance/skeletons/multi_instance/Vagrantfile +29 -0
- data/test/acceptance/skeletons/preemptible/Vagrantfile +17 -0
- data/test/acceptance/skeletons/scopes/Vagrantfile +18 -0
- data/test/unit/base.rb +1 -1
- data/test/unit/common/config_test.rb +62 -13
- data/vagrant-google.gemspec +4 -3
- data/vagrant-spec.config.rb +2 -2
- data/vagrantfile_examples/Vagrantfile.multiple_machines +93 -0
- data/vagrantfile_examples/Vagrantfile.provision_single +48 -0
- data/vagrantfile_examples/Vagrantfile.simple +29 -0
- data/vagrantfile_examples/Vagrantfile.zone_config +40 -0
- metadata +39 -8
- data/lib/vagrant-google/action/sync_folders.rb +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9138dfef6eb002e0a0b062826a22779273f99e3e
|
4
|
+
data.tar.gz: 64f03a09fcb48ff555452da308eb887b0415a62c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3540aa6eb5f490cd3342bb3e17f87415975a5d6f722aa9f623f9fbb013423b4a4c87cf6fce36c3399db520d1d4e1f933eca74a7f5754b8fae336c3f73632d908
|
7
|
+
data.tar.gz: de4b191f28d94ff4e9767025253e17dfb5d8f64cc5833ea18a50c062d3e5f5ad1b6fb2aba3253a3e3b28de810cf969b221dfcb35255ca01673cba4436d6f6873
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-07-13 18:02:44 +0000 using RuboCop version 0.31.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 2
|
9
|
+
Lint/LiteralInCondition:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
# Offense count: 3
|
13
|
+
Lint/ParenthesesAsGroupedExpression:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
Lint/RescueException:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
# Offense count: 4
|
21
|
+
# Cop supports --auto-correct.
|
22
|
+
Lint/UnusedBlockArgument:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
# Offense count: 14
|
26
|
+
# Cop supports --auto-correct.
|
27
|
+
Lint/UnusedMethodArgument:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
# Offense count: 2
|
31
|
+
Lint/UselessAssignment:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
# Offense count: 12
|
35
|
+
Metrics/AbcSize:
|
36
|
+
Max: 155
|
37
|
+
|
38
|
+
# Offense count: 2
|
39
|
+
# Configuration parameters: CountComments.
|
40
|
+
Metrics/ClassLength:
|
41
|
+
Max: 156
|
42
|
+
|
43
|
+
# Offense count: 4
|
44
|
+
Metrics/CyclomaticComplexity:
|
45
|
+
Max: 22
|
46
|
+
|
47
|
+
# Offense count: 62
|
48
|
+
# Configuration parameters: AllowURI, URISchemes.
|
49
|
+
Metrics/LineLength:
|
50
|
+
Max: 132
|
51
|
+
|
52
|
+
# Offense count: 15
|
53
|
+
# Configuration parameters: CountComments.
|
54
|
+
Metrics/MethodLength:
|
55
|
+
Max: 124
|
56
|
+
|
57
|
+
# Offense count: 1
|
58
|
+
# Configuration parameters: CountComments.
|
59
|
+
Metrics/ModuleLength:
|
60
|
+
Max: 141
|
61
|
+
|
62
|
+
# Offense count: 4
|
63
|
+
Metrics/PerceivedComplexity:
|
64
|
+
Max: 22
|
65
|
+
|
66
|
+
# Offense count: 1
|
67
|
+
Style/AccessorMethodName:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
# Offense count: 7
|
71
|
+
# Cop supports --auto-correct.
|
72
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
73
|
+
Style/AndOr:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
# Offense count: 18
|
77
|
+
Style/Documentation:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
# Offense count: 1
|
81
|
+
# Cop supports --auto-correct.
|
82
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
83
|
+
Style/DotPosition:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
# Offense count: 9
|
87
|
+
# Cop supports --auto-correct.
|
88
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
89
|
+
Style/EmptyLinesAroundBlockBody:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
# Offense count: 1
|
93
|
+
# Cop supports --auto-correct.
|
94
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
95
|
+
Style/EmptyLinesAroundClassBody:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
# Offense count: 1
|
99
|
+
# Cop supports --auto-correct.
|
100
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
101
|
+
Style/EmptyLinesAroundModuleBody:
|
102
|
+
Enabled: false
|
103
|
+
|
104
|
+
# Offense count: 2
|
105
|
+
# Configuration parameters: Exclude.
|
106
|
+
Style/FileName:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# Offense count: 2
|
110
|
+
# Cop supports --auto-correct.
|
111
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
112
|
+
Style/FirstParameterIndentation:
|
113
|
+
Enabled: false
|
114
|
+
|
115
|
+
# Offense count: 1
|
116
|
+
# Configuration parameters: MinBodyLength.
|
117
|
+
Style/GuardClause:
|
118
|
+
Enabled: false
|
119
|
+
|
120
|
+
# Offense count: 33
|
121
|
+
# Cop supports --auto-correct.
|
122
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
123
|
+
Style/HashSyntax:
|
124
|
+
Enabled: false
|
125
|
+
|
126
|
+
# Offense count: 2
|
127
|
+
# Cop supports --auto-correct.
|
128
|
+
Style/InfiniteLoop:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
# Offense count: 3
|
132
|
+
# Cop supports --auto-correct.
|
133
|
+
Style/MethodCallParentheses:
|
134
|
+
Enabled: false
|
135
|
+
|
136
|
+
# Offense count: 19
|
137
|
+
# Cop supports --auto-correct.
|
138
|
+
Style/NegatedIf:
|
139
|
+
Enabled: false
|
140
|
+
|
141
|
+
# Offense count: 1
|
142
|
+
# Cop supports --auto-correct.
|
143
|
+
Style/NilComparison:
|
144
|
+
Enabled: false
|
145
|
+
|
146
|
+
# Offense count: 1
|
147
|
+
# Cop supports --auto-correct.
|
148
|
+
Style/Not:
|
149
|
+
Enabled: false
|
150
|
+
|
151
|
+
# Offense count: 2
|
152
|
+
# Cop supports --auto-correct.
|
153
|
+
# Configuration parameters: AllowMultipleReturnValues.
|
154
|
+
Style/RedundantReturn:
|
155
|
+
Enabled: false
|
156
|
+
|
157
|
+
# Offense count: 1
|
158
|
+
# Cop supports --auto-correct.
|
159
|
+
Style/RedundantSelf:
|
160
|
+
Enabled: false
|
161
|
+
|
162
|
+
# Offense count: 8
|
163
|
+
# Cop supports --auto-correct.
|
164
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
165
|
+
Style/SignalException:
|
166
|
+
Enabled: false
|
167
|
+
|
168
|
+
# Offense count: 2
|
169
|
+
# Cop supports --auto-correct.
|
170
|
+
# Configuration parameters: SupportedStyles.
|
171
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
172
|
+
EnforcedStyle: no_space
|
173
|
+
|
174
|
+
# Offense count: 1
|
175
|
+
# Cop supports --auto-correct.
|
176
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
177
|
+
Style/SpaceBeforeBlockBraces:
|
178
|
+
Enabled: false
|
179
|
+
|
180
|
+
# Offense count: 1
|
181
|
+
# Cop supports --auto-correct.
|
182
|
+
Style/SpaceBeforeComma:
|
183
|
+
Enabled: false
|
184
|
+
|
185
|
+
# Offense count: 342
|
186
|
+
# Cop supports --auto-correct.
|
187
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
188
|
+
Style/StringLiterals:
|
189
|
+
Enabled: false
|
190
|
+
|
191
|
+
# Offense count: 6
|
192
|
+
# Cop supports --auto-correct.
|
193
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
194
|
+
Style/StringLiteralsInInterpolation:
|
195
|
+
Enabled: false
|
196
|
+
|
197
|
+
# Offense count: 4
|
198
|
+
# Cop supports --auto-correct.
|
199
|
+
# Configuration parameters: IgnoredMethods.
|
200
|
+
Style/SymbolProc:
|
201
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 0.1.6 (Unreleased)
|
2
|
+
|
3
|
+
* Added support for service account definitions [tcr]
|
4
|
+
* Added support for preemptible instances [jcdang]
|
5
|
+
* Implemented auto_restart and on_host_maintenance options [jcdang]
|
6
|
+
* Added support for IP address specification by name [temikus]
|
7
|
+
* Instance name now defaults to time + uuid [temikus]
|
8
|
+
* Removed legacy rsync code, switched to Vagrant built-in SyncedFolders [temikus]
|
9
|
+
* Implemented vagrant halt and reload actions [temikus]
|
10
|
+
* Switched to fog-google metagem [temikus]
|
11
|
+
* Added a linter and custom acceptance tests [temikus]
|
12
|
+
* Updated documentation and examples [mbrukman, temikus]
|
13
|
+
* Miscellaneous UI/UX updates and bugfixes [temikus]
|
14
|
+
|
1
15
|
# 0.1.5 (May 2015)
|
2
16
|
|
3
17
|
* Added support for JSON private keys [temikus]
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an
|
|
4
4
|
[Google Compute Engine](http://cloud.google.com/compute/) (GCE) provider to
|
5
5
|
Vagrant, allowing Vagrant to control and provision instances in GCE.
|
6
6
|
|
7
|
-
**NOTE:** This plugin requires Vagrant 1.2
|
7
|
+
**NOTE:** This plugin requires Vagrant 1.2+.
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
@@ -91,8 +91,8 @@ end
|
|
91
91
|
|
92
92
|
And then run `vagrant up --provider=google`.
|
93
93
|
|
94
|
-
This will start
|
95
|
-
with an n1-standard-1 machine, and the "default" network within your project.
|
94
|
+
This will start a Debian 7 (Wheezy) instance in the `us-central1-f` zone,
|
95
|
+
with an `n1-standard-1` machine, and the `"default"` network within your project.
|
96
96
|
And assuming your SSH information (see below) was filled in properly within
|
97
97
|
your Vagrantfile, SSH and provisioning will work as well.
|
98
98
|
|
@@ -110,15 +110,32 @@ respective `~/.ssh/authorized_keys` entries. Most new GCE users will use the
|
|
110
110
|
[Cloud SDK](https://cloud.google.com/sdk/) `gcloud compute` utility when first
|
111
111
|
getting started with GCE. This utility has built in support for creating SSH
|
112
112
|
key pairs, and uploading the public key to the GCE metadata service. By
|
113
|
-
default, `
|
113
|
+
default, `gcloud compute` creates a key pair named
|
114
114
|
`~/.ssh/google_compute_engine[.pub]`.
|
115
115
|
|
116
116
|
Note that you can use the more standard `~/.ssh/id_rsa[.pub]` files, but you
|
117
117
|
will need to manually add your public key to the GCE metadata service so your
|
118
118
|
VMs will pick up the the key. Note that they public key is typically
|
119
119
|
prefixed with the username, so that the daemon on the VM adds the public key
|
120
|
-
to the correct user account.
|
121
|
-
|
120
|
+
to the correct user account.
|
121
|
+
|
122
|
+
Additionally, you will probably need to add the key and username to override
|
123
|
+
settings in your Vagrantfile like so:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
config.vm.provider :google do |google, override|
|
127
|
+
|
128
|
+
#...google provider settings are skipped...
|
129
|
+
|
130
|
+
override.ssh.username = "testuser"
|
131
|
+
override.ssh.private_key_path = "~/.ssh/id_rsa"
|
132
|
+
|
133
|
+
#...google provider settings are skipped...
|
134
|
+
|
135
|
+
end
|
136
|
+
```
|
137
|
+
|
138
|
+
See the links below for more help with SSH and GCE VMs.
|
122
139
|
|
123
140
|
* https://cloud.google.com/compute/docs/instances#sshing
|
124
141
|
* https://cloud.google.com/compute/docs/console#sshkeys
|
@@ -126,8 +143,8 @@ GCE VMs.
|
|
126
143
|
## Box Format
|
127
144
|
|
128
145
|
Every provider in Vagrant must introduce a custom box format. This provider
|
129
|
-
introduces `google` boxes. You can view an example box in
|
130
|
-
[
|
146
|
+
introduces `google` boxes. You can view an example box in
|
147
|
+
[example_boxes/](https://github.com/mitchellh/vagrant-google/tree/master/example_boxes).
|
131
148
|
That directory also contains instructions on how to build a box.
|
132
149
|
|
133
150
|
The box format is basically just the required `metadata.json` file along with
|
@@ -156,8 +173,15 @@ This provider exposes quite a few provider-specific configuration options:
|
|
156
173
|
"default".
|
157
174
|
* `tags` - An array of tags to apply to this instance.
|
158
175
|
* `zone` - The zone name where the instance will be created.
|
159
|
-
* `can_ip_forward` - Boolean
|
160
|
-
* `external_ip` - The external IP address to use.
|
176
|
+
* `can_ip_forward` - Boolean whether to enable IP Forwarding.
|
177
|
+
* `external_ip` - The external IP address to use (supports names).
|
178
|
+
* `preemptible` - Boolean whether to enable preemptibility. Default is false.
|
179
|
+
* `auto_restart` - Boolean whether to enable auto_restart. Default is true.
|
180
|
+
* `on_host_maintenance` - What to do on host maintenance. Default is "MIGRATE".
|
181
|
+
* `service_accounts` or `scopes` - An array of OAuth2 account scopes for
|
182
|
+
services that the instance will have access to. Those can be both full API
|
183
|
+
scopes and just endpoint aliases (the part after `...auth/`), for example:
|
184
|
+
`['bigquery', 'https://www.googleapis.com/auth/compute']`.
|
161
185
|
|
162
186
|
These can be set like typical provider-specific configuration:
|
163
187
|
|
@@ -197,6 +221,7 @@ Vagrant.configure("2") do |config|
|
|
197
221
|
zone1f.machine_type = "n1-standard-4"
|
198
222
|
zone1f.zone = "us-central1-f"
|
199
223
|
zone1f.metadata = {'custom' => 'metadata', 'testing' => 'foobarbaz'}
|
224
|
+
zone1f.scopes = ['bigquery', 'monitoring', 'https://www.googleapis.com/auth/compute']
|
200
225
|
zone1f.tags = ['web', 'app1']
|
201
226
|
end
|
202
227
|
end
|
@@ -205,10 +230,10 @@ end
|
|
205
230
|
|
206
231
|
The zone-specific configurations will override the top-level configurations
|
207
232
|
when that zone is used. They otherwise inherit the top-level configurations,
|
208
|
-
as you would
|
233
|
+
as you would expect.
|
209
234
|
|
210
|
-
There are a few example
|
211
|
-
[vagrantfile_examples/ directory](https://github.com/mitchellh/vagrant-google/tree/master/vagrantfile_examples/)
|
235
|
+
There are a few example Vagrantfiles located in the
|
236
|
+
[vagrantfile_examples/ directory](https://github.com/mitchellh/vagrant-google/tree/master/vagrantfile_examples/).
|
212
237
|
|
213
238
|
## Networks
|
214
239
|
|
@@ -222,22 +247,20 @@ There is minimal support for synced folders. Upon `vagrant up`,
|
|
222
247
|
`vagrant reload`, and `vagrant provision`, the Google provider will use
|
223
248
|
`rsync` (if available) to uni-directionally sync the folder to the remote
|
224
249
|
machine over SSH.
|
225
|
-
|
226
|
-
This is good enough for all built-in Vagrant provisioners (shell, chef, and
|
227
|
-
puppet) to work!
|
250
|
+
See [Vagrant Synced folders: rsync](https://docs.vagrantup.com/v2/synced-folders/rsync.html)
|
228
251
|
|
229
252
|
## Development
|
230
253
|
|
231
254
|
To work on the `vagrant-google` plugin, clone this repository out, and use
|
232
255
|
[Bundler](http://gembundler.com) to get the dependencies:
|
233
256
|
|
234
|
-
```
|
257
|
+
```sh
|
235
258
|
$ bundle
|
236
259
|
```
|
237
260
|
|
238
261
|
Once you have the dependencies, verify the unit tests pass with `rake`:
|
239
262
|
|
240
|
-
```
|
263
|
+
```sh
|
241
264
|
$ bundle exec rake
|
242
265
|
```
|
243
266
|
|
@@ -246,7 +269,7 @@ the plugin without installing it into your Vagrant environment by just
|
|
246
269
|
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
|
247
270
|
that uses it, and uses bundler to execute Vagrant:
|
248
271
|
|
249
|
-
```
|
272
|
+
```sh
|
250
273
|
$ bundle exec vagrant up --provider=google
|
251
274
|
```
|
252
275
|
|
@@ -259,7 +282,7 @@ Before you start acceptance tests, you'll need to set the authentication variabl
|
|
259
282
|
|
260
283
|
Next, export your GCP authentication data:
|
261
284
|
|
262
|
-
```
|
285
|
+
```sh
|
263
286
|
export GOOGLE_CLIENT_EMAIL="your-google_service_account_email@developer.gserviceaccount.com"
|
264
287
|
export GOOGLE_PROJECT_ID="your-google-cloud-project-id"
|
265
288
|
export GOOGLE_JSON_KEY_LOCATION="/full/path/to/your/private-key.json"
|
@@ -269,8 +292,8 @@ export GOOGLE_SSH_KEY_LOCATION="/home/testuser/.ssh/id_rsa"
|
|
269
292
|
```
|
270
293
|
|
271
294
|
After, you can run acceptance tests by running the `run` task in `acceptance` namespace:
|
272
|
-
```
|
273
|
-
bundle exec rake acceptance:run
|
295
|
+
```sh
|
296
|
+
$ bundle exec rake acceptance:run
|
274
297
|
```
|
275
298
|
|
276
299
|
## Changelog
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
Vagrant.configure("2") do |config|
|
18
|
+
config.vm.provider :google do |google|
|
19
|
+
google.image = "debian-7-wheezy-v20150127"
|
20
|
+
google.machine_type = "n1-standard-1"
|
21
|
+
google.zone = "us-central1-f"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
# Copyright 2013 Google Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
Vagrant.configure("2") do |config|
|
18
|
+
config.vm.provider :google do |google, override|
|
19
|
+
|
20
|
+
if ENV['GOOGLE_SSH_USER'] and ENV['GOOGLE_SSH_KEY_LOCATION']
|
21
|
+
override.ssh.username = ENV['GOOGLE_SSH_USER']
|
22
|
+
override.ssh.private_key_path = ENV['GOOGLE_SSH_KEY_LOCATION']
|
23
|
+
end
|
24
|
+
|
25
|
+
google.image = "debian-7-wheezy-v20150127"
|
26
|
+
google.machine_type = "n1-standard-1"
|
27
|
+
google.zone = "us-central1-f"
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -11,7 +11,7 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
require "fog"
|
14
|
+
require "fog/google"
|
15
15
|
require "log4r"
|
16
16
|
|
17
17
|
module VagrantPlugins
|
@@ -29,20 +29,16 @@ module VagrantPlugins
|
|
29
29
|
def call(env)
|
30
30
|
provider_config = env[:machine].provider_config
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
# Build 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
|
+
}
|
38
|
+
if provider_config.google_json_key_location.nil?
|
39
|
+
fog_config[:google_key_location] = provider_config.google_key_location
|
39
40
|
else
|
40
|
-
fog_config =
|
41
|
-
:provider => :google,
|
42
|
-
:google_project => provider_config.google_project_id,
|
43
|
-
:google_client_email => provider_config.google_client_email,
|
44
|
-
:google_key_location => provider_config.google_key_location
|
45
|
-
}
|
41
|
+
fog_config[:google_json_key_location] = provider_config.google_json_key_location
|
46
42
|
end
|
47
43
|
|
48
44
|
@logger.info("Connecting to Google...")
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright 2015 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 stopped and branch in the middleware.
|
19
|
+
class IsTerminated
|
20
|
+
def initialize(app, env)
|
21
|
+
@app = app
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
env[:result] = env[:machine].state.id == :TERMINATED
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -35,19 +35,23 @@ module VagrantPlugins
|
|
35
35
|
zone = env[:machine].provider_config.zone
|
36
36
|
|
37
37
|
# Get the configs
|
38
|
-
zone_config
|
39
|
-
image
|
40
|
-
name
|
41
|
-
machine_type
|
42
|
-
disk_size
|
43
|
-
disk_name
|
44
|
-
disk_type
|
45
|
-
network
|
46
|
-
metadata
|
47
|
-
tags
|
48
|
-
can_ip_forward
|
49
|
-
external_ip
|
50
|
-
|
38
|
+
zone_config = env[:machine].provider_config.get_zone_config(zone)
|
39
|
+
image = zone_config.image
|
40
|
+
name = zone_config.name
|
41
|
+
machine_type = zone_config.machine_type
|
42
|
+
disk_size = zone_config.disk_size
|
43
|
+
disk_name = zone_config.disk_name
|
44
|
+
disk_type = zone_config.disk_type
|
45
|
+
network = zone_config.network
|
46
|
+
metadata = zone_config.metadata
|
47
|
+
tags = zone_config.tags
|
48
|
+
can_ip_forward = zone_config.can_ip_forward
|
49
|
+
external_ip = zone_config.external_ip
|
50
|
+
preemptible = zone_config.preemptible
|
51
|
+
auto_restart = zone_config.auto_restart
|
52
|
+
on_host_maintenance = zone_config.on_host_maintenance
|
53
|
+
autodelete_disk = zone_config.autodelete_disk
|
54
|
+
service_accounts = zone_config.service_accounts
|
51
55
|
|
52
56
|
# Launch!
|
53
57
|
env[:ui].info(I18n.t("vagrant_google.launching_instance"))
|
@@ -63,26 +67,27 @@ module VagrantPlugins
|
|
63
67
|
env[:ui].info(" -- Tags: '#{tags}'")
|
64
68
|
env[:ui].info(" -- IP Forward: #{can_ip_forward}")
|
65
69
|
env[:ui].info(" -- External IP: #{external_ip}")
|
70
|
+
env[:ui].info(" -- Preemptible: #{preemptible}")
|
71
|
+
env[:ui].info(" -- Auto Restart: #{auto_restart}")
|
72
|
+
env[:ui].info(" -- On Maintenance: #{on_host_maintenance}")
|
66
73
|
env[:ui].info(" -- Autodelete Disk: #{autodelete_disk}")
|
74
|
+
env[:ui].info(" -- Scopes: #{service_accounts}")
|
67
75
|
begin
|
68
76
|
request_start_time = Time.now().to_i
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
if address.in_use?
|
73
|
-
raise Errors::ExternalIpError,
|
74
|
-
:externalip => external_ip
|
75
|
-
end
|
76
|
-
end
|
77
|
+
# Warn on ssh-key overrides
|
78
|
+
if env[:machine].config.ssh.username.nil?
|
79
|
+
env[:ui].warn(I18n.t("vagrant_google.warn_ssh_vagrant_user"))
|
77
80
|
end
|
78
|
-
#Check if
|
81
|
+
# Check if specified external ip is available
|
82
|
+
external_ip = get_external_ip(env, external_ip) if external_ip
|
83
|
+
# Check if disk type is available in the zone
|
79
84
|
if !disk_type.nil?
|
80
85
|
disk_type_obj = env[:google_compute].list_disk_types(zone).body['items'].select { |dt| dt['name'] == disk_type } || []
|
81
86
|
if !disk_type_obj.empty?
|
82
87
|
disk_type = disk_type_obj[0]["selfLink"]
|
83
88
|
else
|
84
89
|
raise Errors::DiskTypeError,
|
85
|
-
|
90
|
+
:disktype => disk_type
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
@@ -112,18 +117,22 @@ module VagrantPlugins
|
|
112
117
|
end
|
113
118
|
|
114
119
|
defaults = {
|
115
|
-
:name
|
116
|
-
:zone_name
|
117
|
-
:machine_type
|
118
|
-
:disk_size
|
119
|
-
:disk_type
|
120
|
-
:image
|
121
|
-
:network
|
122
|
-
:metadata
|
123
|
-
:tags
|
124
|
-
:can_ip_forward
|
125
|
-
:external_ip
|
126
|
-
:
|
120
|
+
:name => name,
|
121
|
+
:zone_name => zone,
|
122
|
+
:machine_type => machine_type,
|
123
|
+
:disk_size => disk_size,
|
124
|
+
:disk_type => disk_type,
|
125
|
+
:image => image,
|
126
|
+
:network => network,
|
127
|
+
:metadata => metadata,
|
128
|
+
:tags => tags,
|
129
|
+
:can_ip_forward => can_ip_forward,
|
130
|
+
:external_ip => external_ip,
|
131
|
+
:preemptible => preemptible,
|
132
|
+
:auto_restart => auto_restart,
|
133
|
+
:on_host_maintenance => on_host_maintenance,
|
134
|
+
:disks => [disk.get_as_boot_disk(true, autodelete_disk)],
|
135
|
+
:service_accounts => service_accounts
|
127
136
|
}
|
128
137
|
server = env[:google_compute].servers.create(defaults)
|
129
138
|
@logger.info("Machine '#{zone}:#{name}' created.")
|
@@ -184,6 +193,20 @@ module VagrantPlugins
|
|
184
193
|
destroy_env[:force_confirm_destroy] = true
|
185
194
|
env[:action_runner].run(Action.action_destroy, destroy_env)
|
186
195
|
end
|
196
|
+
|
197
|
+
def get_external_ip(env, external_ip)
|
198
|
+
address = env[:google_compute].addresses.get_by_ip_address_or_name(external_ip)
|
199
|
+
if address.nil?
|
200
|
+
raise Errors::ExternalIpDoesNotExistError,
|
201
|
+
:externalip => external_ip
|
202
|
+
end
|
203
|
+
if address.in_use?
|
204
|
+
raise Errors::ExternalIpInUseError,
|
205
|
+
:externalip => external_ip
|
206
|
+
end
|
207
|
+
# Resolve the name to IP address
|
208
|
+
address.address
|
209
|
+
end
|
187
210
|
end
|
188
211
|
end
|
189
212
|
end
|