fog-google 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +5 -5
  2. data/.codecov.yml +2 -0
  3. data/.rubocop.yml +4 -1
  4. data/CHANGELOG.md +51 -0
  5. data/CONTRIBUTING.md +85 -17
  6. data/CONTRIBUTORS.md +6 -4
  7. data/Gemfile +6 -0
  8. data/MIGRATING.md +1 -11
  9. data/README.md +15 -4
  10. data/ci/credentials.yml.template +2 -0
  11. data/ci/docker-image/Dockerfile +1 -3
  12. data/ci/pipeline.yml +117 -12
  13. data/ci/tasks/run-int.sh +3 -2
  14. data/ci/tasks/run-int.yml +1 -1
  15. data/examples/create_instance.rb +40 -25
  16. data/examples/get_list_images.rb +1 -1
  17. data/examples/load-balance.rb +1 -1
  18. data/examples/metadata.rb +1 -1
  19. data/examples/network.rb +1 -1
  20. data/fog-google.gemspec +8 -6
  21. data/lib/fog/compute/google/models/address.rb +1 -1
  22. data/lib/fog/compute/google/models/backend_service.rb +1 -1
  23. data/lib/fog/compute/google/models/disk.rb +2 -2
  24. data/lib/fog/compute/google/models/firewall.rb +23 -3
  25. data/lib/fog/compute/google/models/forwarding_rule.rb +1 -1
  26. data/lib/fog/compute/google/models/global_address.rb +1 -1
  27. data/lib/fog/compute/google/models/global_forwarding_rule.rb +1 -1
  28. data/lib/fog/compute/google/models/http_health_check.rb +2 -2
  29. data/lib/fog/compute/google/models/image.rb +1 -1
  30. data/lib/fog/compute/google/models/instance_group_manager.rb +1 -1
  31. data/lib/fog/compute/google/models/instance_template.rb +1 -1
  32. data/lib/fog/compute/google/models/route.rb +1 -1
  33. data/lib/fog/compute/google/models/server.rb +59 -5
  34. data/lib/fog/compute/google/models/servers.rb +1 -1
  35. data/lib/fog/compute/google/models/ssl_certificate.rb +1 -1
  36. data/lib/fog/compute/google/models/subnetwork.rb +1 -1
  37. data/lib/fog/compute/google/models/target_http_proxy.rb +1 -1
  38. data/lib/fog/compute/google/models/target_https_proxy.rb +14 -1
  39. data/lib/fog/compute/google/models/target_instance.rb +1 -1
  40. data/lib/fog/compute/google/models/target_pool.rb +1 -1
  41. data/lib/fog/compute/google/models/url_map.rb +1 -1
  42. data/lib/fog/compute/google/requests/insert_server.rb +1 -1
  43. data/lib/fog/dns/google/models/record.rb +1 -1
  44. data/lib/fog/google/models/sql/instance.rb +1 -1
  45. data/lib/fog/google/models/sql/user.rb +1 -1
  46. data/lib/fog/google/version.rb +1 -1
  47. data/lib/fog/storage/google_json.rb +4 -1
  48. data/lib/fog/storage/google_json/mock.rb +3 -0
  49. data/lib/fog/storage/google_json/models/file.rb +2 -2
  50. data/lib/fog/storage/google_json/models/files.rb +2 -2
  51. data/lib/fog/storage/google_json/real.rb +3 -0
  52. data/lib/fog/storage/google_json/requests/get_object_http_url.rb +6 -7
  53. data/lib/fog/storage/google_json/requests/get_object_https_url.rb +6 -7
  54. data/lib/fog/storage/google_json/requests/get_object_url.rb +4 -4
  55. data/lib/fog/storage/google_json/utils.rb +7 -1
  56. data/lib/fog/storage/google_xml/models/file.rb +2 -2
  57. data/lib/fog/storage/google_xml/models/files.rb +4 -4
  58. data/lib/fog/storage/google_xml/requests/get_object_http_url.rb +8 -7
  59. data/lib/fog/storage/google_xml/requests/get_object_https_url.rb +7 -7
  60. data/lib/fog/storage/google_xml/requests/get_object_url.rb +5 -4
  61. data/lib/fog/storage/google_xml/utils.rb +7 -1
  62. data/tasks/test.rake +45 -23
  63. data/test/helpers/integration_test_helper.rb +67 -0
  64. data/test/helpers/test_helper.rb +14 -10
  65. data/test/integration/compute/core_compute/test_coverage.rb +6 -0
  66. data/test/integration/compute/{test_disk_types.rb → core_compute/test_disk_types.rb} +0 -0
  67. data/test/integration/compute/{disks/test_compute_disk_models.rb → core_compute/test_disks.rb} +0 -0
  68. data/test/integration/compute/{test_images.rb → core_compute/test_images.rb} +0 -0
  69. data/test/integration/compute/core_compute/test_machine_types.rb +42 -0
  70. data/test/integration/compute/core_compute/test_operations.rb +27 -0
  71. data/test/integration/compute/core_compute/test_projects.rb +19 -0
  72. data/test/integration/compute/{test_regions.rb → core_compute/test_regions.rb} +0 -0
  73. data/test/integration/compute/core_compute/test_servers.rb +109 -0
  74. data/test/integration/compute/{test_snapshots.rb → core_compute/test_snapshots.rb} +0 -0
  75. data/test/integration/compute/core_compute/test_zones.rb +35 -0
  76. data/test/integration/compute/core_networking/test_addresses.rb +84 -0
  77. data/test/integration/compute/core_networking/test_coverage.rb +6 -0
  78. data/test/integration/compute/core_networking/test_firewalls.rb +11 -0
  79. data/test/integration/compute/core_networking/test_networks.rb +41 -0
  80. data/test/integration/compute/core_networking/test_routes.rb +26 -0
  81. data/test/integration/compute/core_networking/test_subnetworks.rb +11 -0
  82. data/test/integration/compute/instance_groups/test_coverage.rb +6 -0
  83. data/test/integration/compute/{test_instance_group_managers.rb → instance_groups/test_instance_group_managers.rb} +0 -0
  84. data/test/integration/compute/instance_groups/test_instance_groups.rb +11 -0
  85. data/test/integration/compute/{test_instance_templates.rb → instance_groups/test_instance_templates.rb} +0 -0
  86. data/test/integration/compute/{test_backend_services.rb → loadbalancing/test_backend_services.rb} +0 -0
  87. data/test/integration/compute/loadbalancing/test_coverage.rb +6 -0
  88. data/test/integration/compute/{test_forwarding_rules.rb → loadbalancing/test_forwarding_rules.rb} +0 -0
  89. data/test/integration/compute/loadbalancing/test_global_addresses.rb +11 -0
  90. data/test/integration/compute/{test_global_forwarding_rules.rb → loadbalancing/test_global_forwarding_rules.rb} +0 -0
  91. data/test/integration/compute/{test_http_health_checks.rb → loadbalancing/test_http_health_checks.rb} +0 -0
  92. data/test/integration/compute/loadbalancing/test_ssl_certificates.rb +11 -0
  93. data/test/integration/compute/{test_target_http_proxies.rb → loadbalancing/test_target_http_proxies.rb} +0 -0
  94. data/test/integration/compute/loadbalancing/test_target_https_proxies.rb +11 -0
  95. data/test/integration/compute/{test_target_instances.rb → loadbalancing/test_target_instances.rb} +0 -0
  96. data/test/integration/compute/loadbalancing/test_target_pools.rb +55 -0
  97. data/test/integration/compute/{test_url_maps.rb → loadbalancing/test_url_maps.rb} +0 -0
  98. data/test/integration/factories/addresses_factory.rb +16 -0
  99. data/test/integration/factories/collection_factory.rb +24 -3
  100. data/test/integration/factories/disks_factory.rb +1 -0
  101. data/test/integration/factories/firewalls_factory.rb +13 -0
  102. data/test/integration/factories/global_addresses_factory.rb +15 -0
  103. data/test/integration/factories/instance_groups_factory.rb +16 -0
  104. data/test/integration/factories/instance_template_factory.rb +1 -0
  105. data/test/integration/factories/networks_factory.rb +16 -0
  106. data/test/integration/factories/ssl_certificates_factory.rb +13 -0
  107. data/test/integration/factories/subnetworks_factory.rb +22 -0
  108. data/test/integration/factories/target_https_proxies_factory.rb +26 -0
  109. data/test/integration/factories/target_pools_factory.rb +2 -2
  110. data/test/integration/monitoring/test_coverage.rb +6 -0
  111. data/test/integration/monitoring/test_timeseries.rb +1 -1
  112. data/test/integration/pubsub/test_coverage.rb +6 -0
  113. data/test/integration/sql/{test_common_flags.rb → sqlv1/test_common_flags.rb} +0 -0
  114. data/test/integration/sql/{test_common_tiers.rb → sqlv1/test_common_tiers.rb} +0 -0
  115. data/test/integration/sql/sqlv1/test_coverage.rb +6 -0
  116. data/test/integration/sql/{test_v1_certs.rb → sqlv1/test_v1_certs.rb} +0 -0
  117. data/test/integration/sql/{test_v1_instances.rb → sqlv1/test_v1_instances.rb} +0 -0
  118. data/test/integration/sql/{test_v1_users.rb → sqlv1/test_v1_users.rb} +0 -0
  119. data/test/integration/sql/sqlv2/test_coverage.rb +6 -0
  120. data/test/integration/sql/{test_v2_instances.rb → sqlv2/test_v2_instances.rb} +0 -0
  121. data/test/integration/storage/test_coverage.rb +6 -0
  122. data/test/unit/storage/test_json_requests.rb +45 -0
  123. data/test/unit/storage/test_xml_requests.rb +20 -0
  124. metadata +115 -92
  125. data/test/integration/compute/addresses/addresses_shared.rb +0 -59
  126. data/test/integration/compute/addresses/test_compute_address_models.rb +0 -105
  127. data/test/integration/compute/addresses/test_compute_address_requests.rb +0 -52
  128. data/test/integration/compute/disks/test_compute_disk_requests.rb +0 -92
  129. data/test/integration/compute/test_compute_addresses_collection.rb +0 -75
  130. data/test/integration/compute/test_compute_networks_collection.rb +0 -69
  131. data/test/integration/compute/test_servers.rb +0 -54
  132. data/test/integration/compute/test_target_pools.rb +0 -38
