Class: Fog::Compute::Google::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Google::Real
show all
- Includes:
- Collections, 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_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/insert_disk.rb,
lib/fog/google/requests/compute/list_images.rb,
lib/fog/google/requests/compute/delete_image.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/list_servers.rb,
lib/fog/google/requests/compute/set_metadata.rb,
lib/fog/google/requests/compute/delete_server.rb,
lib/fog/google/requests/compute/insert_server.rb,
lib/fog/google/requests/compute/list_networks.rb,
lib/fog/google/requests/compute/delete_address.rb,
lib/fog/google/requests/compute/delete_network.rb,
lib/fog/google/requests/compute/insert_address.rb,
lib/fog/google/requests/compute/insert_network.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/delete_firewall.rb,
lib/fog/google/requests/compute/delete_snapshot.rb,
lib/fog/google/requests/compute/insert_firewall.rb,
lib/fog/google/requests/compute/insert_snapshot.rb,
lib/fog/google/requests/compute/get_machine_type.rb,
lib/fog/google/requests/compute/get_zone_operation.rb,
lib/fog/google/requests/compute/list_machine_types.rb,
lib/fog/google/requests/compute/get_global_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/list_global_operations.rb,
lib/fog/google/requests/compute/delete_global_operation.rb
Instance Attribute Summary collapse
Attributes included from Shared
#api_version, #project
Instance Method Summary
collapse
-
#attach_disk(instance, zone, deviceName) ⇒ Object
-
#build_response(result) ⇒ Object
result = Google::APIClient::Result returns Excon::Response.
-
#build_result(api_method, parameters, body_object = nil) ⇒ Object
-
#delete_address(address_name, region_name) ⇒ Object
-
#delete_disk(disk_name, zone_name) ⇒ Object
-
#delete_firewall(firewall_name) ⇒ Object
-
#delete_global_operation(operation) ⇒ Object
-
#delete_image(image_name) ⇒ Object
-
#delete_network(network_name) ⇒ Object
-
#delete_server(server_name, zone_name = nil) ⇒ Object
-
#delete_snapshot(snapshot_name, zone_name) ⇒ Object
-
#delete_zone_operation(zone_name, operation) ⇒ Object
-
#detach_disk(instance, zone, deviceName) ⇒ Object
-
#format_metadata(metadata) ⇒ Object
-
#get_address(address_name, region_name) ⇒ Object
-
#get_disk(disk_name, zone_name) ⇒ Object
-
#get_firewall(firewall_name) ⇒ Object
-
#get_global_operation(operation) ⇒ Object
-
#get_image(image_name, project = @project) ⇒ Object
-
#get_machine_type(machine_type_name, zone_name = nil) ⇒ Object
-
#get_network(network_name) ⇒ Object
-
#get_server(server_name, zone_name) ⇒ Object
-
#get_snapshot(snap_name, project = @project) ⇒ Object
-
#get_zone(zone_name) ⇒ Object
-
#get_zone_operation(zone_name, operation) ⇒ Object
-
#handle_disks(options) ⇒ Object
-
#initialize(options) ⇒ Real
constructor
-
#insert_address(address_name, region_name) ⇒ Object
-
#insert_disk(disk_name, zone_name, image_name = nil, opts = {}) ⇒ Object
-
#insert_firewall(firewall_name, source_range = [], allowed = [], network = @default_network, source_tags = []) ⇒ Object
-
#insert_image(image_name, options = {}) ⇒ Object
-
#insert_network(network_name, ip_range) ⇒ Object
-
#insert_server(server_name, zone_name, options = {}, *deprecated_args) ⇒ Object
-
#insert_snapshot(disk_name, zone_name, project = @project, opts = {}) ⇒ Object
-
#list_addresses(region_name) ⇒ Object
-
#list_disks(zone_name) ⇒ Object
-
#list_firewalls ⇒ Object
-
#list_global_operations ⇒ Object
-
#list_images(project = nil) ⇒ Object
-
#list_machine_types(zone_name) ⇒ Object
-
#list_networks ⇒ Object
-
#list_servers(zone_name) ⇒ Object
-
#list_snapshots(project = nil) ⇒ Object
-
#list_zone_operations(zone) ⇒ Object
-
#list_zones ⇒ Object
-
#set_metadata(instance, zone, metadata = {}) ⇒ Object
-
#set_tags(instance, zone, tags = []) ⇒ Object
Methods included from Shared
#backoff_if_unfound, #build_excon_response, #find_zone, #shared_initialize
Constructor Details
#initialize(options) ⇒ Real
Returns a new instance of Real.
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
|
# File 'lib/fog/google/compute.rb', line 846
def initialize(options)
base_url = 'https://www.googleapis.com/compute/'
api_scope_url = 'https://www.googleapis.com/auth/compute'
shared_initialize(options)
google_client_email = options[:google_client_email]
@api_url = base_url + api_version + '/projects/'
begin
require 'google/api_client'
rescue LoadError => e
Fog::Logger.warning("Please install the google-api-client gem before using this provider.")
throw e
end
key = ::Google::APIClient::KeyUtils.load_from_pkcs12(File.expand_path(options[:google_key_location]), 'notasecret')
@client = ::Google::APIClient.new({
:application_name => "fog",
:application_version => Fog::VERSION,
})
@client.authorization = Signet::OAuth2::Client.new({
:audience => 'https://accounts.google.com/o/oauth2/token',
:auth_provider_x509_cert_url => "https://www.googleapis.com/oauth2/v1/certs",
:client_x509_cert_url => "https://www.googleapis.com/robot/v1/metadata/x509/#{google_client_email}",
:issuer => google_client_email,
:scope => api_scope_url,
:signing_key => key,
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
})
@client.authorization.fetch_access_token!
@compute = @client.discovered_api('compute', api_version)
@default_network = 'default'
end
|
Instance Attribute Details
#api_url ⇒ Object
Returns the value of attribute api_url.
844
845
846
|
# File 'lib/fog/google/compute.rb', line 844
def api_url
@api_url
end
|
#client ⇒ Object
Returns the value of attribute client.
844
845
846
|
# File 'lib/fog/google/compute.rb', line 844
def client
@client
end
|
#compute ⇒ Object
Returns the value of attribute compute.
844
845
846
|
# File 'lib/fog/google/compute.rb', line 844
def compute
@compute
end
|
Instance Method Details
#attach_disk(instance, zone, deviceName) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/google/requests/compute/attach_disk.rb', line 13
def attach_disk(instance, zone, deviceName)
api_method = @compute.instances.attach_disk
parameters = {
'project' => @project,
'instance' => instance,
'zone' => zone
}
body_object = {
"deviceName" => deviceName
}
result = self.build_result(api_method, parameters, body_object=body_object)
response = self.build_response(result)
end
|
#build_response(result) ⇒ Object
result = Google::APIClient::Result returns Excon::Response
900
901
902
|
# File 'lib/fog/google/compute.rb', line 900
def build_response(result)
build_excon_response(result.body.nil? ? nil : Fog::JSON.decode(result.body), result.status)
end
|
#build_result(api_method, parameters, body_object = nil) ⇒ Object
883
884
885
886
887
888
889
890
891
892
893
894
895
896
|
# File 'lib/fog/google/compute.rb', line 883
def build_result(api_method, parameters, body_object=nil)
if body_object
result = @client.execute(
:api_method => api_method,
:parameters => parameters,
:body_object => body_object
)
else
result = @client.execute(
:api_method => api_method,
:parameters => parameters
)
end
end
|
#delete_address(address_name, region_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/google/requests/compute/delete_address.rb', line 15
def delete_address(address_name, region_name)
api_method = @compute.addresses.delete
parameters = {
'project' => @project,
'address' => address_name,
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_disk(disk_name, zone_name) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/fog/google/requests/compute/delete_disk.rb', line 35
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
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_firewall(firewall_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/delete_firewall.rb', line 15
def delete_firewall(firewall_name)
api_method = @compute.firewalls.delete
parameters = {
'project' => @project,
'firewall' => firewall_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_global_operation(operation) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/google/requests/compute/delete_global_operation.rb', line 16
def delete_global_operation(operation)
api_method = @compute.global_operations.delete
parameters = {
'project' => @project,
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_image(image_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/delete_image.rb', line 15
def delete_image(image_name)
api_method = @compute.images.delete
parameters = {
'project' => @project,
'image' => image_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_network(network_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/delete_network.rb', line 15
def delete_network(network_name)
api_method = @compute.networks.delete
parameters = {
'project' => @project,
'network' => network_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_server(server_name, zone_name = nil) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/fog/google/requests/compute/delete_server.rb', line 57
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
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_snapshot(snapshot_name, zone_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/google/requests/compute/delete_snapshot.rb', line 15
def delete_snapshot(snapshot_name, zone_name)
if zone_name.start_with? 'http'
zone_name = zone_name.split('/')[-1]
end
api_method = @compute.snapshots.delete
parameters = {
'project' => @project,
'snapshot' => snapshot_name,
'zone' => zone_name,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#delete_zone_operation(zone_name, operation) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/google/requests/compute/delete_zone_operation.rb', line 16
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
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#detach_disk(instance, zone, deviceName) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/google/requests/compute/detach_disk.rb', line 13
def detach_disk(instance, zone, deviceName)
api_method = @compute.instances.detach_disk
parameters = {
'project' => @project,
'instance' => instance,
'zone' => zone,
}
body_object = { "deviceName" => deviceName }
result = self.build_result(api_method, parameters, body_object=body_object)
response = self.build_response(result)
end
|
116
117
118
|
# File 'lib/fog/google/requests/compute/insert_server.rb', line 116
def format_metadata(metadata)
{ "items" => metadata.map {|k,v| {"key" => k, "value" => v}} }
end
|
#get_address(address_name, region_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/google/requests/compute/get_address.rb', line 15
def get_address(address_name, region_name)
api_method = @compute.addresses.get
parameters = {
'project' => @project,
'address' => address_name,
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_disk(disk_name, zone_name) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/fog/google/requests/compute/get_disk.rb', line 39
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
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_firewall(firewall_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/get_firewall.rb', line 15
def get_firewall(firewall_name)
api_method = @compute.firewalls.get
parameters = {
'project' => @project,
'firewall' => firewall_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_global_operation(operation) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/google/requests/compute/get_global_operation.rb', line 16
def get_global_operation(operation)
api_method = @compute.global_operations.get
parameters = {
'project' => @project,
'operation' => operation
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_image(image_name, project = @project) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fog/google/requests/compute/get_image.rb', line 28
def get_image(image_name, project=@project)
api_method = @compute.images.get
parameters = {
'image' => image_name,
'project' => project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_machine_type(machine_type_name, zone_name = nil) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/fog/google/requests/compute/get_machine_type.rb', line 30
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' => 'google',
'machineType' => machine_type_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_network(network_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/get_network.rb', line 15
def get_network(network_name)
api_method = @compute.networks.get
parameters = {
'project' => @project,
'network' => network_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_server(server_name, zone_name) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/fog/google/requests/compute/get_server.rb', line 60
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
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_snapshot(snap_name, project = @project) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/fog/google/requests/compute/get_snapshot.rb', line 15
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,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_zone(zone_name) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fog/google/requests/compute/get_zone.rb', line 28
def get_zone(zone_name)
api_method = @compute.zones.get
parameters = {
'project' => @project,
'zone' => zone_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#get_zone_operation(zone_name, operation) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/fog/google/requests/compute/get_zone_operation.rb', line 40
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
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#handle_disks(options) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/fog/google/requests/compute/insert_server.rb', line 101
def handle_disks(options)
disks = []
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) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fog/google/requests/compute/insert_address.rb', line 15
def insert_address(address_name, region_name)
api_method = @compute.addresses.insert
parameters = {
'project' => @project,
'region' => region_name,
}
body_object = { 'name' => address_name }
result = self.build_result(api_method, parameters,
body_object=body_object)
response = self.build_response(result)
end
|
#insert_disk(disk_name, zone_name, image_name = nil, opts = {}) ⇒ Object
67
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 67
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
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 }
if image_name.nil?
if opts.has_key?('sourceSnapshot')
snap = snapshots.get(opts.delete('sourceSnapshot'))
raise ArgumentError.new('Invalid source snapshot') unless snap
body_object['sourceSnapshot'] = @api_url + snap.resource_url
elsif opts.has_key?('sizeGb')
body_object['sizeGb'] = opts.delete('sizeGb')
else
raise ArgumentError.new('Must specify image OR snapshot OR '\
'disk size when creating a disk.')
end
end
body_object.merge!(opts)
result = self.build_result(api_method, parameters,
body_object)
response = self.build_response(result)
end
|
#insert_firewall(firewall_name, source_range = [], allowed = [], network = @default_network, source_tags = []) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/google/requests/compute/insert_firewall.rb', line 14
def insert_firewall(firewall_name, source_range=[], allowed=[], network=@default_network, source_tags=[])
api_method = @compute.firewalls.insert
parameters = {
'project' => @project,
}
body_object = {
"name" => firewall_name,
"network" => "#{@api_url}#{@project}/global/networks/#{network}",
"allowed" => allowed,
}
body_object["sourceRanges"] = source_range if !source_range.empty?
body_object["sourceTags"] = source_tags if !source_tags.empty?
result = self.build_result(api_method, parameters, body_object=body_object)
response = self.build_response(result)
end
|
#insert_image(image_name, options = {}) ⇒ Object
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/insert_image.rb', line 15
def insert_image(image_name, options={})
api_method = @compute.images.insert
parameters = {
'project' => @project,
}
body_object = {
'sourceType' => 'RAW',
'name' => image_name,
'rawDisk' => options.delete('rawDisk')
}
body_object.merge!(options)
result = self.build_result(api_method,
parameters,
body_object=body_object)
response = self.build_response(result)
end
|
#insert_network(network_name, ip_range) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/fog/google/requests/compute/insert_network.rb', line 15
def insert_network(network_name, ip_range)
api_method = @compute.networks.insert
parameters = {
'project' => @project,
}
body_object = {
'name' => network_name,
'IPv4Range' => ip_range
}
result = self.build_result(api_method, parameters,
body_object=body_object)
response = self.build_response(result)
end
|
#insert_server(server_name, zone_name, options = {}, *deprecated_args) ⇒ Object
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
|
# File 'lib/fog/google/requests/compute/insert_server.rb', line 120
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.has_key? 'network'
network = options.delete 'network'
elsif @default_network
network = @default_network
end
access_config = {'type' => 'ONE_TO_ONE_NAT', 'name' => 'External NAT'}
if options.has_key? 'externalIp'
access_config['natIP'] = options.delete 'externalIp'
end
networkInterfaces = []
if ! network.nil?
networkInterface = { 'network' => @api_url + @project + "/global/networks/#{network}" }
networkInterface['accessConfigs'] = [access_config]
networkInterfaces << networkInterface
end
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'] = format_metadata options['metadata'] if options['metadata']
body_object['tags'] = { 'items' => options.delete('tags') } if options['tags']
body_object.merge!(options)
result = self.build_result(api_method, parameters,
body_object=body_object)
response = self.build_response(result)
end
|
#insert_snapshot(disk_name, zone_name, project = @project, opts = {}) ⇒ Object
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
40
41
42
43
|
# File 'lib/fog/google/requests/compute/insert_snapshot.rb', line 15
def insert_snapshot(disk_name, zone_name, project=@project, opts={})
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 }
body_object.merge(opts)
result = self.build_result(api_method, parameters,
body_object)
response = self.build_response(result)
end
|
#list_addresses(region_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/list_addresses.rb', line 15
def list_addresses(region_name)
api_method = @compute.addresses.list
parameters = {
'project' => @project,
'region' => region_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_disks(zone_name) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fog/google/requests/compute/list_disks.rb', line 21
def list_disks(zone_name)
api_method = @compute.disks.list
parameters = {
'project' => @project,
'zone' => zone_name
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_firewalls ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/google/requests/compute/list_firewalls.rb', line 15
def list_firewalls
api_method = @compute.firewalls.list
parameters = {
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_global_operations ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/list_global_operations.rb', line 16
def list_global_operations
api_method = @compute.global_operations.list
parameters = {
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_images(project = nil) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fog/google/requests/compute/list_images.rb', line 21
def list_images(project=nil)
api_method = @compute.images.list
project=@project if project.nil?
parameters = {
'project' => project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_machine_types(zone_name) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/fog/google/requests/compute/list_machine_types.rb', line 22
def list_machine_types(zone_name)
api_method = @compute.machine_types.list
parameters = {
'project' => @project,
'zone' => zone_name,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_networks ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/google/requests/compute/list_networks.rb', line 15
def list_networks
api_method = @compute.networks.list
parameters = {
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_servers(zone_name) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/fog/google/requests/compute/list_servers.rb', line 23
def list_servers(zone_name)
api_method = @compute.instances.list
parameters = {
'project' => @project,
'zone' => zone_name,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_snapshots(project = nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/google/requests/compute/list_snapshots.rb', line 15
def list_snapshots(project=nil)
api_method = @compute.snapshots.list
project=@project if project.nil?
parameters = {
'project' => project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_zone_operations(zone) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/google/requests/compute/list_zone_operations.rb', line 16
def list_zone_operations(zone)
api_method = @compute.zone_operations.list
parameters = {
'zone' => zone,
'project' => @project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
#list_zones ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/google/requests/compute/list_zones.rb', line 21
def list_zones
api_method = @compute.zones.list
parameters = {
'project' => @project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/fog/google/requests/compute/set_metadata.rb', line 15
def set_metadata(instance, zone, metadata={})
api_method = @compute.instances.set_metadata
parameters = {
'project' => @project,
'instance' => instance,
'zone' => zone
}
body_object = {
"items" => metadata.to_a.map {|pair| { :key => pair[0], :value => pair[1] } }
}
result = self.build_result(
api_method,
parameters,
body_object=body_object
)
response = self.build_response(result)
end
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/google/requests/compute/set_tags.rb', line 15
def set_tags(instance, zone, tags=[])
api_method = @compute.instances.set_tags
parameters = {
'project' => @project,
'instance' => instance,
'zone' => zone
}
body_object = { "items" => tags }
result = self.build_result(
api_method,
parameters,
body_object=body_object
)
response = self.build_response(result)
end
|