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

[slicehost][compute] get first pass of bootstrap working

This commit is contained in:
geemus 2010-09-27 20:38:17 -07:00
parent 9de9069433
commit 99ba20f411
3 changed files with 52 additions and 3 deletions

View file

@ -18,8 +18,8 @@ module Fog
attribute :progress
attribute :status
attr_accessor :password, :username
attr_writer :private_key, :private_key_path, :public_key, :public_key_path
attr_reader :password
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
def initialize(attributes={})
@flavor_id ||= 1

View file

@ -15,10 +15,13 @@ module Fog
attribute :flavor_id, :aliases => 'flavor-id'
attribute :image_id, :aliases => 'image-id'
attribute :name
attribute :password, :aliases => 'root-password'
attribute :progress
attribute :status
attr_accessor :password
alias_method :'root-password=', :password=
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
def initialize(attributes={})
@flavor_id ||= 1
super
@ -40,6 +43,22 @@ module Fog
connection.images.get(@image_id)
end
def private_key_path
File.expand_path(@private_key_path ||= Fog.credentials[:private_key_path])
end
def private_key
@private_key ||= File.read(private_key_path)
end
def public_key_path
File.expand_path(@public_key_path ||= Fog.credentials[:public_key_path])
end
def public_key
@public_key ||= File.read(public_key_path)
end
def ready?
@status == 'active'
end
@ -57,6 +76,29 @@ module Fog
true
end
def setup(credentials = {})
requires :addresses, :identity, :public_key, :username
Fog::SSH.new(addresses.first, username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
%{passwd -l root},
%{echo "#{attributes.to_json}" >> ~/attributes.json}
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
def ssh(commands)
requires :addresses, :identity, :private_key, :username
@ssh ||= Fog::SSH.new(addresses.first, username, :key_data => [private_key])
@ssh.run(commands)
end
def username
@username ||= 'root'
end
end
end

View file

@ -14,6 +14,13 @@ module Fog
load(data)
end
def bootstrap(new_attributes = {})
server = create(new_attributes)
server.wait_for { ready? }
server.setup(:password => server.password)
server
end
def get(server_id)
if server_id && server = connection.get_slice(server_id).body
new(server)