data/ci/tasks/run-int.sh CHANGED
@@ -16,6 +16,7 @@ check_param google_project
16
16
  check_param google_client_email
17
17
  check_param google_json_key_data
18
18
  check_param rake_task
19
+ check_param codecov_token
19
20
 
20
21
  echo $google_json_key_data > `pwd`/service_account_key.json
21
22
 
@@ -28,8 +29,8 @@ EOL
28
29
 
29
30
  pushd ${release_dir} > /dev/null
30
31
 
31
- bundle install
32
+ bundle install --jobs=3 --retry=3
32
33
 
33
- FOG_MOCK=false rake ${rake_task}
34
+ FOG_MOCK=false COVERAGE=true CODECOV_TOKEN=${codecov_token} rake ${rake_task}
34
35
 
35
36
  popd > /dev/null
data/ci/tasks/run-int.yml CHANGED
@@ -2,7 +2,7 @@
2
2
  platform: linux
3
3
  image_resource:
4
4
  type: docker-image
5
- source: {repository: everlag/fog-google}
5
+ source: {repository: rubyfog/fog-google}
6
6
  inputs:
7
7
  - name: fog-google-src
8
8
  path: src/fog-google
@@ -3,21 +3,23 @@
3
3
 
4
4
  require "bundler"
5
5
  Bundler.require(:default, :development)
