vagrant-google 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37c9594b020e4a74df8366e5e1f3fcdf0485c44d
4
- data.tar.gz: 085e323ca610795a1159b8d2594028d962d6feae
3
+ metadata.gz: f08596de9a161ed1f61216096b5f7692a1459d09
4
+ data.tar.gz: 1120e3b316b5d776499757f35fdf23997f4635a3
5
5
  SHA512:
6
- metadata.gz: 3c67a320ce73ced7004bfcd893463ff28f2d652aa6ef73f69758a48a72bf04b684d8ae23fd93db8b46a052ec05cd345c92dc24f7c1f567611c9171e79ff27d03
7
- data.tar.gz: d0b4c0d7a71fb51663f6d327d4010704c0b59f70f19e594d3c52a4a8f55c5376500a733d66462dc342b375a4c4fca84d43cc9e15b73d63aff46474325d975428
6
+ metadata.gz: 59ad9e52c85be68a78cdfc65254a7a77e011907ce8bc10707eb4e2dfb083ffa1bbbd2c6af7c2ec0511a7af35aa37553d984a1af96eb19ba0807325a64a112cf7
7
+ data.tar.gz: 5ddf509702c160023f006fc0f8c47efff95aea216b49d9727c5cb258535cdb87114a0fe19d3fd37d354d63b6fc6d1399ffd94b544b956566261550ee6d3647d9
data/.rubocop.yml CHANGED
@@ -1,7 +1,11 @@
1
1
  # Importing TODO list to sanely lint new submissions.
2
2
  inherit_from: .rubocop_todo.yml
3
3
 
4
+ # Custom project config
4
5
  AllCops:
5
6
  Exclude:
6
7
  - './Vagrantfile'
7
- - './vagrant-google.gemspec'
8
+ - './vagrant-google.gemspec'
9
+
10
+ Style/EmptyLinesAroundBlockBody:
11
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-01-03 11:45:58 +0100 using RuboCop version 0.35.1.
3
+ # on 2016-03-25 19:11:49 +0100 using RuboCop version 0.38.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -17,28 +17,19 @@ Lint/NestedMethodDefinition:
17
17
  Exclude:
18
18
  - 'lib/vagrant-google/action/sync_folders.rb'
19
19
 
20
- # Offense count: 3
21
- Lint/ParenthesesAsGroupedExpression:
22
- Exclude:
23
- - 'tasks/acceptance.rake'
24
-
25
20
  # Offense count: 1
26
21
  Lint/RescueException:
27
22
  Exclude:
28
23
  - 'lib/vagrant-google/action/read_state.rb'
29
24
 
30
- # Offense count: 6
25
+ # Offense count: 1
31
26
  # Cop supports --auto-correct.
32
27
  # Configuration parameters: IgnoreEmptyBlocks.
33
28
  Lint/UnusedBlockArgument:
34
29
  Exclude:
35
30
  - 'lib/vagrant-google/action/sync_folders.rb'
36
- - 'test/acceptance/skeletons/generic/Vagrantfile'
37
- - 'test/acceptance/skeletons/multi_instance/Vagrantfile'
38
- - 'test/acceptance/skeletons/preemptible/Vagrantfile'
39
- - 'test/acceptance/skeletons/scopes/Vagrantfile'
40
31
 
41
- # Offense count: 16
32
+ # Offense count: 17
42
33
  # Cop supports --auto-correct.
43
34
  # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
44
35
  Lint/UnusedMethodArgument:
@@ -51,30 +42,26 @@ Lint/UselessAssignment:
51
42
 
52
43
  # Offense count: 11
53
44
  Metrics/AbcSize:
54
- Max: 133
55
-
56
- # Offense count: 1
57
- # Configuration parameters: CountComments.
58
- Metrics/ClassLength:
59
- Max: 146
45
+ Max: 54
60
46
 
61
- # Offense count: 5
47
+ # Offense count: 4
62
48
  Metrics/CyclomaticComplexity:
63
- Max: 22
49
+ Max: 16
64
50
 
65
- # Offense count: 68
66
- # Configuration parameters: AllowURI, URISchemes.
51
+ # Offense count: 71
52
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
53
+ # URISchemes: http, https
67
54
  Metrics/LineLength:
68
55
  Max: 131
69
56
 
70
- # Offense count: 14
57
+ # Offense count: 15
71
58
  # Configuration parameters: CountComments.
72
59
  Metrics/MethodLength:
73
60
  Max: 35
74
61
 
75
- # Offense count: 4
62
+ # Offense count: 3
76
63
  Metrics/PerceivedComplexity:
77
- Max: 22
64
+ Max: 16
78
65
 
79
66
  # Offense count: 1
80
67
  Style/AccessorMethodName:
