Skip to content

Commit

Permalink
Merge pull request #25 from dprince/config_cleanup
Browse files Browse the repository at this point in the history
Configuration cleanup.
  • Loading branch information
Dan Prince committed Jan 8, 2012
2 parents 1c5ec95 + 55e1b09 commit 8d8e313
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
- Upgrade to Rails 3.
- Add support for OpenStack API.
- Remove option to create .rackspace_cloud file on gateway server.
- Rename CC_AUTHORIZED_KEYS to AUTHORIZED_KEYS.
- Rename RACKSPACE_CLOUD_SERVER_NAME_PREFIX to SERVER_NAME_PREFIX.

* Fri Nov 4 2011 Dan Prince <[email protected]> - 2.4.1
- Fix windows image detection code.
Expand Down
26 changes: 8 additions & 18 deletions app/models/linux_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,24 @@ def ping_test(test_ip)

end

# Generates a personalities hash (See Cloud Servers API docs for details)
# Generates a personalities hash suitable for use with bindings
private
def generate_personalities

# server group keys
auth_key_set=Set.new(self.server_group.ssh_public_keys.collect { |x| x.public_key.chomp })
# user keys
auth_key_set.merge(self.server_group.user.ssh_public_keys.collect { |x| x.public_key.chomp })

# add keys from the Server Group (added via XML API)
# new lines
authorized_keys=auth_key_set.inject("") { |sum, key| sum + key + "\n"}

# add any keys from the config files
if not ENV['CC_AUTHORIZED_KEYS'].blank? then
authorized_keys += ENV['CC_AUTHORIZED_KEYS']
# add any keys from the config files
if not ENV['AUTHORIZED_KEYS'].blank? then
authorized_keys += ENV['AUTHORIZED_KEYS']
end

# append the public key from the ServerGroup
# write keys to a file
authorized_keys += IO.read(self.server_group.ssh_key_basepath+".pub")
tmp_auth_keys=Tempfile.new "cs_auth_keys"
tmp_auth_keys.chmod(0600)
Expand All @@ -213,18 +215,6 @@ def generate_personalities
personalities.store(tmp_auth_keys.path, "/root/.ssh/authorized_keys")
personalities.store(File.join(Rails.root, 'config', 'root_ssh_config'), "/root/.ssh/config")

# create a .rackspace_cloud file with username/password info
cloud_key_config=%{
userid: #{ENV['RACKSPACE_CLOUD_USERNAME']}
api_key: #{ENV['RACKSPACE_CLOUD_API_KEY']}
}
tmp_cloud_key=Tempfile.new "cs_cloud_keys"
tmp_cloud_key.chmod(0600)
tmp_cloud_key.write(cloud_key_config)
tmp_cloud_key.flush
@tmp_files << tmp_cloud_key
personalities.store(tmp_cloud_key.path, "/root/.rackspace_cloud")

return personalities

end
Expand Down
8 changes: 5 additions & 3 deletions app/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,18 @@ def create_cloud_server(schedule_client_openvpn=false)

begin
server_name_prefix=""
if not ENV['RACKSPACE_CLOUD_SERVER_NAME_PREFIX'].blank? then
server_name_prefix=ENV['RACKSPACE_CLOUD_SERVER_NAME_PREFIX']
if not ENV['SERVER_NAME_PREFIX'].blank? then
server_name_prefix=ENV['SERVER_NAME_PREFIX']
end

conn = self.account_connection

# Rackspace enforces unique server names. This works around that...
retry_suffix=self.retry_count > 0 ? "#{rand(10)}-#{self.retry_count}" : "#{rand(10)}"
server_id, admin_password = conn.create_server("#{server_name_prefix}#{self.name}-#{self.server_group_id}-#{retry_suffix}", self.image_id, self.flavor_id, generate_personalities)

@tmp_files.each {|f| f.close(true)} #Remove tmp personalities files
#harvest server ID and IP information

self.cloud_server_id_number = server_id
self.admin_password = admin_password if is_windows
save!
Expand Down
7 changes: 2 additions & 5 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
config.assets.debug = true
end

#ENV['RACKSPACE_CLOUD_USERNAME'] = ""
#ENV['RACKSPACE_CLOUD_API_KEY'] = ""

# Optional prefix for cloud server names.
ENV['RACKSPACE_CLOUD_SERVER_NAME_PREFIX'] = ""
ENV['SERVER_NAME_PREFIX'] = ""

# List any authorized ssh public keys that should get installed on the cloud
# servers to provide keyless SSH access.
#ENV['CC_AUTHORIZED_KEYS'] = ""
#ENV['AUTHORIZED_KEYS'] = ""

# Optional EPEL_BASE_URL. Use this option to specify a specific EPEL
# mirror to be used by Redhat/Centos images.
Expand Down
7 changes: 2 additions & 5 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@
config.active_support.deprecation = :notify
end

#ENV['RACKSPACE_CLOUD_USERNAME'] = "test"
#ENV['RACKSPACE_CLOUD_API_KEY'] = "test"

# Optional prefix for cloud server names.
ENV['RACKSPACE_CLOUD_SERVER_NAME_PREFIX'] = ""
ENV['SERVER_NAME_PREFIX'] = ""

# List any authorized ssh public keys that should get installed on the cloud
# servers to provide keyless SSH access.
# ENV['CC_AUTHORIZED_KEYS'] = ""
# ENV['AUTHORIZED_KEYS'] = ""

# Optional EPEL_BASE_URL. Use this option to specify a specific EPEL
# mirror to be used by Redhat/Centos images.
Expand Down
3 changes: 0 additions & 3 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,3 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end

#ENV['RACKSPACE_CLOUD_USERNAME'] = "test"
#ENV['RACKSPACE_CLOUD_API_KEY'] = "test"
10 changes: 5 additions & 5 deletions contrib/runner_scripts/cleanup_servers.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'timeout'

CS_NAME_PREFIX=ENV['RACKSPACE_CLOUD_SERVER_NAME_PREFIX']
if CS_NAME_PREFIX.blank? then
puts "RACKSPACE_CLOUD_SERVER_NAME_PREFIX is required in order to use this script."
SERVER_NAME_PREFIX=ENV['SERVER_NAME_PREFIX']
if SERVER_NAME_PREFIX.blank? then
puts "SERVER_NAME_PREFIX is required in order to use this script."
exit 1
end
Account.find(:all, :conditions => ["cloud_servers_username IS NOT NULL AND cloud_servers_username != '' and cloud_servers_api_key IS NOT NULL and cloud_servers_api_key != ''"], :group => "cloud_servers_api_key").each do |acct|
Account.find(:all, :conditions => ["username IS NOT NULL AND username != '' AND api_key IS NOT NULL AND api_key != ''"], :group => "api_key").each do |acct|

begin
conn = acct.get_connection
conn.all_servers do |server|

exp = Regexp.new("^#{CS_NAME_PREFIX}")
exp = Regexp.new("^#{SERVER_NAME_PREFIX}")
if server[:name] =~ exp then

server = Server.find(:first, :conditions => ["cloud_server_id_number = ? AND historical = 0", server[:id]])
Expand Down

0 comments on commit 8d8e313

Please sign in to comment.