beaker-google 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,18 +17,34 @@ module Beaker
17
17
  BASE_URL = "https://www.googleapis.com/compute/#{API_VERSION}/projects/"
18
18
  CENTOS_PROJECT = 'centos-cloud'
19
19
  DEBIAN_PROJECT = 'debian-cloud'
20
+ RHEL_PROJECT = 'rhel-cloud'
21
+ SLES_PROJECT = 'sles-cloud'
20
22
  DEFAULT_ZONE_NAME = 'us-central1-a'
21
23
  DEFAULT_MACHINE_TYPE = 'n1-highmem-2'
22
24
  DEFAULT_DISK_SIZE = 25
23
25
 
24
- #Create a new instance of the Google Compute Engine helper object
25
- #@param [Hash{Symbol=>String}] options The options hash containing configuration values
26
- #@option options [String] :gce_project The Google Compute Project name to connect to
27
- #@option options [String] :gce_keyfile The location of the Google Compute service account keyfile
28
- #@option options [String] :gce_password The password for the Google Compute service account key
29
- #@option options [String] :gce_email The email address for the Google Compute service account
30
- #@option options [String] :gce_machine_type A Google Compute machine type used to create instances, defaults to n1-highmem-2
31
- #@option options [Integer] :timeout The amount of time to attempt execution before quiting and exiting with failure
26
+ # Create a new instance of the Google Compute Engine helper object
27
+ #
28
+ # @param [Hash{Symbol=>String}] options The options hash containing
29
+ # configuration values
30
+ #
31
+ # @option options [String] :gce_project The Google Compute Project name to
32
+ # connect to
33
+ #
34
+ # @option options [String] :gce_keyfile The location of the Google Compute
35
+ # service account keyfile
36
+ #
37
+ # @option options [String] :gce_password The password for the Google Compute
38
+ # service account key
39
+ #
40
+ # @option options [String] :gce_email The email address for the Google
41
+ # Compute service account
42
+ #
43
+ # @option options [String] :gce_machine_type A Google Compute machine type
44
+ # used to create instances, defaults to n1-highmem-2
45
+ #
46
+ # @option options [Integer] :timeout The amount of time to attempt execution
47
+ # before quiting and exiting with failure
32
48
  def initialize(options)
33
49
  @options = options
34
50
  @logger = options[:logger]
@@ -39,54 +55,91 @@ module Beaker
39
55
  set_client(Beaker::Version::STRING)
40
56
  set_compute_api(API_VERSION, start, attempts)
41
57
 