@@ -84,14 +71,14 @@ Style/AccessorMethodName:
84
71
  # Offense count: 8
85
72
  # Cop supports --auto-correct.
86
73
  # Configuration parameters: EnforcedStyle, SupportedStyles.
74
+ # SupportedStyles: always, conditionals
87
75
  Style/AndOr:
88
76
  Exclude:
89
77
  - 'example_boxes/gce-test/Vagrantfile'
90
78
  - 'lib/vagrant-google/config.rb'
91
79
  - 'test/unit/common/config_test.rb'
92
80
 
93
- # Offense count: 19
94
- # Configuration parameters: Exclude.
81
+ # Offense count: 18
95
82
  Style/Documentation:
96
83
  Exclude:
97
84
  - 'spec/**/*'
@@ -108,31 +95,26 @@ Style/Documentation:
108
95
  - 'lib/vagrant-google/plugin.rb'
109
96
  - 'lib/vagrant-google/provider.rb'
110
97
  - 'lib/vagrant-google/util/timer.rb'
111
- - 'lib/vagrant-google/version.rb'
112
98
 
113
99
  # Offense count: 1
114
100
  # Cop supports --auto-correct.
115
101
  # Configuration parameters: EnforcedStyle, SupportedStyles.
102
+ # SupportedStyles: leading, trailing
116
103
  Style/DotPosition:
117
104
  Enabled: false
118
105
 
119
106
  # Offense count: 9
120
107
  # Cop supports --auto-correct.
121
108
  # Configuration parameters: EnforcedStyle, SupportedStyles.
109
+ # SupportedStyles: empty_lines, no_empty_lines
122
110
  Style/EmptyLinesAroundBlockBody:
123
111
  Exclude:
124
- - 'example_boxes/gce-test/Vagrantfile'
125
- - 'lib/vagrant-google/action/start_instance.rb'
126
- - 'tasks/acceptance.rake'
127
- - 'test/acceptance/shared/context_google.rb'
128
- - 'test/acceptance/skeletons/generic/Vagrantfile'
129
- - 'test/acceptance/skeletons/preemptible/Vagrantfile'
130
- - 'test/acceptance/skeletons/scopes/Vagrantfile'
131
- - 'test/unit/common/config_test.rb'
112
+
132
113
 
133
114
  # Offense count: 1
134
115
  # Cop supports --auto-correct.
135
116
  # Configuration parameters: EnforcedStyle, SupportedStyles.
117
+ # SupportedStyles: empty_lines, no_empty_lines
136
118
  Style/EmptyLinesAroundClassBody:
137
119
  Exclude:
138
120
  - 'lib/vagrant-google/action/stop_instance.rb'
@@ -140,12 +122,13 @@ Style/EmptyLinesAroundClassBody:
140
122
  # Offense count: 1
141
123
  # Cop supports --auto-correct.
142
124
  # Configuration parameters: EnforcedStyle, SupportedStyles.
125
+ # SupportedStyles: empty_lines, no_empty_lines
143
126
  Style/EmptyLinesAroundModuleBody:
144
127
  Exclude:
145
128
  - 'lib/vagrant-google/action/stop_instance.rb'
146
129
 
147
130
  # Offense count: 2
148
- # Configuration parameters: Exclude.
131
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
149
132
  Style/FileName:
150
133
  Exclude:
151
134
  - 'lib/vagrant-google.rb'
@@ -153,12 +136,13 @@ Style/FileName:
153
136
 
154
137
  # Offense count: 2
155
138
  # Cop supports --auto-correct.
156
- # Configuration parameters: EnforcedStyle, SupportedStyles.
139
+ # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
140
+ # SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
157
141
  Style/FirstParameterIndentation:
158
142
  Exclude:
159
143
  - 'lib/vagrant-google/action/run_instance.rb'
160
144
 
161
- # Offense count: 2
145
+ # Offense count: 1
162
146
  # Configuration parameters: MinBodyLength.
163
147
  Style/GuardClause:
164
148
  Exclude:
@@ -167,6 +151,7 @@ Style/GuardClause:
167
151
  # Offense count: 40
168
152
  # Cop supports --auto-correct.
169
153
  # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
154
+ # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
170
155
  Style/HashSyntax:
171
156
  Enabled: false
172
157
 
@@ -186,6 +171,7 @@ Style/LeadingCommentSpace:
186
171
  # Offense count: 1
187
172
  # Cop supports --auto-correct.
188
173
  # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
174
+ # SupportedStyles: skip_modifier_ifs, always
189
175
  Style/Next:
190
176
  Exclude:
191
177
  - 'lib/vagrant-google/action/sync_folders.rb'
@@ -219,34 +205,22 @@ Style/RedundantSelf:
219
205
  # Offense count: 1
