Permalink
Browse files

Merge remote-tracking branch 'sashap/master'

Conflicts:
	lib/fog/rackspace/models/compute_v2/servers.rb
  • Loading branch information...
brianhartsock committed Nov 14, 2012
2 parents 794f115 + 01241dc commit 62a111f73da6ddc20ba2779cc7b6c303bcd73e41
Showing with 24 additions and 0 deletions.
  1. +22 −0 lib/fog/rackspace/models/compute_v2/server.rb
  2. +2 −0 lib/fog/rackspace/models/compute_v2/servers.rb
@@ -97,6 +97,14 @@ def attachments
})
end
end
+
+ def private_ip_address
+ addresses['private'].select{|a| a["version"] == 4}[0]["addr"]
+ end
+
+ def public_ip_address
+ ipv4_address
+ end
def ready?
state == ACTIVE
@@ -142,6 +150,20 @@ def change_admin_password(password)
@password = password
true
end
+
+ def setup(credentials = {})
+ requires :public_ip_address, :identity, :public_key, :username
+ Fog::SSH.new(public_ip_address, username, credentials).run([
+ %{mkdir .ssh},
+ %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
+ %{passwd -l #{username}},
+ %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
+ %{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
+ ])
+ rescue Errno::ECONNREFUSED
+ sleep(1)
+ retry
+ end
private
@@ -4,6 +4,7 @@
module Fog
module Compute
class RackspaceV2
+
class Servers < Fog::Collection
model Fog::Compute::RackspaceV2::Server
@@ -16,6 +17,7 @@ def all
def bootstrap(new_attributes = {})
server = create(new_attributes)
server.wait_for { ready? }
+ server.setup(:password => server.password)
server
end

0 comments on commit 62a111f

Please sign in to comment.