mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2089 from icco/multiple-ssh-keys
[google|compute] Fix a bug when dealing with multiple ssh keys
This commit is contained in:
commit
901f70c525
3 changed files with 36 additions and 8 deletions
|
@ -112,6 +112,18 @@ module Fog
|
||||||
@default_network = 'default'
|
@default_network = 'default'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: Total hack, create zone and zones model.
|
||||||
|
def zones
|
||||||
|
zones = []
|
||||||
|
self.list_zones.data[:body]["items"].each do |z|
|
||||||
|
if z["status"] == "UP"
|
||||||
|
zones.push z["name"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return zones
|
||||||
|
end
|
||||||
|
|
||||||
def build_result(api_method, parameters, body_object=nil)
|
def build_result(api_method, parameters, body_object=nil)
|
||||||
if body_object
|
if body_object
|
||||||
result = @client.execute(
|
result = @client.execute(
|
||||||
|
|
|
@ -67,6 +67,23 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_ssh_key username, key
|
||||||
|
if self.metadata.nil?
|
||||||
|
self.metadata = Hash.new("")
|
||||||
|
end
|
||||||
|
|
||||||
|
# You can have multiple SSH keys, seperated by newlines.
|
||||||
|
# https://developers.google.com/compute/docs/console?hl=en#sshkeys
|
||||||
|
if !self.metadata["sshKeys"].empty?
|
||||||
|
self.metadata["sshKeys"] += "\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
self.metadata["sshKeys"] += "#{username}:#{key.strip}"
|
||||||
|
|
||||||
|
return self.metadata
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def reload
|
def reload
|
||||||
data = service.get_server(self.name, self.zone).body
|
data = service.get_server(self.name, self.zone).body
|
||||||
self.merge_attributes(data)
|
self.merge_attributes(data)
|
||||||
|
@ -77,13 +94,11 @@ module Fog
|
||||||
requires :machine_type
|
requires :machine_type
|
||||||
requires :zone_name
|
requires :zone_name
|
||||||
|
|
||||||
if self.metadata.nil?
|
if not service.zones.include? self.zone_name
|
||||||
self.metadata = {}
|
raise ArgumentError.new "#{self.zone_name.inspect} is either down or you don't have permission to use it."
|
||||||
end
|
end
|
||||||
|
|
||||||
self.metadata.merge!({
|
self.add_ssh_key(self.username, self.public_key) if self.public_key
|
||||||
"sshKeys" => "#{username}:#{public_key.strip}"
|
|
||||||
}) if public_key
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
'image' => image_name,
|
'image' => image_name,
|
||||||
|
@ -94,10 +109,11 @@ module Fog
|
||||||
'disks' => disks,
|
'disks' => disks,
|
||||||
'kernel' => kernel,
|
'kernel' => kernel,
|
||||||
'metadata' => metadata
|
'metadata' => metadata
|
||||||
}
|
}.delete_if {|key, value| value.nil?}
|
||||||
options.delete_if {|key, value| value.nil?}
|
|
||||||
service.insert_server(name, zone_name, options)
|
service.insert_server(name, zone_name, options)
|
||||||
data = service.backoff_if_unfound {service.get_server(self.name, self.zone_name).body}
|
data = service.backoff_if_unfound {service.get_server(self.name, self.zone_name).body}
|
||||||
|
|
||||||
service.servers.merge_attributes(data)
|
service.servers.merge_attributes(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ module Fog
|
||||||
:name => "fog-#{Time.now.to_i}",
|
:name => "fog-#{Time.now.to_i}",
|
||||||
:image_name => "debian-7-wheezy-v20130617",
|
:image_name => "debian-7-wheezy-v20130617",
|
||||||
:machine_type => "n1-standard-1",
|
:machine_type => "n1-standard-1",
|
||||||
:zone_name => "us-central1-a",
|
:zone_name => "us-central1-b",
|
||||||
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
|
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
|
||||||
:public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
|
:public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
|
||||||
:username => ENV['USER'],
|
:username => ENV['USER'],
|
||||||
|
|
Loading…
Add table
Reference in a new issue