220
206
  # Cop supports --auto-correct.
221
207
  # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
208
+ # SupportedStyles: slashes, percent_r, mixed
222
209
  Style/RegexpLiteral:
223
210
  Exclude:
224
211
  - 'lib/vagrant-google/action/sync_folders.rb'
225
212
 
226
- # Offense count: 10
227
- # Cop supports --auto-correct.
228
- # Configuration parameters: EnforcedStyle, SupportedStyles.
229
- Style/SignalException:
230
- Exclude:
231
- - 'lib/vagrant-google/action/run_instance.rb'
232
- - 'lib/vagrant-google/action/sync_folders.rb'
233
- - 'lib/vagrant-google/config.rb'
234
- - 'lib/vagrant-google/plugin.rb'
235
- - 'test/acceptance/provider/halt_spec.rb'
236
- - 'test/acceptance/provider/multi_instance_spec.rb'
237
- - 'test/acceptance/provider/preemptible_spec.rb'
238
- - 'test/acceptance/provider/reload_spec.rb'
239
- - 'test/acceptance/provider/scopes_spec.rb'
240
-
241
213
  # Offense count: 2
242
214
  # Cop supports --auto-correct.
243
215
  # Configuration parameters: SupportedStyles.
216
+ # SupportedStyles: space, no_space
244
217
  Style/SpaceAroundEqualsInParameterDefault:
245
218
  EnforcedStyle: no_space
246
219
 
247
220
  # Offense count: 3
248
221
  # Cop supports --auto-correct.
249
222
  # Configuration parameters: EnforcedStyle, SupportedStyles.
223
+ # SupportedStyles: space, no_space
250
224
  Style/SpaceBeforeBlockBraces:
251
225
  Enabled: false
252
226
 
@@ -259,24 +233,28 @@ Style/SpaceBeforeComma:
259
233
  # Offense count: 2
260
234
  # Cop supports --auto-correct.
261
235
  # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
236
+ # SupportedStyles: space, no_space
262
237
  Style/SpaceInsideBlockBraces:
263
238
  Enabled: false
264
239
 
265
- # Offense count: 384
240
+ # Offense count: 392
266
241
  # Cop supports --auto-correct.
267
- # Configuration parameters: EnforcedStyle, SupportedStyles.
242
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
243
+ # SupportedStyles: single_quotes, double_quotes
268
244
  Style/StringLiterals:
269
245
  Enabled: false
270
246
 
271
247
  # Offense count: 7
272
248
  # Cop supports --auto-correct.
273
249
  # Configuration parameters: EnforcedStyle, SupportedStyles.
250
+ # SupportedStyles: single_quotes, double_quotes
274
251
  Style/StringLiteralsInInterpolation:
275
252
  Enabled: false
276
253
 
277
254
  # Offense count: 4
278
255
  # Cop supports --auto-correct.
279
256
  # Configuration parameters: IgnoredMethods.
257
+ # IgnoredMethods: respond_to
280
258
  Style/SymbolProc:
281
259
  Exclude:
282
260
  - 'test/unit/common/config_test.rb'
