fog-maestrodev 1.18.0.20131126183714 → 1.18.0.20131127194823

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +8 -8
  2. data/fog.gemspec +2 -2
  3. data/lib/fog/brightbox/compute/image_selector.rb +1 -1
  4. data/lib/fog/brightbox/compute/shared.rb +8 -10
  5. data/lib/fog/brightbox/compute.rb +7 -9
  6. data/lib/fog/brightbox/models/compute/api_client.rb +1 -1
  7. data/lib/fog/brightbox/models/compute/application.rb +1 -4
  8. data/lib/fog/brightbox/models/compute/cloud_ip.rb +8 -5
  9. data/lib/fog/brightbox/models/compute/collaboration.rb +0 -2
  10. data/lib/fog/brightbox/models/compute/collaborations.rb +1 -1
  11. data/lib/fog/brightbox/models/compute/firewall_policy.rb +2 -4
  12. data/lib/fog/brightbox/models/compute/firewall_rule.rb +1 -1
  13. data/lib/fog/brightbox/models/compute/image.rb +1 -3
  14. data/lib/fog/brightbox/models/compute/load_balancer.rb +5 -8
  15. data/lib/fog/brightbox/models/compute/server.rb +28 -20
  16. data/lib/fog/brightbox/models/compute/server_group.rb +9 -11
  17. data/lib/fog/brightbox/models/compute/zone.rb +1 -1
  18. data/lib/fog/brightbox/oauth2.rb +3 -3
  19. data/lib/fog/google/compute.rb +16 -6
  20. data/lib/fog/google/models/compute/disk.rb +7 -1
  21. data/lib/fog/google/models/compute/operation.rb +42 -0
  22. data/lib/fog/google/models/compute/operations.rb +26 -0
  23. data/lib/fog/google/models/compute/server.rb +7 -1
  24. data/lib/fog/google/requests/compute/delete_disk.rb +11 -8
  25. data/lib/fog/google/requests/compute/delete_global_operation.rb +29 -0
  26. data/lib/fog/google/requests/compute/delete_server.rb +11 -7
  27. data/lib/fog/google/requests/compute/delete_zone_operation.rb +33 -0
  28. data/lib/fog/google/requests/compute/{delete_operation.rb → get_global_operation.rb} +5 -6
  29. data/lib/fog/google/requests/compute/get_zone_operation.rb +58 -0
  30. data/lib/fog/google/requests/compute/insert_disk.rb +12 -7
  31. data/lib/fog/google/requests/compute/insert_server.rb +12 -7
  32. data/lib/fog/google/requests/compute/list_zone_operations.rb +1 -0
  33. data/tests/brightbox/models/compute/server_tests.rb +7 -9
  34. metadata +8 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjljMGQzOTJhMWQ4M2QxZmNmMDViM2M5OTJkZDg5OTk0MmVkZmU1Nw==
4
+ NDljMmI1YzY4MmE4YmJiOWU4Y2Q4YjA1NDFjNGZjYWUxZDZhMjg5Nw==
5
5
  data.tar.gz: !binary |-
6
- OGIyYjg4N2YyNWMxMjk0MWY2ODg2ODFjODU1N2I1MzU3YWNkNWU5NA==
6
+ M2Y3MjkyNjgyYjU4ZWQyMWYwOGRiMmRjNDhiOWM5NGU1ODdkMjE0ZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZWVkMmUxNTBkYTg1MDdmZTk4M2I2OWY4ZDExNDVkYzFkOWVhYmJiZjQxYWYx
10
- MzU4Yzg2NTExZjg1YjMzZTM4NzNiNmRiZTYwZGNjZTZkY2ViZTVkNGVjNDFm
11
- N2Q1NGQ2NTQ4OGU5YzI0M2M5MzQ2MGRkNjdkZTZhOTVlODI0Y2E=
9
+ Nzg1NDY3OGM4YzQxOTVjM2QyYTgzZGYwM2VhMTBiMDc3ZjhiZTA4YTJiZGUz
10
+ OTY0YWRjNGVjM2Y4NzNjNjllMDE3NzFiMThiNjIzM2NlMWI0NGNhYjg4MGY0
11
+ N2U1MTUxYmZmNDllYzIwMGRlNWJhOGY2ZTE4ZDlkYjZjNDRlYjg=
12
12
  data.tar.gz: !binary |-
13
- Y2EzYThmMzY4ZTE4YjFjZjc5MjkxOTljZmQ2ZWYxZmFjNGUyZTc2ZGRlODc4
14
- ZDM1NGQwMmUwZWY2ZDE2ZGI0MTEwNzFlYzdhZjhhNDIzNTZjNzI0ZWQyZTc0
15
- OWFiN2JkYmUyYWU4Y2NiMTUwZjNjMzI3Njc2OGNiNWY4YmU0NjY=
13
+ N2E1ZmUwMmEzOWYxNWM1YzdjZGIwZDIxYWYwZjNmZmMyYmEwOTJiYjA1OWVm
14
+ Mjc1Njk1ZWQ5MDBlZWM1YzhmMTMxNTZiM2ZjMTdlNGRjYjAxZTZjMDcwMzJl
15
+ YjQzYTlhNWFiNjlkODRmM2ViOTNkYzdjNzk4ZjljYWI3ZGY5Njc=
data/fog.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  ## If your rubyforge_project name is different, then edit it and comment out
7
7
  ## the sub! line in the Rakefile