6
- # Uncomment this if you want to make real requests to GCE (you _will_ be billed!)
7
- # WebMock.disable!
8
6
 
9
- def test
7
+ def example
8
+ p "Connecting to Google API"
10
9
  connection = Fog::Compute.new(:provider => "Google")
11
10
 
11
+ p "Creating disk"
12
12
  disk = connection.disks.create(
13
13
  :name => "fog-smoke-test-#{Time.now.to_i}",
14
14
  :size_gb => 10,
15
15
  :zone => "us-central1-f",
16
- :source_image => "debian-8-jessie-v20180329"
16
+ :source_image => "debian-9-stretch-v20180611"
17
17
  )
18
18
 
19
+ p "Waiting for disk to be ready"
19
20
  disk.wait_for { disk.ready? }
20
21
 
22
+ p "Creating a server"
21
23
  server = connection.servers.create(
22
24
  :name => "fog-smoke-test-#{Time.now.to_i}",
23
25
  :disks => [disk],
@@ -25,34 +27,47 @@ def test
25
27
  :private_key_path => File.expand_path("~/.ssh/id_rsa"),
26
28
  :public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
27
29
  :zone => "us-central1-f",
30
+ # Will be simplified, see https://github.com/fog/fog-google/issues/360
31
+ :network_interfaces => [{ :network => "global/networks/default",
32
+ :access_configs => [{
33
+ :name => "External NAT",
34
+ :type => "ONE_TO_ONE_NAT"
35
+ }] }],
28
36
  :username => ENV["USER"],
37
+ :metadata => { :items => [{ :key => "foo", :value => "bar" }] },
29
38
  :tags => ["fog"],
30
39
  :service_accounts => { :scopes => %w(sql-admin bigquery https://www.googleapis.com/auth/compute) }
31
40
  )
32
41
 
33
- # Wait_for routine copied here to show errors, if necessary.
34
- duration = 0
35
- interval = 5
36
- timeout = 600
37
- start = Time.now
38
- until server.sshable? || duration > timeout
39
- # puts duration
40
- # puts " ----- "
41
-
42
- server.reload
43
-
44
- # p "ready?: #{server.ready?}"
45
- # p "public_ip_address: #{server.public_ip_address.inspect}"
46
- # p "public_key: #{server.public_key.inspect}"
47
- # p "metadata: #{server.metadata.inspect}"
48
- # p "sshable?: #{server.sshable?}"
49
-
50
- sleep(interval.to_f)
51
- duration = Time.now - start
42
+ p "Waiting for server to be ready"
43
+ # .sshable? requires 'net-ssh' gem to be added to the gemfile
44
+ begin
45
+ duration = 0
46
+ interval = 5
47
+ timeout = 600
48
+ start = Time.now
49
+ until server.sshable? || duration > timeout
50
+ puts duration
51
+ puts " ----- "
52
+
53
+ server.reload
54
+
55
+ p "ready?: #{server.ready?}"
56
+ p "public_ip_address: #{server.public_ip_address.inspect}"
57
+ p "public_key: #{server.public_key.inspect}"
58
+ p "metadata: #{server.metadata.inspect}"
59
+ p "sshable?: #{server.sshable?}"
60
+
61
+ sleep(interval.to_f)
62
+ duration = Time.now - start
63
+ end
64
+ raise "Could not bootstrap sshable server." unless server.ssh("whoami")
65
+ rescue NameError
66
+ server.wait_for { ready? }
52
67
  end
53
68
 
54
- raise "Could not bootstrap sshable server." unless server.ssh("whoami")
69
+ p "Deleting server"
55
70
  raise "Could not delete server." unless server.destroy
56
71
  end
57
72
 
58
- test
73
+ example
@@ -23,7 +23,7 @@ def test
23
23
 
24
24
  puts "Fetching a single image from a global project..."
25
25
  puts "------------------------------------------------"
26
- img = connection.images.get("debian-8-jessie-v20180329")
26
+ img = connection.images.get("debian-9-stretch-v20180611")
27
27
  raise "Could not GET the image" unless img
28
28
  puts img.inspect
29
29
 
@@ -24,7 +24,7 @@ def test
24
24
  :name => "#{name}-#{i}",
25
25
  :size_gb => 10,
26
26
  :zone_name => zone,
27
- :source_image => "debian-8-jessie-v20180329"
27
+ :source_image => "debian-9-stretch-v20180611"
28
28
  )
29
29
  disk.wait_for { disk.ready? }
30
30
  rescue
data/examples/metadata.rb CHANGED
@@ -15,7 +15,7 @@ def test
15
15
  :name => name,
16
16
  :size_gb => 10,
17
17
  :zone_name => "us-central1-f",
18
- :source_image => "debian-8-jessie-v20180329"
18
+ :source_image => "debian-9-stretch-v20180611"
19
19
  )
