fog-google 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CONTRIBUTING.md +66 -1
  4. data/CONTRIBUTORS.md +1 -0
  5. data/README.md +24 -7
  6. data/Rakefile +14 -5
  7. data/examples/image_create.rb +1 -1
  8. data/examples/launch_micro_instance.rb +1 -1
  9. data/lib/fog/google/compute.rb +6 -2
  10. data/lib/fog/google/models/compute/addresses.rb +13 -0
  11. data/lib/fog/google/models/compute/backend_services.rb +3 -4
  12. data/lib/fog/google/models/compute/global_forwarding_rules.rb +5 -3
  13. data/lib/fog/google/models/compute/images.rb +8 -2
  14. data/lib/fog/google/models/compute/resource_views.rb +2 -2
  15. data/lib/fog/google/models/compute/server.rb +37 -3
  16. data/lib/fog/google/models/compute/target_http_proxies.rb +5 -2
  17. data/lib/fog/google/models/compute/target_http_proxy.rb +1 -1
  18. data/lib/fog/google/models/compute/target_instance.rb +2 -2
  19. data/lib/fog/google/models/compute/target_instances.rb +21 -8
  20. data/lib/fog/google/models/compute/url_map.rb +1 -1
  21. data/lib/fog/google/models/compute/url_maps.rb +5 -2
  22. data/lib/fog/google/requests/compute/insert_target_instance.rb +1 -1
  23. data/lib/fog/google/requests/compute/list_aggregated_target_instances.rb +42 -0
  24. data/lib/fog/google/version.rb +1 -1
  25. data/test/helpers/integration_test_helper.rb +22 -0
  26. data/test/helpers/test_collection.rb +37 -0
  27. data/test/helpers/test_helper.rb +19 -0
  28. data/test/integration/compute/test_backend_services.rb +11 -0
  29. data/test/integration/compute/test_disk_types.rb +39 -0
  30. data/test/integration/compute/test_disks.rb +11 -0
  31. data/test/integration/compute/test_forwarding_rules.rb +11 -0
  32. data/test/integration/compute/test_global_forwarding_rules.rb +11 -0
  33. data/test/integration/compute/test_http_health_checks.rb +11 -0
  34. data/test/integration/compute/test_images.rb +11 -0
  35. data/test/integration/compute/test_regions.rb +33 -0
  36. data/test/integration/compute/test_servers.rb +28 -0
  37. data/test/integration/compute/test_target_http_proxies.rb +11 -0
  38. data/test/integration/compute/test_target_instances.rb +11 -0
  39. data/test/integration/compute/test_target_pools.rb +11 -0
  40. data/test/integration/compute/test_url_maps.rb +11 -0
  41. data/test/integration/factories/backend_services_factory.rb +19 -0
  42. data/test/integration/factories/collection_factory.rb +27 -0
  43. data/test/integration/factories/disks_factory.rb +13 -0
  44. data/test/integration/factories/forwarding_rules_factory.rb +21 -0
  45. data/test/integration/factories/global_forwarding_rules_factory.rb +19 -0
  46. data/test/integration/factories/http_health_checks_factory.rb +11 -0
  47. data/test/integration/factories/images_factory.rb +12 -0
  48. data/test/integration/factories/servers_factory.rb +21 -0
  49. data/test/integration/factories/target_http_proxies_factory.rb +19 -0
  50. data/test/integration/factories/target_instances_factory.rb +20 -0
  51. data/test/integration/factories/target_pools_factory.rb +24 -0
  52. data/test/integration/factories/url_maps_factory.rb +19 -0
  53. data/test/integration/test_authentication.rb +59 -0
  54. data/tests/helpers/collection_helper.rb +2 -0
  55. data/tests/helpers/model_helper.rb +2 -0
  56. metadata +61 -31
  57. data/.ruby-version +0 -1
  58. data/spec/minitest_helper.rb +0 -15
  59. data/tests/credentials_tests.rb +0 -73
  60. data/tests/models/compute/backend_service_tests.rb +0 -7
  61. data/tests/models/compute/backend_services_tests.rb +0 -8
  62. data/tests/models/compute/disk_tests.rb +0 -9
  63. data/tests/models/compute/disk_types_tests.rb +0 -22
  64. data/tests/models/compute/disks_tests.rb +0 -9
  65. data/tests/models/compute/forwarding_rule_tests.rb +0 -8
  66. data/tests/models/compute/forwarding_rules_tests.rb +0 -8
  67. data/tests/models/compute/global_forwarding_rule_tests.rb +0 -7
  68. data/tests/models/compute/global_forwarding_rules_tests.rb +0 -7
  69. data/tests/models/compute/http_health_check_tests.rb +0 -5
  70. data/tests/models/compute/http_health_checks_tests.rb +0 -5
  71. data/tests/models/compute/image_tests.rb +0 -6
  72. data/tests/models/compute/images_tests.rb +0 -6
  73. data/tests/models/compute/region_tests.rb +0 -10
  74. data/tests/models/compute/regions_tests.rb +0 -19
  75. data/tests/models/compute/server_tests.rb +0 -37
  76. data/tests/models/compute/servers_tests.rb +0 -14
  77. data/tests/models/compute/target_http_proxies_tests.rb +0 -7
  78. data/tests/models/compute/target_http_proxy_test.rb +0 -6
  79. data/tests/models/compute/target_instance_tests.rb +0 -7
  80. data/tests/models/compute/target_instances_tests.rb +0 -7
  81. data/tests/models/compute/target_pool_tests.rb +0 -12
  82. data/tests/models/compute/target_pools_tests.rb +0 -11
  83. data/tests/models/compute/url_map_tests.rb +0 -6
  84. data/tests/models/compute/url_maps_tests.rb +0 -7
