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.
- checksums.yaml +5 -5
- data/.codecov.yml +2 -0
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +51 -0
- data/CONTRIBUTING.md +85 -17
- data/CONTRIBUTORS.md +6 -4
- data/Gemfile +6 -0
- data/MIGRATING.md +1 -11
- data/README.md +15 -4
- data/ci/credentials.yml.template +2 -0
- data/ci/docker-image/Dockerfile +1 -3
- data/ci/pipeline.yml +117 -12
- data/ci/tasks/run-int.sh +3 -2
- data/ci/tasks/run-int.yml +1 -1
- data/examples/create_instance.rb +40 -25
- data/examples/get_list_images.rb +1 -1
- data/examples/load-balance.rb +1 -1
- data/examples/metadata.rb +1 -1
- data/examples/network.rb +1 -1
- data/fog-google.gemspec +8 -6
- data/lib/fog/compute/google/models/address.rb +1 -1
- data/lib/fog/compute/google/models/backend_service.rb +1 -1
- data/lib/fog/compute/google/models/disk.rb +2 -2
- data/lib/fog/compute/google/models/firewall.rb +23 -3
- data/lib/fog/compute/google/models/forwarding_rule.rb +1 -1
- data/lib/fog/compute/google/models/global_address.rb +1 -1
- data/lib/fog/compute/google/models/global_forwarding_rule.rb +1 -1
- data/lib/fog/compute/google/models/http_health_check.rb +2 -2
- data/lib/fog/compute/google/models/image.rb +1 -1
- data/lib/fog/compute/google/models/instance_group_manager.rb +1 -1
- data/lib/fog/compute/google/models/instance_template.rb +1 -1
- data/lib/fog/compute/google/models/route.rb +1 -1
- data/lib/fog/compute/google/models/server.rb +59 -5
- data/lib/fog/compute/google/models/servers.rb +1 -1
- data/lib/fog/compute/google/models/ssl_certificate.rb +1 -1
- data/lib/fog/compute/google/models/subnetwork.rb +1 -1
- data/lib/fog/compute/google/models/target_http_proxy.rb +1 -1
- data/lib/fog/compute/google/models/target_https_proxy.rb +14 -1
- data/lib/fog/compute/google/models/target_instance.rb +1 -1
- data/lib/fog/compute/google/models/target_pool.rb +1 -1
- data/lib/fog/compute/google/models/url_map.rb +1 -1
- data/lib/fog/compute/google/requests/insert_server.rb +1 -1
- data/lib/fog/dns/google/models/record.rb +1 -1
- data/lib/fog/google/models/sql/instance.rb +1 -1
- data/lib/fog/google/models/sql/user.rb +1 -1
- data/lib/fog/google/version.rb +1 -1
- data/lib/fog/storage/google_json.rb +4 -1
- data/lib/fog/storage/google_json/mock.rb +3 -0
- data/lib/fog/storage/google_json/models/file.rb +2 -2
- data/lib/fog/storage/google_json/models/files.rb +2 -2
- data/lib/fog/storage/google_json/real.rb +3 -0
- data/lib/fog/storage/google_json/requests/get_object_http_url.rb +6 -7
- data/lib/fog/storage/google_json/requests/get_object_https_url.rb +6 -7
- data/lib/fog/storage/google_json/requests/get_object_url.rb +4 -4
- data/lib/fog/storage/google_json/utils.rb +7 -1
- data/lib/fog/storage/google_xml/models/file.rb +2 -2
- data/lib/fog/storage/google_xml/models/files.rb +4 -4
- data/lib/fog/storage/google_xml/requests/get_object_http_url.rb +8 -7
- data/lib/fog/storage/google_xml/requests/get_object_https_url.rb +7 -7
- data/lib/fog/storage/google_xml/requests/get_object_url.rb +5 -4
- data/lib/fog/storage/google_xml/utils.rb +7 -1
- data/tasks/test.rake +45 -23
- data/test/helpers/integration_test_helper.rb +67 -0
- data/test/helpers/test_helper.rb +14 -10
- data/test/integration/compute/core_compute/test_coverage.rb +6 -0
- data/test/integration/compute/{test_disk_types.rb → core_compute/test_disk_types.rb} +0 -0
- data/test/integration/compute/{disks/test_compute_disk_models.rb → core_compute/test_disks.rb} +0 -0
- data/test/integration/compute/{test_images.rb → core_compute/test_images.rb} +0 -0
- data/test/integration/compute/core_compute/test_machine_types.rb +42 -0
- data/test/integration/compute/core_compute/test_operations.rb +27 -0
- data/test/integration/compute/core_compute/test_projects.rb +19 -0
- data/test/integration/compute/{test_regions.rb → core_compute/test_regions.rb} +0 -0
- data/test/integration/compute/core_compute/test_servers.rb +109 -0
- data/test/integration/compute/{test_snapshots.rb → core_compute/test_snapshots.rb} +0 -0
- data/test/integration/compute/core_compute/test_zones.rb +35 -0
- data/test/integration/compute/core_networking/test_addresses.rb +84 -0
- data/test/integration/compute/core_networking/test_coverage.rb +6 -0
- data/test/integration/compute/core_networking/test_firewalls.rb +11 -0
- data/test/integration/compute/core_networking/test_networks.rb +41 -0
- data/test/integration/compute/core_networking/test_routes.rb +26 -0
- data/test/integration/compute/core_networking/test_subnetworks.rb +11 -0
- data/test/integration/compute/instance_groups/test_coverage.rb +6 -0
- data/test/integration/compute/{test_instance_group_managers.rb → instance_groups/test_instance_group_managers.rb} +0 -0
- data/test/integration/compute/instance_groups/test_instance_groups.rb +11 -0
- data/test/integration/compute/{test_instance_templates.rb → instance_groups/test_instance_templates.rb} +0 -0
- data/test/integration/compute/{test_backend_services.rb → loadbalancing/test_backend_services.rb} +0 -0
- data/test/integration/compute/loadbalancing/test_coverage.rb +6 -0
- data/test/integration/compute/{test_forwarding_rules.rb → loadbalancing/test_forwarding_rules.rb} +0 -0
- data/test/integration/compute/loadbalancing/test_global_addresses.rb +11 -0
- data/test/integration/compute/{test_global_forwarding_rules.rb → loadbalancing/test_global_forwarding_rules.rb} +0 -0
- data/test/integration/compute/{test_http_health_checks.rb → loadbalancing/test_http_health_checks.rb} +0 -0
- data/test/integration/compute/loadbalancing/test_ssl_certificates.rb +11 -0
- data/test/integration/compute/{test_target_http_proxies.rb → loadbalancing/test_target_http_proxies.rb} +0 -0
- data/test/integration/compute/loadbalancing/test_target_https_proxies.rb +11 -0
- data/test/integration/compute/{test_target_instances.rb → loadbalancing/test_target_instances.rb} +0 -0
- data/test/integration/compute/loadbalancing/test_target_pools.rb +55 -0
- data/test/integration/compute/{test_url_maps.rb → loadbalancing/test_url_maps.rb} +0 -0
- data/test/integration/factories/addresses_factory.rb +16 -0
- data/test/integration/factories/collection_factory.rb +24 -3
- data/test/integration/factories/disks_factory.rb +1 -0
- data/test/integration/factories/firewalls_factory.rb +13 -0
- data/test/integration/factories/global_addresses_factory.rb +15 -0
- data/test/integration/factories/instance_groups_factory.rb +16 -0
- data/test/integration/factories/instance_template_factory.rb +1 -0
- data/test/integration/factories/networks_factory.rb +16 -0
- data/test/integration/factories/ssl_certificates_factory.rb +13 -0
- data/test/integration/factories/subnetworks_factory.rb +22 -0
- data/test/integration/factories/target_https_proxies_factory.rb +26 -0
- data/test/integration/factories/target_pools_factory.rb +2 -2
- data/test/integration/monitoring/test_coverage.rb +6 -0
- data/test/integration/monitoring/test_timeseries.rb +1 -1
- data/test/integration/pubsub/test_coverage.rb +6 -0
- data/test/integration/sql/{test_common_flags.rb → sqlv1/test_common_flags.rb} +0 -0
- data/test/integration/sql/{test_common_tiers.rb → sqlv1/test_common_tiers.rb} +0 -0
- data/test/integration/sql/sqlv1/test_coverage.rb +6 -0
- data/test/integration/sql/{test_v1_certs.rb → sqlv1/test_v1_certs.rb} +0 -0
- data/test/integration/sql/{test_v1_instances.rb → sqlv1/test_v1_instances.rb} +0 -0
- data/test/integration/sql/{test_v1_users.rb → sqlv1/test_v1_users.rb} +0 -0
- data/test/integration/sql/sqlv2/test_coverage.rb +6 -0
- data/test/integration/sql/{test_v2_instances.rb → sqlv2/test_v2_instances.rb} +0 -0
- data/test/integration/storage/test_coverage.rb +6 -0
- data/test/unit/storage/test_json_requests.rb +45 -0
- data/test/unit/storage/test_xml_requests.rb +20 -0
- metadata +115 -92
- data/test/integration/compute/addresses/addresses_shared.rb +0 -59
- data/test/integration/compute/addresses/test_compute_address_models.rb +0 -105
- data/test/integration/compute/addresses/test_compute_address_requests.rb +0 -52
- data/test/integration/compute/disks/test_compute_disk_requests.rb +0 -92
- data/test/integration/compute/test_compute_addresses_collection.rb +0 -75
- data/test/integration/compute/test_compute_networks_collection.rb +0 -69
- data/test/integration/compute/test_servers.rb +0 -54
- 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
data/examples/create_instance.rb
CHANGED
@@ -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
|
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-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
69
|
+
p "Deleting server"
|
55
70
|
raise "Could not delete server." unless server.destroy
|
56
71
|
end
|
57
72
|
|
58
|
-
|
73
|
+
example
|
data/examples/get_list_images.rb
CHANGED
@@ -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-
|
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
|
|
data/examples/load-balance.rb
CHANGED
data/examples/metadata.rb
CHANGED
data/examples/network.rb
CHANGED
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
|
-
|
33
|
-
|
31
|
+
|
32
|
+
# Debugger
|
34
33
|
spec.add_development_dependency "pry"
|
35
34
|
spec.add_development_dependency "pry-byebug"
|
36
|
-
|
35
|
+
|
36
|
+
# Testing gems
|
37
37
|
spec.add_development_dependency "retriable"
|
38
|
-
spec.add_development_dependency "
|
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"
|
@@ -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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
65
|
+
operation.wait_for { ready? }
|
66
66
|
reload
|
67
67
|
end
|
68
68
|
|
@@ -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 {
|
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 {
|
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 {
|
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-
|
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
|
-
#
|
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
|
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 {
|
544
|
+
operation.wait_for { ready? }
|
491
545
|
reload
|
492
546
|
end
|
493
547
|
|