1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

add set_metadata to upload ssh keys

This commit is contained in:
Nat Welch 2013-04-30 18:11:22 -07:00
parent e282de66b1
commit 1220c8989b
4 changed files with 48 additions and 6 deletions

View file

@ -13,6 +13,7 @@ module Fog
attribute :state, :aliases => 'status'
attribute :zone_name, :aliases => 'zone'
attribute :machine_type, :aliases => 'machineType'
attribute :metadata
def destroy
requires :name
@ -59,11 +60,8 @@ module Fog
end
def setup(credentials = {})
requires :public_ip_address, :identity, :public_key, :username
Fog::SSH.new(public_ip_address, username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
])
requires :public_ip_address, :public_key, :username
service.set_metadata(self.instance, self.zone, {'sshKeys' => self.public_key })
rescue Errno::ECONNREFUSED
sleep(1)
retry

View file

@ -4,7 +4,7 @@ module Fog
class Mock
def insert_network(network_name)
def insert_network(network_name, ip_range)
Fog::Mock.not_implemented
end

View file

@ -0,0 +1,36 @@
module Fog
module Compute
class Google
class Mock
def set_metadata(instance, zone, metadata={})
Fog::Mock.not_implemented
end
end
class Real
def set_metadata(instance, zone, metadata={})
api_method = @compute.instance.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
end
end
end
end

View file

@ -7,6 +7,14 @@ Shindo.tests("Fog::Compute[:google] | server model", ['google']) do
@instance.ready?
end
test('#sshable?') do
@instance.sshable?
end
test('#ssh') do
@instance.ssh("uname") == "Linux"
end
test('#destroy') do
response = @instance.destroy
response.body['operationType'] == 'delete'