58
+ @options[:gce_project] = ENV['BEAKER_gce_project'] if ENV['BEAKER_gce_project']
59
+ @options[:gce_keyfile] = ENV['BEAKER_gce_keyfile'] if ENV['BEAKER_gce_keyfile']
60
+
61
+ unless (@options[:gce_keyfile] && File.exist?(@options[:gce_keyfile]))
62
+ @options[:gce_keyfile] = File.join(ENV['HOME'], '.beaker', 'gce', %(#{@options[:gce_project]}.p12))
63
+ end
64
+
65
+ @options[:gce_password] = ENV['BEAKER_gce_password'] if ENV['BEAKER_gce_password']
66
+ # This is the GCE default so there's usually not a reason to specify it
67
+ @options[:gce_password] = 'notasecret' unless @options[:gce_password]
68
+
69
+ @options[:gce_email] = ENV['BEAKER_gce_email'] if ENV['BEAKER_gce_email']
70
+
42
71
  raise 'You must specify a gce_project for Google Compute Engine instances!' unless @options[:gce_project]
43
- raise 'You must specify a gce_keyfile for Google Compute Engine instances!' unless @options[:gce_keyfile]
44
- raise 'You must specify a gce_password for Google Compute Engine instances!' unless @options[:gce_password]
72
+
73
+ raise "Could not find gce_keyfile for Google Compute Engine at '#{@options[:gce_keyfile]}'!" unless File.exist?(@options[:gce_keyfile])
74
+
45
75
  raise 'You must specify a gce_email for Google Compute Engine instances!' unless @options[:gce_email]
46
76
 
47
77
  authenticate(@options[:gce_keyfile], @options[:gce_password], @options[:gce_email], start, attempts)
48
78
  end
49
79
 
50
- #Determines the default Google Compute zone based upon options and defaults
51
- #@return The full URL to the default zone in which Google Compute requests will be sent
80
+ # Determines the default Google Compute zone based upon options and
81
+ # defaults
82
+ #
83
+ # @return The full URL to the default zone in which Google Compute requests
84
+ # will be sent
52
85
  def default_zone
53
86
  BASE_URL + @options[:gce_project] + '/global/zones/' + DEFAULT_ZONE_NAME
54
87
  end
55
88
 
56
- #Determines the default Google Compute network based upon defaults and options
57
- #@return The full URL to the default network in which Google Compute instances will operate
89
+ # Determines the default Google Compute network based upon defaults and
90
+ # options
91
+ #
92
+ # @return The full URL to the default network in which Google Compute
93
+ # instances will operate
58
94
  def default_network
59
95
  BASE_URL + @options[:gce_project] + '/global/networks/default'
60
96
  end
61
97
 
62
- #Determines the Google Compute project which contains bases instances of type name
63
- #@param [String] name The platform type to search for
64
- #@return The Google Compute project name
65
- #@raise [Exception] If the provided platform type name is unsupported
98
+ # Determines the Google Compute project which contains bases instances of
99
+ # type name
100
+ #
101
+ # @param [String] name The platform type to search for
102
+ #
103
+ # @return The Google Compute project name
104
+ #
105
+ # @raise [Exception] If the provided platform type name is unsupported
66
106
  def get_platform_project(name)
67
107
  if name =~ /debian/
68
108
  return DEBIAN_PROJECT
69
109
  elsif name =~ /centos/
70
110
  return CENTOS_PROJECT
111
+ elsif name =~ /rhel/
112
+ return RHEL_PROJECT
113
+ elsif name =~ /sles/
114
+ return SLES_PROJECT
71
115
  else
72
116
  raise "Unsupported platform for Google Compute Engine: #{name}"
73
117
  end
74
118
  end
75
119
 
76
- #Create the Google APIClient object which will be used for accessing the Google Compute API
77
- #@param version The version number of Beaker currently running
120
+ # Create the Google APIClient object which will be used for accessing the
121
+ # Google Compute API
122
+ #
123
+ # @param version The version number of Beaker currently running
78
124
  def set_client(version)
79
- @client = Google::APIClient.new({:application_name => "Beaker", :application_version => version})
80
- end
81
-
82
- #Discover the currently active Google Compute API
83
- #@param [String] version The version of the Google Compute API to discover
84
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
85
- # further code execution attempts remain
86
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
87
- #@raise [Exception] Raised if we fail to discover the Google Compute API, either through errors or running out of attempts
125
+ @client = ::Google::APIClient.new({:application_name => "Beaker", :application_version => version})
126
+ end
127
+
128
+ # Discover the currently active Google Compute API
129
+ #
130
+ # @param [String] version The version of the Google Compute API to discover
131
+ #
132
+ # @param [Integer] start The time when we started code execution, it is
133
+ # compared to Time.now to determine how many further code execution
134
+ # attempts remain
135
+ #
136
+ # @param [Integer] attempts The total amount of attempts to execute that we
137
+ # are willing to allow
138
+ #
139
+ # @raise [Exception] Raised if we fail to discover the Google Compute API,
140
+ # either through errors or running out of attempts
88
141
  def set_compute_api version, start, attempts
89
- try = (Time.now - start) / SLEEPWAIT
142
+ try = (Time.now - start)/SLEEPWAIT
90
143
  while try <= attempts
91
144
  begin
92
145
  @compute = @client.discovered_api('compute', version)
@@ -102,18 +155,31 @@ module Beaker
102
155
  end
103
156
  end
104
157
 
105
- #Creates an authenticated connection to the Google Compute Engine API
106
- #@param [String] keyfile The location of the Google Compute Service Account keyfile to use for authentication
107
- #@param [String] password The password for the provided Google Compute Service Account key
108
- #@param [String] email The email address of the Google Compute Service Account we are using to connect
109
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
110
- # further code execution attempts remain
111
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
112
- #@raise [Exception] Raised if we fail to create an authenticated connection to the Google Compute API, either through errors or running out of attempts
158
+ # Creates an authenticated connection to the Google Compute Engine API
159
+ #
160
+ # @param [String] keyfile The location of the Google Compute Service
161
+ # Account keyfile to use for authentication
162
+ #
163
+ # @param [String] password The password for the provided Google Compute
164
+ # Service Account key
165
+ #
166
+ # @param [String] email The email address of the Google Compute Service
167
+ # Account we are using to connect
168
+ #
169
+ # @param [Integer] start The time when we started code execution, it is
170
+ # compared to Time.now to determine how many further code execution
171
+ # attempts remain
172
+ #
173
+ # @param [Integer] attempts The total amount of attempts to execute that we
174
+ # are willing to allow
175
+ #
176
+ # @raise [Exception] Raised if we fail to create an authenticated
177
+ # connection to the Google Compute API, either through errors or running
178
+ # out of attempts
113
179
  def authenticate(keyfile, password, email, start, attempts)
114
180
  # OAuth authentication, using the service account
115
- key = Google::APIClient::PKCS12.load_key(keyfile, password)
116
- service_account = Google::APIClient::JWTAsserter.new(
181
+ key = ::Google::APIClient::PKCS12.load_key(keyfile, password)
182
+ service_account = ::Google::APIClient::JWTAsserter.new(
117
183
  email,
118
184
  AUTH_URL,
119
185
  key)
@@ -133,12 +199,19 @@ module Beaker
133
199
  end
134
200
  end
135
201
 
136
- #Executes a provided Google Compute request using a previously configured and authenticated Google Compute client connection
137
- #@param [Hash] req A correctly formatted Google Compute request object
138
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
139
- # further code execution attempts remain
140
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
141
- #@raise [Exception] Raised if we fail to execute the request, either through errors or running out of attempts
202
+ # Executes a provided Google Compute request using a previously configured
203
+ # and authenticated Google Compute client connection
204
+ #
205
+ # @param [Hash] req A correctly formatted Google Compute request object
206
+ #
207
+ # @param [Integer] start The time when we started code execution, it is
208
+ # compared to Time.now to determine how many further code execution
209
+ # attempts remain
210
+ # @param [Integer] attempts The total amount of attempts to execute that we
211
+ # are willing to allow
212
+ #
213
+ # @raise [Exception] Raised if we fail to execute the request, either
214
+ # through errors or running out of attempts
142
215
  def execute req, start, attempts
143
216
  last_error = parsed = nil
144
217
  try = (Time.now - start) / SLEEPWAIT
@@ -157,32 +230,42 @@ module Beaker
157
230
  end
158
231
  end
159
232
  return parsed
160
- #retry errors
233
+ # retry errors
161
234
  rescue Faraday::Error::ConnectionFailed => e
162
235
  @logger.debug "ConnectionFailed attempting Google Compute execute command"
163
236
  try += 1
164
237
  last_error = e
165
238
  end
166
239
  end
167
- #we only get down here if we've used up all our tries
240
+ # we only get down here if we've used up all our tries
168
241
  raise last_error
169
242
  end
170
243
 
171
- #Determines the latest image available for the provided platform name. We currently only support debian-7 and centos-6 platforms.
172
- #@param [String] platform The platform type to search for an instance of, must be one of /debian-7-.*/ or /centos-6-.*/
173
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
174
- # further code execution attempts remain
175
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
176
- #@return [Hash] The image hash of the latest, non-deprecated image for the provided platform
177
- #@raise [Exception] Raised if we fail to execute the request, either through errors or running out of attempts
244
+ # Determines the latest image available for the provided platform name.
245
+ #
246
+ # Only images of the form (platform)-(version)-(version) are currently supported
247
+ #
248
+ # @param [String] platform The platform type to search for an instance of.
249
+ #
250
+ # @param [Integer] start The time when we started code execution, it is
251
+ # compared to Time.now to determine how many further code execution
252
+ # attempts remain
253
+ #
254
+ # @param [Integer] attempts The total amount of attempts to execute that we
255
+ # are willing to allow
256
+ #
257
+ # @return [Hash] The image hash of the latest, non-deprecated image for the
258
+ # provided platform
259
+ #
260
+ # @raise [Exception] Raised if we fail to execute the request, either
261
+ # through errors or running out of attempts
178
262
  def get_latest_image(platform, start, attempts)
179
- #use the platform version numbers instead of codenames
180
- platform = platform.with_version_number
181
263
  #break up my platform for information
182
264
  platform_name, platform_version, platform_extra_info = platform.split('-', 3)
183
265
  #find latest image to use
184
266
  result = execute( image_list_req(get_platform_project(platform_name)), start, attempts )
185
267
  images = result["items"]
268
+
186
269
  #reject images of the wrong version of the given platform
187
270
  images.delete_if { |image| image['name'] !~ /^#{platform_name}-#{platform_version}/}
188
271
  #reject deprecated images
@@ -194,54 +277,89 @@ module Beaker
194
277
  images[0]
195
278
  end
196
279
 
197
- #Determines the Google Compute machineType object based upon the selected gce_machine_type option
198
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
199
- # further code execution attempts remain
200
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
201
- #@return [Hash] The machineType hash
202
- #@raise [Exception] Raised if we fail get the machineType, either through errors or running out of attempts
280
+ # Determines the Google Compute machineType object based upon the selected
281
+ # gce_machine_type option
282
+ #
283
+ # @param [Integer] start The time when we started code execution, it is
284
+ # compared to Time.now to determine how many further code execution
285
+ # attempts remain
286
+ #
287
+ # @param [Integer] attempts The total amount of attempts to execute that we
288
+ # are willing to allow
289
+ #
290
+ # @return [Hash] The machineType hash
291
+ #
292
+ # @raise [Exception] Raised if we fail get the machineType, either through
293
+ # errors or running out of attempts
203
294
  def get_machineType(start, attempts)
204
295
  execute( machineType_get_req, start, attempts )
205
296
  end
206
297
 
207
- #Determines the Google Compute network object in use for the current connection
208
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
209
- # further code execution attempts remain
210
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
211
- #@return [Hash] The network hash
212
- #@raise [Exception] Raised if we fail get the network, either through errors or running out of attempts
298
+ # Determines the Google Compute network object in use for the current connection
299
+ # @param [Integer] start The time when we started code execution, it is
300
+ # compared to Time.now to determine how many further code execution
301
+ # attempts remain
302
+ #
303
+ # @param [Integer] attempts The total amount of attempts to execute that we
304
+ # are willing to allow
305
+ #
306
+ # @return [Hash] The network hash
307
+ #
308
+ # @raise [Exception] Raised if we fail get the network, either through
309
+ # errors or running out of attempts
213
310
  def get_network(start, attempts)
214
311
  execute( network_get_req, start, attempts)
215
312
  end
216
313
 
217
- #Determines a list of existing Google Compute instances
218
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
219
- # further code execution attempts remain
220
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
221
- #@return [Array[Hash]] The instances array of hashes
222
- #@raise [Exception] Raised if we fail determine the list of existing instances, either through errors or running out of attempts
314
+ # Determines a list of existing Google Compute instances
315
+ #
316
+ # @param [Integer] start The time when we started code execution, it is
317
+ # compared to Time.now to determine how many further code execution
318
+ # attempts remain
319
+ #
320
+ # @param [Integer] attempts The total amount of attempts to execute that we
321
+ # are willing to allow
322
+ #
323
+ # @return [Array[Hash]] The instances array of hashes
324
+ #
325
+ # @raise [Exception] Raised if we fail determine the list of existing
326
+ # instances, either through errors or running out of attempts
223
327
  def list_instances(start, attempts)
224
328
  instances = execute( instance_list_req(), start, attempts )
225
329
  instances["items"]
226
330
  end
227
331
 
228
- #Determines a list of existing Google Compute disks
229
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
230
- # further code execution attempts remain
231
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
232
- #@return [Array[Hash]] The disks array of hashes
233
- #@raise [Exception] Raised if we fail determine the list of existing disks, either through errors or running out of attempts
332
+ # Determines a list of existing Google Compute disks
333
+ #
334
+ # @param [Integer] start The time when we started code execution, it is
335
+ # compared to Time.now to determine how many further code execution
336
+ # attempts remain
337
+ #
338
+ # @param [Integer] attempts The total amount of attempts to execute that we
339
+ # are willing to allow
340
+ #
341
+ # @return [Array[Hash]] The disks array of hashes
342
+ #
343
+ # @raise [Exception] Raised if we fail determine the list of existing
344
+ # disks, either through errors or running out of attempts
234
345
  def list_disks(start, attempts)
235
346
  disks = execute( disk_list_req(), start, attempts )
236
347
  disks["items"]
237
348
  end
238
349
 
239
- #Determines a list of existing Google Compute firewalls
240
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
241
- # further code execution attempts remain
242
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
243
- #@return [Array[Hash]] The firewalls array of hashes
244
- #@raise [Exception] Raised if we fail determine the list of existing firewalls, either through errors or running out of attempts
350
+ # Determines a list of existing Google Compute firewalls
351
+ #
352
+ # @param [Integer] start The time when we started code execution, it is
353
+ # compared to Time.now to determine how many further code execution
354
+ # attempts remain
355
+ #
356
+ # @param [Integer] attempts The total amount of attempts to execute that we
357
+ # are willing to allow
358
+ #
359
+ # @return [Array[Hash]] The firewalls array of hashes
360
+ #
361
+ # @raise [Exception] Raised if we fail determine the list of existing
362
+ # firewalls, either through errors or running out of attempts
245
363
  def list_firewalls(start, attempts)
246
364
  result = execute( firewall_list_req(), start, attempts )
247
365
  firewalls = result["items"]
@@ -249,24 +367,41 @@ module Beaker
249
367
  firewalls
250
368
  end
251
369
 
252
- #Create a Google Compute firewall on the current connection
253
- #@param [String] name The name of the firewall to create
254
- #@param [Hash] network The Google Compute network hash in which to create the firewall
255
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
256
- # further code execution attempts remain
257
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
258
- #@raise [Exception] Raised if we fail create the firewall, either through errors or running out of attempts
370
+ # Create a Google Compute firewall on the current connection
371
+ #
372
+ # @param [String] name The name of the firewall to create
373
+ #
374
+ # @param [Hash] network The Google Compute network hash in which to create
375
+ # the firewall
376
+ #
377
+ # @param [Integer] start The time when we started code execution, it is
378
+ # compared to Time.now to determine how many further code execution
379
+ # attempts remain
380
+ #
381
+ # @param [Integer] attempts The total amount of attempts to execute that we
382
+ # are willing to allow
383
+ #
384
+ # @raise [Exception] Raised if we fail create the firewall, either through
385
+ # errors or running out of attempts
259
386
  def create_firewall(name, network, start, attempts)
260
387
  execute( firewall_insert_req( name, network['selfLink'] ), start, attempts )
261
388
  end
262
389
 
263
- #Create a Google Compute disk on the current connection
264
- #@param [String] name The name of the disk to create
265
- #@param [Hash] img The Google Compute image to use for instance creation
266
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
267
- # further code execution attempts remain
268
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
269
- #@raise [Exception] Raised if we fail create the disk, either through errors or running out of attempts
390
+ # Create a Google Compute disk on the current connection
391
+ #
392
+ # @param [String] name The name of the disk to create
393
+ #
394
+ # @param [Hash] img The Google Compute image to use for instance creation
395
+ #
396
+ # @param [Integer] start The time when we started code execution, it is
397
+ # compared to Time.now to determine how many further code execution
398
+ # attempts remain
399
+ #
400
+ # @param [Integer] attempts The total amount of attempts to execute that we
401
+ # are willing to allow
402
+ #
403
+ # @raise [Exception] Raised if we fail create the disk, either through
404
+ # errors or running out of attempts
270
405
  def create_disk(name, img, start, attempts)
271
406
  #create a new boot disk for this instance
272
407
  disk = execute( disk_insert_req( name, img['selfLink'] ), start, attempts )
@@ -289,15 +424,26 @@ module Beaker
289
424
  disk
290
425
  end
291
426
 
292
- #Create a Google Compute instance on the current connection
293
- #@param [String] name The name of the instance to create
294
- #@param [Hash] img The Google Compute image to use for instance creation
295
- #@param [Hash] machineType The Google Compute machineType
296
- #@param [Hash] disk The Google Compute disk to attach to the newly created instance
297
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
298
- # further code execution attempts remain
299
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
300
- #@raise [Exception] Raised if we fail create the instance, either through errors or running out of attempts
427
+ # Create a Google Compute instance on the current connection
428
+ #
429
+ # @param [String] name The name of the instance to create
430
+ #
431
+ # @param [Hash] img The Google Compute image to use for instance creation
432
+ #
433
+ # @param [Hash] machineType The Google Compute machineType
434
+ #
435
+ # @param [Hash] disk The Google Compute disk to attach to the newly created
436
+ # instance
437
+ #
438
+ # @param [Integer] start The time when we started code execution, it is
439
+ # compared to Time.now to determine how many further code execution
440
+ # attempts remain
441
+ #
442
+ # @param [Integer] attempts The total amount of attempts to execute that we
443
+ # are willing to allow
444
+ #
445
+ # @raise [Exception] Raised if we fail create the instance, either through
446
+ # errors or running out of attempts
301
447
  def create_instance(name, img, machineType, disk, start, attempts)
302
448
  #add a new instance of the image
303
449
  instance = execute( instance_insert_req( name, img['selfLink'], machineType['selfLink'], disk['selfLink'] ), start, attempts)
@@ -319,14 +465,26 @@ module Beaker
319
465
  instance
320
466
  end
321
467
 
322
- #Add key/value pairs to a Google Compute instance on the current connection
323
- #@param [String] name The name of the instance to add metadata to
324
- #@param [String] fingerprint A hash of the metadata's contents of the given instance
325
- #@param [Array<Hash>] data An array of hashes. Each hash should have a key and a value.
326
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
327
- # further code execution attempts remain
328
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
329
- #@raise [Exception] Raised if we fail to add metadata, either through errors or running out of attempts
468
+ # Add key/value pairs to a Google Compute instance on the current
469
+ # connection
470
+ #
471
+ # @param [String] name The name of the instance to add metadata to
472
+ #
473
+ # @param [String] fingerprint A hash of the metadata's contents of the
474
+ # given instance
475
+ #
476
+ # @param [Array<Hash>] data An array of hashes. Each hash should have a
477
+ # key and a value.
478
+ #
479
+ # @param [Integer] start The time when we started code execution, it is
480
+ # compared to Time.now to determine how many further code execution
481
+ # attempts remain
482
+ #
483
+ # @param [Integer] attempts The total amount of attempts to execute that we
484
+ # are willing to allow
485
+ #
486
+ # @raise [Exception] Raised if we fail to add metadata, either through
487
+ # errors or running out of attempts
330
488
  def setMetadata_on_instance(name, fingerprint, data, start, attempts)
331
489
  zone_operation = execute( instance_setMetadata_req( name, fingerprint, data), start, attempts )
332
490
  status = ''
@@ -347,15 +505,23 @@ module Beaker
347
505
  zone_operation
348
506
  end
349
507
 
350
- #Delete a Google Compute instance on the current connection
351
- #@param [String] name The name of the instance to delete
352
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
353
- # further code execution attempts remain
354
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
355
- #@raise [Exception] Raised if we fail delete the instance, either through errors or running out of attempts
508
+ # Delete a Google Compute instance on the current connection
509
+ #
510
+ # @param [String] name The name of the instance to delete
511
+ #
512
+ # @param [Integer] start The time when we started code execution, it is
513
+ # compared to Time.now to determine how many further code execution
514
+ # attempts remain
515
+ #
516
+ # @param [Integer] attempts The total amount of attempts to execute that we
517
+ # are willing to allow
518
+ #
519
+ # @raise [Exception] Raised if we fail delete the instance, either through
520
+ # errors or running out of attempts
356
521
  def delete_instance(name, start, attempts)
357
522
  result = execute( instance_delete_req( name ), start, attempts )
358
- #ensure deletion of instance
523
+
524
+ # Ensure deletion of instance
359
525
  try = (Time.now - start) / SLEEPWAIT
360
526
  while try <= attempts
361
527
  begin
@@ -371,15 +537,23 @@ module Beaker
371
537
  @logger.debug("#{name} instance was not removed before timeout, may still exist")
372
538
  end
373
539
 
374
- #Delete a Google Compute disk on the current connection
375
- #@param [String] name The name of the disk to delete
376
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
377
- # further code execution attempts remain
378
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
379
- #@raise [Exception] Raised if we fail delete the disk, either through errors or running out of attempts
540
+ # Delete a Google Compute disk on the current connection
541
+ #
542
+ # @param [String] name The name of the disk to delete
543
+ #
544
+ # @param [Integer] start The time when we started code execution, it is
545
+ # compared to Time.now to determine how many further code execution
546
+ # attempts remain
547
+ #
548
+ # @param [Integer] attempts The total amount of attempts to execute that we
549
+ # are willing to allow
550
+ #
551
+ # @raise [Exception] Raised if we fail delete the disk, either through
552
+ # errors or running out of attempts
380
553
  def delete_disk(name, start, attempts)
381
554
  result = execute( disk_delete_req( name ), start, attempts )
382
- #ensure deletion of disk
555
+
556
+ # Ensure deletion of disk
383
557
  try = (Time.now - start) / SLEEPWAIT
384
558
  while try <= attempts
385
559
  begin
@@ -395,12 +569,19 @@ module Beaker
395
569
  @logger.debug("#{name} disk was not removed before timeout, may still exist")
396
570
  end
397
571
 
398
- #Delete a Google Compute firewall on the current connection
399
- #@param [String] name The name of the firewall to delete
400
- #@param [Integer] start The time when we started code execution, it is compared to Time.now to determine how many
401
- # further code execution attempts remain
402
- #@param [Integer] attempts The total amount of attempts to execute that we are willing to allow
403
- #@raise [Exception] Raised if we fail delete the firewall, either through errors or running out of attempts
572
+ # Delete a Google Compute firewall on the current connection
573
+ #
574
+ # @param [String] name The name of the firewall to delete
575
+ #
576
+ # @param [Integer] start The time when we started code execution, it is
577
+ # compared to Time.now to determine how many further code execution
578
+ # attempts remain
579
+ #
580
+ # @param [Integer] attempts The total amount of attempts to execute that we
581
+ # are willing to allow
582
+ #
583
+ # @raise [Exception] Raised if we fail delete the firewall, either through
584
+ # errors or running out of attempts
404
585
  def delete_firewall(name, start, attempts)
405
586
  result = execute( firewall_delete_req( name ), start, attempts )
406
587
  #ensure deletion of disk
@@ -419,60 +600,78 @@ module Beaker
419
600
  @logger.debug("#{name} firewall was not removed before timeout, may still exist")
420
601
  end
421
602
 
422
-
423
- #Create a Google Compute list all images request
424
- #@param [String] name The Google Compute project name to query
425
- #@return [Hash] A correctly formatted Google Compute request hash
603
+ # Create a Google Compute list all images request
604
+ #
605
+ # @param [String] name The Google Compute project name to query
606
+ #
607
+ # @return [Hash] A correctly formatted Google Compute request hash
426
608
  def image_list_req(name)
427
609
  { :api_method => @compute.images.list,
428
610
  :parameters => { 'project' => name } }
429
611
  end
430
612
 
431
- #Create a Google Compute list all disks request
432
- #@return [Hash] A correctly formatted Google Compute request hash
613
+ # Create a Google Compute list all disks request
614
+ #
615
+ # @return [Hash] A correctly formatted Google Compute request hash
433
616
  def disk_list_req
434
617
  { :api_method => @compute.disks.list,
435
618
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME } }
436
619
  end
437
620
 
438
- #Create a Google Compute get disk request
439
- #@param [String] name The name of the disk to query for
440
- #@return [Hash] A correctly formatted Google Compute request hash
621
+ # Create a Google Compute get disk request
622
+ #
623
+ # @param [String] name The name of the disk to query for
624
+ #
625
+ # @return [Hash] A correctly formatted Google Compute request hash
441
626
  def disk_get_req(name)
442
627
  { :api_method => @compute.disks.get,
443
628
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'disk' => name } }
444
629
  end
445
630
 
446
- #Create a Google Compute disk delete request
447
- #@param [String] name The name of the disk delete
448
- #@return [Hash] A correctly formatted Google Compute request hash
631
+ # Create a Google Compute disk delete request
632
+ #
633
+ # @param [String] name The name of the disk delete
634
+ #
635
+ # @return [Hash] A correctly formatted Google Compute request hash
449
636
  def disk_delete_req(name)
450
637
  { :api_method => @compute.disks.delete,
451
638
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'disk' => name } }
452
639
  end
453
640
 
454
- #Create a Google Compute disk create request
455
- #@param [String] name The name of the disk to create
456
- #@param [String] source The link to a Google Compute image to base the disk creation on
457
- #@return [Hash] A correctly formatted Google Compute request hash
641
+ # Create a Google Compute disk create request
642
+ #
643
+ # @param [String] name The name of the disk to create
644
+ #
645
+ # @param [String] source The link to a Google Compute image to base the
646
+ # disk creation on
647
+ #
648
+ # @return [Hash] A correctly formatted Google Compute request hash
649
+ #
458
650
  def disk_insert_req(name, source)
459
651
  { :api_method => @compute.disks.insert,
460
652
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'sourceImage' => source },
461
653
  :body_object => { 'name' => name, 'sizeGb' => DEFAULT_DISK_SIZE } }
