1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/google/requests/compute/set_metadata.rb
Ferran Rodenas 3ebe34c280 [google|compute] Refactor Compute to use the new Shared module
Commit d801b27 introduced a new Shared module with logic to initialize
a google_client_api and to make requests.

This commit refactors Compute to use the new Shared module.
2014-07-30 12:19:50 -07:00

39 lines
1.3 KiB
Ruby

module Fog
module Compute
class Google
class Mock
def set_metadata(instance, zone, fingerprint, metadata={})
Fog::Mock.not_implemented
end
end
class Real
# 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.metadata['fingerprint']
# * metadata<~Hash> - A new metadata
#
# ==== Returns
# * response<~Excon::Response>
def set_metadata(instance, zone, fingerprint, metadata={})
api_method = @compute.instances.set_metadata
parameters = {
'project' => @project,
'instance' => instance,
'zone' => zone
}
body_object = {
'fingerprint' => fingerprint,
"items" => metadata.to_a.map {|pair| { :key => pair[0], :value => pair[1] } }
}
request(api_method, parameters, body_object=body_object)
end
end
end
end
end