20
20
 
21
21
  disk.wait_for { disk.ready? }
data/examples/network.rb CHANGED
@@ -24,7 +24,7 @@ def test
24
24
  :name => name,
25
25
  :size_gb => 10,
26
26
  :zone_name => "us-central1-a",
27
- :source_image => "debian-8-jessie-v20180329"
27
+ :source_image => "debian-9-stretch-v20180611"
28
28
  )
29
29
 
30
30
  disk.wait_for { disk.ready? }
data/fog-google.gemspec CHANGED
@@ -26,16 +26,18 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  # Hard Requirement as of 1.0
28
28
  spec.add_dependency "google-api-client", "~> 0.23.0"
29
-
30
- spec.add_development_dependency "coveralls"
29
+
31
30
  spec.add_development_dependency "mime-types"
32
- spec.add_development_dependency "minitest"
33
- spec.add_development_dependency "osrcry"
31
+
32
+ # Debugger
34
33
  spec.add_development_dependency "pry"
35
34
  spec.add_development_dependency "pry-byebug"
36
- spec.add_development_dependency "rake"
35
+
36
+ # Testing gems
37
37
  spec.add_development_dependency "retriable"
38
- spec.add_development_dependency "rubocop"
38
+ spec.add_development_dependency "rake"
39
+ spec.add_development_dependency "minitest"
40
+ spec.add_development_dependency "minitest-reporters"
39
41
  spec.add_development_dependency "shindo"