462
654
  end
463
655
 
464
- #Create a Google Compute get firewall request
465
- #@param [String] name The name of the firewall to query fo
466
- #@return [Hash] A correctly formatted Google Compute request hash
656
+ # Create a Google Compute get firewall request
657
+ #
658
+ # @param [String] name The name of the firewall to query for
659
+ #
660
+ # @return [Hash] A correctly formatted Google Compute request hash
467
661
  def firewall_get_req(name)
468
662
  { :api_method => @compute.firewalls.get,
469
663
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'firewall' => name } }
470
664
  end
471
665
 
472
- #Create a Google Compute insert firewall request, open ports 443, 8140 and 61613
473
- #@param [String] name The name of the firewall to create
474
- #@param [String] network The link to the Google Compute network to attach this firewall to
475
- #@return [Hash] A correctly formatted Google Compute request hash
666
+ # Create a Google Compute insert firewall request, open ports 443, 8140 and
667
+ # 61613
668
+ #
669
+ # @param [String] name The name of the firewall to create
670
+ #
671
+ # @param [String] network The link to the Google Compute network to attach
672
+ # this firewall to
673
+ #
674
+ # @return [Hash] A correctly formatted Google Compute request hash
476
675
  def firewall_insert_req(name, network)
477
676
  { :api_method => @compute.firewalls.insert,
478
677
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME },
@@ -482,39 +681,48 @@ module Beaker
482
681
  'sourceRanges' => [ "0.0.0.0/0" ] } }
