Class: Fog::Compute::Google::Real

Inherits:
Object
  • Object
show all
Includes:
Shared, Google::Shared
Defined in:
lib/fog/google/compute.rb,
lib/fog/google/requests/compute/get_disk.rb,
lib/fog/google/requests/compute/get_zone.rb,
lib/fog/google/requests/compute/set_tags.rb,
lib/fog/google/requests/compute/get_image.rb,
lib/fog/google/requests/compute/get_route.rb,
lib/fog/google/requests/compute/get_region.rb,
lib/fog/google/requests/compute/get_server.rb,
lib/fog/google/requests/compute/list_disks.rb,
lib/fog/google/requests/compute/list_zones.rb,
lib/fog/google/requests/compute/attach_disk.rb,
lib/fog/google/requests/compute/delete_disk.rb,
lib/fog/google/requests/compute/detach_disk.rb,
lib/fog/google/requests/compute/get_address.rb,
lib/fog/google/requests/compute/get_network.rb,
lib/fog/google/requests/compute/get_project.rb,
lib/fog/google/requests/compute/get_url_map.rb,
lib/fog/google/requests/compute/insert_disk.rb,
lib/fog/google/requests/compute/list_images.rb,
lib/fog/google/requests/compute/list_routes.rb,
lib/fog/google/requests/compute/stop_server.rb,
lib/fog/google/requests/compute/delete_image.rb,
lib/fog/google/requests/compute/delete_route.rb,
lib/fog/google/requests/compute/get_firewall.rb,
lib/fog/google/requests/compute/get_snapshot.rb,
lib/fog/google/requests/compute/insert_image.rb,
lib/fog/google/requests/compute/insert_route.rb,
lib/fog/google/requests/compute/list_regions.rb,
lib/fog/google/requests/compute/list_servers.rb,
lib/fog/google/requests/compute/reset_server.rb,
lib/fog/google/requests/compute/set_metadata.rb,
lib/fog/google/requests/compute/start_server.rb,
lib/fog/google/requests/compute/delete_server.rb,
lib/fog/google/requests/compute/get_disk_type.rb,
lib/fog/google/requests/compute/get_zone_view.rb,
lib/fog/google/requests/compute/insert_server.rb,
lib/fog/google/requests/compute/list_networks.rb,
lib/fog/google/requests/compute/list_url_maps.rb,
lib/fog/google/requests/compute/delete_address.rb,
lib/fog/google/requests/compute/delete_network.rb,
lib/fog/google/requests/compute/delete_url_map.rb,
lib/fog/google/requests/compute/insert_address.rb,
lib/fog/google/requests/compute/insert_network.rb,
lib/fog/google/requests/compute/insert_url_map.rb,
lib/fog/google/requests/compute/list_addresses.rb,
lib/fog/google/requests/compute/list_firewalls.rb,
lib/fog/google/requests/compute/list_snapshots.rb,
lib/fog/google/requests/compute/update_url_map.rb,
lib/fog/google/requests/compute/delete_firewall.rb,
lib/fog/google/requests/compute/delete_snapshot.rb,
lib/fog/google/requests/compute/get_region_view.rb,
lib/fog/google/requests/compute/get_target_pool.rb,
lib/fog/google/requests/compute/insert_firewall.rb,
lib/fog/google/requests/compute/insert_snapshot.rb,
lib/fog/google/requests/compute/list_disk_types.rb,
lib/fog/google/requests/compute/list_zone_views.rb,
lib/fog/google/requests/compute/delete_zone_view.rb,
lib/fog/google/requests/compute/get_machine_type.rb,
lib/fog/google/requests/compute/insert_zone_view.rb,
lib/fog/google/requests/compute/validate_url_map.rb,
lib/fog/google/requests/compute/list_region_views.rb,
lib/fog/google/requests/compute/list_target_pools.rb,
lib/fog/google/requests/compute/delete_region_view.rb,
lib/fog/google/requests/compute/delete_target_pool.rb,
lib/fog/google/requests/compute/get_zone_operation.rb,
lib/fog/google/requests/compute/insert_region_view.rb,
lib/fog/google/requests/compute/insert_target_pool.rb,
lib/fog/google/requests/compute/list_machine_types.rb,
lib/fog/google/requests/compute/get_backend_service.rb,
lib/fog/google/requests/compute/get_forwarding_rule.rb,
lib/fog/google/requests/compute/get_target_instance.rb,
lib/fog/google/requests/compute/get_backend_services.rb,
lib/fog/google/requests/compute/get_global_operation.rb,
lib/fog/google/requests/compute/get_region_operation.rb,
lib/fog/google/requests/compute/list_zone_operations.rb,
lib/fog/google/requests/compute/delete_zone_operation.rb,
lib/fog/google/requests/compute/get_http_health_check.rb,
lib/fog/google/requests/compute/get_target_http_proxy.rb,
lib/fog/google/requests/compute/list_aggregated_disks.rb,
lib/fog/google/requests/compute/list_backend_services.rb,
lib/fog/google/requests/compute/list_forwarding_rules.rb,
lib/fog/google/requests/compute/list_target_instances.rb,
lib/fog/google/requests/compute/set_server_scheduling.rb,
lib/fog/google/requests/compute/add_url_map_host_rules.rb,
lib/fog/google/requests/compute/delete_backend_service.rb,
lib/fog/google/requests/compute/delete_forwarding_rule.rb,
lib/fog/google/requests/compute/delete_target_instance.rb,
lib/fog/google/requests/compute/get_target_pool_health.rb,
lib/fog/google/requests/compute/insert_backend_service.rb,
lib/fog/google/requests/compute/insert_forwarding_rule.rb,
lib/fog/google/requests/compute/insert_target_instance.rb,
lib/fog/google/requests/compute/list_global_operations.rb,
lib/fog/google/requests/compute/list_region_operations.rb,
lib/fog/google/requests/compute/add_zone_view_resources.rb,
lib/fog/google/requests/compute/delete_global_operation.rb,
lib/fog/google/requests/compute/delete_region_operation.rb,
lib/fog/google/requests/compute/list_aggregated_servers.rb,
lib/fog/google/requests/compute/list_http_health_checks.rb,
lib/fog/google/requests/compute/add_server_access_config.rb,
lib/fog/google/requests/compute/delete_http_health_check.rb,
lib/fog/google/requests/compute/delete_target_http_proxy.rb,
lib/fog/google/requests/compute/insert_http_health_check.rb,
lib/fog/google/requests/compute/insert_target_http_proxy.rb,
lib/fog/google/requests/compute/list_target_http_proxies.rb,
lib/fog/google/requests/compute/list_zone_view_resources.rb,
lib/fog/google/requests/compute/add_region_view_resources.rb,
lib/fog/google/requests/compute/add_target_pool_instances.rb,
lib/fog/google/requests/compute/add_url_map_path_matchers.rb,
lib/fog/google/requests/compute/list_aggregated_addresses.rb,
lib/fog/google/requests/compute/get_backend_service_health.rb,
lib/fog/google/requests/compute/get_global_forwarding_rule.rb,
lib/fog/google/requests/compute/list_aggregated_disk_types.rb,
lib/fog/google/requests/compute/list_region_view_resources.rb,
lib/fog/google/requests/compute/set_forwarding_rule_target.rb,
lib/fog/google/requests/compute/delete_server_access_config.rb,
lib/fog/google/requests/compute/remove_target_pool_instance.rb,
lib/fog/google/requests/compute/set_server_disk_auto_delete.rb,
lib/fog/google/requests/compute/add_backend_service_backends.rb,
lib/fog/google/requests/compute/list_global_forwarding_rules.rb,
lib/fog/google/requests/compute/remove_target_pool_instances.rb,
lib/fog/google/requests/compute/set_common_instance_metadata.rb,
lib/fog/google/requests/compute/add_target_pool_health_checks.rb,
lib/fog/google/requests/compute/delete_global_forwarding_rule.rb,
lib/fog/google/requests/compute/get_server_serial_port_output.rb,
lib/fog/google/requests/compute/insert_global_forwarding_rule.rb,
lib/fog/google/requests/compute/list_aggregated_machine_types.rb,
lib/fog/google/requests/compute/set_target_http_proxy_url_map.rb,
lib/fog/google/requests/compute/remove_target_pool_health_checks.rb,
lib/fog/google/requests/compute/set_global_forwarding_rule_target.rb