data/README.md CHANGED
@@ -52,16 +52,15 @@ Service Account for API Access.
52
52
  1. Next, visit the [Developers Console](https://console.developers.google.com)
53
53
  make sure to enable the `Google Compute Engine` service for your project
54
54
  If prompted, review and agree to the terms of service.
55
- 1. While still in the Developers Console, go to `API & AUTH`, `Credentials`
56
- section and click the `Create new Client ID` button. In the pop-up dialog,
57
- select the `Service Account` radio button and the click the
58
- `Create Client ID` button.
59
- 1. Make sure to download the *P12 private key* and save this file in a secure
55
+ 1. While still in the Developers Console, go to `Permissions`, `Service Accounts`
56
+ section and click the `Create service account` button. In the pop-up dialog,
57
+ click the `Furnish a new private key` box.
58
+ 1. Download the JSON private key and save this file in a secure
60
59
  and reliable location. This key file will be used to authorize all API
61
60
  requests to Google Compute Engine.
62
- 1. Still on the same page, find the newly created `Service Account` text
63
- block on the API Access page. Record the `Email address` (it should end
64
- with `@developer.gserviceaccount.com`) associated with the new Service
61
+ 1. Still on the same page, find the
62
+ `Email address` (it should end
63
+ with `gserviceaccount.com`) associated with the new Service
65
64
  Account you just created. You will need this email address and the
66
65
  location of the private key file to properly configure this Vagrant plugin.
67
66
  1. Add the SSH key you're going to use to GCE Metadata in `Compute` ->
@@ -167,18 +166,25 @@ configuration for this provider.
167
166
 
168
167
  This provider exposes quite a few provider-specific configuration options:
169
168
 
170
- * `google_client_email` - The Client Email address for your Service Account.
169
+ * `google_client_email` - The Client Email address for your Service Account.
170
+ (Can also be configured with `GOOGLE_CLIENT_EMAIL` environment variable.)
171
171
  * `google_key_location` - The location of the P12 private key file matching your
172
- Service Account.
172
+ Service Account.
173
+ (Can also be configured with `GOOGLE_KEY_LOCATION` environment variable.)
173
174
  * `google_json_key_location` - The location of the JSON private key file matching your
174
- Service Account.
175
- * `google_project_id` - The Project ID for your Google Cloud Platform account.
175
+ Service Account.
176
+ (Can also be configured with `GOOGLE_JSON_KEY_LOCATION` environment variable.)
177
+ * `google_project_id` - The Project ID for your Google Cloud Platform account.
178
+ (Can also be configured with `GOOGLE_PROJECT_ID` environment variable.)
176
179
  * `image` - The image name to use when booting your instance.
180
+ * `instance_group` - Unmanaged instance group to add the machine to. If one
181
+ doesn't exist it will be created.
177
182
  * `instance_ready_timeout` - The number of seconds to wait for the instance
178
183
  to become "ready" in GCE. Defaults to 20 seconds.
179
184
  * `machine_type` - The machine type to use. The default is "n1-standard-1".
180
185
  * `disk_size` - The disk size in GB. The default is 10.
181
186
  * `disk_name` - The disk name to use. If the disk exists, it will be reused, otherwise created.
187
+ * `disk_type` - Whether to use Standard disk or SSD disk. Use either `pd-ssd` or `pd-standard`.
182
188
  * `metadata` - Custom key/value pairs of metadata to add to the instance.
183
189
  * `name` - The name of your instance. The default is "i-yyyymmddhh-randomsd",
184
190
  e.g. 10/08/2015 13:15:15 is "i-2015081013-15637fda".
@@ -149,6 +149,7 @@ module VagrantPlugins
149
149
  b1.use WarnNetworks
150
150
  b1.use WarnSshKeys
151
151
  b1.use RunInstance
152
+ b1.use AssignInstanceGroups
152
153
  end
153
154
  end
154
155
  end
@@ -173,6 +174,7 @@ module VagrantPlugins
173
174
 
174
175
  # The autoload farm
175
176
  action_root = Pathname.new(File.expand_path("../action", __FILE__))
177
+ autoload :AssignInstanceGroups, action_root.join("assign_instance_groups")
176
178
  autoload :ConnectGoogle, action_root.join("connect_google")
177
179
  autoload :IsCreated, action_root.join("is_created")
178
180
  autoload :IsTerminated, action_root.join("is_terminated")
@@ -0,0 +1,73 @@
1
+ # Copyright 2016 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
+ # Action to assign instance groups. Looks for the 'instance_group'
18
+ # parameter in the zone config and adds the instance to it.
19
+ # If the instance group does not exist in the specified zone, it tries to
20
+ # create one first.
21
+ #
22
+ # This action manipulates unmanaged instance groups
23
+ # https://cloud.google.com/compute/docs/instance-groups/unmanaged-groups
24
+ class AssignInstanceGroups
25
+ def initialize(app, env)
26
+ @app = app
27
+ @logger = Log4r::Logger.new(
28
+ "vagrant_google::action::assign_instance_groups")
29
+ end
30
+
31
+ def call(env)
32
+ zone = env[:machine].provider_config.zone
33
+ zone_config = env[:machine].provider_config.get_zone_config(zone)
34
+ instance_name = zone_config.name
35
+ instance_group_name = zone_config.instance_group
36
+
37
+ if instance_group_name
38
+ group = env[:google_compute].instance_groups.get(instance_group_name,
39
+ zone)
40
+ if group.nil?
41
+ # If instance group doesn't exist, attempt to create it
42
+ env[:ui].info(I18n.t("vagrant_google.instance_group_create"))
43
+ instance_group_config = {
44
+ name: instance_group_name,
45
+ zone: zone,
46
+ description: "Created by Vagrant"
47
+ }
48
+ env[:google_compute].instance_groups.create(instance_group_config)
49
+ end
50
+
51
+ # Add the machine to instance group
52
+ env[:ui].info(I18n.t("vagrant_google.instance_group_add"))
53
+
54
+ response = env[:google_compute].instance_groups.add_instance(
55
+ group: instance_group_name,
56
+ zone: zone,
57
+ instance: instance_name
58
+ )
59
+ unless response.body["status"] == "DONE"
60
+ operation = env[:google_compute].operations.get(
61
+ operation.body["name"], zone)
62
+ env[:ui].info(I18n.t("vagrant_google.waiting_for_operation",
63
+ name: operation.body["name"]))
64
+ operation.wait_for { ready? }
65
+ end
66
+ end
67
+
68
+ @app.call(env)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -26,14 +26,14 @@ module VagrantPlugins
26
26
  Fog::Compute::Google::NotFound,
27
27
  Fog::Compute::Google::Error,
28
28
  Fog::Errors::Error
29
- ]
29
+ ].freeze
30
30
 