483
682
  end
484
683
 
485
- #Create a Google Compute delete firewall request
486
- #@param [String] name The name of the firewall to delete
487
- #@return [Hash] A correctly formatted Google Compute request hash
684
+ # Create a Google Compute delete firewall request
685
+ #
686
+ # @param [String] name The name of the firewall to delete
687
+ #
688
+ # @return [Hash] A correctly formatted Google Compute request hash
488
689
  def firewall_delete_req(name)
489
690
  { :api_method => @compute.firewalls.delete,
490
691
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'firewall' => name } }
491
692
  end
492
693
 
493
- #Create a Google Compute list firewall request
494
- #@return [Hash] A correctly formatted Google Compute request hash
694
+ # Create a Google Compute list firewall request
695
+ #
696
+ # @return [Hash] A correctly formatted Google Compute request hash
495
697
  def firewall_list_req()
496
698
  { :api_method => @compute.firewalls.list,
497
699
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME } }
498
700
  end
499
701
 
500
- #Create a Google Compute get network request
501
- #@param [String] name (default) The name of the network to access information about
502
- #@return [Hash] A correctly formatted Google Compute request hash
702
+ # Create a Google Compute get network request
703
+ #
704
+ # @param [String] name (default) The name of the network to access
705
+ # information about
706
+ #
707
+ # @return [Hash] A correctly formatted Google Compute request hash
503
708
  def network_get_req(name = 'default')