40
42
  spec.add_development_dependency "vcr"
41
43
  spec.add_development_dependency "webmock"
@@ -40,7 +40,7 @@ module Fog
40
40
  operation = Fog::Compute::Google::Operations
41
41
  .new(:service => service)
42
42
  .get(data.name, nil, data.region)
43
- operation.wait_for { !pending? }
43
+ operation.wait_for { ready? }
44
44
  reload
45
45
  end
46
46
 
@@ -31,7 +31,7 @@ module Fog
31
31
 
32
32
  data = service.insert_backend_service(name, options)
33
33
  operation = Fog::Compute::Google::Operations.new(:service => service).get(data.name)
34
- operation.wait_for { !pending? }
34
+ operation.wait_for { ready? }
35
35
  reload
36
36
  end
37
37
 
@@ -50,7 +50,7 @@ module Fog
50
50
  data = service.insert_disk(name, zone, options[:source_image], options)
51
51
  operation = Fog::Compute::Google::Operations.new(:service => service)
52
52
  .get(data.name, data.zone)
53
- operation.wait_for { !pending? }
53
+ operation.wait_for { ready? }
54
54
  reload
55
55
  end
56
56
 
@@ -108,7 +108,7 @@ module Fog
108
108
  data = service.create_disk_snapshot(snapshot_name, name, zone_name, snapshot)