Instance Attribute Summary collapse

Attributes included from Google::Shared

#api_url, #api_version, #project

Instance Method Summary collapse

Methods included from Shared

#find_zone

Methods included from Google::Shared

#build_excon_response, #create_signing_key, #initialize_google_client, #new_pk12_google_client, #request, #shared_initialize

Constructor Details

#initialize(options) ⇒ Real

Returns a new instance of Real.



1057
1058
1059
1060
1061
1062
1063
1064
# File 'lib/fog/google/compute.rb', line 1057

def initialize(options)
  shared_initialize(options[:google_project], GOOGLE_COMPUTE_API_VERSION, GOOGLE_COMPUTE_BASE_URL)
  options.merge!(:google_api_scope_url => GOOGLE_COMPUTE_API_SCOPE_URLS.join(' '))

  @client = initialize_google_client(options)
  @compute = @client.discovered_api('compute', api_version)
  @resourceviews = @client.discovered_api('resourceviews', 'v1beta1')
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



1054
1055
1056
# File 'lib/fog/google/compute.rb', line 1054

def client
  @client
end

#computeObject (readonly)

Returns the value of attribute compute.



1055
1056
1057
# File 'lib/fog/google/compute.rb', line 1055

def compute
  @compute
end

Instance Method Details

#add_backend_service_backends(backend_service, new_backends) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/add_backend_service_backends.rb', line 11

def add_backend_service_backends(backend_service, new_backends)
  api_method = @compute.backend_services.patch
  parameters = {
    'project' => @project,
    'backendService' => backend_service.name,
  }
  if backend_service.backends then
    backend_service.backends.concat(new_backends)
  else
    backend_service.backends = new_backends
  end
  body_object = backend_service
  
  request(api_method, parameters, body_object)
end

#add_region_view_resources(region_view, resources, region) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/add_region_view_resources.rb', line 11

def add_region_view_resources(region_view, resources, region)
  api_method = @resourceviews.region_views.add_resources
  parameters = {
    'projectName' => @project,
    'resourceViewName' => region_view,
    'region' => region
  }
  body = {
    'resources' => resources
  }

  request(api_method, parameters, body_object=body)
end

#add_server_access_config(identity, zone, nic, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/google/requests/compute/add_server_access_config.rb', line 11

def add_server_access_config(identity, zone, nic, options = {})
  api_method = @compute.instances.add_access_config
  parameters = {
    'project'  => @project,
    'instance' => identity,
    'zone'     => zone.split('/')[-1],
    'networkInterface' => nic,
  }

  body_object = {
    'type' => 'ONE_TO_ONE_NAT',
  }

  body_object['name'] = options[:name] ? options[:name] : 'External NAT'
  body_object['natIP'] = options[:address] if options[:address]

  request(api_method, parameters, body_object)
end

#add_target_pool_health_checks(target_pool, health_checks) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/add_target_pool_health_checks.rb', line 11

def add_target_pool_health_checks(target_pool, health_checks)
  api_method = @compute.target_pools.add_health_check
  parameters = {
    'project' => @project,
    'targetPool' => target_pool.name,
    'region' => target_pool.region.split('/')[-1]
  }
  body = {
    'healthChecks' => health_checks.map { |i| { 'healthCheck' => i } }
  }

  request(api_method, parameters, body_object=body)
end

#add_target_pool_instances(target_pool, instances) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/add_target_pool_instances.rb', line 11

def add_target_pool_instances(target_pool, instances)
  api_method = @compute.target_pools.add_instance
  parameters = {
    'project' => @project,
    'targetPool' => target_pool.name,
    'region' => target_pool.region.split('/')[-1]
  }
  body = {
    'instances' => instances.map { |i| { 'instance' => i } }
  }

  request(api_method, parameters, body_object=body)
end

#add_url_map_host_rules(url_map, host_rules) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/google/requests/compute/add_url_map_host_rules.rb', line 11

def add_url_map_host_rules(url_map, host_rules)
  api_method = @compute.url_maps.update
  parameters = {
    'project' => @project,
    'urlMap' => url_map.name
  }
  if  url_map.hostRules then  url_map.hostRules.concat( host_rules) else  url_map.hostRules = host_rules end
  body = url_map

  request(api_method, parameters, body_object=body)
end

#add_url_map_path_matchers(url_map, path_matchers) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/add_url_map_path_matchers.rb', line 11

def add_url_map_path_matchers(url_map, path_matchers)
  api_method = @compute.url_maps.update
  parameters = {
    'project' => @project,
    'urlMap' => url_map.name
  }
  
  if url_map.pathMatchers then
    url_map.pathMatchers.concat(path_matchers)
  else
    url_map.pathMatchers = path_matchers
  end

  request(api_method, parameters, body_object=url_map)
end

#add_zone_view_resources(zone_view, resources, zone) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/add_zone_view_resources.rb', line 11

def add_zone_view_resources(zone_view, resources, zone)
  api_method = @resourceviews.zone_views.addresources
  parameters = {
    'projectName' => @project,
    'resourceViewName' => zone_view.name,
    'zone' => zone
  }
  body = {
    'resources' => resources
  }

  request(api_method, parameters, body_object=body)
end

#attach_disk(instance, zone, source, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/google/requests/compute/attach_disk.rb', line 11

def attach_disk(instance, zone, source, options = {})
  api_method = @compute.instances.attach_disk
  parameters = {
    'project' => @project,
    'instance' => instance,
    'zone' => zone.split('/')[-1],
  }

  writable = options.delete(:writable)
  body_object = {
    'type' =>       'PERSISTENT',
    'source' =>     source,
    'mode' =>       writable ? 'READ_WRITE' : 'READ_ONLY',
    'deviceName' => options.delete(:deviceName),
    'boot' =>       options.delete(:boot),
    'autoDelete' => options.delete(:autoDelete),
  }

  request(api_method, parameters, body_object)
end

#delete_address(address_name, region_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/delete_address.rb', line 11