31
31
  def initialize(app, env)
32
32
  @app = app
33
33
  @logger = Log4r::Logger.new("vagrant_google::action::run_instance")
34
34
  end
35
35
 
36
- def call(env) # rubocop:disable Metrics/MethodLength
36
+ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
37
37
  # Initialize metrics if they haven't been
38
38
  env[:metrics] ||= {}
39
39
 
@@ -43,6 +43,7 @@ module VagrantPlugins
43
43
  # Get the configs
44
44
  zone_config = env[:machine].provider_config.get_zone_config(zone)
45
45
  image = zone_config.image
46
+ instance_group = zone_config.instance_group
46
47
  name = zone_config.name
47
48
  machine_type = zone_config.machine_type
48
49
  disk_size = zone_config.disk_size
@@ -67,6 +68,7 @@ module VagrantPlugins
67
68
  env[:ui].info(" -- Disk size: #{disk_size} GB")
68
69
  env[:ui].info(" -- Disk name: #{disk_name}")
69
70
  env[:ui].info(" -- Image: #{image}")
71
+ env[:ui].info(" -- Instance Group: #{instance_group}")
70
72
  env[:ui].info(" -- Zone: #{zone}") if zone
71
73
  env[:ui].info(" -- Network: #{network}") if network
72
74
  env[:ui].info(" -- Metadata: '#{metadata}'")
@@ -16,7 +16,7 @@ require "securerandom"
16
16
 
17
17
  module VagrantPlugins
18
18
  module Google
19
- class Config < Vagrant.plugin("2", :config)
19
+ class Config < Vagrant.plugin("2", :config) # rubocop:disable Metrics/ClassLength
20
20
  # The Service Account Client ID Email address
21
21
  #
22
22
  # @return [String]
@@ -42,6 +42,11 @@ module VagrantPlugins
42
42
  # @return [String]
43
43
  attr_accessor :image
44
44
 
45
+ # The instance group name to put the instance in.
46
+ #
47
+ # @return [String]
48
+ attr_accessor :instance_group
49
+
45
50
  # The type of machine to launch, such as "n1-standard-1"
46
51
  #
47
52
  # @return [String]
@@ -132,8 +137,8 @@ module VagrantPlugins
132
137
  #
133
138
  # @return [Array]
134
139
  attr_accessor :service_accounts
135
- alias_method :scopes, :service_accounts
136
- alias_method :scopes=, :service_accounts=
140
+ alias scopes service_accounts
141
+ alias scopes= service_accounts=
137
142
 
138
143
  def initialize(zone_specific=false)
139
144
  @google_client_email = UNSET_VALUE
@@ -141,6 +146,7 @@ module VagrantPlugins
141
146
  @google_json_key_location = UNSET_VALUE
142
147
  @google_project_id = UNSET_VALUE
143
148
  @image = UNSET_VALUE
149
+ @instance_group = UNSET_VALUE
144
150
  @machine_type = UNSET_VALUE
145
151
  @disk_size = UNSET_VALUE
146
152
  @disk_name = UNSET_VALUE
@@ -227,7 +233,7 @@ module VagrantPlugins
227
233
  end
228
234
  end
229
235
 
230
- def finalize!
236
+ def finalize! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
231
237
  # Try to get access keys from standard Google environment variables; they
232
238
  # will default to nil if the environment variables are not present.
233
239
  @google_client_email = ENV['GOOGLE_CLIENT_EMAIL'] if @google_client_email == UNSET_VALUE
@@ -238,6 +244,9 @@ module VagrantPlugins
238
244
  # Image must be nil, since we can't default that
239
245
  @image = "debian-7-wheezy-v20150127" if @image == UNSET_VALUE
240
246
 
247
+ # Default instance group name is nil
248
+ @instance_group = nil if @instance_group == UNSET_VALUE
249
+
241
250
  # Default instance type is an n1-standard-1
242
251
  @machine_type = "n1-standard-1" if @machine_type == UNSET_VALUE
243
252
 
@@ -13,6 +13,6 @@
13
13
  # limitations under the License.
14
14
  module VagrantPlugins
15
15
  module Google
16
- VERSION = "0.2.3"
16
+ VERSION = "0.2.4".freeze
17
17
  end