@@ -7,20 +7,33 @@ module Fog
7
7
  class TargetInstances < Fog::Collection
8
8
  model Fog::Compute::Google::TargetInstance
9
9
 
10
- def all(zone = nil)
11
- if zone.nil?
12
- data = []
13
- data = service.list_target_instances.body['items'] || []
14
-
10
+ def all(filters={})
11
+ if filters['zone']
12
+ data = service.list_target_instances(filters['zone']).body['items'] || []
15
13
  else
16
- data = service.list_target_instances(zone).body['items'] || []
14
+ data = []
15
+ service.list_aggregated_target_instances.body['items'].each_value do |zone|
16
+ data.concat(zone['targetInstances']) if zone['targetInstances']
17
+ end
17
18
  end
18
19
  load(data)
19
20
  end
20
21
 
21
22
  def get(identity, zone=nil)
22
- response = service.get_target_instance(identity, zone)
23
- new(response.body) unless response.nil?
23
+ response = nil
24
+ if zone
25
+ response = service.get_target_instance(identity, zone).body
26
+ else
27
+ target_instances = service.list_aggregated_target_instances(:filter => "name eq .*#{identity}").body['items']
28
+ target_instance = target_instances.each_value.select { |zone| zone.key?('targetInstances') }
29
+
30
+ # It can only be 1 target_instance with the same name across all regions
31
+ response = target_instance.first['targetInstances'].first unless target_instance.empty?
32
+ end
33
+ return nil if response.nil?
34
+ new(response)
35
+ rescue Fog::Errors::NotFound
36
+ nil
24
37
  end
25
38
  end
26
39
  end
@@ -8,7 +8,7 @@ module Fog
8
8
 
9
9
  attribute :kind, :aliases => 'kind'
10
10
  attribute :creationTimestamp, :aliases => 'creation_timestamp'
11
- attribute :defaultService, :aliases => 'default_service'
11
+ attribute :defaultService, :aliases => ['default_service', :default_service]
12
12
  attribute :description, :aliases => 'description'
13
13
  attribute :fingerprint, :aliases => 'fingerprint'
14
14
  attribute :hostRules, :aliases => 'host_rules'
@@ -13,8 +13,11 @@ module Fog
13
13
  end
14
14
 
15
15
  def get(identity)
16
- response = service.get_url_map(identity)
17
- new(response.body) unless response.nil?
16
+ if url_map = service.get_url_map(identity).body
17
+ new(url_map)
18
+ end
19
+ rescue Fog::Errors::NotFound
20
+ nil
18
21
  end
19
22
  end
20
23
  end
@@ -44,7 +44,7 @@ module Fog
44
44
  'project' => @project,
45
45
  'zone' => zone_name,
46
46
  }
47
- body_object = { 'name' => target_pool_name }
47
+ body_object = { 'name' => target_instance_name }
48
48
  body_object.merge!(opts)
49
49
 
50
50
  request(api_method, parameters, body_object=body_object)