109
109
  operation = Fog::Compute::Google::Operations.new(:service => service)
110
110
  .get(data.name, data.zone)
111
- operation.wait_for { !pending? }
111
+ operation.wait_for { ready? }
112
112
  service.snapshots.get(snapshot_name)
113
113
  end
114
114
 
@@ -8,8 +8,24 @@ module Fog
8
8
  class Firewall < Fog::Model
9
9
  identity :name
10
10
 
11
+ # Allowed ports in API format
12
+ #
13
+ # @example
14
+ # [
15
+ # { :ip_protocol => "TCP",
16
+ # :ports => ["201"] }
17
+ # ]
18
+ # @return [Array<Hash>]
11
19
  attribute :allowed
12
20
  attribute :creation_timestamp, :aliases => "creationTimestamp"
21
+ # Denied ports in API format
22
+ #
23
+ # @example
24
+ # [
25
+ # { :ip_protocol => "TCP",
26
+ # :ports => ["201"] }
27
+ # ]
28
+ # @return [Array<Hash>]
13
29
  attribute :denied
14
30
  attribute :description
15
31
  attribute :destination_ranges, :aliases => "destinationRanges"
@@ -28,6 +44,10 @@ module Fog
28
44
  def save
29
45
  requires :identity
30
46
 
47
+ unless self.allowed || self.denied
48
+ raise Fog::Errors::Error.new("Firewall needs denied or allowed ports specified")
49
+ end
50
+
31
51
  id.nil? ? create : update
32
52
  end
33
53
 
@@ -35,7 +55,7 @@ module Fog
35
55
  data = service.insert_firewall(identity, attributes)
36
56
  operation = Fog::Compute::Google::Operations.new(:service => service)
37
57
  .get(data.name)
38
- operation.wait_for { !pending? }
58
+ operation.wait_for { ready? }
39
59
  reload
40
60
  end
41
61
 
@@ -45,7 +65,7 @@ module Fog
45
65
  data = service.update_firewall(identity, attributes)
46
66
  operation = Fog::Compute::Google::Operations.new(:service => service)
47
67
  .get(data.name)
48
- operation.wait_for { !pending? }
68
+ operation.wait_for { ready? }
49
69
  reload
50
70
  end
51
71
 
@@ -55,7 +75,7 @@ module Fog
55
75
  data = service.patch_firewall(identity, diff)
56
76
  operation = Fog::Compute::Google::Operations.new(:service => service)
57
77
  .get(data.name)
58
- operation.wait_for { !pending? }
78
+ operation.wait_for { ready? }
59
79
  reload
60
80
  end
61
81
 
@@ -27,7 +27,7 @@ module Fog
27
27
  data = service.insert_forwarding_rule(identity, region, attributes)
28
28
  operation = Fog::Compute::Google::Operations.new(:service => service)
29
29
  .get(data.name, nil, data.region)
30
- operation.wait_for { !pending? }
30
+ operation.wait_for { ready? }
31
31
  reload
32
32
  end
33
33
 
@@ -27,7 +27,7 @@ module Fog
27
27
  data = service.insert_global_address(identity, attributes)
28
28
  operation = Fog::Compute::Google::Operations.new(:service => service)
29
29
  .get(data.name)
30
- operation.wait_for { !pending? }
30
+ operation.wait_for { ready? }
31
31
  reload
32
32
  end
33
33
 
@@ -27,7 +27,7 @@ module Fog
27
27
  data = service.insert_global_forwarding_rule(identity, attributes)
28
28
  operation = Fog::Compute::Google::Operations.new(:service => service)
29
29
  .get(data.name, nil, data.region)
30
- operation.wait_for { !pending? }
30
+ operation.wait_for { ready? }
31
31
  reload
32
32
  end
33
33
 