18
18
  end
data/locales/en.yml CHANGED
@@ -4,6 +4,10 @@ en:
4
4
  The machine is already created.
5
5
  already_status: |-
6
6
  The machine is already in %{status} status.
7
+ instance_group_create: |-
8
+ Instance group doesn't exist, trying to create...
9
+ instance_group_add: |-
10
+ Adding machine to the instance group...
7
11
  launching_instance: |-
8
12
  Launching an instance with the following settings...
9
13
  not_created: |-
@@ -23,6 +27,8 @@ en:
23
27
  Stopping the instance...
24
28
  terminating: |-
25
29
  Terminating the instance...
30
+ waiting_for_operation: |-
31
+ Waiting for GCP operation '%{name}' to finish...
26
32
  waiting_for_ready: |-
27
33
  Waiting for instance to become "ready"...
28
34
  waiting_for_ssh: |-
@@ -30,19 +30,28 @@ namespace :acceptance do
30
30
  yellow "NOTE: For acceptance tests to be functional, correct ssh key needs to be added to GCE metadata."
31
31
 
32
32
  if !ENV["GOOGLE_JSON_KEY_LOCATION"] && !ENV["GOOGLE_KEY_LOCATION"]
33
- abort ("Environment variables GOOGLE_JSON_KEY_LOCATION or GOOGLE_KEY_LOCATION are not set. Aborting.")
33
+ abort "Environment variables GOOGLE_JSON_KEY_LOCATION or GOOGLE_KEY_LOCATION are not set. Aborting."
34
34
  end
35
35
 
36
36
  unless ENV["GOOGLE_PROJECT_ID"]
37
- abort ("Environment variable GOOGLE_PROJECT_ID is not set. Aborting.")
37
+ abort "Environment variable GOOGLE_PROJECT_ID is not set. Aborting."
38
38
  end
39
39
 
40
40
  unless ENV["GOOGLE_CLIENT_EMAIL"]
41
- abort ("Environment variable GOOGLE_CLIENT_EMAIL is not set. Aborting.")
41
+ abort "Environment variable GOOGLE_CLIENT_EMAIL is not set. Aborting."
42
42
  end
43
43
 
44
44
  unless ENV["GOOGLE_SSH_USER"]
45
- puts "WARNING: GOOGLE_SSH_USER variable is not set. Will try to start tests using insecure Vagrant private key."
45
+ yellow "WARNING: GOOGLE_SSH_USER variable is not set. Will try to start tests using insecure Vagrant private key."
46
+ end
47
+
48
+ if ENV["GOOGLE_SSH_KEY_LOCATION"]
49
+ if File.read(ENV["GOOGLE_SSH_KEY_LOCATION"]).include?('ENCRYPTED')
50
+ unless `ssh-add -L`.include?(ENV["GOOGLE_SSH_KEY_LOCATION"])
51
+ 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."
53
+ end
54
+ end
46
55
  end
47
56
  end
48
57
 
@@ -53,6 +62,7 @@ namespace :acceptance do
53
62
  preemptible
54
63
  reload
55
64
  scopes
65
+ instance_groups
56
66
  provisioner/shell
57
67
  provisioner/chef-solo
58
68
  ).map{ |s| "provider/google/#{s}" }
data/tasks/boxes.rake ADDED
@@ -0,0 +1,20 @@
1
+ # Boxes maintenance tasks
2
+ namespace :boxes do
3
+ task :update => [:repack_main, :repack_testing]
4
+
5
+ task :repack_main do
6
+ boxes_dir = File.expand_path("../../example_boxes", __FILE__)
7
+ Dir.chdir(boxes_dir)
8
+
9
+ puts "Repacking main box"
10
+ system('tar cvzf ../google.box -C ./gce ./metadata.json ./Vagrantfile')
11
+ end
12
+
13
+ task :repack_testing do
14
+ boxes_dir = File.expand_path("../../example_boxes", __FILE__)
15
+ Dir.chdir(boxes_dir)
16
+
17
+ puts "Repacking test box"
18
+ system('tar cvzf ../google-test.box -C ./gce-test ./metadata.json ./Vagrantfile')
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ # This test check that the instance groups logic doesn't break the provisioning
2
+ # process.
3
+ #
4
+ # TODO: Reach out using Fog credentials and verify group existence.
5
+ # TODO: Clean up the created instance groups automatically
6
+ shared_examples 'provider/instance_groups' do |provider, options|
7
+ unless options[:box]
8
+ raise ArgumentError,
9
+ "box option must be specified for provider: #{provider}"
10
+ end
11
+
12
+ include_context 'acceptance'
13
+
14
+ before do
15
+ environment.skeleton('instance_groups')
16
+ assert_execute('vagrant', 'box', 'add', 'basic', options[:box])
17
+ assert_execute('vagrant', 'up', "--provider=#{provider}")
18
+ end
19
+
20
+ after do
21
+ assert_execute('vagrant', 'destroy', '--force')
22
+ end
23
+
24
+ it 'should bring up machine with an instance group' do
25
+ status("Test: machine is running after up")
26
+ result = execute("vagrant", "ssh", "-c", "echo foo")
27
+ expect(result).to exit_with(0)
28
+ expect(result.stdout).to match(/foo\n$/)
29
+ end
30
+ end
@@ -4,7 +4,7 @@
4
4
  Vagrant.configure("2") do |config|