@@ -0,0 +1,42 @@
1
+ module Fog
2
+ module Compute
3
+ class Google
4
+ # XXX @ihmccreery added this mock to get the Shindo tests to pass. I don't really understand how mocks are supposed to work; I'm in the process of moving
5
+ # all testing over to Minitest, but in the meantime, the Shindo tests need to pass. This Mock should be considered with a *lot* of skepticism.
6
+ class Mock
7
+ def list_aggregated_target_instances(options = {})
8
+ # Create a Hash of unique zones from the target_instances Array previously filled when target_instances are created
9
+ zones = Hash[self.data[:target_instances].values.map { |target_instance| ["zones/#{target_instance['zone'].split('/')[-1]}", {'targetInstances' => [] }] }]
10
+ if options[:filter]
11
+ # Look up for the target_instance name
12
+ target_instance = self.data[:target_instances][options[:filter].gsub(/name eq \.\*/, '')]
13
+ # Fill the zones Hash with the target_instance (if it's found)
14
+ zones["zones/#{target_instance['zone'].split('/')[-1]}"]['targetInstances'].concat([target_instance]) if target_instance
15
+ else
16
+ # Fill the zones Hash with the target_instances attached to each zone
17
+ self.data[:target_instances].values.each { |target_instance| zones["zones/#{target_instance['zone'].split('/')[-1]}"]['targetInstances'].concat([target_instance]) }
18
+ end
19
+ build_excon_response({
20
+ "kind" => "compute#targetInstanceAggregatedList",
21
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/aggregated/targetInstances",
22
+ "id" => "projects/#{@project}/aggregated/targetInstances",
23
+ "items" => zones
24
+
25
+ })
26
+ end
27
+ end
28
+
29
+ class Real
30
+ def list_aggregated_target_instances(options = {})
31
+ api_method = @compute.target_instances.aggregated_list
32
+ parameters = {
33
+ 'project' => @project,
34
+ }
35
+ parameters['filter'] = options[:filter] if options[:filter]
36
+
37
+ request(api_method, parameters)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Google
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -0,0 +1,22 @@
1
+ require 'helpers/test_helper'
2
+ require 'helpers/test_collection'
3
+
4
+ # Use :test credentials in ~/.fog for live integration testing
5
+ # XXX not sure if this will work on Travis CI or not
6
+ Fog.credential = :test
7
+
8
+ # Helpers
9
+
10
+ TEST_ZONE = "us-central1-f"
11
+ TEST_REGION = "us-central1"
12
+ TEST_SIZE_GB = 10
13
+ TEST_MACHINE_TYPE = "n1-standard-1"
14
+ # XXX This depends on a public image in gs://fog-test-bucket; there may be a better way to do this
15
+ # The image was created like so: https://cloud.google.com/compute/docs/images#export_an_image_to_google_cloud_storage
16
+ TEST_RAW_DISK_SOURCE = "http://storage.googleapis.com/fog-test-bucket/fog-test-raw-disk-source.image.tar.gz"
17
+
18
+ class FogIntegrationTest < MiniTest::Test
19
+ def namespaced_name
20
+ "#{self.class.to_s}_#{name}"
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ module TestCollection
2
+ # Anything that includes TestCollection must, during setup, assign @subject and @factory, where
3
+ # @subject is the collection under test, (e.g. Fog::Compute[:google].servers)
4
+ # @factory is a CollectionFactory
5
+
6
+ def test_lifecycle
7
+ one = @subject.new(@factory.params)
8
+ one.save
9
+ two = @subject.create(@factory.params)
10
+
11
+ # XXX HACK compares identities
12
+ # should be replaced with simple includes? when `==` is properly implemented in fog-core; see fog/fog-core#148
13
+ assert_includes @subject.all.map(&:identity), one.identity
14
+ assert_includes @subject.all.map(&:identity), two.identity
15
+
16
+ assert_equal one.identity, @subject.get(one.identity).identity
17
+ assert_equal two.identity, @subject.get(two.identity).identity
18
+
19
+ one.destroy
20
+ two.destroy
21
+
22
+ Fog.wait_for { !@subject.all.map(&:identity).include? one.identity }
23
+ Fog.wait_for { !@subject.all.map(&:identity).include? two.identity }
24
+ end
25
+
26
+ def test_get_returns_nil_if_resource_does_not_exist
27
+ assert_nil @subject.get('fog-test-fake-identity')
28
+ end
29
+
30
+ def test_enumerable
31
+ assert_respond_to @subject, :each
32
+ end
33
+
34
+ def teardown
35
+ @factory.cleanup
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ # The next line was added to squelch a warning message in Ruby 1.9.
2
+ # It ensures we're using the gem, not the built-in Minitest
3
+ # See https://github.com/seattlerb/minitest/#install
4
+ gem 'minitest'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ if ENV['COVERAGE']
9
+ require 'coveralls'
10
+ require 'simplecov'
11
+
12
+ SimpleCov.start do
13
+ add_filter '/test/'
14
+ end
15
+ end
16
+
17
+ require File.join(File.dirname(__FILE__), '../../lib/fog/google.rb')
18
+
19
+ Coveralls.wear! if ENV['COVERAGE']
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/backend_services_factory"
3
+
4
+ class TestBackendServices < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].backend_services
9
+ @factory = BackendServicesFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ class TestDiskTypes < FogIntegrationTest
4
+ NAMES = %w(local-ssd pd-ssd pd-standard)
5
+ ZONES = %w(https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/us-central1-a
6
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/us-central1-b
7
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/us-central1-c
8
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/us-central1-f
9
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/europe-west1-b
10
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/europe-west1-c
11
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/europe-west1-d
12
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/asia-east1-a
13
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/asia-east1-b
14
+ https://www.googleapis.com/compute/v1/projects/graphite-fog/zones/asia-east1-c)
15
+
16
+ def setup
17
+ @subject = Fog::Compute[:google].disk_types
18
+ end
19
+
20
+ def test_all
21
+ assert_equal (NAMES.size * ZONES.size), @subject.all.size
22
+ end
23
+
24
+ def test_get
25
+ NAMES.each do |name|
26
+ ZONES.each do |zone|
27
+ refute_nil @subject.get(name, zone)
28
+ end
29
+ end
30
+ end
31
+
32
+ def test_bad_get
33
+ assert_nil @subject.get("bad-name")
34
+ end
35
+
36
+ def test_enumerable
37
+ assert_respond_to @subject, :each
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/disks_factory"
3
+
4
+ class TestDisks < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].disks
9
+ @factory = DisksFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/forwarding_rules_factory"
3
+
4
+ class TestForwardingRules < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].forwarding_rules
9
+ @factory = ForwardingRulesFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/global_forwarding_rules_factory"
3
+
4
+ class TestGlobalForwardingRules < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].global_forwarding_rules
9
+ @factory = GlobalForwardingRulesFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/http_health_checks_factory"
3
+
4
+ class TestHttpHealthChecks < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].http_health_checks
9
+ @factory = HttpHealthChecksFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/images_factory"
3
+
4
+ class TestImages < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].images
9
+ @factory = ImagesFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ class TestRegions < FogIntegrationTest
4
+ NAMES = %w(asia-east1 europe-west1 us-central1)
5
+
6
+ def setup
7
+ @subject = Fog::Compute[:google].regions
8
+ end
9
+
10
+ def test_all
11
+ assert_equal NAMES.size, @subject.all.size
12
+ end
13
+
14
+ def test_get
15
+ NAMES.each do |name|
16
+ refute_nil @subject.get(name)
17
+ end
18
+ end
19
+
20
+ def test_up
21
+ NAMES.each do |name|
22
+ assert @subject.get(name).up?
23
+ end
24
+ end
25
+
26
+ def test_bad_get
27
+ assert_nil @subject.get("bad-name")
28
+ end
29
+
30
+ def test_enumerable
31
+ assert_respond_to @subject, :each
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/servers_factory"
3
+
4
+ class TestServers < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].servers
9
+ @factory = ServersFactory.new(namespaced_name)
10
+ end
11
+
12
+ def test_bootstrap_ssh_destroy
13
+ resource_name = @factory.resource_name
14
+ instance = @subject.bootstrap({:name => resource_name})
15
+ assert instance.ready?
16
+ instance.wait_for { sshable? }
17
+ assert_match /Linux/, instance.ssh("uname").first.stdout
18
+ assert_equal instance.destroy.operation_type, "delete"
19
+ Fog.wait_for { !@subject.all.map(&:identity).include? instance.identity }
20
+ # XXX clean up after bootstrap's automatic creation of disks
21
+ # This should be removed when
22
+ # https://github.com/fog/fog-google/issues/17
23
+ # is solved
24
+ disk = Fog::Compute[:google].disks.get(resource_name)
25
+ disk.destroy
26
+ Fog.wait_for { !Fog::Compute[:google].disks.all.map(&:identity).include? disk.identity }
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/target_http_proxies_factory"
3
+
4
+ class TestTargetHttpProxies < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].target_http_proxies
9
+ @factory = TargetHttpProxiesFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/target_instances_factory"
3
+
4
+ class TestTargetInstances < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].target_instances
9
+ @factory = TargetInstancesFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/target_pools_factory"
3
+
4
+ class TestTargetPools < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].target_pools
9
+ @factory = TargetPoolsFactory.new(namespaced_name)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/url_maps_factory"
3
+
4
+ class TestUrlMaps < FogIntegrationTest
5
+ include TestCollection
6
+
7
+ def setup
8
+ @subject = Fog::Compute[:google].url_maps
9
+ @factory = UrlMapsFactory.new(namespaced_name)
10
+ end
11
+ end