fog 1.12.1 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +1 -1
  2. data/Gemfile +5 -0
  3. data/Rakefile +14 -4
  4. data/bin/fog +22 -0
  5. data/changelog.txt +262 -0
  6. data/fog.gemspec +8 -4
  7. data/lib/fog/aws.rb +11 -0
  8. data/lib/fog/aws/auto_scaling.rb +15 -18
  9. data/lib/fog/aws/beanstalk.rb +8 -10
  10. data/lib/fog/aws/cloud_formation.rb +9 -12
  11. data/lib/fog/aws/compute.rb +8 -10
  12. data/lib/fog/aws/credential_fetcher.rb +6 -6
  13. data/lib/fog/aws/elasticache.rb +13 -17
  14. data/lib/fog/aws/elb.rb +29 -31
  15. data/lib/fog/aws/iam.rb +10 -13
  16. data/lib/fog/aws/models/auto_scaling/group.rb +6 -3
  17. data/lib/fog/aws/models/compute/spot_request.rb +1 -11
  18. data/lib/fog/aws/models/rds/log_file.rb +26 -0
  19. data/lib/fog/aws/models/rds/log_files.rb +50 -0
  20. data/lib/fog/aws/models/rds/server.rb +3 -1
  21. data/lib/fog/aws/models/rds/snapshot.rb +1 -0
  22. data/lib/fog/aws/models/rds/snapshots.rb +20 -13
  23. data/lib/fog/aws/parsers/rds/db_parser.rb +1 -1
  24. data/lib/fog/aws/parsers/rds/describe_db_log_files.rb +44 -0
  25. data/lib/fog/aws/parsers/rds/download_db_logfile_portion.rb +26 -0
  26. data/lib/fog/aws/parsers/ses/verify_domain_identity.rb +26 -0
  27. data/lib/fog/aws/parsers/storage/complete_multipart_upload.rb +1 -1
  28. data/lib/fog/aws/parsers/sts/assume_role.rb +30 -0
  29. data/lib/fog/aws/rds.rb +27 -14
  30. data/lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb +8 -0
  31. data/lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb +8 -1
  32. data/lib/fog/aws/requests/compute/create_volume.rb +3 -3
  33. data/lib/fog/aws/requests/rds/create_db_instance.rb +3 -1
  34. data/lib/fog/aws/requests/rds/describe_db_log_files.rb +67 -0
  35. data/lib/fog/aws/requests/rds/download_db_logfile_portion.rb +63 -0
  36. data/lib/fog/aws/requests/ses/send_raw_email.rb +1 -1
  37. data/lib/fog/aws/requests/ses/verify_domain_identity.rb +30 -0
  38. data/lib/fog/aws/requests/storage/complete_multipart_upload.rb +6 -2
  39. data/lib/fog/aws/requests/storage/get_object.rb +1 -1
  40. data/lib/fog/aws/requests/sts/assume_role.rb +46 -0
  41. data/lib/fog/aws/ses.rb +26 -9
  42. data/lib/fog/aws/storage.rb +2 -1
  43. data/lib/fog/aws/sts.rb +31 -21
  44. data/lib/fog/bin.rb +0 -1
  45. data/lib/fog/bin/openstack.rb +5 -0
  46. data/lib/fog/brightbox/compute.rb +20 -212
  47. data/lib/fog/brightbox/compute/shared.rb +232 -0
  48. data/lib/fog/brightbox/models/compute/collaboration.rb +43 -0
  49. data/lib/fog/brightbox/models/compute/collaborations.rb +23 -0
  50. data/lib/fog/brightbox/models/compute/user_collaboration.rb +29 -0
  51. data/lib/fog/brightbox/models/compute/user_collaborations.rb +23 -0
  52. data/lib/fog/brightbox/requests/compute/accept_user_collaboration.rb +21 -0
  53. data/lib/fog/brightbox/requests/compute/create_collaboration.rb +23 -0
  54. data/lib/fog/brightbox/requests/compute/delete_collaboration.rb +28 -0
  55. data/lib/fog/brightbox/requests/compute/delete_user_collaboration.rb +28 -0
  56. data/lib/fog/brightbox/requests/compute/destroy_user_collaboration.rb +21 -0
  57. data/lib/fog/brightbox/requests/compute/get_collaboration.rb +21 -0
  58. data/lib/fog/brightbox/requests/compute/get_user_collaboration.rb +21 -0
  59. data/lib/fog/brightbox/requests/compute/list_collaborations.rb +19 -0
  60. data/lib/fog/brightbox/requests/compute/list_user_collaborations.rb +19 -0
  61. data/lib/fog/brightbox/requests/compute/reject_user_collaboration.rb +21 -0
  62. data/lib/fog/brightbox/requests/compute/resend_collaboration.rb +21 -0
  63. data/lib/fog/cloudsigma/docs/getting_started.md +59 -0
  64. data/lib/fog/core.rb +7 -2
  65. data/lib/fog/core/connection.rb +62 -29
  66. data/lib/fog/core/deprecated/connection.rb +24 -0
  67. data/lib/fog/core/parser.rb +1 -1
  68. data/lib/fog/digitalocean/examples/getting_started.md +1 -1
  69. data/lib/fog/digitalocean/models/compute/server.rb +2 -2
  70. data/lib/fog/google/compute.rb +31 -7
  71. data/lib/fog/google/models/compute/disk.rb +80 -0
  72. data/lib/fog/google/models/compute/disks.rb +28 -0
  73. data/lib/fog/google/models/compute/image.rb +36 -0
  74. data/lib/fog/google/models/compute/server.rb +46 -33
  75. data/lib/fog/google/models/compute/servers.rb +15 -8
  76. data/lib/fog/google/requests/compute/delete_server.rb +5 -2
  77. data/lib/fog/google/requests/compute/get_disk.rb +3 -0
  78. data/lib/fog/google/requests/compute/get_server.rb +7 -1
  79. data/lib/fog/google/requests/compute/insert_disk.rb +8 -2
  80. data/lib/fog/google/requests/compute/insert_server.rb +51 -22
  81. data/lib/fog/google/requests/compute/list_machine_types.rb +3 -2
  82. data/lib/fog/google/requests/storage/get_object.rb +1 -1
  83. data/lib/fog/hp/requests/storage/get_object.rb +1 -1
  84. data/lib/fog/hp/storage.rb +26 -9
  85. data/lib/fog/ibm/requests/compute/create_instance.rb +20 -15
  86. data/lib/fog/internet_archive/requests/storage/get_object.rb +1 -1
  87. data/lib/fog/{core/json.rb → json.rb} +13 -2
  88. data/lib/fog/metering.rb +25 -0
  89. data/lib/fog/openstack.rb +1 -0
  90. data/lib/fog/openstack/metering.rb +215 -0
  91. data/lib/fog/openstack/models/compute/flavors.rb +2 -2
  92. data/lib/fog/openstack/models/compute/metadata.rb +1 -1
  93. data/lib/fog/openstack/models/compute/server.rb +5 -2
  94. data/lib/fog/openstack/models/image/images.rb +1 -1
  95. data/lib/fog/openstack/models/metering/meter.rb +0 -0
  96. data/lib/fog/openstack/models/metering/meters.rb +0 -0
  97. data/lib/fog/openstack/models/metering/resource.rb +24 -0
  98. data/lib/fog/openstack/models/metering/resources.rb +25 -0
  99. data/lib/fog/openstack/models/volume/volume.rb +3 -1
  100. data/lib/fog/openstack/models/volume/volumes.rb +2 -1
  101. data/lib/fog/openstack/network.rb +1 -1
  102. data/lib/fog/openstack/requests/compute/create_flavor.rb +1 -1
  103. data/lib/fog/openstack/requests/compute/create_server.rb +19 -1
  104. data/lib/fog/openstack/requests/compute/detach_volume.rb +2 -1
  105. data/lib/fog/openstack/requests/compute/list_flavors_detail.rb +4 -3
  106. data/lib/fog/openstack/requests/compute/list_security_groups.rb +1 -1
  107. data/lib/fog/openstack/requests/identity/create_tenant.rb +2 -2
  108. data/lib/fog/openstack/requests/metering/get_resource.rb +32 -0
  109. data/lib/fog/openstack/requests/metering/get_samples.rb +55 -0
  110. data/lib/fog/openstack/requests/metering/get_statistics.rb +56 -0
  111. data/lib/fog/openstack/requests/metering/list_meters.rb +50 -0
  112. data/lib/fog/openstack/requests/metering/list_resources.rb +32 -0
  113. data/lib/fog/openstack/requests/volume/create_volume.rb +4 -2
  114. data/lib/fog/rackspace.rb +16 -1
  115. data/lib/fog/rackspace/block_storage.rb +13 -28
  116. data/lib/fog/rackspace/cdn.rb +10 -24
  117. data/lib/fog/rackspace/compute.rb +17 -45
  118. data/lib/fog/rackspace/compute_v2.rb +13 -33
  119. data/lib/fog/rackspace/databases.rb +13 -29
  120. data/lib/fog/rackspace/dns.rb +27 -23
  121. data/lib/fog/rackspace/identity.rb +10 -26
  122. data/lib/fog/rackspace/load_balancers.rb +13 -29
  123. data/lib/fog/rackspace/mock_data.rb +3 -3
  124. data/lib/fog/rackspace/models/compute/server.rb +1 -1
  125. data/lib/fog/rackspace/models/dns/zones.rb +34 -21
  126. data/lib/fog/rackspace/models/identity/users.rb +2 -2
  127. data/lib/fog/rackspace/models/storage/file.rb +1 -0
  128. data/lib/fog/rackspace/requests/dns/list_domains.rb +2 -2
  129. data/lib/fog/rackspace/requests/storage/delete_multiple_objects.rb +75 -0
  130. data/lib/fog/rackspace/requests/storage/delete_static_large_object.rb +50 -0
  131. data/lib/fog/rackspace/requests/storage/get_object.rb +3 -1
  132. data/lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb +44 -0
  133. data/lib/fog/rackspace/requests/storage/put_object_manifest.rb +3 -30
  134. data/lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb +60 -0
  135. data/lib/fog/rackspace/service.rb +43 -1
  136. data/lib/fog/rackspace/storage.rb +25 -43
  137. data/lib/fog/riakcs/provisioning.rb +2 -1
  138. data/lib/fog/riakcs/usage.rb +2 -1
  139. data/lib/fog/vcloud/requests/compute/configure_vm_cpus.rb +1 -1
  140. data/lib/fog/vcloud/requests/compute/configure_vm_memory.rb +1 -1
  141. data/lib/fog/version.rb +1 -1
  142. data/lib/fog/vsphere/requests/compute/get_folder.rb +1 -1
  143. data/lib/fog/xenserver/compute.rb +2 -0
  144. data/lib/fog/xenserver/models/compute/server.rb +9 -7
  145. data/lib/fog/xenserver/requests/compute/snapshot_revert.rb +22 -0
  146. data/lib/fog/xenserver/requests/compute/snapshot_server.rb +22 -0
  147. data/lib/fog/xml.rb +21 -0
  148. data/lib/fog/xml/sax_parser_connection.rb +43 -0
  149. data/lib/tasks/changelog_task.rb +1 -0
  150. data/tests/aws/models/auto_scaling/groups_test.rb +22 -0
  151. data/tests/aws/requests/compute/volume_tests.rb +3 -3
  152. data/tests/aws/requests/rds/helper.rb +14 -0
  153. data/tests/aws/requests/rds/log_file_tests.rb +19 -0
  154. data/tests/aws/requests/ses/verified_domain_identity_tests.rb +16 -0
  155. data/tests/aws/requests/sts/assume_role_tests.rb +19 -0
  156. data/tests/brightbox/requests/compute/collaboration_tests.rb +41 -0
  157. data/tests/brightbox/requests/compute/helper.rb +46 -2
  158. data/tests/brightbox/requests/compute/user_collaboration_tests.rb +67 -0
  159. data/tests/core/connection_tests.rb +26 -0
  160. data/tests/helper.rb +13 -0
  161. data/tests/openstack/requests/metering/meter_tests.rb +52 -0
  162. data/tests/openstack/requests/metering/resource_tests.rb +19 -0
  163. data/tests/openvz/helper.rb +14 -8
  164. data/tests/rackspace/block_storage_tests.rb +9 -0
  165. data/tests/rackspace/compute_tests.rb +9 -0
  166. data/tests/rackspace/compute_v2_tests.rb +9 -0
  167. data/tests/rackspace/databases_tests.rb +9 -0
  168. data/tests/rackspace/dns_tests.rb +20 -0
  169. data/tests/rackspace/helper.rb +12 -1
  170. data/tests/rackspace/identity_tests.rb +25 -0
  171. data/tests/rackspace/load_balancer_tests.rb +10 -0
  172. data/tests/rackspace/models/block_storage/volume_tests.rb +2 -2
  173. data/tests/rackspace/models/compute_v2/metadata_tests.rb +2 -2
  174. data/tests/rackspace/models/compute_v2/server_tests.rb +22 -21
  175. data/tests/rackspace/models/dns/zones_tests.rb +19 -5
  176. data/tests/rackspace/models/storage/file_tests.rb +22 -6
  177. data/tests/rackspace/rackspace_tests.rb +35 -0
  178. data/tests/rackspace/requests/block_storage/snapshot_tests.rb +2 -3
  179. data/tests/rackspace/requests/block_storage/volume_type_tests.rb +4 -11
  180. data/tests/rackspace/requests/compute_v2/address_tests.rb +1 -1
  181. data/tests/rackspace/requests/compute_v2/attachment_tests.rb +8 -9
  182. data/tests/rackspace/requests/compute_v2/flavor_tests.rb +1 -1
  183. data/tests/rackspace/requests/compute_v2/metadata_tests.rb +4 -4
  184. data/tests/rackspace/requests/databases/database_tests.rb +23 -20
  185. data/tests/rackspace/requests/databases/user_tests.rb +6 -6
  186. data/tests/rackspace/requests/identity/user_tests.rb +4 -1
  187. data/tests/rackspace/requests/load_balancers/usage_tests.rb +4 -2
  188. data/tests/rackspace/requests/storage/large_object_tests.rb +303 -59
  189. data/tests/rackspace/requests/storage/object_tests.rb +73 -18
  190. data/tests/rackspace/service_tests.rb +83 -0
  191. data/tests/rackspace/storage_tests.rb +9 -0
  192. data/tests/xenserver/models/compute/server_tests.rb +11 -1
  193. metadata +89 -19
  194. data/tests/core/user_agent_tests.rb +0 -6
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # Ends an existing 'accepted' collaboration
6
+ #
7
+ # @param [String] identifier Unique reference to identify the resource
8
+ #
9
+ # @return [Hash] The JSON response parsed to a Hash
10
+ #
11
+ # @see https://api.gb1.brightbox.com/1.0/#user_collaboration_destroy_user_collaboration
12
+ #
13
+ def destroy_user_collaboration(identifier)
14
+ return nil if identifier.nil? || identifier == ""
15
+ wrapped_request("delete", "/1.0/user/collaborations/#{identifier}", [200])
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # Shows details of one collaboration
6
+ #
7
+ # @param [String] identifier Unique reference to identify the resource
8
+ #
9
+ # @return [Hash] if successful Hash version of JSON object
10
+ #
11
+ # @see https://api.gb1.brightbox.com/1.0/#collaboration_get_collaboration
12
+ #
13
+ def get_collaboration(identifier)
14
+ return nil if identifier.nil? || identifier == ""
15
+ wrapped_request("get", "/1.0/collaborations/#{identifier}", [200])
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # Shows details of one collaboration
6
+ #
7
+ # @param [String] identifier Unique reference to identify the resource
8
+ #
9
+ # @return [Hash] if successful Hash version of JSON object
10
+ #
11
+ # @see https://api.gb1.brightbox.com/1.0/#user_collaboration_get_user_collaboration
12
+ #
13
+ def get_user_collaboration(identifier)
14
+ return nil if identifier.nil? || identifier == ""
15
+ wrapped_request("get", "/1.0/user/collaborations/#{identifier}", [200])
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # Lists all the account collaborations
6
+ #
7
+ #
8
+ # @return [Hash] if successful Hash version of JSON object
9
+ #
10
+ # @see https://api.gb1.brightbox.com/1.0/#collaboration_list_collaborations
11
+ #
12
+ def list_collaborations
13
+ wrapped_request("get", "/1.0/collaborations", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # Lists all collaborations the user is involved with
6
+ #
7
+ #
8
+ # @return [Hash] if successful Hash version of JSON object
9
+ #
10
+ # @see https://api.gb1.brightbox.com/1.0/#user_collaboration_list_user_collaborations
11
+ #
12
+ def list_user_collaborations
13
+ wrapped_request("get", "/1.0/user/collaborations", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # Rejects the collaboration and removes the offer
6
+ #
7
+ # @param [String] identifier Unique reference to identify the resource
8
+ #
9
+ # @return [Hash] if successful Hash version of JSON object
10
+ #
11
+ # @see https://api.gb1.brightbox.com/1.0/#user_collaboration_reject_user_collaboration
12
+ #
13
+ def reject_user_collaboration(identifier)
14
+ return nil if identifier.nil? || identifier == ""
15
+ wrapped_request("post", "/1.0/user/collaborations/#{identifier}/reject", [200])
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # Resends the invitation email to the collaborator
6
+ #
7
+ # @param [String] identifier Unique reference to identify the resource
8
+ #
9
+ # @return [Hash] if successful Hash version of JSON object
10
+ #
11
+ # @see https://api.gb1.brightbox.com/1.0/#collaboration_resend_collaboration
12
+ #
13
+ def resend_collaboration(identifier)
14
+ return nil if identifier.nil? || identifier == ""
15
+ wrapped_request("post", "/1.0/collaborations/#{identifier}/resend", [200])
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,59 @@
1
+ # Getting Started with Fog on CloudSigma
2
+
3
+ ## Requirements
4
+
5
+ In order to use CloudSigma with Fog, you must use Fog version 1.12.0 or later.
6
+
7
+ ## Setting credentials
8
+
9
+ Fog uses `~/.fog` to store credentials. To add CloudSigma as your default provider, simply add the following:
10
+
11
+ :default:
12
+ :cloudsigma_username: user@example.com
13
+ :cloudsigma_password: SomeRandomPassword
14
+ :cloudsigma_host: zrh.cloudsigma.com
15
+
16
+ Please note that you need to specify the host. If you're on the Zurich-based cloud, you will need to enter `zrh.cloudsigma.com` and if you're on the Las Vegas cloud, you'll need to enter `lvs.cloudsigma.com`.
17
+
18
+
19
+ ## Creating a server
20
+
21
+ You can of course interact with Fog directly from your Ruby application, but in this example, we'll simply use the `fog` CLI tool. In the example below, we'll first create a 5GB disk, then we create server with 2Ghz CPU and 2GB RAM. Finally we attach the drive and boot up the server.
22
+
23
+ $ fog
24
+ > cs = Compute[:CloudSigma]
25
+ > drive = cs.volumes.create(:name => 'fog_drive', :size => '5368709120', :media => 'disk')
26
+ > server = cs.servers.create(:name => 'fog_server', :cpu => '2000', :mem => '2147483648', :vnc_password => 'foobar')
27
+ > server.mount_volume(drive.uuid)
28
+ > server.update
29
+ > server.start
30
+
31
+ Now, this wasn't very useful by itself since the drive we created was just a blank drive (as a result it cannot boot). It does however illustrate a minimal work flow.
32
+
33
+ To make this a bit more useful, let's try to attach an ISO image (in this case Ubuntu 12.04 LTS), and boot into the installer. To do this, we'll run the following commands (assuming you haven't closed the session from above). You can either upload your own installer image, or you can use one from the drives library. In either case, you need to pass the UUID for the drive.
34
+
35
+ > server.stop
36
+ > ubuntu_image_uuid = '41d848c2-44e4-4428-9406-84e95bb1288d'
37
+ > server.unmount(drive.uuid)
38
+ > server.mount_volume(ubuntu_image_uuid, 'ide', '0:0', 1)
39
+ > server.mount_volume(drive.uuid, 'virtio', '0:0', 2)
40
+ > server.update
41
+ > server.start
42
+
43
+ What this does is to stop the server, unmount the previous drive, then we attach the Ubuntu installation drive as an IDE device (on bus 0:0), with the boot order 1 (first). We then mount the system drive as Virtio device (on bus 0:0) with the boot order 2. Finally we push the changes to the server and start it. This will bring you into the Ubuntu installation.
44
+
45
+ In order to actually run the installer, you need to open a VNC session to the server. This can be done bye issue the following command:
46
+
47
+ > server.open_vnc
48
+
49
+ That will print out the VNC URL, among with other data. You can simply pass the value of 'vnc_url' into your VNC client. When opening the session, you also need to provide the password, which we set to 'foobar' during the server creation.
50
+
51
+ After you're done with the installation, you can unmount the Ubuntu installation disk by running the following command:
52
+
53
+ > server.unmount(ubuntu_image_uuid)
54
+
55
+ You might also want to close the VNC session to increase security. This can be done by running:
56
+
57
+ > server.close_vnc
58
+
59
+ That's it. You've now set up a fully working Ubuntu server on CloudSigma using fog.
@@ -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'
@@ -32,6 +30,13 @@ require 'fog/core/time'
32
30
  require 'fog/core/timeout'
33
31
  require 'fog/core/wait_for'
34
32
 
33
+ # data exchange specific (to be extracted and used on a per provider basis)
34
+ require 'fog/xml'
35
+ require 'fog/json'
36
+
37
+ # deprecation wrappers
38
+ require 'fog/core/deprecated/connection'
39
+
35
40
  # service wrappers
36
41
  require 'fog/compute'
37
42
  require 'fog/identity'
@@ -1,40 +1,73 @@
1
1
  module Fog
2
- class Connection
2
+ module Core
3
3
 
4
- def initialize(url, persistent=false, params={})
5
- unless params.has_key?(:debug_response)
6
- params[:debug_response] = true
7
- end
8
- params[:headers] ||= {}
9
- params[:headers]['User-Agent'] ||= "fog/#{Fog::VERSION}"
10
- @excon = Excon.new(url, params)
11
- @persistent = persistent
12
- end
13
-
14
- def request(params, &block)
15
- unless @persistent
16
- reset
17
- end
18
- unless block_given?
19
- if (parser = params.delete(:parser))
20
- body = Nokogiri::XML::SAX::PushParser.new(parser)
21
- params[:response_block] = lambda { |chunk, remaining, total| body << chunk }
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
- response = @excon.request(params, &block)
26
-
27
- if parser
28
- body.finish
29
- response.body = parser.response
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
- response
33
- end
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
- def reset
36
- @excon.reset
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
@@ -1,4 +1,4 @@
1
- require 'nokogiri'
1
+ require "nokogiri"
2
2
 
3
3
  module Fog
4
4
  module Parsers
@@ -22,7 +22,7 @@ First, create a connection to the host:
22
22
  ```ruby
23
23
  require 'fog'
24
24
 
25
- do = Fog::Compute.new({
25
+ docean = Fog::Compute.new({
26
26
  :provider => 'DigitalOcean',
27
27
  :digitalocean_api_key => 'poiuweoruwoeiuroiwuer', # your API key here
28
28
  :digitalocean_client_id => 'lkjasoidfuoiu' # your client key here
@@ -76,12 +76,12 @@ module Fog
76
76
  #
77
77
  # Usually called by Fog::Collection#create
78
78
  #
79
- # do = Fog::Compute.new({
79
+ # docean = Fog::Compute.new({
80
80
  # :provider => 'DigitalOcean',
81
81
  # :digitalocean_api_key => 'key-here', # your API key here
82
82
  # :digitalocean_client_id => 'client-id-here' # your client key here
83
83
  # })
84
- # do.servers.create :name => 'foobar',
84
+ # docean.servers.create :name => 'foobar',
85
85
  # :image_id => image_id_here,
86
86
  # :flavor_id => flavor_id_here,
87
87
  # :region_id => region_id_here
@@ -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 = 'v1beta14'
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
- #NOTE: loaded here to avoid requiring this as a core Fog dependency
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
- RUNNING_STATE = 'RUNNING'
158
+ RUNNING = 'RUNNING'
135
159
 
136
160
  end
137
161
  end