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
|
@bin = new_bin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.credentials
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
def self.mock!
|
def self.mock!
|
||||||
@mocking = true
|
@mocking = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -104,20 +104,23 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def private_key_path
|
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
|
end
|
||||||
|
|
||||||
def private_key
|
def private_key
|
||||||
@private_key ||= File.read(private_key_path)
|
@private_key ||= private_key_path && File.read(private_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def public_key_path
|
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
|
end
|
||||||
|
|
||||||
def public_key
|
def public_key
|
||||||
@public_key ||= File.read(public_key_path)
|
@public_key ||= public_key_path && File.read(public_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?
|
def ready?
|
||||||
@state == 'running'
|
@state == 'running'
|
||||||
end
|
end
|
||||||
|
@ -161,14 +164,17 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup(credentials = {})
|
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
|
sleep(10) # takes a bit before EC2 instances will play nice
|
||||||
Fog::SSH.new(ip_address, username, credentials).run([
|
commands = [
|
||||||
%{mkdir .ssh},
|
%{mkdir .ssh},
|
||||||
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
|
|
||||||
%{passwd -l root},
|
%{passwd -l root},
|
||||||
%{echo "#{attributes.to_json}" >> ~/attributes.json}
|
%{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
|
rescue Errno::ECONNREFUSED => e
|
||||||
sleep(1)
|
sleep(1)
|
||||||
retry
|
retry
|
||||||
|
|
|
@ -37,13 +37,15 @@ module Fog
|
||||||
def bootstrap(new_attributes = {})
|
def bootstrap(new_attributes = {})
|
||||||
server = connection.servers.new(new_attributes)
|
server = connection.servers.new(new_attributes)
|
||||||
|
|
||||||
# first or create fog_#{credential} keypair
|
unless new_attributes[:key_name]
|
||||||
unless server.key_pair = connection.key_pairs.get("fog_#{Fog.credential}")
|
# first or create fog_#{credential} keypair
|
||||||
name = Fog.respond_to?(:credential) && Fog.credential || :default
|
name = Fog.respond_to?(:credential) && Fog.credential || :default
|
||||||
server.key_pair = connection.key_pairs.create(
|
unless server.key_pair = connection.key_pairs.get("fog_#{name}")
|
||||||
:name => "fog_#{name}",
|
server.key_pair = connection.key_pairs.create(
|
||||||
:public_key => server.public_key
|
:name => "fog_#{name}",
|
||||||
)
|
:public_key => server.public_key
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# make sure port 22 is open in the first security group
|
# make sure port 22 is open in the first security group
|
||||||
|
|
|
@ -51,19 +51,21 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def private_key_path
|
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
|
end
|
||||||
|
|
||||||
def private_key
|
def private_key
|
||||||
@private_key ||= File.read(private_key_path)
|
@private_key ||= private_key_path && File.read(private_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def public_key_path
|
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
|
end
|
||||||
|
|
||||||
def public_key
|
def public_key
|
||||||
@public_key ||= File.read(public_key_path)
|
@public_key ||= public_key_path && File.read(public_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?
|
def ready?
|
||||||
|
|
|
@ -15,6 +15,7 @@ module Fog
|
||||||
ENV["FOG_RC"] || '~/.fog'
|
ENV["FOG_RC"] || '~/.fog'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
remove_method :credentials
|
||||||
def credentials
|
def credentials
|
||||||
@credentials ||= begin
|
@credentials ||= begin
|
||||||
path = File.expand_path(config_path)
|
path = File.expand_path(config_path)
|
||||||
|
|
|
@ -48,19 +48,21 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def private_key_path
|
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
|
end
|
||||||
|
|
||||||
def private_key
|
def private_key
|
||||||
@private_key ||= File.read(private_key_path)
|
@private_key ||= private_key_path && File.read(private_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def public_key_path
|
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
|
end
|
||||||
|
|
||||||
def public_key
|
def public_key
|
||||||
@public_key ||= File.read(public_key_path)
|
@public_key ||= public_key_path && File.read(public_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?
|
def ready?
|
||||||
|
|
|
@ -44,19 +44,21 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def private_key_path
|
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
|
end
|
||||||
|
|
||||||
def private_key
|
def private_key
|
||||||
@private_key ||= File.read(private_key_path)
|
@private_key ||= private_key_path && File.read(private_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def public_key_path
|
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
|
end
|
||||||
|
|
||||||
def public_key
|
def public_key
|
||||||
@public_key ||= File.read(public_key_path)
|
@public_key ||= public_key_path && File.read(public_key_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ready?
|
def ready?
|
||||||
|
|
Loading…
Add table
Reference in a new issue