mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] exploring bootstrapping
This commit is contained in:
parent
936cfc0e95
commit
72ef919413
5 changed files with 47 additions and 3 deletions
|
@ -34,6 +34,8 @@ module Fog
|
|||
:bluebox_api_key: INTENTIONALLY_LEFT_BLANK
|
||||
:bluebox_customer_id: INTENTIONALLY_LEFT_BLANK
|
||||
:local_root: INTENTIONALLY_LEFT_BLANK
|
||||
:public_key_path: INTENTIONALLY_LEFT_BLANK
|
||||
:private_key_path: INTENTIONALLY_LEFT_BLANK
|
||||
:rackspace_api_key: INTENTIONALLY_LEFT_BLANK
|
||||
:rackspace_username: INTENTIONALLY_LEFT_BLANK
|
||||
:slicehost_password: INTENTIONALLY_LEFT_BLANK
|
||||
|
|
|
@ -9,7 +9,6 @@ module Fog
|
|||
identity :id
|
||||
|
||||
attribute :addresses
|
||||
attribute :password, 'adminPass'
|
||||
attribute :flavor_id, 'flavorId'
|
||||
attribute :host_id, 'hostId'
|
||||
attribute :image_id, 'imageId'
|
||||
|
@ -19,6 +18,8 @@ module Fog
|
|||
attribute :progress
|
||||
attribute :status
|
||||
|
||||
attr_accessor :password, :private_key_path, :public_key_path
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_server(@id)
|
||||
|
@ -50,6 +51,14 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def private_key_path
|
||||
@private_key_path || Fog.credentials[:private_key_path]
|
||||
end
|
||||
|
||||
def public_key_path
|
||||
@public_key_path || Fog.credentials[:public_key_path]
|
||||
end
|
||||
|
||||
def save
|
||||
requires :flavor_id, :image_id
|
||||
options = {
|
||||
|
@ -63,8 +72,35 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def ssh(commands)
|
||||
requires :addresses, :identity, :private_key_path
|
||||
@ssh ||= Fog::SSH.new(@addresses['public'].first, 'root', :keys => [private_key_path])
|
||||
@ssh.run(commands)
|
||||
end
|
||||
|
||||
def setup
|
||||
requires :addresses, :identity, :password, :public_key_path
|
||||
Fog::SSH.new(@addresses['public'].first, 'root', :password => password).run([
|
||||
%{mkdir .ssh},
|
||||
%{echo "#{File.read(File.expand_path(public_key_path))}" >> ~/.ssh/authorized_keys},
|
||||
%{passwd -l root},
|
||||
%{echo "#{attributes.to_json}" >> ~/attributes.json},
|
||||
%{echo "#{metadata.to_json}" >> ~/metadata.json}
|
||||
])
|
||||
rescue Errno::ECONNREFUSED
|
||||
sleep(1)
|
||||
retry
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def adminPass=(new_admin_pass)
|
||||
@password = new_admin_pass
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,6 +20,13 @@ module Fog
|
|||
load(data)
|
||||
end
|
||||
|
||||
def bootstrap(new_attributes = {})
|
||||
server = create(new_attributes)
|
||||
server.wait_for { ready? }
|
||||
server.setup
|
||||
server
|
||||
end
|
||||
|
||||
def get(server_id)
|
||||
if server = connection.get_server_details(server_id).body['server']
|
||||
new(server)
|
||||
|
|
|
@ -77,7 +77,6 @@ module Fog
|
|||
|
||||
def request(params)
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
|
||||
begin
|
||||
response = @connection.request(params.merge!({
|
||||
:headers => {
|
||||
|
|
|
@ -54,7 +54,7 @@ module Fog
|
|||
sudoable_command = command.sub(/^sudo/, %{sudo -p 'fog sudo password:'})
|
||||
escaped_command = sudoable_command.sub(/'/, %{'"'"'})
|
||||
channel.request_pty
|
||||
result = Result.new(command)
|
||||
result = Result.new(escaped_command)
|
||||
channel.exec(%{bash -lc '#{escaped_command}'}) do |channel, success|
|
||||
unless success
|
||||
raise "Could not execute command: #{command.inspect}"
|
||||
|
|
Loading…
Reference in a new issue