8
8
  s.name = 'fog-maestrodev'
9
- s.version = '1.18.0.20131126183714'
10
- s.date = '2013-11-26'
9
+ s.version = '1.18.0.20131127194823'
10
+ s.date = '2013-11-27'
11
11
  s.rubyforge_project = 'fog'
12
12
 
13
13
  ## Make sure your summary is short. The description may be as long
@@ -32,7 +32,7 @@ module Fog
32
32
  img["official"] == true &&
33
33
  img["arch"] == "i686" &&
34
34
  img["name"] =~ /ubuntu/i
35
- end.sort do |a,b|
35
+ end.sort do |a, b|
36
36
  # Reverse sort so "raring" > "precise" and "13.10" > "13.04"
37
37
  b["name"].downcase <=> a["name"].downcase
38
38
  end.first["id"]
@@ -63,7 +63,7 @@ module Fog
63
63
  # Request account can be changed at anytime and changes behaviour of future requests
64
64
  @scoped_account = @configured_account
65
65
 
66
- credential_options = {:username => username, :password => password}
66
+ credential_options = { :username => username, :password => password }
67
67
  @credentials = CredentialSet.new(client_id, client_secret, credential_options)
68
68
 
69
69
  # If existing tokens have been cached, allow continued use of them in the service
@@ -175,7 +175,7 @@ module Fog
175
175
  @default_image_id = Fog.credentials[:brightbox_default_image] || select_default_image
176
176
  end
177
177
 
178
- private
178
+ private
179
179
 
180
180
  # This makes a request of the API based on the configured setting for
181
181
  # token management.
@@ -200,13 +200,11 @@ module Fog
200
200
  #
201
201
  # @return [Excon::Response]
202
202
  def managed_token_request(options)
203
- begin
204
- get_access_token unless access_token_available?
205
- response = authenticated_request(options)
206
- rescue Excon::Errors::Unauthorized
207
- get_access_token
208
- response = authenticated_request(options)
209
- end
203
+ get_access_token unless access_token_available?
204
+ authenticated_request(options)
205
+ rescue Excon::Errors::Unauthorized
206
+ get_access_token
207
+ authenticated_request(options)
210
208
  end
211
209
 
212
210
  # This request makes an authenticated request of the API using currently
@@ -221,7 +219,7 @@ module Fog
221
219
  headers = options[:headers] || {}
222
220
  headers.merge!("Authorization" => "OAuth #{@credentials.access_token}", "Content-Type" => "application/json")
223
221
  options[:headers] = headers
224
- # TODO This is just a wrapper around a call to Excon::Connection#request
222
+ # TODO: This is just a wrapper around a call to Excon::Connection#request
225
223
  # so can be extracted from Compute by passing in the connection,
226
224
  # credentials and options
227
225
  @connection.request(options)
@@ -166,7 +166,7 @@ module Fog
166
166
  _request
167
167
  end
168
168
 
169
- private
169
+ private
170
170
 
171
171
  def _request
172
172
  raise Fog::Errors::MockNotImplemented
@@ -236,7 +236,7 @@ module Fog
236
236
  _wrapped_request(method, path, expected_responses, parameters)
237
237
  end
238
238
 
239
- private
239
+ private
240
240
 
241
241
  # Wrapped request is the non-standard form of request introduced by mistake
242
242
  #
@@ -256,20 +256,18 @@ module Fog
256
256
 
257
257
  # Select the account to scope for this request
258
258
  account = scoped_account(parameters.fetch(:account_id, nil))
259
- if account
260
- request_options[:query] = { :account_id => account }
261
- end
259
+ request_options[:query] = { :account_id => account } if account
262
260
 
263
261
  request_options[:body] = Fog::JSON.encode(parameters) unless parameters.empty?
264
262
 
265
263
  response = make_request(request_options)
266
264
 
267
- # FIXME We should revert to returning the Excon::Request after a suitable
265
+ # FIXME: We should revert to returning the Excon::Request after a suitable
268
266
  # configuration option is in place to switch back to this incorrect behaviour
269
- unless response.body.empty?
270
- Fog::JSON.decode(response.body)
271
- else
267
+ if response.body.empty?
272
268
  response
269
+ else
270
+ Fog::JSON.decode(response.body)
273
271
  end
274
272
  end
275
273
 
@@ -14,7 +14,7 @@ module Fog
14
14
  options = {
15
15
  :name => name,
16
16
  :description => description
17
- }.delete_if {|k,v| v.nil? || v == "" }
17
+ }.delete_if { |k, v| v.nil? || v == "" }
18
18
  data = service.create_api_client(options)
19
19
  merge_attributes(data)
20
20
  true
@@ -3,9 +3,7 @@ require 'fog/core/model'
3
3
  module Fog
4
4
  module Compute
5
5
  class Brightbox
6
-
7
6
  class Application < Fog::Model
8
-
9
7
  identity :id
10
8
  attribute :url
11
9
  attribute :name
@@ -15,12 +13,11 @@ module Fog
15
13
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
16
14
  options = {
17
15
  :name => name
18
- }.delete_if {|k,v| v.nil? || v == "" }
16
+ }.delete_if { |k, v| v.nil? || v == "" }
19
17
  data = service.create_application(options)