504
709
  { :api_method => @compute.networks.get,
505
710
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'network' => name } }
506
711
  end
507
712
 
508
- #Create a Google Compute zone operation request
509
- #@return [Hash] A correctly formatted Google Compute request hash
713
+ # Create a Google Compute zone operation request
714
+ #
715
+ # @return [Hash] A correctly formatted Google Compute request hash
510
716
  def operation_get_req(name)
511
717
  { :api_method => @compute.zone_operations.get,
512
718
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'operation' => name } }
513
719
  end
514
720
 
515
- #Set tags on a Google Compute instance
516
- #@param [Array<String>] data An array of tags to be added to an instance
517
- #@return [Hash] A correctly formatted Google Compute request hash
721
+ # Set tags on a Google Compute instance
722
+ #
723
+ # @param [Array<String>] data An array of tags to be added to an instance
724
+ #
725
+ # @return [Hash] A correctly formatted Google Compute request hash
518
726
  def instance_setMetadata_req(name, fingerprint, data)
519
727
  { :api_method => @compute.instances.set_metadata,
520
728
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'instance' => name },
@@ -524,35 +732,47 @@ module Beaker
524
732
  }
525
733
  end
526
734
 
527
- #Create a Google Compute list instance request
528
- #@return [Hash] A correctly formatted Google Compute request hash
735
+ # Create a Google Compute list instance request
736
+ #
737
+ # @return [Hash] A correctly formatted Google Compute request hash
529
738
  def instance_list_req
