fog 1.12.1 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/Gemfile +5 -0
- data/Rakefile +14 -4
- data/bin/fog +22 -0
- data/changelog.txt +262 -0
- data/fog.gemspec +8 -4
- data/lib/fog/aws.rb +11 -0
- data/lib/fog/aws/auto_scaling.rb +15 -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/auto_scaling/group.rb +6 -3
- data/lib/fog/aws/models/compute/spot_request.rb +1 -11
- data/lib/fog/aws/models/rds/log_file.rb +26 -0
- data/lib/fog/aws/models/rds/log_files.rb +50 -0
- data/lib/fog/aws/models/rds/server.rb +3 -1
- data/lib/fog/aws/models/rds/snapshot.rb +1 -0
- data/lib/fog/aws/models/rds/snapshots.rb +20 -13
- data/lib/fog/aws/parsers/rds/db_parser.rb +1 -1
- data/lib/fog/aws/parsers/rds/describe_db_log_files.rb +44 -0
- data/lib/fog/aws/parsers/rds/download_db_logfile_portion.rb +26 -0
- data/lib/fog/aws/parsers/ses/verify_domain_identity.rb +26 -0
- data/lib/fog/aws/parsers/storage/complete_multipart_upload.rb +1 -1
- data/lib/fog/aws/parsers/sts/assume_role.rb +30 -0
- data/lib/fog/aws/rds.rb +27 -14
- data/lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb +8 -0
- data/lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb +8 -1
- 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/rds/describe_db_log_files.rb +67 -0
- data/lib/fog/aws/requests/rds/download_db_logfile_portion.rb +63 -0
- data/lib/fog/aws/requests/ses/send_raw_email.rb +1 -1
- data/lib/fog/aws/requests/ses/verify_domain_identity.rb +30 -0
- data/lib/fog/aws/requests/storage/complete_multipart_upload.rb +6 -2
- data/lib/fog/aws/requests/storage/get_object.rb +1 -1
- data/lib/fog/aws/requests/sts/assume_role.rb +46 -0
- data/lib/fog/aws/ses.rb +26 -9
- data/lib/fog/aws/storage.rb +2 -1
- data/lib/fog/aws/sts.rb +31 -21
- data/lib/fog/bin.rb +0 -1
- data/lib/fog/bin/openstack.rb +5 -0
- data/lib/fog/brightbox/compute.rb +20 -212
- data/lib/fog/brightbox/compute/shared.rb +232 -0
- data/lib/fog/brightbox/models/compute/collaboration.rb +43 -0
- data/lib/fog/brightbox/models/compute/collaborations.rb +23 -0
- data/lib/fog/brightbox/models/compute/user_collaboration.rb +29 -0
- data/lib/fog/brightbox/models/compute/user_collaborations.rb +23 -0
- data/lib/fog/brightbox/requests/compute/accept_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/create_collaboration.rb +23 -0
- data/lib/fog/brightbox/requests/compute/delete_collaboration.rb +28 -0
- data/lib/fog/brightbox/requests/compute/delete_user_collaboration.rb +28 -0
- data/lib/fog/brightbox/requests/compute/destroy_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/get_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/get_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/list_collaborations.rb +19 -0
- data/lib/fog/brightbox/requests/compute/list_user_collaborations.rb +19 -0
- data/lib/fog/brightbox/requests/compute/reject_user_collaboration.rb +21 -0
- data/lib/fog/brightbox/requests/compute/resend_collaboration.rb +21 -0
- data/lib/fog/cloudsigma/docs/getting_started.md +59 -0
- 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/digitalocean/examples/getting_started.md +1 -1
- data/lib/fog/digitalocean/models/compute/server.rb +2 -2
- 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/google/requests/storage/get_object.rb +1 -1
- data/lib/fog/hp/requests/storage/get_object.rb +1 -1
- data/lib/fog/hp/storage.rb +26 -9
- data/lib/fog/ibm/requests/compute/create_instance.rb +20 -15
- data/lib/fog/internet_archive/requests/storage/get_object.rb +1 -1
- data/lib/fog/{core/json.rb → json.rb} +13 -2
- data/lib/fog/metering.rb +25 -0
- data/lib/fog/openstack.rb +1 -0
- data/lib/fog/openstack/metering.rb +215 -0
- data/lib/fog/openstack/models/compute/flavors.rb +2 -2
- data/lib/fog/openstack/models/compute/metadata.rb +1 -1
- data/lib/fog/openstack/models/compute/server.rb +5 -2
- data/lib/fog/openstack/models/image/images.rb +1 -1
- data/lib/fog/openstack/models/metering/meter.rb +0 -0
- data/lib/fog/openstack/models/metering/meters.rb +0 -0
- data/lib/fog/openstack/models/metering/resource.rb +24 -0
- data/lib/fog/openstack/models/metering/resources.rb +25 -0
- data/lib/fog/openstack/models/volume/volume.rb +3 -1
- data/lib/fog/openstack/models/volume/volumes.rb +2 -1
- data/lib/fog/openstack/network.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_flavor.rb +1 -1
- data/lib/fog/openstack/requests/compute/create_server.rb +19 -1
- data/lib/fog/openstack/requests/compute/detach_volume.rb +2 -1
- data/lib/fog/openstack/requests/compute/list_flavors_detail.rb +4 -3
- data/lib/fog/openstack/requests/compute/list_security_groups.rb +1 -1
- data/lib/fog/openstack/requests/identity/create_tenant.rb +2 -2
- data/lib/fog/openstack/requests/metering/get_resource.rb +32 -0
- data/lib/fog/openstack/requests/metering/get_samples.rb +55 -0
- data/lib/fog/openstack/requests/metering/get_statistics.rb +56 -0
- data/lib/fog/openstack/requests/metering/list_meters.rb +50 -0
- data/lib/fog/openstack/requests/metering/list_resources.rb +32 -0
- data/lib/fog/openstack/requests/volume/create_volume.rb +4 -2
- data/lib/fog/rackspace.rb +16 -1
- 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 +27 -23
- 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/dns/zones.rb +34 -21
- 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/dns/list_domains.rb +2 -2
- data/lib/fog/rackspace/requests/storage/delete_multiple_objects.rb +75 -0
- data/lib/fog/rackspace/requests/storage/delete_static_large_object.rb +50 -0
- data/lib/fog/rackspace/requests/storage/get_object.rb +3 -1
- data/lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb +44 -0
- data/lib/fog/rackspace/requests/storage/put_object_manifest.rb +3 -30
- data/lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb +60 -0
- data/lib/fog/rackspace/service.rb +43 -1
- data/lib/fog/rackspace/storage.rb +25 -43
- data/lib/fog/riakcs/provisioning.rb +2 -1
- data/lib/fog/riakcs/usage.rb +2 -1
- data/lib/fog/vcloud/requests/compute/configure_vm_cpus.rb +1 -1
- data/lib/fog/vcloud/requests/compute/configure_vm_memory.rb +1 -1
- data/lib/fog/version.rb +1 -1
- data/lib/fog/vsphere/requests/compute/get_folder.rb +1 -1
- 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/lib/tasks/changelog_task.rb +1 -0
- data/tests/aws/models/auto_scaling/groups_test.rb +22 -0
- data/tests/aws/requests/compute/volume_tests.rb +3 -3
- data/tests/aws/requests/rds/helper.rb +14 -0
- data/tests/aws/requests/rds/log_file_tests.rb +19 -0
- data/tests/aws/requests/ses/verified_domain_identity_tests.rb +16 -0
- data/tests/aws/requests/sts/assume_role_tests.rb +19 -0
- data/tests/brightbox/requests/compute/collaboration_tests.rb +41 -0
- data/tests/brightbox/requests/compute/helper.rb +46 -2
- data/tests/brightbox/requests/compute/user_collaboration_tests.rb +67 -0
- data/tests/core/connection_tests.rb +26 -0
- data/tests/helper.rb +13 -0
- data/tests/openstack/requests/metering/meter_tests.rb +52 -0
- data/tests/openstack/requests/metering/resource_tests.rb +19 -0
- data/tests/openvz/helper.rb +14 -8
- 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 +20 -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/dns/zones_tests.rb +19 -5
- 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/requests/storage/large_object_tests.rb +303 -59
- data/tests/rackspace/requests/storage/object_tests.rb +73 -18
- 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 +89 -19
- 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.
|
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'
|
@@ -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'
|
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
@@ -22,7 +22,7 @@ First, create a connection to the host:
|
|
22
22
|
```ruby
|
23
23
|
require 'fog'
|
24
24
|
|
25
|
-
|
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
|
-
#
|
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
|
-
#
|
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
|
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
|