5
5
  config.vm.box = "basic"
6
6
 
7
- config.vm.provider :google do |google, override|
7
+ config.vm.provider :google do |google|
8
8
 
9
9
  google.zone = "europe-west1-d"
10
10
 
@@ -0,0 +1,15 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.vm.box = "basic"
3
+
4
+ config.vm.provider :google do |google|
5
+
6
+ google.zone = "europe-west1-d"
7
+
8
+ google.zone_config "europe-west1-d" do |zone1d|
9
+ zone1d.name = "vagrant-acceptance-instance-groups"
10
+ zone1d.instance_group = "vagrant-acceptance-#{('a'..'z').to_a.sample(8).join}"
11
+ zone1d.image = "debian-7-wheezy-v20150603"
12
+ zone1d.zone = "europe-west1-d"
13
+ end
14
+ end
15
+ end
@@ -2,11 +2,11 @@ Vagrant.configure("2") do |config|
2
2
  config.vm.box = "basic"
3
3
 
4
4
  config.vm.define :z1a do |z1a|
5
- z1a.vm.provider :google do |google, override|
5
+ z1a.vm.provider :google do |google|
6
6
  google.zone = "europe-west1-c"
7
7
 
8
8
  google.zone_config "europe-west1-c" do |z1a_zone|
9
- z1a_zone.name = "vagrant-testing-acceptance-multi-z1a"
9
+ z1a_zone.name = "vagrant-acceptance-multi-z1a"
10
10
  z1a_zone.image = "debian-7-wheezy-v20150603"
11
11
  z1a_zone.machine_type = "n1-standard-1"
12
12
  z1a_zone.zone = "europe-west1-c"
@@ -15,7 +15,7 @@ Vagrant.configure("2") do |config|
15
15
  end
16
16
 
17
17
  config.vm.define :z1b do |z1b|
18
- z1b.vm.provider :google do |google, override|
18
+ z1b.vm.provider :google do |google|
19
19
  google.zone = "europe-west1-d"
20
20
 
21
21
  google.zone_config "europe-west1-d" do |z1b_zone|
@@ -1,12 +1,12 @@
1
1
  Vagrant.configure("2") do |config|
2
2
  config.vm.box = "basic"
3
3
 
4
- config.vm.provider :google do |google, override|
4
+ config.vm.provider :google do |google|
5
5
 
6
6
  google.zone = "europe-west1-d"
7
7
 
8
8
  google.zone_config "europe-west1-d" do |zone1d|
9
- zone1d.name = "vagrant-testing-preemptible"
9
+ zone1d.name = "vagrant-acceptance-preemptible"
10
10
  zone1d.image = "debian-7-wheezy-v20150603"
11
11
  zone1d.zone = "europe-west1-d"
12
12
  zone1d.preemptible = true
@@ -1,12 +1,12 @@
1
1
  Vagrant.configure("2") do |config|
2
2
  config.vm.box = "basic"
3
3
 
4
- config.vm.provider :google do |google, override|
4
+ config.vm.provider :google do |google|
5
5
 
6
6
  google.zone = "europe-west1-d"
7
7
 
8
8
  google.zone_config "europe-west1-d" do |zone1d|
