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'
|
||||
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)
|
||||
if body_object
|
||||
result = @client.execute(
|
||||
|
|
|
@ -67,6 +67,23 @@ module Fog
|
|||
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
|
||||
data = service.get_server(self.name, self.zone).body
|
||||
self.merge_attributes(data)
|
||||
|
@ -77,13 +94,11 @@ module Fog
|
|||
requires :machine_type
|
||||
requires :zone_name
|
||||
|
||||
if self.metadata.nil?
|
||||
self.metadata = {}
|
||||
if not service.zones.include? self.zone_name
|
||||
raise ArgumentError.new "#{self.zone_name.inspect} is either down or you don't have permission to use it."
|
||||
end
|
||||
|
||||
self.metadata.merge!({
|
||||
"sshKeys" => "#{username}:#{public_key.strip}"
|
||||
}) if public_key
|
||||
self.add_ssh_key(self.username, self.public_key) if self.public_key
|
||||
|
||||
options = {
|
||||
'image' => image_name,
|
||||
|
@ -94,10 +109,11 @@ module Fog
|
|||
'disks' => disks,
|
||||
'kernel' => kernel,
|
||||
'metadata' => metadata
|
||||
}
|
||||
options.delete_if {|key, value| value.nil?}
|
||||
}.delete_if {|key, value| value.nil?}
|
||||
|
||||
service.insert_server(name, zone_name, options)
|
||||
data = service.backoff_if_unfound {service.get_server(self.name, self.zone_name).body}
|
||||
|
||||
service.servers.merge_attributes(data)
|
||||
end
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ module Fog
|
|||
:name => "fog-#{Time.now.to_i}",
|
||||
:image_name => "debian-7-wheezy-v20130617",
|
||||
:machine_type => "n1-standard-1",
|
||||
:zone_name => "us-central1-a",
|
||||
:zone_name => "us-central1-b",
|
||||
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
|
||||
:public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
|
||||
:username => ENV['USER'],
|
||||
|
|
Loading…
Add table
Reference in a new issue