20
18
  merge_attributes(data)
21
19
  true
22
20
  end
23
-
24
21
  end
25
22
  end
26
23
  end
@@ -26,13 +26,16 @@ module Fog
26
26
  attribute :port_translators
27
27
  attribute :name
28
28
 
29
+ # Attempt to map or point the Cloud IP to the destination resource.
30
+ #
31
+ # @param [Object] destination
32
+ #
29
33
  def map(destination)
30
34
  requires :identity
31
- case destination
32
- when Fog::Compute::Brightbox::Server
33
- final_destination = destination.interfaces.first["id"]
34
- when Fog::Compute::Brightbox::LoadBalancer
35
- final_destination = destination.id
35
+ if destination.respond_to?(:mapping_identity)
36
+ final_destination = destination.mapping_identity
37
+ elsif destination.respond_to?(:identity)
38
+ final_destination = destination.identity
36
39
  else
37
40
  final_destination = destination
38
41
  end
@@ -43,9 +43,7 @@ module Fog
43
43
  merge_attributes(data)
44
44
  true
45
45
  end
46
-
47
46
  end
48
47
  end
49
48
  end
50
49
  end
51
-
@@ -31,7 +31,7 @@ module Fog
31
31
  def invite(email, role)
32
32
  return nil if email.nil? || email == ""
33
33
  return nil if role.nil? || role == ""
34
- options = {:email => email, :role => role}
34
+ options = { :email => email, :role => role }
35
35
  data = service.create_collaboration(options)
36
36
  new(data)
37
37
  end
@@ -26,7 +26,7 @@ module Fog
26
26
  :server_group => server_group_id,
27
27
  :name => name,
28
28
  :description => description
29
- }.delete_if {|k,v| v.nil? || v == "" }
29
+ }.delete_if { |k, v| v.nil? || v == "" }
30
30
  data = service.create_firewall_policy(options)
31
31
  merge_attributes(data)
32
32
  true
@@ -54,12 +54,10 @@ module Fog
54
54
 
55
55
  def destroy
56
56
  requires :identity
57
- data = service.destroy_firewall_policy(identity)
57
+ service.destroy_firewall_policy(identity)
58
58
  true
59
59
  end
60
-
61
60
  end
62
-
63
61
  end
64
62
  end
65
63
  end
@@ -35,7 +35,7 @@ module Fog
35
35
  :destination => destination,
36
36
  :destination_port => destination_port,
37
37
  :icmp_type_name => icmp_type_name
38
- }.delete_if {|k,v| v.nil? || v == "" }
38
+ }.delete_if { |k, v| v.nil? || v == "" }
39
39
  data = service.create_firewall_rule(options)
40
40
  merge_attributes(data)
41
41
  true
@@ -47,7 +47,7 @@ module Fog
47
47
  :name => name,
48
48
  :username => username,
49
49
  :description => description
50
- }.delete_if {|k,v| v.nil? || v == "" }
50
+ }.delete_if { |k, v| v.nil? || v == "" }
51
51
  data = service.create_image(options)
52
52
  merge_attributes(data)
53
53
  true
@@ -58,9 +58,7 @@ module Fog
58
58
  service.destroy_image(identity)
59
59
  true
60
60
  end
61
-
62
61
  end
63
-
64
62
  end
65
63
  end
66
64
  end
@@ -52,7 +52,7 @@ module Fog
52
52
  :name => name,
53
53
  :certificate_pem => certificate_pem,
54
54
  :certificate_private_key => certificate_private_key
55
- }.delete_if {|k,v| v.nil? || v == "" }
55
+ }.delete_if { |k, v| v.nil? || v == "" }
56
56
  data = service.create_load_balancer(options)
57
57
  merge_attributes(data)
58
58
  true
@@ -94,16 +94,13 @@ module Fog
94
94
  end
95
95
  end
96
96
 
97
- private
97
+ private
98
98
 
99
99
  def time_or_original(value)
100
- begin
101
- Time.parse(value)
102
- rescue TypeError, ArgumentError
103
- value
104
- end
100
+ Time.parse(value)
101
+ rescue TypeError, ArgumentError
102
+ value
105
103
  end
106
-
107
104
  end
108
105
  end
109
106
  end
@@ -37,7 +37,7 @@ module Fog
37
37
  attribute :zone
38
38
  attribute :server_type
39
39
 
40
- def initialize(attributes={})
40
+ def initialize(attributes = {})
41
41
  # Call super first to initialize the service object for our default image
42
42
  super
43
43
  self.image_id ||= service.default_image
@@ -83,10 +83,10 @@ module Fog
83
83
  def reboot(use_hard_reboot = true)
84
84
  requires :identity
85
85
  if ready?
86
- unless use_hard_reboot
87
- soft_reboot
88
- else
86
+ if use_hard_reboot
89
87
  hard_reboot
88
+ else
89
+ soft_reboot
90
90
  end
91
91
  else
92
92
  # Not able to reboot if not ready in the first place
@@ -137,23 +137,23 @@ module Fog
137
137
  end
138
138
 
139
139
  def private_ip_address