@@ -53,7 +53,7 @@ module Fog
53
53
  data = service.insert_http_health_check(name, opts)
54
54
  operation = Fog::Compute::Google::Operations.new(:service => service)
55
55
  .get(data.name, data.zone)
56
- operation.wait_for { !pending? }
56
+ operation.wait_for { ready? }
57
57
  reload
58
58
  end
59
59
 
@@ -62,7 +62,7 @@ module Fog
62
62
  data = service.update_http_health_check(name, opts)
63
63
  operation = Fog::Compute::Google::Operations.new(:service => service)
64
64
  .get(data.name, data.zone)
65
- operation.wait_for { !pending? }
65
+ operation.wait_for { ready? }
66
66
  reload
67
67
  end
68
68
 
@@ -68,7 +68,7 @@ module Fog
68
68
  data = service.insert_image(name, attributes)
69
69
  operation = Fog::Compute::Google::Operations.new(:service => service)
70
70
  .get(data.name)
71
- operation.wait_for { !pending? }
71
+ operation.wait_for { ready? }
72
72
  reload
73
73
  end
74
74
 
@@ -23,7 +23,7 @@ module Fog
23
23
  data = service.insert_instance_group_manager(name, zone.split("/")[-1], instance_template, base_instance_name,
24
24
  target_size, target_pools, named_ports, description)
25
25
  operation = Fog::Compute::Google::Operations.new(:service => service).get(data.name, zone.split("/")[-1])
26
- operation.wait_for { !pending? }
26
+ operation.wait_for { ready? }
27
27
  reload
28
28
  end
29
29
 
@@ -30,7 +30,7 @@ module Fog
30
30
 
31
31
  data = service.insert_instance_template(name, properties, description)
32
32
  operation = Fog::Compute::Google::Operations.new(:service => service).get(data.name)
33
- operation.wait_for { !pending? }
33
+ operation.wait_for { ready? }
34
34
  reload
35
35
  end
36
36
 
@@ -30,7 +30,7 @@ module Fog
30
30
  data = service.insert_route(identity, network, dest_range, priority, attributes)
31
31
  operation = Fog::Compute::Google::Operations.new(:service => service)
32
32
  .get(data.name)
33
- operation.wait_for { !pending? }
33
+ operation.wait_for { ready? }
34
34
  reload
35
35
  end
36
36
 
@@ -27,7 +27,7 @@ module Fog
27
27
  # [
28
28
  # {
29
29
  # :initialize_params => {
30
- # :source_image => "projects/debian-cloud/global/images/family/debian-8"
30
+ # :source_image => "projects/debian-cloud/global/images/family/debian-9"
31
31
  # }
32
32
  # }
33
33
  # ]
@@ -179,6 +179,9 @@ module Fog
179
179
  "userinfo-email" => ["https://www.googleapis.com/auth/userinfo.email"]
180
180
  }.freeze
181
181
 
182
+ # Return the source image of the server's boot disk
183
+ #
184
+ # @return [String] image self link
182
185
  def image_name
183
186
  boot_disk = disks.first
184
187
  unless boot_disk.is_a?(Disk)
@@ -189,6 +192,10 @@ module Fog
189
192
  boot_disk.source_image.nil? ? nil : boot_disk.source_image
190
193
  end
191
194
 
195
+ # Destroy a server.
196
+ #
197
+ # @param async [TrueClass] execute the command asynchronously
198
+ # @return [Fog::Compute::Google::Operation]
192
199
  def destroy(async = true)
193
200
  requires :name, :zone
194
201
 
@@ -200,14 +207,17 @@ module Fog
200
207
  operation
201
208
  end
202
209
 
203
- # Helper method that returns first public ip address
204
- # for Fog::Compute::Server.ssh default behavior
210
+ # Helper method that returns first public ip address needed for
211
+ # Fog::Compute::Server.ssh default behavior.
205
212
  #
206
213
  # @return [String]