def delete_address(address_name, region_name)
  api_method = @compute.addresses.delete
  parameters = {
    'project' => @project,
    'address' => address_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#delete_backend_service(backend_service_name) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/fog/google/requests/compute/delete_backend_service.rb', line 31

def delete_backend_service(backend_service_name)
  api_method = @compute.backend_services.delete
  parameters = {
    'project' => @project,
    'backendService' => backend_service_name
  }

  request(api_method, parameters)
end

#delete_disk(disk_name, zone_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/google/requests/compute/delete_disk.rb', line 31

def delete_disk(disk_name, zone_name)
  if zone_name.start_with? 'http'
    zone_name = zone_name.split('/')[-1]
  end

  api_method = @compute.disks.delete
  parameters = {
    'project' => @project,
    'disk' => disk_name,
    'zone' => zone_name
  }

  request(api_method, parameters)
end

#delete_firewall(firewall_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/delete_firewall.rb', line 11

def delete_firewall(firewall_name)
  api_method = @compute.firewalls.delete
  parameters = {
    'project' => @project,
    'firewall' => firewall_name
  }

  request(api_method, parameters)
end

#delete_forwarding_rule(forwarding_rule_name, region_name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/google/requests/compute/delete_forwarding_rule.rb', line 32

def delete_forwarding_rule(forwarding_rule_name, region_name)
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end

  api_method = @compute.forwarding_rules.delete
  parameters = {
    'project' => @project,
    'forwardingRule' => forwarding_rule_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#delete_global_forwarding_rule(global_forwarding_rule_name, region_name = 'global') ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/google/requests/compute/delete_global_forwarding_rule.rb', line 31

def delete_global_forwarding_rule(global_forwarding_rule_name, region_name = 'global')
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end

  api_method = @compute.global_forwarding_rules.delete
  parameters = {
    'project' => @project,
    'forwardingRule' => global_forwarding_rule_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#delete_global_operation(operation) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/fog/google/requests/compute/delete_global_operation.rb', line 13

def delete_global_operation(operation)
  api_method = @compute.global_operations.delete
  parameters = {
    'project' => @project,
    'operation' => operation
  }

  request(api_method, parameters)
end

#delete_http_health_check(name) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/fog/google/requests/compute/delete_http_health_check.rb', line 29

def delete_http_health_check(name)
  api_method = @compute.http_health_checks.delete
  parameters = {
    'project' => @project,
    'httpHealthCheck' => name
  }

  request(api_method, parameters)
end

#delete_image(image_name) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/fog/google/requests/compute/delete_image.rb', line 30

def delete_image(image_name)
  api_method = @compute.images.delete
  parameters = {
    'project' => @project,
    'image' => image_name
  }

  request(api_method, parameters)
end

#delete_network(network_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/delete_network.rb', line 11

def delete_network(network_name)
  api_method = @compute.networks.delete
  parameters = {
    'project' => @project,
    'network' => network_name
  }

  request(api_method, parameters)
end

#delete_region_operation(region_name, operation) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/delete_region_operation.rb', line 13

def delete_region_operation(region_name, operation)
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end
  api_method = @compute.region_operations.delete
  parameters = {
    'project' => @project,
    'region' => region_name,
    'operation' => operation
  }

  request(api_method, parameters)
end

#delete_region_view(region_view, region) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/delete_region_view.rb', line 11

def delete_region_view(region_view, region)
  api_method = @resourceviews.region_views.delete
  parameters = {
    'projectName' => @project,
    'resourceViewName' => region_view,
    'region' => region
  }

  request(api_method, parameters)
end

#delete_route(identity) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/delete_route.rb', line 11

def delete_route(identity)
  api_method = @compute.routes.delete
  parameters = {
    'project' => @project,
    'route' => identity,
  }

  request(api_method, parameters)
end

#delete_server(server_name, zone_name = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fog/google/requests/compute/delete_server.rb', line 55

def delete_server(server_name, zone_name=nil)
  zone_name = find_zone(zone_name)
  api_method = @compute.instances.delete
  parameters = {
    'project' => @project,
    'zone' => zone_name,
    'instance' => server_name
  }

  request(api_method, parameters)
end

#delete_server_access_config(identity, zone, nic, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/google/requests/compute/delete_server_access_config.rb', line 11

def delete_server_access_config(identity, zone, nic, options = {})
  api_method = @compute.instances.delete_access_config
  parameters = {
    'project'  => @project,
    'instance' => identity,
    'zone'     => zone.split('/')[-1],
    'networkInterface' => nic,
    'accessConfig'     => options[:access_config].nil? ? 'External NAT' : options[:access_config],
  }

  request(api_method, parameters)
end

#delete_snapshot(snapshot_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/delete_snapshot.rb', line 11

def delete_snapshot(snapshot_name)
  api_method = @compute.snapshots.delete
  parameters = {
    'project' => @project,
    'snapshot' => snapshot_name,
  }

  request(api_method, parameters)
end

#delete_target_http_proxy(name) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/fog/google/requests/compute/delete_target_http_proxy.rb', line 31

def delete_target_http_proxy(name)
  api_method = @compute.target_http_proxies.delete
  parameters = {
    'project' => @project,
    'targetHttpProxy' => name
  }

  request(api_method, parameters)
end

#delete_target_instance(target_instance_name, zone_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/google/requests/compute/delete_target_instance.rb', line 31

def delete_target_instance(target_instance_name, zone_name)
  if zone_name.start_with? 'http'
    zone_name = zone_name.split('/')[-1]
  end

  api_method = @compute.target_instances.delete
  parameters = {
    'project' => @project,
    'targetInstance' => target_instance_name,
    'zone' => zone_name
  }

  request(api_method, parameters)
end

#delete_target_pool(target_pool_name, region_name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/google/requests/compute/delete_target_pool.rb', line 32

def delete_target_pool(target_pool_name, region_name)
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end

  api_method = @compute.target_pools.delete
  parameters = {
    'project' => @project,
    'targetPool' => target_pool_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#delete_url_map(name) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/fog/google/requests/compute/delete_url_map.rb', line 31

def delete_url_map(name)
  api_method = @compute.url_maps.delete
  parameters = {
    'project' => @project,
    'urlMap' => name
  }

  request(api_method, parameters)
end

#delete_zone_operation(zone_name, operation) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/delete_zone_operation.rb', line 13

def delete_zone_operation(zone_name, operation)
  if zone_name.start_with? 'http'
    zone_name = zone_name.split('/')[-1]
  end
  api_method = @compute.zone_operations.delete
  parameters = {
    'project' => @project,
    'zone' => zone_name,
    'operation' => operation
  }

  request(api_method, parameters)
end

#delete_zone_view(zone_view, zone) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/delete_zone_view.rb', line 11

def delete_zone_view(zone_view, zone)
  api_method = @resourceviews.zone_views.delete
  parameters = {
    'projectName' => @project,
    'resourceViewName' => zone_view,
    'zone' => zone
  }

  request(api_method, parameters)
end

#detach_disk(instance, zone, deviceName) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/google/requests/compute/detach_disk.rb', line 11

def detach_disk(instance, zone, deviceName)
  api_method = @compute.instances.detach_disk
  parameters = {
    'project' => @project,
    'instance' => instance,
    'zone' => zone.split('/')[-1],
    'deviceName' => deviceName
  }

  request(api_method, parameters)
end

#format_metadata(metadata) ⇒ Object



112
113
114
# File 'lib/fog/google/requests/compute/insert_server.rb', line 112

def ()
  { "items" => .map {|k,v| {"key" => k, "value" => v}} }
end

#get_address(address_name, region_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/get_address.rb', line 11

def get_address(address_name, region_name)
  api_method = @compute.addresses.get
  parameters = {
    'project' => @project,
    'address' => address_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#get_backend_service(service_name) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/fog/google/requests/compute/get_backend_service.rb', line 15

def get_backend_service(service_name)
  api_method = @compute.backend_services.get
  parameters = {
    'project' => @project,
    'backendService' => service_name
  }
  request(api_method, parameters)
end

#get_backend_service_health(backend_service) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/get_backend_service_health.rb', line 11

def get_backend_service_health(backend_service)
  api_method = @compute.backend_services.get_health
  parameters = {
    'project' => @project,
    'backendService' => backend_service.name
  }
  health_results = backend_service.backends.map do |backend|
    body = { 'group' => backend['group'] }
    resp = request(api_method, parameters, body_object= body)
    [backend['group'], resp.data[:body]['healthStatus']]
  end
  Hash[health_results]
end

#get_backend_services(service_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/get_backend_services.rb', line 11

def get_backend_services(service_name)
  api_method = @compute.backend_services.get
  parameters = {
    'project' => @project,
    'backendService' => service_name
  }
  result = self.build_result(api_method, parameters)
  response = self.build_response(result)
end

#get_disk(disk_name, zone_name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/google/requests/compute/get_disk.rb', line 35

def get_disk(disk_name, zone_name)
  if zone_name.start_with? 'http'
    zone_name = zone_name.split('/')[-1]
  end

  api_method = @compute.disks.get
  parameters = {
    'project' => @project,
    'disk' => disk_name,
    'zone' => zone_name
  }

  request(api_method, parameters)
end

#get_disk_type(identity, zone) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/google/requests/compute/get_disk_type.rb', line 29

def get_disk_type(identity, zone)
  api_method = @compute.disk_types.get
  parameters = {
    'project'  => @project,
    'zone'     => zone.split('/')[-1],
    'diskType' => identity,
  }

  request(api_method, parameters)
end

#get_firewall(firewall_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/get_firewall.rb', line 11

def get_firewall(firewall_name)
  api_method = @compute.firewalls.get
  parameters = {
    'project' => @project,
    'firewall' => firewall_name
  }

  request(api_method, parameters)
end

#get_forwarding_rule(forwarding_rule_name, region_name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/google/requests/compute/get_forwarding_rule.rb', line 29

def get_forwarding_rule(forwarding_rule_name, region_name)
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end

  api_method = @compute.forwarding_rules.get
  parameters = {
    'project' => @project,
    'forwardingRule' => forwarding_rule_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#get_global_forwarding_rule(global_forwarding_rule_name, region_name = 'global') ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/google/requests/compute/get_global_forwarding_rule.rb', line 15

def get_global_forwarding_rule(global_forwarding_rule_name, region_name = 'global')
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end

  api_method = @compute.global_forwarding_rules.get
  parameters = {
    'project' => @project,
    'forwardingRule' => global_forwarding_rule_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#get_global_operation(operation) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/fog/google/requests/compute/get_global_operation.rb', line 38

def get_global_operation(operation)
  api_method = @compute.global_operations.get
  parameters = {
    'project' => @project,
    'operation' => operation
  }

  request(api_method, parameters)
end

#get_http_health_check(name) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/fog/google/requests/compute/get_http_health_check.rb', line 27

def get_http_health_check(name)
  api_method = @compute.http_health_checks.get
  parameters = {
    'project' => @project,
    'httpHealthCheck' => name
  }

  request(api_method, parameters)
end

#get_image(image_name, project = @project) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/fog/google/requests/compute/get_image.rb', line 24

def get_image(image_name, project=@project)
  api_method = @compute.images.get
  parameters = {
    'image' => image_name,
    'project' => project,
  }

  request(api_method, parameters)
end

#get_machine_type(machine_type_name, zone_name = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/google/requests/compute/get_machine_type.rb', line 26

def get_machine_type(machine_type_name, zone_name = nil)
  zone_name = list_zones.body['items'].first['name'] if zone_name.nil?
  if zone_name.start_with? 'http'
    zone_name = zone_name.split('/')[-1]
  end
  api_method = @compute.machine_types.get
  parameters = {
    'zone' => zone_name,
    'project' => @project,
    'machineType' => machine_type_name
  }

  request(api_method, parameters)
end

#get_network(network_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/get_network.rb', line 11

def get_network(network_name)
  api_method = @compute.networks.get
  parameters = {
    'project' => @project,
    'network' => network_name
  }

  request(api_method, parameters)
end

#get_project(identity) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/fog/google/requests/compute/get_project.rb', line 11

def get_project(identity)
  api_method = @compute.projects.get
  parameters = {
    :project => identity,
  }

  request(api_method, parameters)
end

#get_region(identity) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/fog/google/requests/compute/get_region.rb', line 25

def get_region(identity)
  api_method = @compute.regions.get
  parameters = {
    'project' => @project,
    'region' => identity.split('/')[-1],
  }

  request(api_method, parameters)
end

#get_region_operation(region_name, operation) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/google/requests/compute/get_region_operation.rb', line 38

def get_region_operation(region_name, operation)
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end

  api_method = @compute.region_operations.get
  parameters = {
    'project' => @project,
    'region' => region_name,
    'operation' => operation
  }

  request(api_method, parameters)
end

#get_region_view(region_view_name, region) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/get_region_view.rb', line 11

def get_region_view(region_view_name, region)
  api_method = @resourceviews.region_views.get
  parameters = {
    'projectName' => @project,
    'resourceViewName' => region_view_name,
    'region' => region
  }

  request(api_method, parameters)
end

#get_route(identity) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/get_route.rb', line 11

def get_route(identity)
  api_method = @compute.routes.get
  parameters = {
    'project' => @project,
    'route' => identity,
  }

  request(api_method, parameters)
end

#get_server(server_name, zone_name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/google/requests/compute/get_server.rb', line 56

def get_server(server_name, zone_name)
  if zone_name.is_a? Excon::Response
    zone = zone_name.body["name"]
  else
    zone = zone_name
  end

  api_method = @compute.instances.get
  parameters = {
    'project' => @project,
    'zone' => zone,
    'instance' => server_name
  }

  request(api_method, parameters)
end

#get_server_serial_port_output(identity, zone) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/get_server_serial_port_output.rb', line 11

def get_server_serial_port_output(identity, zone)
  api_method = @compute.instances.get_serial_port_output
  parameters = {
    'project'  => @project,
    'instance' => identity,
    'zone'     => zone.split('/')[-1],
  }

  request(api_method, parameters)
end

#get_snapshot(snap_name, project = @project) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/get_snapshot.rb', line 11

def get_snapshot(snap_name, project=@project)
  if snap_name.nil?
    raise ArgumentError.new "snap_name must not be nil."
  end

  api_method = @compute.snapshots.get
  parameters = {
    'snapshot' => snap_name,
    'project'  => project,
  }

  request(api_method, parameters)
end

#get_target_http_proxy(name) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/get_target_http_proxy.rb', line 15

def get_target_http_proxy(name)
  api_method = @compute.target_http_proxies.get
  parameters = {
    'project' => @project,
    'targetHttpProxy' => name
  }

  request(api_method, parameters)
end

#get_target_instance(target_instance_name, zone_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/google/requests/compute/get_target_instance.rb', line 15

def get_target_instance(target_instance_name, zone_name)
  if zone_name.start_with? 'http'
    zone_name = zone_name.split('/')[-1]
  end

  api_method = @compute.target_instances.get
  parameters = {
    'project' => @project,
    'targetInstance' => target_instance_name,
    'zone' => zone_name
  }

  request(api_method, parameters)
end

#get_target_pool(target_pool_name, region_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/google/requests/compute/get_target_pool.rb', line 23

def get_target_pool(target_pool_name, region_name)
  if region_name.start_with? 'http'
    region_name = region_name.split('/')[-1]
  end

  api_method = @compute.target_pools.get
  parameters = {
    'project' => @project,
    'targetPool' => target_pool_name,
    'region' => region_name
  }

  request(api_method, parameters)
end

#get_target_pool_health(target_pool) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/get_target_pool_health.rb', line 11

def get_target_pool_health(target_pool)
  api_method = @compute.target_pools.get_health
  parameters = {
    'project' => @project,
    'targetPool' => target_pool.name,
    'region' => target_pool.region.split('/')[-1]
  }

  health_results = target_pool.instances.map do |instance|
    body = { 'instance' => instance }
    resp = request(api_method, parameters, body_object=body)
    [instance, resp.data[:body]['healthStatus']]
  end
  Hash[health_results]
end

#get_url_map(name) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/get_url_map.rb', line 15

def get_url_map(name)
  api_method = @compute.url_maps.get
  parameters = {
    'project' => @project,
    'urlMap' => name
  }

  request(api_method, parameters)
end

#get_zone(zone_name) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/fog/google/requests/compute/get_zone.rb', line 24

def get_zone(zone_name)
  api_method = @compute.zones.get
  parameters = {
    'project' => @project,
    'zone' => zone_name
  }

  request(api_method, parameters)
end

#get_zone_operation(zone_name, operation) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/google/requests/compute/get_zone_operation.rb', line 38

def get_zone_operation(zone_name, operation)
  if zone_name.start_with? 'http'
    zone_name = zone_name.split('/')[-1]
  end

  api_method = @compute.zone_operations.get
  parameters = {
    'project' => @project,
    'zone' => zone_name,
    'operation' => operation
  }

  request(api_method, parameters)
end

#get_zone_view(zone_view_name, zone) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/get_zone_view.rb', line 11

def get_zone_view(zone_view_name, zone)
  api_method = @resourceviews.zone_views.get
  parameters = {
    'projectName' => @project,
    'resourceViewName' => zone_view_name,
    'zone' => zone
  }

  request(api_method, parameters)
end

#handle_disks(options) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fog/google/requests/compute/insert_server.rb', line 97

def handle_disks(options)
  disks = []
  # An array of persistent disks. You must supply a boot disk as the first disk in
  # this array and mark it as a boot disk using the disks[].boot property.
  options.delete('disks').each do |disk|
    if disk.is_a? Disk
      disks << disk.get_object
    else
      disks << disk
    end
  end
  disks.first['boot'] = true
  disks
end

#insert_address(address_name, region_name, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/google/requests/compute/insert_address.rb', line 11

def insert_address(address_name, region_name, options = {})
  api_method = @compute.addresses.insert
  parameters = {
    'project' => @project,
    'region' => region_name,
  }
  body_object = { 'name' => address_name }
  body_object['description'] = options[:description] if options[:description]

  request(api_method, parameters, body_object)
end

#insert_backend_service(backend_service_name, opts = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/google/requests/compute/insert_backend_service.rb', line 50

def insert_backend_service(backend_service_name, opts = {})
  api_method = @compute.backend_services.insert
  parameters = {
    'project' => @project
  }
  body_object = { 'name' => backend_service_name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object=body_object)
end

#insert_disk(disk_name, zone_name, image_name = nil, opts = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/fog/google/requests/compute/insert_disk.rb', line 68

def insert_disk(disk_name, zone_name, image_name=nil, opts={})
  api_method = @compute.disks.insert
  parameters = {
    'project' => @project,
    'zone' => zone_name
  }

  if image_name
    # New disk from image
    image = images.get(image_name)
    raise ArgumentError.new("Invalid image specified: #{image_name}") unless image
    @image_url = @api_url + image.resource_url
    parameters['sourceImage'] = @image_url
  end

  body_object = { 'name' => disk_name }
  body_object['type'] = opts.delete('type')

  # According to Google docs, if image name is not present, only one of
  # sizeGb or sourceSnapshot need to be present, one will create blank
  # disk of desired size, other will create disk from snapshot
  if image_name.nil?
    if opts.key?('sourceSnapshot')
      # New disk from snapshot
      snap = snapshots.get(opts.delete('sourceSnapshot'))
      raise ArgumentError.new('Invalid source snapshot') unless snap
      body_object['sourceSnapshot'] = @api_url + snap.resource_url
    elsif opts.key?('sizeGb')
      # New blank disk
      body_object['sizeGb'] = opts.delete('sizeGb')
    else
      raise ArgumentError.new('Must specify image OR snapshot OR '\
                              'disk size when creating a disk.')
    end

  end

  # Merge in any remaining options (only 'description' should remain)
  body_object.merge!(opts)

  request(api_method, parameters, body_object)
end

#insert_firewall(firewall_name, allowed, network = GOOGLE_COMPUTE_DEFAULT_NETWORK, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/google/requests/compute/insert_firewall.rb', line 11

def insert_firewall(firewall_name, allowed, network = GOOGLE_COMPUTE_DEFAULT_NETWORK, options = {})
  unless network.start_with? 'http'
    network = "#{@api_url}#{@project}/global/networks/#{network}"
  end

  api_method = @compute.firewalls.insert
  parameters = {
    'project' => @project,
  }
  body_object = {
    "name" => firewall_name,
    "network" => network,
    "allowed" => allowed,
  }
  unless options[:description].nil?
    body_object["description"] = options[:description]
  end
  unless options[:source_ranges].nil? || options[:source_ranges].empty?
    body_object["sourceRanges"] = options[:source_ranges]
  end
  unless options[:source_tags].nil? || options[:source_tags].empty?
    body_object["sourceTags"] = options[:source_tags]
  end
  unless options[:target_tags].nil? || options[:target_tags].empty?
    body_object["targetTags"] = options[:target_tags]
  end

  request(api_method, parameters, body_object)
end

#insert_forwarding_rule(forwarding_rule_name, region_name, opts = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/google/requests/compute/insert_forwarding_rule.rb', line 46

def insert_forwarding_rule(forwarding_rule_name, region_name, opts = {})
  api_method = @compute.forwarding_rules.insert
  parameters = {
    'project' => @project,
    'region' => region_name
  }
  body_object = { 'name' => forwarding_rule_name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object=body_object)
end

#insert_global_forwarding_rule(global_forwarding_rule_name, opts = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/google/requests/compute/insert_global_forwarding_rule.rb', line 43

def insert_global_forwarding_rule(global_forwarding_rule_name, opts = {})
  api_method = @compute.global_forwarding_rules.insert
  parameters = {
    'project' => @project,
  }
  body_object = { 'name' => global_forwarding_rule_name, 'region' => 'global' }
  body_object.merge!(opts)

  request(api_method, parameters,body_object=body_object)
end

#insert_http_health_check(name, opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/google/requests/compute/insert_http_health_check.rb', line 45

def insert_http_health_check(name, opts={})
  api_method = @compute.http_health_checks.insert
  parameters = {
    'project' => @project
  }

  body_object = { 'name' => name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object)
end

#insert_image(image_name, options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/google/requests/compute/insert_image.rb', line 44

def insert_image(image_name, options={})
  api_method = @compute.images.insert

  parameters = {
    'project' => @project,
  }

  body_object = {
    'sourceType'      => 'RAW',
    'name'            => image_name,
  }

  # Merge in the remaining params 
  body_object.merge!(options)

  request(api_method, parameters, body_object=body_object)
end

#insert_network(network_name, ip_range, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/insert_network.rb', line 11

def insert_network(network_name, ip_range, options = {})
  api_method = @compute.networks.insert
  parameters = {
    'project' => @project,
  }
  body_object = {
    'name' => network_name,
    'IPv4Range' => ip_range
  }

  body_object['description'] = options[:description] if options[:description]
  body_object['gatewayIPv4'] = options[:gateway_ipv4] if options[:gateway_ipv4]

  request(api_method, parameters, body_object)
end

#insert_region_view(region_view_name, region_name, opts = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/google/requests/compute/insert_region_view.rb', line 11

def insert_region_view(region_view_name, region_name, opts = {})
  api_method = @resourceviews.region_views.insert
  parameters = {
    'projectName' => @project,
    'region' => region_name
  }
  body_object = { 'name' => region_view_name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object=body_object)
end

#insert_route(name, network, dest_range, priority, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/google/requests/compute/insert_route.rb', line 11

def insert_route(name, network, dest_range, priority, options = {})
  api_method = @compute.routes.insert
  parameters = {
    'project' => @project,
  }
  body_object = {
    'name' => name,
    'network' => network,
    'destRange' => dest_range,
    'priority' => priority,
  }
  body_object['description'] = options[:description] if options[:description]
  unless options[:tags].nil? || options[:tags].empty?
    body_object['tags'] = options[:tags]
  end
  body_object['nextHopInstance'] = options[:next_hop_instance] if options[:next_hop_instance]
  body_object['nextHopGateway'] = options[:next_hop_gateway] if options[:next_hop_gateway]
  body_object['nextHopIp'] = options[:next_hop_ip] if options[:next_hop_ip]

  request(api_method, parameters, body_object)
end

#insert_server(server_name, zone_name, options = {}, *deprecated_args) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/fog/google/requests/compute/insert_server.rb', line 116

def insert_server(server_name, zone_name, options={}, *deprecated_args)
  if deprecated_args.length > 0 or not options.is_a? Hash
    raise ArgumentError.new 'Too many parameters specified. This may be the cause of code written for an outdated'\
        ' version of fog. Usage: server_name, zone_name, [options]'
  end
  api_method = @compute.instances.insert
  parameters = {
      'project' => @project,
      'zone' => zone_name,
  }
  body_object = {:name => server_name}

  body_object['machineType'] = @api_url + @project + "/zones/#{zone_name}/machineTypes/#{options.delete 'machineType'}"
  network = nil
  if options.key? 'network'
    network = options.delete 'network'
  else
    network = GOOGLE_COMPUTE_DEFAULT_NETWORK
  end

  # ExternalIP is default value for server creation
  access_config = {'type' => 'ONE_TO_ONE_NAT', 'name' => 'External NAT'}
  # leave natIP undefined to use an IP from a shared ephemeral IP address pool
  if options.key? 'externalIp'
    access_config['natIP'] = options.delete 'externalIp'
    # If set to 'false', that would mean user does no want to allocate an external IP
    access_config = nil if access_config['natIP'] == false
  end

  networkInterfaces = []
  if ! network.nil?
    networkInterface = { 'network' => @api_url + @project + "/global/networks/#{network}" }
    networkInterface['accessConfigs'] = [access_config] if access_config
    networkInterfaces <<  networkInterface
  end

  scheduling = {
    'automaticRestart' => false,
    'onHostMaintenance' => "MIGRATE"
  }
  if options.key? 'auto_restart'
    scheduling['automaticRestart'] = options.delete 'auto_restart'
    scheduling['automaticRestart'] = scheduling['automaticRestart'].class == TrueClass
  end
  if options.key? 'on_host_maintenance'
    ohm = options.delete 'on_host_maintenance'
    scheduling['onHostMaintenance'] = (ohm.respond_to?("upcase") &&
            ohm.upcase == "MIGRATE" && "MIGRATE") || "TERMINATE"
  end
  body_object['scheduling'] = scheduling

  # @see https://developers.google.com/compute/docs/networking#canipforward
  if options.key? 'can_ip_forward'
    body_object['canIpForward'] = options.delete 'can_ip_forward'
  end

  # TODO: add other networks
  body_object['networkInterfaces'] = networkInterfaces

  if options['disks'].nil? or options['disks'].empty?
    raise ArgumentError.new "Empty value for field 'disks'. Boot disk must be specified"
  end
  body_object['disks'] = handle_disks(options)

  options['metadata'] =  options['metadata'] if options['metadata']

  body_object['tags'] = { 'items' => options.delete('tags') } if options['tags']

  body_object.merge!(options) # Adds in all remaining options that weren't explicitly handled.

  request(api_method, parameters, body_object=body_object)
end

#insert_snapshot(disk_name, zone_name, project = @project, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/google/requests/compute/insert_snapshot.rb', line 11

def insert_snapshot(disk_name, zone_name, project=@project, opts={})
  # This is unfortunate, since we might be called from 2 contexts
  # 1. disk.snapshot <-- here validation of disk_name is not needed
  # 2. snapshot.create <-- here we must validate the disk_name
  #
  # Validation would involve 'get'ing the disk by that name. This is
  # redundant (and expensive) for case (1) which is likely the common
  # codepath. So we won't do it.

  api_method = @compute.disks.create_snapshot

  parameters = {
    'disk'    => disk_name,
    'zone'    => zone_name,
    'project' => @project,
  }

  snap_name = opts.delete('name')
  raise ArgumentError.new('Must specify snapshot name') unless snap_name
  body_object = { 'name' => snap_name }

  # Merge in any remaining options (description)
  body_object.merge!(opts)

  request(api_method, parameters, body_object)
end

#insert_target_http_proxy(name, opts = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/google/requests/compute/insert_target_http_proxy.rb', line 39

def insert_target_http_proxy(name, opts={})
  api_method = @compute.target_http_proxies.insert
  parameters = {
    'project' => @project
  }
  body_object = { 'name' => name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object)
end

#insert_target_instance(target_instance_name, zone_name, opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/google/requests/compute/insert_target_instance.rb', line 41

def insert_target_instance(target_instance_name, zone_name, opts = {})
  api_method = @compute.target_instances.insert
  parameters = {
    'project' => @project,
    'zone' => zone_name,
  }
  body_object = { 'name' => target_pool_name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object=body_object)
end

#insert_target_pool(target_pool_name, region_name, opts = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/google/requests/compute/insert_target_pool.rb', line 44

def insert_target_pool(target_pool_name, region_name, opts = {})
  api_method = @compute.target_pools.insert
  parameters = {
    'project' => @project,
    'region' => region_name
  }
  body_object = { 'name' => target_pool_name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object=body_object)
end

#insert_url_map(url_map_name, opts = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/google/requests/compute/insert_url_map.rb', line 42

def insert_url_map(url_map_name, opts = {})
  api_method = @compute.url_maps.insert
  parameters = {
    'project' => @project,
  }
  body_object = { 'name' => url_map_name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object=body_object)
end

#insert_zone_view(zone_view_name, zone_name, opts = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/google/requests/compute/insert_zone_view.rb', line 11

def insert_zone_view(zone_view_name, zone_name, opts = {})
  api_method = @resourceviews.zone_views.insert
  parameters = {
    'projectName' => @project,
    'zone' => zone_name
#            'zone' => zone_name
  }
  body_object = { 'name' => zone_view_name }
  body_object.merge!(opts)

  request(api_method, parameters, body_object=body_object)
end

#list_addresses(region_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/list_addresses.rb', line 11

def list_addresses(region_name)
  api_method = @compute.addresses.list
  parameters = {
    'project' => @project,
    'region' => region_name
  }

  request(api_method, parameters)
end

#list_aggregated_addresses(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/list_aggregated_addresses.rb', line 11

def list_aggregated_addresses(options = {})
  api_method = @compute.addresses.aggregated_list
  parameters = {
    'project' => @project,
  }
  parameters['filter'] = options[:filter] if options[:filter]

  request(api_method, parameters)
end

#list_aggregated_disk_types(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/fog/google/requests/compute/list_aggregated_disk_types.rb', line 28

def list_aggregated_disk_types(options = {})
  api_method = @compute.disk_types.aggregated_list
  parameters = {
    'project' => @project,
  }
  parameters['filter'] = options[:filter] if options[:filter]

  request(api_method, parameters)
end

#list_aggregated_disks(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/fog/google/requests/compute/list_aggregated_disks.rb', line 28

def list_aggregated_disks(options = {})
  api_method = @compute.disks.aggregated_list
  parameters = {
    'project' => @project,
  }
  parameters['filter'] = options[:filter] if options[:filter]

  request(api_method, parameters)
end

#list_aggregated_machine_typesObject



11
12
13
14
15
16
17
18
# File 'lib/fog/google/requests/compute/list_aggregated_machine_types.rb', line 11

def list_aggregated_machine_types
  api_method = @compute.machine_types.aggregated_list
  parameters = {
    'project' => @project,
  }

  request(api_method, parameters)
end

#list_aggregated_servers(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/fog/google/requests/compute/list_aggregated_servers.rb', line 28

def list_aggregated_servers(options = {})
  api_method = @compute.instances.aggregated_list
  parameters = {
    'project' => @project,
  }
  parameters['filter'] = options[:filter] if options[:filter]

  request(api_method, parameters)
end

#list_backend_servicesObject



18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_backend_services.rb', line 18

def list_backend_services
  api_method = @compute.backend_services.list
  parameters = {
    'project' => @project,
  }

  request(api_method, parameters)
end

#list_disk_types(zone) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/fog/google/requests/compute/list_disk_types.rb', line 34

def list_disk_types(zone)
  api_method = @compute.disk_types.list
  parameters = {
    'project' => @project,
    'zone'    => zone.split('/')[-1],
  }

  request(api_method, parameters)
end

#list_disks(zone_name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_disks.rb', line 17

def list_disks(zone_name)
  api_method = @compute.disks.list
  parameters = {
    'project' => @project,
    'zone' => zone_name
  }

  request(api_method, parameters)
end

#list_firewallsObject



11
12
13
14
15
16
17
18
# File 'lib/fog/google/requests/compute/list_firewalls.rb', line 11

def list_firewalls
  api_method = @compute.firewalls.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#list_forwarding_rules(region_name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_forwarding_rules.rb', line 17

def list_forwarding_rules(region_name)
  api_method = @compute.forwarding_rules.list
  parameters = {
    'project' => @project,
    'region' => region_name
  }

  request(api_method, parameters)
end

#list_global_forwarding_rules(region_name = 'global') ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/fog/google/requests/compute/list_global_forwarding_rules.rb', line 18

def list_global_forwarding_rules(region_name = 'global')
  api_method = @compute.global_forwarding_rules.list
  parameters = {
    'project' => @project,
    'region' => region_name
  }

  request(api_method, parameters)
end

#list_global_operationsObject



13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/list_global_operations.rb', line 13

def list_global_operations
  api_method = @compute.global_operations.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#list_http_health_checksObject



18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_http_health_checks.rb', line 18

def list_http_health_checks
  api_method = @compute.http_health_checks.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#list_images(project = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_images.rb', line 17

def list_images(project=nil)
  api_method = @compute.images.list
  project=@project if project.nil?
  parameters = {
    'project' => project
  }

  request(api_method, parameters)
end

#list_machine_types(zone_name) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/fog/google/requests/compute/list_machine_types.rb', line 18

def list_machine_types(zone_name)
  api_method = @compute.machine_types.list
  parameters = {
    'project' => @project,
    'zone' => zone_name,
  }

  request(api_method, parameters)
end

#list_networksObject



11
12
13
14
15
16
17
18
# File 'lib/fog/google/requests/compute/list_networks.rb', line 11

def list_networks
  api_method = @compute.networks.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#list_region_operations(region) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/fog/google/requests/compute/list_region_operations.rb', line 13

def list_region_operations(region)
  api_method = @compute.region_operations.list
  parameters = {
    'region' => region,
    'project' => @project,
  }

  request(api_method, parameters)
end

#list_region_view_resources(region_view) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/list_region_view_resources.rb', line 11

def list_region_view_resources(region_view)
  api_method = @resourceviews.region_views.list_resources
  parameters = {
    'projectName' => @project,
    'region' => region_view.region,
    'resourceViewName' => region_view.name
  }

  request(api_method, parameters)
end

#list_region_views(region_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/list_region_views.rb', line 11

def list_region_views(region_name)
  api_method = @resourceviews.region_views.list
  parameters = {
    'projectName' => @project,
    'region' => region_name,
  }

  request(api_method, parameters)
end

#list_regionsObject



74
75
76
77
78
79
80
81
# File 'lib/fog/google/requests/compute/list_regions.rb', line 74

def list_regions
  api_method = @compute.regions.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#list_routesObject



11
12
13
14
15
16
17
18
# File 'lib/fog/google/requests/compute/list_routes.rb', line 11

def list_routes
  api_method = @compute.routes.list
  parameters = {
    'project' => @project,
  }

  request(api_method, parameters)
end

#list_servers(zone_name) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/fog/google/requests/compute/list_servers.rb', line 19

def list_servers(zone_name)
  api_method = @compute.instances.list
  parameters = {
    'project' => @project,
    'zone' => zone_name,
  }

  request(api_method, parameters)
end

#list_snapshots(project = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/list_snapshots.rb', line 11

def list_snapshots(project=nil)
  api_method = @compute.snapshots.list
  project=@project if project.nil?
  parameters = {
    'project' => project
  }

  request(api_method, parameters)
end

#list_target_http_proxiesObject



18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_target_http_proxies.rb', line 18

def list_target_http_proxies
  api_method = @compute.target_http_proxies.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#list_target_instances(zone_name) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/fog/google/requests/compute/list_target_instances.rb', line 18

def list_target_instances(zone_name)
  api_method = @compute.target_instances.list
  parameters = {
    'project' => @project,
    'zone' => zone_name
  }

  request(api_method, parameters)
end

#list_target_pools(region_name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_target_pools.rb', line 17

def list_target_pools(region_name)
  api_method = @compute.target_pools.list
  parameters = {
    'project' => @project,
    'region' => region_name
  }

  request(api_method, parameters)
end

#list_url_mapsObject



18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/list_url_maps.rb', line 18

def list_url_maps
  api_method = @compute.url_maps.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#list_zone_operations(zone) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/fog/google/requests/compute/list_zone_operations.rb', line 13

def list_zone_operations(zone)
  api_method = @compute.zone_operations.list
  parameters = {
    'zone' => zone,
    'project' => @project,
  }

  request(api_method, parameters)
end

#list_zone_view_resources(zone_view) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/list_zone_view_resources.rb', line 11

def list_zone_view_resources(zone_view)
  api_method = @resourceviews.zone_views.list_resources
  parameters = {
    'projectName' => @project,
    'zone' => zone_view.zone,
    'resourceViewName' => zone_view.name
  }

  request(api_method, parameters)
end

#list_zone_views(zone_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/requests/compute/list_zone_views.rb', line 11

def list_zone_views(zone_name)
  api_method = @resourceviews.zone_views.list
  parameters = {
    'projectName' => @project,
    'zone' => zone_name,
  }

  request(api_method, parameters)
end

#list_zonesObject



17
18
19
20
21
22
23
24
# File 'lib/fog/google/requests/compute/list_zones.rb', line 17

def list_zones
  api_method = @compute.zones.list
  parameters = {
    'project' => @project
  }

  request(api_method, parameters)
end

#remove_target_pool_health_checks(target_pool, health_checks) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/remove_target_pool_health_checks.rb', line 11

def remove_target_pool_health_checks(target_pool, health_checks)
  api_method = @compute.target_pools.remove_health_check
  parameters = {
    'project' => @project,
    'targetPool' => target_pool.name,
    'region' => target_pool.region.split('/')[-1]
  }
  body = {
    'healthChecks' => health_checks.map { |i| { 'healthCheck' => i } }
  }

  request(api_method, parameters, body_object=body)
end

#remove_target_pool_instances(target_pool, instances) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/remove_target_pool_instance.rb', line 11

def remove_target_pool_instances(target_pool, instances)
  api_method = @compute.target_pools.remove_instance
  parameters = {
    'project' => @project,
    'targetPool' => target_pool.name,
    'region' => target_pool.region.split('/')[-1]
  }
  body = {
    'instances' => instances.map { |i| { 'instance' => i } }
  }

  request(api_method, parameters, body_object=body)
end

#reset_server(identity, zone) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/reset_server.rb', line 11

def reset_server(identity, zone)
  api_method = @compute.instances.reset
  parameters = {
    'project'  => @project,
    'instance' => identity,
    'zone'     => zone.split('/')[-1],
  }

  request(api_method, parameters)
end

#set_common_instance_metadata(identity, current_fingerprint, metadata = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/google/requests/compute/set_common_instance_metadata.rb', line 11

def (identity, current_fingerprint,  = {})
  api_method = @compute.projects.
  parameters = {
    :project => identity,
  }
  body_object = {
    :fingerprint => current_fingerprint,
    :items => Array().map { |pair| { :key => pair[0], :value => pair[1] } },
  }

  request(api_method, parameters, body_object)
end

#set_forwarding_rule_target(rule, target) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/set_forwarding_rule_target.rb', line 11

def set_forwarding_rule_target(rule, target)
  api_method = @compute.forwarding_rules.set_target
  parameters = {
    'project' => @project,
    'forwardingRule' => rule.name,
    'region' => rule.region.split('/')[-1]
  }
  body = {
    'target' => target
  }

  request(api_method, parameters, body_object=body)
end

#set_global_forwarding_rule_target(rule, target) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/set_global_forwarding_rule_target.rb', line 11

def set_global_forwarding_rule_target(rule, target)
  api_method = @compute.global_forwarding_rules.set_target
  parameters = {
    'project' => @project,
    'forwardingRule' => rule.name,
    'region' => 'global'
  }
  body = {
    'target' => target
  }

  request(api_method, parameters, body_object=body)
end

#set_metadata(instance, zone, fingerprint, metadata = {}) ⇒ Object

Set an instance metadata

Parameters

  • instance<~String> - Instance name (identity)

  • zone<~String> - Zone short name (without the full path)

  • fingerprint<~String> - The fingerprint of the last metadata. Can be retrieved by reloading the compute object, and checking the metadata fingerprint field.

    instance.reload
    fingerprint = instance.['fingerprint']
    
  • metadata<~Hash> - A new metadata

Returns

  • response<~Excon::Response>



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/google/requests/compute/set_metadata.rb', line 23

def (instance, zone, fingerprint, ={})
  api_method = @compute.instances.
  parameters = {
    'project' => @project,
    'instance' => instance,
    'zone' => zone
  }
  body_object = {
    'fingerprint' => fingerprint,
    "items" => .to_a.map {|pair| { :key => pair[0], :value => pair[1] } }
  }
  request(api_method, parameters, body_object=body_object)
end

#set_server_disk_auto_delete(identity, zone, auto_delete, device_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/google/requests/compute/set_server_disk_auto_delete.rb', line 11

def set_server_disk_auto_delete(identity, zone, auto_delete, device_name)
  api_method = @compute.instances.set_disk_auto_delete
  parameters = {
    'project'    => @project,
    'instance'   => identity,
    'zone'       => zone.split('/')[-1],
    'autoDelete' => auto_delete,
    'deviceName' => device_name,
  }

  request(api_method, parameters)
end

#set_server_scheduling(identity, zone, on_host_maintenance, automatic_restart) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/requests/compute/set_server_scheduling.rb', line 11

def set_server_scheduling(identity, zone, on_host_maintenance, automatic_restart)
  api_method = @compute.instances.set_scheduling
  parameters = {
    'project'  => @project,
    'instance' => identity,
    'zone'     => zone.split('/')[-1],
  }

  body_object = {
    'onHostMaintenance' => on_host_maintenance,
    'automaticRestart'  => automatic_restart,
  }

  request(api_method, parameters, body_object)
end

#set_tags(instance, zone, fingerprint, tags = []) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/set_tags.rb', line 11

def set_tags(instance, zone, fingerprint, tags=[])
  api_method = @compute.instances.set_tags
  parameters = {
    'project' => @project,
    'instance' => instance,
    'zone' => zone
  }
  body_object = { "fingerprint" => fingerprint, "items" => tags }
  request(api_method, parameters, body_object=body_object)
end

#set_target_http_proxy_url_map(target_http_proxy, url_map) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/google/requests/compute/set_target_http_proxy_url_map.rb', line 11

def set_target_http_proxy_url_map(target_http_proxy, url_map)
  api_method = @compute.target_http_proxies.set_url_map
  parameters = {
    'project' => @project,
    'targetHttpProxy' => target_http_proxy.name,
  }
  url_map = url_map.self_link unless url_map.class == String
  body = {
    'urlMap' => url_map
  }

  request(api_method, parameters, body_object=body)
end

#start_server(identity, zone_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/start_server.rb', line 11

def start_server(identity, zone_name)
  api_method = @compute.instances.start
  parameters = {
    'project' => @project,
    'zone' => zone_name,
    'instance' => identity,
  }

  request(api_method, parameters)
end

#stop_server(identity, zone_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/stop_server.rb', line 11

def stop_server(identity, zone_name)
  api_method = @compute.instances.stop
  parameters = {
    'project' => @project,
    'zone' => zone_name,
    'instance' => identity,
  }

  request(api_method, parameters)
end

#update_url_map(url_map, host_rules, path_matchers = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/google/requests/compute/update_url_map.rb', line 11

def update_url_map(url_map, host_rules, path_matchers = nil)
  api_method = @compute.url_maps.update
  parameters = {
    'project' => @project,
    'urlMap' => url_map.name
  }
  
  # add new properties to the url_map resource
  if  url_map.hostRules then
    url_map.hostRules.concat(host_rules)
  else
    url_map.hostRules = host_rules
  end

  # a path matcher can only be created with a host rule that uses it
  if path_matchers then
    if url_map.pathMatchers then
      url_map.pathMatchers.concat(path_matchers)
    else
      url_map.pathMatchers = path_matchers
    end
  end

  request(api_method, parameters, body_object=url_map)
end

#validate_url_map(url_map) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/requests/compute/validate_url_map.rb', line 11

def validate_url_map(url_map)
  api_method = @compute.url_maps.validate
  parameters = {
    'project' => @project,
    'urlMap' => url_map.name
  }
  body = { 'resource' => url_map }

  request(api_method, parameters, body_object = body)
end