From 01241dca930dc17e16022e70fd60568b1495362e Mon Sep 17 00:00:00 2001 From: sashap Date: Thu, 1 Nov 2012 13:24:43 -0700 Subject: [PATCH] Adding bootstrap and setup for RackspaceV2 servers --- lib/fog/rackspace/models/compute_v2/server.rb | 14 ++++++++++++++ lib/fog/rackspace/models/compute_v2/servers.rb | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/fog/rackspace/models/compute_v2/server.rb b/lib/fog/rackspace/models/compute_v2/server.rb index 3307259c6..8f2ef91c5 100644 --- a/lib/fog/rackspace/models/compute_v2/server.rb +++ b/lib/fog/rackspace/models/compute_v2/server.rb @@ -145,6 +145,20 @@ module Fog @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 diff --git a/lib/fog/rackspace/models/compute_v2/servers.rb b/lib/fog/rackspace/models/compute_v2/servers.rb index b1bd69eb2..ad4288e45 100644 --- a/lib/fog/rackspace/models/compute_v2/servers.rb +++ b/lib/fog/rackspace/models/compute_v2/servers.rb @@ -4,6 +4,7 @@ require 'fog/rackspace/models/compute_v2/server' module Fog module Compute class RackspaceV2 + class Servers < Fog::Collection model Fog::Compute::RackspaceV2::Server @@ -13,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) data = connection.get_server(server_id).body['server'] new(data)