diff --git a/CHANGELOG b/CHANGELOG index 915feaa..6114fd1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 - 2.4.1 - Fix windows image detection code. diff --git a/app/models/linux_server.rb b/app/models/linux_server.rb index f827293..778e1e4 100644 --- a/app/models/linux_server.rb +++ b/app/models/linux_server.rb @@ -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) @@ -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 diff --git a/app/models/server.rb b/app/models/server.rb index 636c67f..53cc35a 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -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! diff --git a/config/environments/development.rb b/config/environments/development.rb index 23cf724..10d3689 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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. diff --git a/config/environments/production.rb b/config/environments/production.rb index b9d9fb4..1a9936d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -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. diff --git a/config/environments/test.rb b/config/environments/test.rb index 8d0f6d9..ea38a73 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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" diff --git a/contrib/runner_scripts/cleanup_servers.rb b/contrib/runner_scripts/cleanup_servers.rb index 93159bf..d8e48d4 100644 --- a/contrib/runner_scripts/cleanup_servers.rb +++ b/contrib/runner_scripts/cleanup_servers.rb @@ -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]])