mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
fixes to make bootstrap play nicer, especially outside the bin/fog context
This commit is contained in:
parent
398d9bc400
commit
4c8c25f361
7 changed files with 45 additions and 26 deletions
|
@ -52,6 +52,10 @@ module Fog
|
|||
@bin = new_bin
|
||||
end
|
||||
|
||||
def self.credentials
|
||||
{}
|
||||
end
|
||||
|
||||
def self.mock!
|
||||
@mocking = true
|
||||
end
|
||||
|
|
|
@ -104,20 +104,23 @@ module Fog
|
|||
end
|
||||
|
||||
def private_key_path
|
||||
File.expand_path(@private_key_path ||= Fog.credentials[:private_key_path])
|
||||
@private_key_path ||= Fog.credentials[:private_key_path]
|
||||
@private_key_path &&= File.expand_path(@private_key_path)
|
||||
end
|
||||
|
||||
def private_key
|
||||
@private_key ||= File.read(private_key_path)
|
||||
@private_key ||= private_key_path && File.read(private_key_path)
|
||||
end
|
||||
|
||||
def public_key_path
|
||||
File.expand_path(@public_key_path ||= Fog.credentials[:public_key_path])
|
||||
@public_key_path ||= Fog.credentials[:public_key_path]
|
||||
@public_key_path &&= File.expand_path(@public_key_path)
|
||||
end
|
||||
|
||||
def public_key
|
||||
@public_key ||= File.read(public_key_path)
|
||||
@public_key ||= public_key_path && File.read(public_key_path)
|
||||
end
|
||||
|
||||
def ready?
|
||||
@state == 'running'
|
||||
end
|
||||
|
@ -161,14 +164,17 @@ module Fog
|
|||
end
|
||||
|
||||
def setup(credentials = {})
|
||||
requires :identity, :ip_address, :public_key, :username
|
||||
requires :identity, :ip_address, :username
|
||||
sleep(10) # takes a bit before EC2 instances will play nice
|
||||
Fog::SSH.new(ip_address, username, credentials).run([
|
||||
commands = [
|
||||
%{mkdir .ssh},
|
||||
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
|
||||
%{passwd -l root},
|
||||
%{echo "#{attributes.to_json}" >> ~/attributes.json}
|
||||
])
|
||||
]
|
||||
if public_key
|
||||
commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys}
|
||||
end
|
||||
Fog::SSH.new(ip_address, username, credentials).run(commands)
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
sleep(1)
|
||||
retry
|
||||
|
|
|
@ -37,13 +37,15 @@ module Fog
|
|||
def bootstrap(new_attributes = {})
|
||||
server = connection.servers.new(new_attributes)
|
||||
|
||||
# first or create fog_#{credential} keypair
|
||||
unless server.key_pair = connection.key_pairs.get("fog_#{Fog.credential}")
|
||||
unless new_attributes[:key_name]
|
||||
# first or create fog_#{credential} keypair
|
||||
name = Fog.respond_to?(:credential) && Fog.credential || :default
|
||||
server.key_pair = connection.key_pairs.create(
|
||||
:name => "fog_#{name}",
|
||||
:public_key => server.public_key
|
||||
)
|
||||
unless server.key_pair = connection.key_pairs.get("fog_#{name}")
|
||||
server.key_pair = connection.key_pairs.create(
|
||||
:name => "fog_#{name}",
|
||||
:public_key => server.public_key
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# make sure port 22 is open in the first security group
|
||||
|
|
|
@ -51,19 +51,21 @@ module Fog
|
|||
end
|
||||
|
||||
def private_key_path
|
||||
File.expand_path(@private_key_path ||= Fog.credentials[:private_key_path])
|
||||
@private_key_path ||= Fog.credentials[:private_key_path]
|
||||
@private_key_path &&= File.expand_path(@private_key_path)
|
||||
end
|
||||
|
||||
def private_key
|
||||
@private_key ||= File.read(private_key_path)
|
||||
@private_key ||= private_key_path && File.read(private_key_path)
|
||||
end
|
||||
|
||||
def public_key_path
|
||||
File.expand_path(@public_key_path ||= Fog.credentials[:public_key_path])
|
||||
@public_key_path ||= Fog.credentials[:public_key_path]
|
||||
@public_key_path &&= File.expand_path(@public_key_path)
|
||||
end
|
||||
|
||||
def public_key
|
||||
@public_key ||= File.read(public_key_path)
|
||||
@public_key ||= public_key_path && File.read(public_key_path)
|
||||
end
|
||||
|
||||
def ready?
|
||||
|
|
|
@ -15,6 +15,7 @@ module Fog
|
|||
ENV["FOG_RC"] || '~/.fog'
|
||||
end
|
||||
|
||||
remove_method :credentials
|
||||
def credentials
|
||||
@credentials ||= begin
|
||||
path = File.expand_path(config_path)
|
||||
|
|
|
@ -48,19 +48,21 @@ module Fog
|
|||
end
|
||||
|
||||
def private_key_path
|
||||
File.expand_path(@private_key_path ||= Fog.credentials[:private_key_path])
|
||||
@private_key_path ||= Fog.credentials[:private_key_path]
|
||||
@private_key_path &&= File.expand_path(@private_key_path)
|
||||
end
|
||||
|
||||
def private_key
|
||||
@private_key ||= File.read(private_key_path)
|
||||
@private_key ||= private_key_path && File.read(private_key_path)
|
||||
end
|
||||
|
||||
def public_key_path
|
||||
File.expand_path(@public_key_path ||= Fog.credentials[:public_key_path])
|
||||
@public_key_path ||= Fog.credentials[:public_key_path]
|
||||
@public_key_path &&= File.expand_path(@public_key_path)
|
||||
end
|
||||
|
||||
def public_key
|
||||
@public_key ||= File.read(public_key_path)
|
||||
@public_key ||= public_key_path && File.read(public_key_path)
|
||||
end
|
||||
|
||||
def ready?
|
||||
|
|
|
@ -44,19 +44,21 @@ module Fog
|
|||
end
|
||||
|
||||
def private_key_path
|
||||
File.expand_path(@private_key_path ||= Fog.credentials[:private_key_path])
|
||||
@private_key_path ||= Fog.credentials[:private_key_path]
|
||||
@private_key_path &&= File.expand_path(@private_key_path)
|
||||
end
|
||||
|
||||
def private_key
|
||||
@private_key ||= File.read(private_key_path)
|
||||
@private_key ||= private_key_path && File.read(private_key_path)
|
||||
end
|
||||
|
||||
def public_key_path
|
||||
File.expand_path(@public_key_path ||= Fog.credentials[:public_key_path])
|
||||
@public_key_path ||= Fog.credentials[:public_key_path]
|
||||
@public_key_path &&= File.expand_path(@public_key_path)
|
||||
end
|
||||
|
||||
def public_key
|
||||
@public_key ||= File.read(public_key_path)
|
||||
@public_key ||= public_key_path && File.read(public_key_path)
|
||||
end
|
||||
|
||||
def ready?
|
||||
|
|
Loading…
Add table
Reference in a new issue