9
- zone1d.name = "vagrant-testing-acceptance-scopes"
9
+ zone1d.name = "vagrant-acceptance-scopes"
10
10
  zone1d.scopes = ['sql-admin',
11
11
  'bigquery',
12
12
  'https://www.googleapis.com/auth/compute'
@@ -32,6 +32,7 @@ describe VagrantPlugins::Google::Config do
32
32
 
33
33
  its("name") { should match "i-[0-9]{10}-[0-9a-f]{4}" }
34
34
  its("image") { should == "debian-7-wheezy-v20150127" }
35
+ its("instance_group") { should be_nil }
35
36
  its("zone") { should == "us-central1-f" }
36
37
  its("network") { should == "default" }
37
38
  its("machine_type") { should == "n1-standard-1" }
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.required_rubygems_version = ">= 1.3.6"
29
29
  s.rubyforge_project = "vagrant-google"
30
30
 
31
- s.add_runtime_dependency "fog-google", "~> 0.0.7"
31
+ s.add_runtime_dependency "fog-google", "~> 0.2.0"
32
32
  s.add_runtime_dependency "google-api-client", "< 0.9", ">= 0.6.2"
33
33
 
34
34
  s.add_development_dependency "pry"
@@ -5,6 +5,6 @@ Vagrant::Spec::Acceptance.configure do |c|
5
5
  c.skeleton_paths << File.expand_path("../test/acceptance/skeletons", __FILE__)
6
6
 
7
7
  c.provider "google",
8
- box: "https://github.com/mitchellh/vagrant-google/raw/master/google-test.box",
8
+ box: File.expand_path("../google-test.box", __FILE__),
9
9
  contexts: ["provider-context/google"]
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Johnson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-26 00:00:00.000000000 Z
12
+ date: 2016-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog-google
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: 0.0.7
20
+ version: 0.2.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: 0.0.7
27
+ version: 0.2.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: google-api-client
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -122,19 +122,15 @@ extensions: []
122
122
  extra_rdoc_files: []
123
123
  files:
124
124
  - CHANGELOG.md
125
- - Gemfile
126
- - LICENSE
127
- - README.md
128
- - Rakefile
129
- - example_boxes/README.md
130
- - example_boxes/gce-test/Vagrantfile
131
- - example_boxes/gce-test/metadata.json
132
- - example_boxes/gce/Vagrantfile
133
125
  - example_boxes/gce/metadata.json
126
+ - example_boxes/gce/Vagrantfile
127
+ - example_boxes/gce-test/metadata.json
128
+ - example_boxes/gce-test/Vagrantfile
129
+ - example_boxes/README.md
130
+ - Gemfile
134
131
  - google-test.box
135
132
  - google.box
136
- - lib/vagrant-google.rb
137
- - lib/vagrant-google/action.rb
133
+ - lib/vagrant-google/action/assign_instance_groups.rb
138
134
  - lib/vagrant-google/action/connect_google.rb
139
135
  - lib/vagrant-google/action/is_created.rb
140
136
  - lib/vagrant-google/action/is_terminated.rb
@@ -151,36 +147,44 @@ files:
151
147
  - lib/vagrant-google/action/timed_provision.rb
152
148
  - lib/vagrant-google/action/warn_networks.rb
153
149
  - lib/vagrant-google/action/warn_ssh_keys.rb
150
+ - lib/vagrant-google/action.rb
154
151
  - lib/vagrant-google/config.rb
155
152
  - lib/vagrant-google/errors.rb
156
153
  - lib/vagrant-google/plugin.rb
157
154
  - lib/vagrant-google/provider.rb
158
155
  - lib/vagrant-google/util/timer.rb
159
156
  - lib/vagrant-google/version.rb
157
+ - lib/vagrant-google.rb
158
+ - LICENSE
160
159
  - locales/en.yml
160
+ - Rakefile
161
+ - README.md
161
162
  - tasks/acceptance.rake
163
+ - tasks/boxes.rake
162
164
  - tasks/bundler.rake
163
165
  - tasks/lint.rake
164
166
  - tasks/test.rake
165
167
  - test/acceptance/base.rb
166
168
  - test/acceptance/provider/halt_spec.rb
169
+ - test/acceptance/provider/instance_groups_spec.rb
167
170
  - test/acceptance/provider/multi_instance_spec.rb
168
171
  - test/acceptance/provider/preemptible_spec.rb
169
172
  - test/acceptance/provider/reload_spec.rb
170
173
  - test/acceptance/provider/scopes_spec.rb
171
174
  - test/acceptance/shared/context_google.rb
172
175
  - test/acceptance/skeletons/generic/Vagrantfile
176
+ - test/acceptance/skeletons/instance_groups/Vagrantfile
173
177
  - test/acceptance/skeletons/multi_instance/Vagrantfile
174
178
  - test/acceptance/skeletons/preemptible/Vagrantfile
175
179
  - test/acceptance/skeletons/scopes/Vagrantfile
176
180
  - test/unit/base.rb
177
181
  - test/unit/common/config_test.rb
182
+ - vagrant-google.gemspec
178
183
  - vagrant-spec.config.rb
179
184
  - vagrantfile_examples/Vagrantfile.multiple_machines
180
185
  - vagrantfile_examples/Vagrantfile.provision_single
181
186
  - vagrantfile_examples/Vagrantfile.simple
182
187
  - vagrantfile_examples/Vagrantfile.zone_config
183
- - vagrant-google.gemspec
184
188
  - .gitignore
185
189
  - .rubocop.yml
186
190
  - .rubocop_todo.yml