207
214
  def public_ip_address
208
215
  public_ip_addresses.first
209
216
  end
210
217
 
218
+ # Helper method that returns all of server's public ip addresses.
219
+ #
220
+ # @return [Array]
211
221
  def public_ip_addresses
212
222
  addresses = []
213
223
  if network_interfaces.respond_to? :flat_map
@@ -223,6 +233,17 @@ module Fog
223
233
  addresses
224
234
  end
225
235
 
236
+ # Helper method that returns the first private ip address of the
237
+ # instance.
238
+ #
239
+ # @return [String]
240
+ def private_ip_address
241
+ private_ip_addresses.first
242
+ end
243
+
244
+ # Helper method that returns all of server's private ip addresses.
245
+ #
246
+ # @return [Array]
226
247
  def private_ip_addresses
227
248
  addresses = []
228
249
  if network_interfaces.respond_to? :map
@@ -231,10 +252,21 @@ module Fog
231
252
  addresses
232
253
  end
233
254
 
255
+ # Helper method that returns all of server's ip addresses,
256
+ # both private and public.
257
+ #
258
+ # @return [Array]
234
259
  def addresses
235
260
  private_ip_addresses + public_ip_addresses
236
261
  end
237
262
 
263
+ # Attach a disk to a running server
264
+ #
265
+ # @param disk [Object, String] disk object or a self-link
266
+ # @param async [TrueClass] execute the api call asynchronously
267
+ # @param options [Hash]
268
+ # @return [Object]
269
+ # TODO: Figure out what options hash is for here.
238
270
  def attach_disk(disk, async = true, options = {})
239
271
  requires :identity, :zone
240
272
 
@@ -252,6 +284,11 @@ module Fog
252
284
  reload
253
285
  end
254
286
 
287
+ # Detach disk from a running instance
288
+ #
289
+ # @param device_name [Object]
290
+ # @param async [TrueClass]
291
+ # @returns [Fog::Compute::Google::Server] server object
255
292
  def detach_disk(device_name, async = true)
256
293
  requires :identity, :zone
257
294
 
@@ -264,6 +301,7 @@ module Fog
264
301
  end
265
302
 
266
303
  # Returns metadata items as a Hash.
304
+ #
267
305
  # @return [Hash<String, String>] items
268
306
  def metadata_as_h
269
307
  if metadata.nil? || metadata[:items].nil? || metadata[:items].empty?
@@ -390,16 +428,32 @@ module Fog
390
428
  reload
391
429
  end
392
430
 
431
+ # Check if instance is provisioning. On staging vs. provisioning difference:
432
+ # https://cloud.google.com/compute/docs/instances/checking-instance-status
433
+ #
434
+ # @return [TrueClass or FalseClass]
393
435
  def provisioning?
394
436
  status == PROVISIONING
395
437
  end
396
438
 
397
- # Check if instance is Staging. On staging vs. provisioning difference:
439
+ # Check if instance is staging. On staging vs. provisioning difference:
398
440
  # https://cloud.google.com/compute/docs/instances/checking-instance-status
441
+ #
442
+ # @return [TrueClass or FalseClass]
399
443
  def staging?
400
444
  status == STAGING
401
445
  end
402
446
 
447
+ # Check if instance is stopped.
448
+ #
449
+ # @return [TrueClass or FalseClass]
450
+ def stopped?
451
+ status == "TERMINATED"
452
+ end
453
+
454
+ # Check if instance is ready.
455
+ #
456
+ # @return [TrueClass or FalseClass]
403
457
  def ready?
404
458
  status == RUNNING
405
459
  end
@@ -487,7 +541,7 @@ module Fog
487
541
  operation = Fog::Compute::Google::Operations
488
542
  .new(:service => service)
489
543
  .get(data.name, data.zone)
490
- operation.wait_for { !pending? }
544
+ operation.wait_for { ready? }
491
545
  reload
492
546
  end
493
547