530
739
  { :api_method => @compute.instances.list,
531
740
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME } }
532
741
  end
533
742
 
534
- #Create a Google Compute get instance request
535
- #@param [String] name The name of the instance to query for
536
- #@return [Hash] A correctly formatted Google Compute request hash
743
+ # Create a Google Compute get instance request
744
+ #
745
+ # @param [String] name The name of the instance to query for
746
+ #
747
+ # @return [Hash] A correctly formatted Google Compute request hash
537
748
  def instance_get_req(name)
538
749
  { :api_method => @compute.instances.get,
539
750
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'instance' => name } }
540
751
  end
541
752
 
542
- #Create a Google Compute instance delete request
543
- #@param [String] name The name of the instance to delete
544
- #@return [Hash] A correctly formatted Google Compute request hash
753
+ # Create a Google Compute instance delete request
754
+ #
755
+ # @param [String] name The name of the instance to delete
756
+ #
757
+ # @return [Hash] A correctly formatted Google Compute request hash
545
758
  def instance_delete_req(name)
546
759
  { :api_method => @compute.instances.delete,
547
760
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'instance' => name } }
548
761
  end
549
762
 
550
- #Create a Google Compute instance create request
551
- #@param [String] name The name of the instance to create
552
- #@param [String] image The link to the image to use for instance create
553
- #@param [String] machineType The link to the type of Google Compute instance to create (indicates cpus and memory size)
554
- #@param [String] disk The link to the disk to be used by the newly created instance
555
- #@return [Hash] A correctly formatted Google Compute request hash
763
+ # Create a Google Compute instance create request
764
+ #
765
+ # @param [String] name The name of the instance to create
766
+ #
767
+ # @param [String] image The link to the image to use for instance create
768
+ #
769
+ # @param [String] machineType The link to the type of Google Compute
770
+ # instance to create (indicates cpus and memory size)
771
+ #
772
+ # @param [String] disk The link to the disk to be used by the newly created
773
+ # instance
774
+ #
775
+ # @return [Hash] A correctly formatted Google Compute request hash
556
776
  def instance_insert_req(name, image, machineType, disk)
557
777
  { :api_method => @compute.instances.insert,
558
778
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME },
@@ -566,12 +786,12 @@ module Beaker
566
786
  'network' => default_network } ] } }
567
787
  end
568
788
 
569
- #Create a Google Compute machineType get request
570
- #@return [Hash] A correctly formatted Google Compute request hash
789
+ # Create a Google Compute machineType get request
790
+ #
791
+ # @return [Hash] A correctly formatted Google Compute request hash
571
792
  def machineType_get_req()
572
793
  { :api_method => @compute.machine_types.get,
573
794
  :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'machineType' => @options[:gce_machine_type] || DEFAULT_MACHINE_TYPE } }
574
795
  end
575
-
576
796
  end
577
797
  end