gapinc-fog 1.12.1.1 → 1.12.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -7
- data/bin/fog +22 -0
- data/fog.gemspec +1 -1
- data/lib/fog/aws.rb +11 -0
- data/lib/fog/aws/auto_scaling.rb +13 -18
- data/lib/fog/aws/beanstalk.rb +8 -10
- data/lib/fog/aws/cloud_formation.rb +9 -12
- data/lib/fog/aws/compute.rb +8 -10
- data/lib/fog/aws/credential_fetcher.rb +6 -6
- data/lib/fog/aws/elasticache.rb +13 -17
- data/lib/fog/aws/elb.rb +29 -31
- data/lib/fog/aws/iam.rb +10 -13
- data/lib/fog/aws/models/rds/server.rb +3 -1
- data/lib/fog/aws/models/rds/snapshot.rb +1 -0
- data/lib/fog/aws/parsers/rds/db_parser.rb +1 -1
- data/lib/fog/aws/parsers/ses/verify_domain_identity.rb +26 -0
- data/lib/fog/aws/rds.rb +19 -14
- data/lib/fog/aws/requests/compute/create_volume.rb +3 -3
- data/lib/fog/aws/requests/rds/create_db_instance.rb +3 -1
- data/lib/fog/aws/requests/ses/verify_domain_identity.rb +30 -0
- data/lib/fog/aws/ses.rb +1 -0
- data/lib/fog/aws/storage.rb +2 -1
- data/lib/fog/aws/sts.rb +9 -15
- data/lib/fog/core.rb +7 -2
- data/lib/fog/core/connection.rb +62 -29
- data/lib/fog/core/deprecated/connection.rb +24 -0
- data/lib/fog/core/parser.rb +1 -1
- data/lib/fog/google/compute.rb +31 -7
- data/lib/fog/google/models/compute/disk.rb +80 -0
- data/lib/fog/google/models/compute/disks.rb +28 -0
- data/lib/fog/google/models/compute/image.rb +36 -0
- data/lib/fog/google/models/compute/server.rb +46 -33
- data/lib/fog/google/models/compute/servers.rb +15 -8
- data/lib/fog/google/requests/compute/delete_server.rb +5 -2
- data/lib/fog/google/requests/compute/get_disk.rb +3 -0
- data/lib/fog/google/requests/compute/get_server.rb +7 -1
- data/lib/fog/google/requests/compute/insert_disk.rb +8 -2
- data/lib/fog/google/requests/compute/insert_server.rb +51 -22
- data/lib/fog/google/requests/compute/list_machine_types.rb +3 -2
- data/lib/fog/hp/storage.rb +26 -9
- data/lib/fog/{core/json.rb → json.rb} +13 -2
- data/lib/fog/openstack/models/compute/metadata.rb +1 -1
- data/lib/fog/openstack/models/image/images.rb +1 -1
- data/lib/fog/openstack/requests/compute/detach_volume.rb +2 -1
- data/lib/fog/openstack/requests/compute/list_security_groups.rb +1 -1
- data/lib/fog/rackspace.rb +5 -0
- data/lib/fog/rackspace/block_storage.rb +13 -28
- data/lib/fog/rackspace/cdn.rb +10 -24
- data/lib/fog/rackspace/compute.rb +17 -45
- data/lib/fog/rackspace/compute_v2.rb +13 -33
- data/lib/fog/rackspace/databases.rb +13 -29
- data/lib/fog/rackspace/dns.rb +20 -22
- data/lib/fog/rackspace/identity.rb +10 -26
- data/lib/fog/rackspace/load_balancers.rb +13 -29
- data/lib/fog/rackspace/mock_data.rb +3 -3
- data/lib/fog/rackspace/models/compute/server.rb +1 -1
- data/lib/fog/rackspace/models/identity/users.rb +2 -2
- data/lib/fog/rackspace/models/storage/file.rb +1 -0
- data/lib/fog/rackspace/requests/storage/get_object.rb +3 -1
- data/lib/fog/rackspace/service.rb +43 -1
- data/lib/fog/rackspace/storage.rb +9 -31
- data/lib/fog/xenserver/compute.rb +2 -0
- data/lib/fog/xenserver/models/compute/server.rb +9 -7
- data/lib/fog/xenserver/requests/compute/snapshot_revert.rb +22 -0
- data/lib/fog/xenserver/requests/compute/snapshot_server.rb +22 -0
- data/lib/fog/xml.rb +21 -0
- data/lib/fog/xml/sax_parser_connection.rb +43 -0
- data/tests/aws/requests/compute/volume_tests.rb +3 -3
- data/tests/aws/requests/rds/helper.rb +1 -0
- data/tests/aws/requests/ses/verified_domain_identity_tests.rb +16 -0
- data/tests/core/connection_tests.rb +26 -0
- data/tests/helper.rb +9 -7
- data/tests/rackspace/block_storage_tests.rb +9 -0
- data/tests/rackspace/compute_tests.rb +9 -0
- data/tests/rackspace/compute_v2_tests.rb +9 -0
- data/tests/rackspace/databases_tests.rb +9 -0
- data/tests/rackspace/dns_tests.rb +9 -0
- data/tests/rackspace/helper.rb +12 -1
- data/tests/rackspace/identity_tests.rb +25 -0
- data/tests/rackspace/load_balancer_tests.rb +10 -0
- data/tests/rackspace/models/block_storage/volume_tests.rb +2 -2
- data/tests/rackspace/models/compute_v2/metadata_tests.rb +2 -2
- data/tests/rackspace/models/compute_v2/server_tests.rb +22 -21
- data/tests/rackspace/models/storage/file_tests.rb +22 -6
- data/tests/rackspace/rackspace_tests.rb +35 -0
- data/tests/rackspace/requests/block_storage/snapshot_tests.rb +2 -3
- data/tests/rackspace/requests/block_storage/volume_type_tests.rb +4 -11
- data/tests/rackspace/requests/compute_v2/address_tests.rb +1 -1
- data/tests/rackspace/requests/compute_v2/attachment_tests.rb +8 -9
- data/tests/rackspace/requests/compute_v2/flavor_tests.rb +1 -1
- data/tests/rackspace/requests/compute_v2/metadata_tests.rb +4 -4
- data/tests/rackspace/requests/databases/database_tests.rb +23 -20
- data/tests/rackspace/requests/databases/user_tests.rb +6 -6
- data/tests/rackspace/requests/identity/user_tests.rb +4 -1
- data/tests/rackspace/requests/load_balancers/usage_tests.rb +4 -2
- data/tests/rackspace/service_tests.rb +83 -0
- data/tests/rackspace/storage_tests.rb +9 -0
- data/tests/xenserver/models/compute/server_tests.rb +11 -1
- metadata +19 -4
- data/tests/core/user_agent_tests.rb +0 -6
data/lib/fog/aws/rds.rb
CHANGED
@@ -10,7 +10,7 @@ module Fog
|
|
10
10
|
class AuthorizationAlreadyExists < Fog::Errors::Error; end
|
11
11
|
|
12
12
|
requires :aws_access_key_id, :aws_secret_access_key
|
13
|
-
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at
|
13
|
+
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :version
|
14
14
|
|
15
15
|
request_path 'fog/aws/requests/rds'
|
16
16
|
request :describe_events
|
@@ -155,6 +155,7 @@ module Fog
|
|
155
155
|
@port = options[:port] || 443
|
156
156
|
@scheme = options[:scheme] || 'https'
|
157
157
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
158
|
+
@version = options[:version] || '2012-09-17' #'2011-04-01'
|
158
159
|
end
|
159
160
|
|
160
161
|
def owner_id
|
@@ -191,12 +192,12 @@ module Fog
|
|
191
192
|
:host => @host,
|
192
193
|
:path => @path,
|
193
194
|
:port => @port,
|
194
|
-
:version =>
|
195
|
+
:version => @version
|
195
196
|
}
|
196
197
|
)
|
197
198
|
|
198
199
|
begin
|
199
|
-
|
200
|
+
@connection.request({
|
200
201
|
:body => body,
|
201
202
|
:expects => 200,
|
202
203
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
@@ -206,23 +207,27 @@ module Fog
|
|
206
207
|
:parser => parser
|
207
208
|
})
|
208
209
|
rescue Excon::Errors::HTTPStatusError => error
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
raise Fog::AWS::RDS::IdentifierTaken.slurp(error, match[2])
|
215
|
-
when 'AuthorizationAlreadyExists'
|
216
|
-
raise Fog::AWS::RDS::AuthorizationAlreadyExists.slurp(error, match[2])
|
210
|
+
match = Fog::AWS::Errors.match_error(error)
|
211
|
+
if match.empty?
|
212
|
+
case error.message
|
213
|
+
when 'Not Found'
|
214
|
+
raise Fog::AWS::RDS::NotFound.slurp(error, 'RDS Instance not found')
|
217
215
|
else
|
218
216
|
raise
|
219
217
|
end
|
220
218
|
else
|
221
|
-
raise
|
219
|
+
raise case match[:code]
|
220
|
+
when 'DBInstanceNotFound', 'DBParameterGroupNotFound', 'DBSnapshotNotFound', 'DBSecurityGroupNotFound'
|
221
|
+
Fog::AWS::RDS::NotFound.slurp(error, match[:message])
|
222
|
+
when 'DBParameterGroupAlreadyExists'
|
223
|
+
Fog::AWS::RDS::IdentifierTaken.slurp(error, match[:message])
|
224
|
+
when 'AuthorizationAlreadyExists'
|
225
|
+
Fog::AWS::RDS::AuthorizationAlreadyExists.slurp(error, match[:message])
|
226
|
+
else
|
227
|
+
Fog::AWS::RDS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
228
|
+
end
|
222
229
|
end
|
223
230
|
end
|
224
|
-
|
225
|
-
response
|
226
231
|
end
|
227
232
|
|
228
233
|
end
|
@@ -13,7 +13,7 @@ module Fog
|
|
13
13
|
# * options<~Hash>
|
14
14
|
# * 'SnapshotId'<~String> - Optional, snapshot to create volume from
|
15
15
|
# * 'VolumeType'<~String> - Optional, volume type. standard or io1, default is standard.
|
16
|
-
# * 'Iops'<~Integer> - Number of IOPS the volume supports. Required if VolumeType is io1, must be between 1 and
|
16
|
+
# * 'Iops'<~Integer> - Number of IOPS the volume supports. Required if VolumeType is io1, must be between 1 and 4000.
|
17
17
|
#
|
18
18
|
# ==== Returns
|
19
19
|
# * response<~Excon::Response>:
|
@@ -83,8 +83,8 @@ module Fog
|
|
83
83
|
raise Fog::Compute::AWS::Error.new("VolumeIOPSLimit => Volume iops of #{iops} is too low; minimum is 100.")
|
84
84
|
end
|
85
85
|
|
86
|
-
if iops >
|
87
|
-
raise Fog::Compute::AWS::Error.new("VolumeIOPSLimit => Volume iops of #{iops} is too high; maximum is
|
86
|
+
if iops > 4000
|
87
|
+
raise Fog::Compute::AWS::Error.new("VolumeIOPSLimit => Volume iops of #{iops} is too high; maximum is 4000.")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -25,6 +25,7 @@ module Fog
|
|
25
25
|
# @param PreferredBackupWindow [String] The daily time range during which automated backups are created if automated backups are enabled
|
26
26
|
# @param PreferredMaintenanceWindow [String] The weekly time range (in UTC) during which system maintenance can occur, which may result in an outage
|
27
27
|
# @param DBSubnetGroupName [String] The name, if any, of the VPC subnet for this RDS instance
|
28
|
+
# @param PubliclyAcccesible [Boolean] Whether an RDS instance inside of the VPC subnet should have a public-facing endpoint
|
28
29
|
#
|
29
30
|
# @return [Excon::Response]:
|
30
31
|
# * body [Hash]:
|
@@ -103,7 +104,8 @@ module Fog
|
|
103
104
|
# "ReadReplicaSourceDBInstanceIdentifier" => nil,
|
104
105
|
# "LatestRestorableTime" => nil,
|
105
106
|
"AvailabilityZone" => options["AvailabilityZone"],
|
106
|
-
"DBSubnetGroupName" => options["DBSubnetGroupName"]
|
107
|
+
"DBSubnetGroupName" => options["DBSubnetGroupName"],
|
108
|
+
"PubliclyAccessible" => options["PubliclyAccessible"]
|
107
109
|
}
|
108
110
|
|
109
111
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class SES
|
4
|
+
class Real
|
5
|
+
|
6
|
+
require 'fog/aws/parsers/ses/verify_domain_identity'
|
7
|
+
|
8
|
+
# Verifies a domain. This action returns a verification authorization
|
9
|
+
# token which must be added as a DNS TXT record to the domain.
|
10
|
+
#
|
11
|
+
# ==== Parameters
|
12
|
+
# * domain<~String> - The domain to be verified
|
13
|
+
# ==== Returns
|
14
|
+
# * response<~Excon::Response>:
|
15
|
+
# * body<~Hash>:
|
16
|
+
# * 'ResponseMetadata'<~Hash>:
|
17
|
+
# * 'VerificationToken'<~String> - Verification token
|
18
|
+
# * 'RequestId'<~String> - Id of request
|
19
|
+
def verify_domain(domain)
|
20
|
+
request({
|
21
|
+
'Action' => 'VerifyDomainIdentity',
|
22
|
+
'Domain' => domain,
|
23
|
+
:parser => Fog::Parsers::AWS::SES::VerifyDomainIdentity.new
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/fog/aws/ses.rb
CHANGED
data/lib/fog/aws/storage.rb
CHANGED
@@ -491,13 +491,14 @@ DATA
|
|
491
491
|
refresh_credentials_if_expired
|
492
492
|
|
493
493
|
expires = Fog::Time.now.to_date_header
|
494
|
+
|
495
|
+
params[:headers]['x-amz-security-token'] = @aws_session_token if @aws_session_token
|
494
496
|
signature = signature(params, expires)
|
495
497
|
|
496
498
|
params = request_params(params)
|
497
499
|
params.delete(:port) unless params[:port]
|
498
500
|
|
499
501
|
params[:headers]['Date'] = expires
|
500
|
-
params[:headers]['x-amz-security-token'] = @aws_session_token if @aws_session_token
|
501
502
|
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
|
502
503
|
# FIXME: ToHashParser should make this not needed
|
503
504
|
original_params = params.dup
|
data/lib/fog/aws/sts.rb
CHANGED
@@ -102,7 +102,7 @@ module Fog
|
|
102
102
|
)
|
103
103
|
|
104
104
|
begin
|
105
|
-
|
105
|
+
@connection.request({
|
106
106
|
:body => body,
|
107
107
|
:expects => 200,
|
108
108
|
:idempotent => idempotent,
|
@@ -111,23 +111,17 @@ module Fog
|
|
111
111
|
:method => 'POST',
|
112
112
|
:parser => parser
|
113
113
|
})
|
114
|
-
|
115
|
-
response
|
116
114
|
rescue Excon::Errors::HTTPStatusError => error
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
else
|
126
|
-
raise
|
127
|
-
end
|
115
|
+
match = Fog::AWS::Errors.match_error(error)
|
116
|
+
raise if match.empty?
|
117
|
+
raise case match[:code]
|
118
|
+
when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError'
|
119
|
+
Fog::AWS::STS.const_get(match[:code]).slurp(error, match[:message])
|
120
|
+
else
|
121
|
+
Fog::AWS::STS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
122
|
+
end
|
128
123
|
end
|
129
124
|
|
130
|
-
|
131
125
|
end
|
132
126
|
|
133
127
|
end
|
data/lib/fog/core.rb
CHANGED
@@ -19,11 +19,9 @@ require 'fog/core/current_machine'
|
|
19
19
|
require 'fog/core/deprecation'
|
20
20
|
require 'fog/core/errors'
|
21
21
|
require 'fog/core/hmac'
|
22
|
-
require 'fog/core/json'
|
23
22
|
require 'fog/core/logger'
|
24
23
|
require 'fog/core/model'
|
25
24
|
require 'fog/core/mock'
|
26
|
-
require 'fog/core/parser' # FIXME: would be better to only load when nokogiri is required
|
27
25
|
require 'fog/core/provider'
|
28
26
|
require 'fog/core/service'
|
29
27
|
require 'fog/core/ssh'
|
@@ -33,6 +31,13 @@ require 'fog/core/timeout'
|
|
33
31
|
require 'fog/core/wait_for'
|
34
32
|
require 'fog/core/class_from_string'
|
35
33
|
|
34
|
+
# data exchange specific (to be extracted and used on a per provider basis)
|
35
|
+
require 'fog/xml'
|
36
|
+
require 'fog/json'
|
37
|
+
|
38
|
+
# deprecation wrappers
|
39
|
+
require 'fog/core/deprecated/connection'
|
40
|
+
|
36
41
|
# service wrappers
|
37
42
|
require 'fog/compute'
|
38
43
|
require 'fog/identity'
|
data/lib/fog/core/connection.rb
CHANGED
@@ -1,40 +1,73 @@
|
|
1
1
|
module Fog
|
2
|
-
|
2
|
+
module Core
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
4
|
+
# Fog::Core::Connection is a generic class to contain a HTTP link to an API.
|
5
|
+
#
|
6
|
+
# It is intended to be subclassed by providers who can then add their own
|
7
|
+
# modifications such as authentication or response object.
|
8
|
+
#
|
9
|
+
class Connection
|
10
|
+
# Prepares the connection and sets defaults for any future requests.
|
11
|
+
#
|
12
|
+
# @param [String] url The destination URL
|
13
|
+
# @param persistent [Boolean]
|
14
|
+
# @param [Hash] params
|
15
|
+
# @option params [String] :body Default text to be sent over a socket. Only used if :body absent in Connection#request params
|
16
|
+
# @option params [Hash<Symbol, String>] :headers The default headers to supply in a request. Only used if params[:headers] is not supplied to Connection#request
|
17
|
+
# @option params [String] :host The destination host's reachable DNS name or IP, in the form of a String
|
18
|
+
# @option params [String] :path Default path; appears after 'scheme://host:port/'. Only used if params[:path] is not supplied to Connection#request
|
19
|
+
# @option params [Fixnum] :port The port on which to connect, to the destination host
|
20
|
+
# @option params [Hash] :query Default query; appended to the 'scheme://host:port/path/' in the form of '?key=value'. Will only be used if params[:query] is not supplied to Connection#request
|
21
|
+
# @option params [String] :scheme The protocol; 'https' causes OpenSSL to be used
|
22
|
+
# @option params [String] :proxy Proxy server; e.g. 'http://myproxy.com:8888'
|
23
|
+
# @option params [Fixnum] :retry_limit Set how many times we'll retry a failed request. (Default 4)
|
24
|
+
# @option params [Class] :instrumentor Responds to #instrument as in ActiveSupport::Notifications
|
25
|
+
# @option params [String] :instrumentor_name Name prefix for #instrument events. Defaults to 'excon'
|
26
|
+
#
|
27
|
+
def initialize(url, persistent=false, params={})
|
28
|
+
unless params.has_key?(:debug_response)
|
29
|
+
params[:debug_response] = true
|
22
30
|
end
|
31
|
+
params[:headers] ||= {}
|
32
|
+
params[:headers]['User-Agent'] ||= "fog/#{Fog::VERSION}"
|
33
|
+
@excon = Excon.new(url, params)
|
34
|
+
@persistent = persistent
|
23
35
|
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
# Makes a request using the connection using Excon
|
38
|
+
#
|
39
|
+
# @param [Hash] params
|
40
|
+
# @option params [String] :body text to be sent over a socket
|
41
|
+
# @option params [Hash<Symbol, String>] :headers The default headers to supply in a request
|
42
|
+
# @option params [String] :host The destination host's reachable DNS name or IP, in the form of a String
|
43
|
+
# @option params [String] :path appears after 'scheme://host:port/'
|
44
|
+
# @option params [Fixnum] :port The port on which to connect, to the destination host
|
45
|
+
# @option params [Hash] :query appended to the 'scheme://host:port/path/' in the form of '?key=value'
|
46
|
+
# @option params [String] :scheme The protocol; 'https' causes OpenSSL to be used
|
47
|
+
# @option params [Proc] :response_block
|
48
|
+
#
|
49
|
+
# @return [Excon::Response]
|
50
|
+
#
|
51
|
+
# @raise [Excon::Errors::StubNotFound]
|
52
|
+
# @raise [Excon::Errors::Timeout]
|
53
|
+
# @raise [Excon::Errors::SocketError]
|
54
|
+
#
|
55
|
+
def request(params, &block)
|
56
|
+
reset unless @persistent
|
57
|
+
@excon.request(params, &block)
|
30
58
|
end
|
31
59
|
|
32
|
-
|
33
|
-
|
60
|
+
# Make {#request} available even when it has been overidden by a subclass
|
61
|
+
# to allow backwards compatibility.
|
62
|
+
#
|
63
|
+
alias_method :original_request, :request
|
64
|
+
protected :original_request
|
34
65
|
|
35
|
-
|
36
|
-
|
66
|
+
# Closes the connection
|
67
|
+
#
|
68
|
+
def reset
|
69
|
+
@excon.reset
|
70
|
+
end
|
37
71
|
end
|
38
|
-
|
39
72
|
end
|
40
73
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "fog/xml"
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
|
5
|
+
# @deprecated Use {Fog::Core::Connection} or {XML::SAXParserConnection} if you
|
6
|
+
# require the response body to be parsed.
|
7
|
+
#
|
8
|
+
# The Connection class is a wrapper around an instance of Excon::Connection
|
9
|
+
# supporting {#request} and {#reset} only.
|
10
|
+
#
|
11
|
+
# {#request} includes an option to perform SAX parsing for XML APIs.
|
12
|
+
#
|
13
|
+
# @see https://github.com/geemus/excon/blob/master/lib/excon/connection.rb
|
14
|
+
#
|
15
|
+
class Connection < Fog::XML::SAXParserConnection
|
16
|
+
def request(params, &block)
|
17
|
+
if (parser = params.delete(:parser))
|
18
|
+
super(parser, params)
|
19
|
+
else
|
20
|
+
original_request(params)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/fog/core/parser.rb
CHANGED
data/lib/fog/google/compute.rb
CHANGED
@@ -41,6 +41,8 @@ module Fog
|
|
41
41
|
request :insert_network
|
42
42
|
request :insert_server
|
43
43
|
|
44
|
+
request :set_metadata
|
45
|
+
|
44
46
|
model_path 'fog/google/models/compute'
|
45
47
|
model :server
|
46
48
|
collection :servers
|
@@ -51,6 +53,9 @@ module Fog
|
|
51
53
|
model :flavor
|
52
54
|
collection :flavors
|
53
55
|
|
56
|
+
model :disk
|
57
|
+
collection :disks
|
58
|
+
|
54
59
|
class Mock
|
55
60
|
include Collections
|
56
61
|
|
@@ -66,16 +71,15 @@ module Fog
|
|
66
71
|
attr_reader :project
|
67
72
|
|
68
73
|
def initialize(options)
|
69
|
-
|
70
|
-
|
71
74
|
base_url = 'https://www.googleapis.com/compute/'
|
72
|
-
api_version = '
|
75
|
+
api_version = 'v1beta15'
|
73
76
|
api_scope_url = 'https://www.googleapis.com/auth/compute'
|
74
77
|
|
75
78
|
@project = options[:google_project]
|
76
79
|
google_client_email = options[:google_client_email]
|
77
80
|
@api_url = base_url + api_version + '/projects/'
|
78
|
-
|
81
|
+
|
82
|
+
# NOTE: loaded here to avoid requiring this as a core Fog dependency
|
79
83
|
begin
|
80
84
|
require 'google/api_client'
|
81
85
|
rescue LoadError
|
@@ -87,6 +91,7 @@ module Fog
|
|
87
91
|
:application_name => "fog",
|
88
92
|
:application_version => Fog::VERSION,
|
89
93
|
})
|
94
|
+
|
90
95
|
@client.authorization = Signet::OAuth2::Client.new({
|
91
96
|
:audience => 'https://accounts.google.com/o/oauth2/token',
|
92
97
|
:auth_provider_x509_cert_url => "https://www.googleapis.com/oauth2/v1/certs",
|
@@ -96,15 +101,14 @@ module Fog
|
|
96
101
|
:signing_key => key,
|
97
102
|
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
|
98
103
|
})
|
99
|
-
@client.authorization.fetch_access_token!
|
100
104
|
|
105
|
+
@client.authorization.fetch_access_token!
|
101
106
|
@compute = @client.discovered_api('compute', api_version)
|
102
107
|
@default_network = 'default'
|
103
108
|
end
|
104
109
|
|
105
110
|
def build_result(api_method, parameters, body_object=nil)
|
106
111
|
if body_object
|
107
|
-
#p api_method, parameters
|
108
112
|
result = @client.execute(
|
109
113
|
:api_method => api_method,
|
110
114
|
:parameters => parameters,
|
@@ -123,15 +127,35 @@ module Fog
|
|
123
127
|
response.body = Fog::JSON.decode(result.body)
|
124
128
|
if response.body["error"]
|
125
129
|
response.status = response.body["error"]["code"]
|
130
|
+
|
131
|
+
response.body["error"]["errors"].each do |error|
|
132
|
+
raise Fog::Errors::Error.new(error["message"])
|
133
|
+
end
|
126
134
|
else
|
127
135
|
response.status = 200
|
128
136
|
end
|
129
137
|
response
|
130
138
|
end
|
131
139
|
|
140
|
+
def backoff_if_unfound(&block)
|
141
|
+
retries_remaining = 10
|
142
|
+
begin
|
143
|
+
result = block.call
|
144
|
+
rescue Exception => msg
|
145
|
+
if msg.to_s.include? 'was not found' and retries_remaining > 0
|
146
|
+
retries_remaining -= 1
|
147
|
+
sleep 0.1
|
148
|
+
retry
|
149
|
+
else
|
150
|
+
raise msg
|
151
|
+
end
|
152
|
+
end
|
153
|
+
result
|
154
|
+
end
|
155
|
+
|
132
156
|
end
|
133
157
|
|
134
|
-
|
158
|
+
RUNNING = 'RUNNING'
|
135
159
|
|
136
160
|
end
|
137
161
|
end
|