140
- unless interfaces.empty?
141
- interfaces.first["ipv4_address"]
142
- else
140
+ if interfaces.empty?
143
141
  nil
142
+ else
143
+ interfaces.first["ipv4_address"]
144
144
  end
145
145
  end
146
146
 
147
147
  def public_ip_address
148
- unless cloud_ips.empty?
149
- cloud_ips.first["public_ip"]
150
- else
148
+ if cloud_ips.empty?
151
149
  nil
150
+ else
151
+ cloud_ips.first["public_ip"]
152
152
  end
153
153
  end
154
154
 
155
155
  def ready?
156
- self.state == 'active'
156
+ state == "active"
157
157
  end
158
158
 
159
159
  def activate_console
@@ -171,20 +171,28 @@ module Fog
171
171
  :zone => zone_id,
172
172
  :user_data => user_data,
173
173
  :server_groups => server_groups
174
- }.delete_if {|k,v| v.nil? || v == "" }
175
- unless flavor_id.nil? || flavor_id == ""
176
- options.merge!(:server_type => flavor_id)
177
- end
174
+ }.delete_if { |k, v| v.nil? || v == "" }
175
+
176
+ options.merge!(:server_type => flavor_id) unless flavor_id.nil? || flavor_id == ""
177
+
178
178
  data = service.create_server(options)
179
179
  merge_attributes(data)
180
180
  true
181
181
  end
182
182
 
183
- private
183
+ # Replaces the server's identifier with it's interface's identifier for Cloud IP mapping
184
+ #
185
+ # @return [String] the identifier to pass to a Cloud IP mapping request
186
+ def mapping_identity
187
+ interfaces.first["id"]
188
+ end
189
+
190
+ private
191
+
184
192
  # Hard reboots are fast, avoiding the OS by doing a "power off"
185
193
  def hard_reboot
186
194
  stop
187
- wait_for { ! ready? }
195
+ wait_for { !ready? }
188
196
  start
189
197
  end
190
198
 
@@ -194,11 +202,11 @@ module Fog
194
202
  # @todo Needs cleaner error handling when the OS times out
195
203
  def soft_reboot
196
204
  shutdown
197
- # FIXME Using side effect of wait_for's (evaluated block) to detect timeouts
205
+ # FIXME: Using side effect of wait_for's (evaluated block) to detect timeouts
198
206
  begin
199
- wait_for(20) { ! ready? }
207
+ wait_for(20) { !ready? }
200
208
  start
201
- rescue Fog::Errors::Timeout => e
209
+ rescue Fog::Errors::Timeout
202
210
  false
203
211
  end
204
212
  end
@@ -3,7 +3,6 @@ require 'fog/core/model'
3
3
  module Fog
4
4
  module Compute
5
5
  class Brightbox
6
-
7
6
  # A server group is a collection of servers
8
7
  #
9
8
  # Certain actions can accept a server group and affect all members
@@ -24,15 +23,15 @@ module Fog
24
23
  options = {
25
24
  :name => name,
26
25
  :description => description
27
- }.delete_if {|k,v| v.nil? || v == "" }
26
+ }.delete_if { |k, v| v.nil? || v == "" }
28
27
  data = service.create_server_group(options)
29
28
  merge_attributes(data)
30
29
  true
31
30
  end
32
31
 
33
32
  def servers
34
- srv_ids = server_ids.collect {|srv| srv["id"]}
35
- srv_ids.collect do |srv_id|
33
+ srv_ids = server_ids.map { |srv| srv["id"] }
34
+ srv_ids.map do |srv_id|
36
35
  service.servers.get(srv_id)
37
36
  end
38
37
  end
@@ -41,7 +40,7 @@ module Fog
41
40
  #
42
41
  # @param [Array] identifiers array of server identifier strings to add
43
42
  # @return [Fog::Compute::ServerGroup]
44
- def add_servers identifiers
43
+ def add_servers(identifiers)
45
44
  requires :identity
46
45
  options = {
47
46
  :servers => server_references(identifiers)
@@ -54,7 +53,7 @@ module Fog
54
53
  #
55
54
  # @param [Array] identifiers array of server identifier strings to remove
56
55
  # @return [Fog::Compute::ServerGroup]
57
- def remove_servers identifiers
56
+ def remove_servers(identifiers)
58
57
  requires :identity
59
58
  options = {
60
59
  :servers => server_references(identifiers)
@@ -68,7 +67,7 @@ module Fog
68
67
  # @param [Array] identifiers array of server identifier strings to move
69
68
  # @param [String] destination_group_id destination server group identifier
70
69
  # @return [Fog::Compute::ServerGroup]
71
- def move_servers identifiers, destination_group_id
70
+ def move_servers(identifiers, destination_group_id)
72
71
  requires :identity
73
72
  options = {
74
73
  :servers => server_references(identifiers),
@@ -84,12 +83,11 @@ module Fog
84
83
  true
85
84
  end
86
85
 
87
- protected
86
+ protected
88
87
 
89
- def server_references identifiers
90
- identifiers.map {|id| {"server" => id} }
88
+ def server_references(identifiers)
89
+ identifiers.map { |id| { "server" => id } }
91
90
  end
92
-
93
91
  end
94
92
  end
95
93
  end
@@ -19,4 +19,4 @@ module Fog
19
19
 
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -18,7 +18,7 @@ module Fog::Brightbox::OAuth2
18
18
  header_content = "#{credentials.client_id}:#{credentials.client_secret}"
19
19
  encoded_credentials = Base64.encode64(header_content).chomp
20
20
 
21
- connection.request({
21
+ connection.request(
22
22
  :path => "/token",
23
23
  :expects => 200,
24
24
  :headers => {
@@ -27,7 +27,7 @@ module Fog::Brightbox::OAuth2
27
27
  },
28
28
  :method => 'POST',
29
29
  :body => Fog::JSON.encode(token_strategy.authorization_body_data)
30
- })
30
+ )
31
31
  end
32
32
 
33
33
  # Encapsulates credentials required to request access tokens from the
@@ -152,7 +152,7 @@ module Fog::Brightbox::OAuth2
152
152
  end
153
153
  end
154
154
 
155
- private
155
+ private
156
156
 
157
157
  # This updates the current credentials if passed a valid response
158
158
  #
@@ -29,13 +29,16 @@ module Fog
29
29
  request :get_network
30
30
  request :get_zone
31
31
  request :get_snapshot
32
+ request :get_global_operation
33
+ request :get_zone_operation
32
34
 
33
35
  request :delete_disk
34
36
  request :delete_firewall
35
37
  request :delete_image
36
38
  request :delete_network
37
- request :delete_operation
38
39
  request :delete_server
40
+ request :delete_global_operation
41
+ request :delete_zone_operation
39
42
 
40
43
  request :insert_disk
41
44
  request :insert_firewall
@@ -59,6 +62,9 @@ module Fog
59
62
  model :disk
60
63
  collection :disks
61
64
 
65
+ model :operation
66
+ collection :operations
67
+
62
68
  model :snapshot
63
69
  collection :snapshots
64
70
 
@@ -73,10 +79,10 @@ module Fog
73
79
  @api_version = 'v1beta16'
74
80
  end
75
81
 
76
- def build_excon_response(body)
82
+ def build_excon_response(body, status=200)
77
83
  response = Excon::Response.new
78
84
  response.body = body
79
- if response.body["error"]
85
+ if response.body and response.body["error"]
80
86
  response.status = response.body["error"]["code"]
81
87
  msg = response.body["error"]["errors"].map{|error| error["message"]}.join(", ")
82
88
  case response.status
@@ -86,7 +92,7 @@ module Fog
86
92
  raise Fog::Errors::Error.new(msg)
87
93
  end
88
94
  else
89
- response.status = 200
95
+ response.status = status
90
96
  end
91
97
  response
92
98
  end
@@ -763,7 +769,8 @@ module Fog
763
769
  }
764
770
  end,
765
771
  :images => {},
766
- :disks => {}
772
+ :disks => {},
773
+ :operations => {}
767
774
  }
768
775
  end
769
776
  end
@@ -782,6 +789,9 @@ module Fog
782
789
  self.class.data(api_version).delete(@project)
783
790
  end
784
791
 
792
+ def random_operation
793
+ "operation-#{Fog::Mock.random_numbers(13)}-#{Fog::Mock.random_hex(13)}-#{Fog::Mock.random_hex(8)}"
794
+ end
785
795
  end
786
796
 
787
797
  class Real
@@ -842,7 +852,7 @@ module Fog
842
852
  # result = Google::APIClient::Result
843
853
  # returns Excon::Response
844
854
  def build_response(result)
845
- build_excon_response(Fog::JSON.decode(result.body))
855
+ build_excon_response(result.body.nil? ? nil : Fog::JSON.decode(result.body), result.status)
846
856
  end
847
857
 
848
858
  end
@@ -38,7 +38,13 @@ module Fog
38
38
 
39
39
  def destroy
40
40
  requires :name, :zone_name
41
- service.delete_disk(name, zone_name)
41
+ operation = service.delete_disk(name, zone_name)
42
+ # wait until "RUNNING" or "DONE" to ensure the operation doesn't fail, raises exception on error
43
+ Fog.wait_for do
44
+ operation = service.get_zone_operation(zone_name, operation.body["name"])
45
+ operation.body["status"] != "PENDING"
46
+ end
47
+ operation
42
48
  end
43
49
 
44
50
  def zone
@@ -0,0 +1,42 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Google
6
+
7
+ class Operation < Fog::Model
8
+
9
+ identity :name
10
+
11
+ attribute :kind, :aliases => 'kind'
12
+ attribute :id, :aliases => 'id'
13
+ attribute :creation_timestamp, :aliases => 'creationTimestamp'
14
+ attribute :zone_name, :aliases => 'zone'
15
+ attribute :status, :aliases => 'status'
16
+ attribute :self_link, :aliases => 'selfLink'
17
+
18
+ def ready?
19
+ self.status == DONE_STATE
20
+ end
21
+
22
+ def pending?
23
+ self.status == PENDING_STATE
24
+ end
25
+
26
+ def reload
27
+ requires :identity
28
+
29
+ data = collection.get(identity, zone)
30
+ new_attributes = data.attributes
31
+ merge_attributes(new_attributes)
32
+ self
33
+ end
34
+
35
+ PENDING_STATE = "PENDING"
36
+ RUNNING_STATE = "RUNNING"
37
+ DONE_STATE = "DONE"
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/google/models/compute/operation'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Google
7
+
8
+ class Operations < Fog::Collection
9
+
10
+ model Fog::Compute::Google::Operation
11
+
12
+ def get(identity, zone=nil)
13
+ if zone.nil?
14
+ response = service.get_global_operation(identity)
15
+ else
16
+ response = service.get_zone_operation(zone, identity)
17
+ end
18
+ return nil if response.nil?
19
+ new(response.body)
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -30,7 +30,13 @@ module Fog
30
30
 
31
31
  def destroy
32
32
  requires :name, :zone
33
- service.delete_server(name, zone)
33
+ operation = service.delete_server(name, zone)
34
+ # wait until "RUNNING" or "DONE" to ensure the operation doesn't fail, raises exception on error
35
+ Fog.wait_for do
36
+ operation = service.get_zone_operation(zone_name, operation.body["name"])
37
+ operation.body["status"] != "PENDING"
38
+ end
39
+ operation
34
40
  end
35
41
 
36
42
  def image
@@ -6,23 +6,26 @@ module Fog
6
6
 
7
7
  def delete_disk(disk_name, zone_name)
8
8
  get_disk(disk_name, zone_name)
9
- self.data[:disks].delete disk_name
10
9
 
11
- build_response(:body => {
10
+ operation = self.random_operation
11
+ self.data[:operations][operation] = {
12
12
  "kind" => "compute#operation",
13
- "id" => "7145812689701515415",
14
- "name" => "operation-1385125998242-4ebc3c7173e70-11e1ad0b",
13
+ "id" => Fog::Mock.random_numbers(19).to_s,
14
+ "name" => operation,
15
15
  "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}",
16
16
  "operationType" => "delete",
17
17
  "targetLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/disks/#{disk_name}",
18
- "targetId" => "6817095360746367667",
19
- "status" => "PENDING",
18
+ "targetId" => self.data[:disks][disk_name]["id"],
19
+ "status" => Fog::Compute::Google::Operation::PENDING_STATE,
20
20
  "user" => "123456789012-qwertyuiopasdfghjkl1234567890qwe@developer.gserviceaccount.com",
21
21
  "progress" => 0,
22
22
  "insertTime" => Time.now.iso8601,
23
23
  "startTime" => Time.now.iso8601,
24
- "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/operation-1385125998242-4ebc3c7173e70-11e1ad0b"
25
- })
24
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/#{operation}"
25
+ }
26
+ self.data[:disks].delete disk_name
27
+
28
+ build_response(:body => self.data[:operations][operation])
26
29
  end
27
30
 
28
31
  end
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Compute
3
+ class Google
4
+
5
+ class Mock
6
+
7
+ def delete_global_operation(operation)
8
+ Fog::Mock.not_implemented
9
+ end
10
+
11
+ end
12
+
13
+ class Real
14
+ # https://developers.google.com/compute/docs/reference/latest/globalOperations
15
+
16
+ def delete_global_operation(operation)
17
+ api_method = @compute.global_operations.delete
18
+ parameters = {
19
+ 'project' => @project,
20
+ 'operation' => operation
21
+ }
22
+
23
+ result = self.build_result(api_method, parameters)
24
+ response = self.build_response(result)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -28,21 +28,25 @@ module Fog
28
28
  server = self.data[:servers][server_name]
29
29
  server["status"] = "STOPPED"
30
30
  server["mock-deletionTimestamp"] = Time.now.iso8601
31
- build_response(:body => {
31
+
32
+ operation = self.random_operation
33
+ self.data[:operations][operation] = {
32
34
  "kind" => "compute#operation",
33
- "id" => "10035781241131638365",
34
- "name" => "operation-1380213292196-4e74bf2fbc3c1-ae707d47",
35
+ "id" => Fog::Mock.random_numbers(19).to_s,
36
+ "name" => operation,
35
37
  "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}",
36
38
  "operationType" => "delete",
37
39
  "targetLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/instances/#{server_name}",
38
- "targetId" => "14544909043643897380",
39
- "status" => "PENDING",
40
+ "targetId" => self.data[:servers][server_name]["id"],
41
+ "status" => Fog::Compute::Google::Operation::PENDING_STATE,
40
42
  "user" => "123456789012-qwertyuiopasdfghjkl1234567890qwe@developer.gserviceaccount.com",
41
43
  "progress" => 0,
42
44
  "insertTime" => Time.now.iso8601,
43
45
  "startTime" => Time.now.iso8601,
44
- "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/operation-1380213292196-4e74bf2fbc3c1-ae707d47"
45
- })
46
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/#{operation}"
47
+ }
48
+
49
+ build_response(:body => self.data[:operations][operation])
46
50
  end
47
51
 
48
52
  end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Compute
3
+ class Google
4
+
5
+ class Mock
6
+
7
+ def delete_zone_operation(zone, operation)
8
+ Fog::Mock.not_implemented
9
+ end
10
+
11
+ end
12
+
13
+ class Real
14
+ # https://developers.google.com/compute/docs/reference/latest/zoneOperations
15
+
16
+ def delete_zone_operation(zone_name, operation)
17
+ if zone_name.start_with? 'http'
18
+ zone_name = zone_name.split('/')[-1]
19
+ end
20
+ api_method = @compute.zone_operations.delete
21
+ parameters = {
22
+ 'project' => @project,
23
+ 'zone' => zone_name,
24
+ 'operation' => operation
25
+ }
26
+
27
+ result = self.build_result(api_method, parameters)
28
+ response = self.build_response(result)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -4,27 +4,26 @@ module Fog
4
4
 
5
5
  class Mock
6
6
 
7
- def delete_operation(operation_name)
7
+ def get_global_operation(operation)
8
8
  Fog::Mock.not_implemented
9
9
  end
10
10
 
11
11
  end
12
12
 
13
13
  class Real
14
+ # https://developers.google.com/compute/docs/reference/latest/globalOperations
14
15
 
15
- def delete_operation(operation_name)
16
- api_method = @compute.operations.delete
16
+ def get_global_operation(operation)
17
+ api_method = @compute.global_operations.get
17
18
  parameters = {
18
19
  'project' => @project,
19
- 'operation' => operation_name
20
+ 'operation' => operation
20
21
  }
21
22
 
22
23
  result = self.build_result(api_method, parameters)
23
24
  response = self.build_response(result)
24
25
  end
25
-
26
26
  end
27
-
28
27
  end
29
28
  end
30
29
  end
@@ -0,0 +1,58 @@
1
+ module Fog
2
+ module Compute
3
+ class Google
4
+
5
+ class Mock
6
+
7
+ def get_zone_operation(zone_name, operation)
8
+ operation = self.data[:operations][operation]
9
+ if operation
10
+ case operation["status"]
11
+ when Fog::Compute::Google::Operation::PENDING_STATE
12
+ operation["status"] = Fog::Compute::Google::Operation::RUNNING_STATE
13
+ operation["progress"] = 50
14
+ else
15
+ operation["status"] = Fog::Compute::Google::Operation::DONE_STATE
16
+ operation["progress"] = 100
17
+ end
18
+ else
19
+ operation = {
20
+ "error" => {
21
+ "errors" => [
22
+ {
23
+ "domain" => "global",
24
+ "reason" => "notFound",
25
+ "message" => "The resource 'projects/#{project}/zones/#{zone_name}/operations/#{operation}' was not found"
26
+ }
27
+ ],
28
+ "code" => 404,
29
+ "message" => "The resource 'projects/#{project}/zones/#{zone_name}/operations/#{operation}' was not found"
30
+ }
31
+ }
32
+ end
33
+ build_response(:body => operation)
34
+ end
35
+ end
36
+
37
+ class Real
38
+ # https://developers.google.com/compute/docs/reference/latest/zoneOperations
39
+
40
+ def get_zone_operation(zone_name, operation)
41
+ if zone_name.start_with? 'http'
42
+ zone_name = zone_name.split('/')[-1]
43
+ end
44
+
45
+ api_method = @compute.zone_operations.get
46
+ parameters = {
47
+ 'project' => @project,
48
+ 'zone' => zone_name,
49
+ 'operation' => operation
50
+ }
51
+
52
+ result = self.build_result(api_method, parameters)
53
+ response = self.build_response(result)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -16,9 +16,10 @@ module Fog
16
16
  end
17
17
  get_zone(zone_name)
18
18
 
19
+ id = Fog::Mock.random_numbers(19).to_s
19
20
  self.data[:disks][disk_name] = {
20
21
  "kind" => "compute#disk",
21
- "id" => Fog::Mock.random_numbers(19),
22
+ "id" => id,
22
23
  "creationTimestamp" => Time.now.iso8601,
23
24
  "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}",
24
25
  "status" => "READY",
@@ -27,20 +28,24 @@ module Fog
27
28
  "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/disks/#{disk_name}"
28
29
  }
29
30
 
30
- build_response(:body => {
31
+ operation = self.random_operation
32
+ self.data[:operations][operation] = {
31
33
  "kind" => "compute#operation",
32
- "id" => "12498846269172327286",
33
- "name" => "operation-1385124218076-4ebc35cfbe9f1-476486c5",
34
+ "id" => Fog::Mock.random_numbers(19).to_s,
35
+ "name" => operation,
34
36
  "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}",
35
37
  "operationType" => "insert",
36
38
  "targetLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/disks/#{disk_name}",
37
- "status" => "PENDING",
39
+ "targetId" => id,
40
+ "status" => Fog::Compute::Google::Operation::PENDING_STATE,
38
41
  "user" => "123456789012-qwertyuiopasdfghjkl1234567890qwe@developer.gserviceaccount.com",
39
42
  "progress" => 0,
40
43
  "insertTime" => Time.now.iso8601,
41
44
  "startTime" => Time.now.iso8601,
42
- "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/operation-1385124218076-4ebc35cfbe9f1-476486c5"
43
- })
45
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/#{operation}"
46
+ }
47
+
48
+ build_response(:body => self.data[:operations][operation])
44
49
  end
45
50
 
46
51
  end
@@ -37,9 +37,10 @@ module Fog
37
37
  end
38
38
  get_zone(zone_name)
39
39
 
40
+ id = Fog::Mock.random_numbers(19).to_s
40
41
  self.data[:servers][server_name] = {
41
42
  "kind" => "compute#instance",
42
- "id" => Fog::Mock.random_numbers(19),
43
+ "id" => id,
43
44
  "creationTimestamp" => Time.now.iso8601,
44
45
  "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}",
45
46
  "status" => "PROVISIONING",
@@ -85,20 +86,24 @@ module Fog
85
86
  "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/instances/#{server_name}"
86
87
  }
87
88
 
88
- build_response(:body => {
89
+ operation = self.random_operation
90
+ self.data[:operations][operation] = {
89
91
  "kind" => "compute#operation",
90
- "id" => "4639689000254420481",
91
- "name" => "operation-1380213292196-4e74bf2fbc3c1-ae707d47",
92
+ "id" => Fog::Mock.random_numbers(19).to_s,
93
+ "name" => operation,
92
94
  "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}",
93
95
  "operationType" => "insert",
94
96
  "targetLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/instances/#{server_name}",
95
- "status" => "PENDING",
97
+ "targetId" => id,
98
+ "status" => Fog::Compute::Google::Operation::PENDING_STATE,
96
99
  "user" => "123456789012-qwertyuiopasdfghjkl1234567890qwe@developer.gserviceaccount.com",
97
100
  "progress" => 0,
98
101
  "insertTime" => Time.now.iso8601,
99
102
  "startTime" => Time.now.iso8601,
100
- "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/operation-1380213292196-4e74bf2fbc3c1-ae707d47"
101
- })
103
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/#{operation}"
104
+ }
105
+
106
+ build_response(:body => self.data[:operations][operation])
102
107
  end
103
108
 
104
109
  end
@@ -11,6 +11,7 @@ module Fog
11
11
  end
12
12
 
13
13
  class Real
14
+ # https://developers.google.com/compute/docs/reference/latest/zoneOperations
14
15
 
15
16
  def list_zone_operations(zone)
16
17
  api_method = @compute.zone_operations.list
@@ -1,21 +1,19 @@
1
1
  Shindo.tests("Fog::Compute[:brightbox] | Server model", ["brightbox"]) do
2
-
3
2
  pending if Fog.mocking?
4
3
 
5
4
  tests("success") do
6
-
7
- unless Fog.mocking?
8
- @server = Brightbox::Compute::TestSupport.get_test_server
9
- server_id = @server.id
10
- end
5
+ @server = Brightbox::Compute::TestSupport.get_test_server
6
+ server_id = @server.id
11
7
 
12
8
  tests("#dns_name") do
13
- pending if Fog.mocking?
14
9
  returns("public.#{@server.fqdn}") { @server.dns_name }
15
10
  end
16
11
 
17
- unless Fog.mocking?
18
- @server.destroy
12
+ tests("#mapping_identity") do
13
+ first_interface_id = @server.interfaces.first["id"]
14
+ returns(first_interface_id) { @server.mapping_identity }
19
15
  end
16
+
17
+ @server.destroy
20
18
  end
21
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-maestrodev
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.0.20131126183714
4
+ version: 1.18.0.20131127194823
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-26 00:00:00.000000000 Z
11
+ date: 2013-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -2194,6 +2194,8 @@ files:
2194
2194
  - lib/fog/google/models/compute/flavors.rb
2195
2195
  - lib/fog/google/models/compute/image.rb
2196
2196
  - lib/fog/google/models/compute/images.rb
2197
+ - lib/fog/google/models/compute/operation.rb
2198
+ - lib/fog/google/models/compute/operations.rb
2197
2199
  - lib/fog/google/models/compute/server.rb
2198
2200
  - lib/fog/google/models/compute/servers.rb
2199
2201
  - lib/fog/google/models/compute/snapshot.rb
@@ -2214,18 +2216,21 @@ files:
2214
2216
  - lib/fog/google/parsers/storage/get_service.rb
2215
2217
  - lib/fog/google/requests/compute/delete_disk.rb
2216
2218
  - lib/fog/google/requests/compute/delete_firewall.rb
2219
+ - lib/fog/google/requests/compute/delete_global_operation.rb
2217
2220
  - lib/fog/google/requests/compute/delete_image.rb
2218
2221
  - lib/fog/google/requests/compute/delete_network.rb
2219
- - lib/fog/google/requests/compute/delete_operation.rb
2220
2222
  - lib/fog/google/requests/compute/delete_server.rb
2223
+ - lib/fog/google/requests/compute/delete_zone_operation.rb
2221
2224
  - lib/fog/google/requests/compute/get_disk.rb
2222
2225
  - lib/fog/google/requests/compute/get_firewall.rb
2226
+ - lib/fog/google/requests/compute/get_global_operation.rb
2223
2227
  - lib/fog/google/requests/compute/get_image.rb
2224
2228
  - lib/fog/google/requests/compute/get_machine_type.rb
2225
2229
  - lib/fog/google/requests/compute/get_network.rb
2226
2230
  - lib/fog/google/requests/compute/get_server.rb
2227
2231
  - lib/fog/google/requests/compute/get_snapshot.rb
2228
2232
  - lib/fog/google/requests/compute/get_zone.rb
2233
+ - lib/fog/google/requests/compute/get_zone_operation.rb
2229
2234
  - lib/fog/google/requests/compute/insert_disk.rb
2230
2235
  - lib/fog/google/requests/compute/insert_firewall.rb
2231
2236
  - lib/fog/google/requests/compute/insert_image.rb