lib/cap-rightscale/configuration/rightscale.rb in cap-rightscale-0.0.9 vs lib/cap-rightscale/configuration/rightscale.rb in cap-rightscale-0.0.10
- old
+ new
@@ -8,32 +8,27 @@
def set_rs_confpath(path)
@rs_confpath = path
end
# register deploy host's /etc/hosts OR dns record(replace 's/ #/-000/' to ServerArray name)
- def use_nick(bool=false)
+ def use_nickname(bool=false)
@use_nick = bool
end
- def enable_hostname
- @use_nick ||= false
+ def domainname(domain)
+ @domain = domain
end
def connect
@auth ||= open(get_rs_confpath) {|f| YAML.load(f)}
@conn ||= RightResource::Connection.new do |c|
c.login(:username => @auth["username"], :password => @auth["password"], :account => @auth["account"])
end
+
RightResource::Base.connection = @conn
end
- def check_role(role)
- return false if ENV['HOSTS']
- return false if ENV['ROLES'] && ENV['ROLES'].split(',').include?("#{role}") == false
- return true
- end
-
# Get RightScale Server Array
# === Parameters
# * _role_ - Capistrano role symbol (ex. :app, :web, :db)
# * _params[:array_id]_ - ex. :array_id => 1[https://my.rightscale.com/server_arrays/{id}]
# * _params[:xxx]_ - ex. :user => "www", :port => 2345, etc...
@@ -54,10 +49,11 @@
params.delete(:array_id) # remove rightscale's parameters
host_list = ServerArray.instances(array.id).select {|i| i[:state] == "operational"}.map do |instance|
hostname = instance[:nickname].sub(/ #[0-9]+$/, "-%03d" % instance[:nickname].match(/[0-9]+$/).to_s.to_i)
+ hostname << ".#{_domain}" if _domain
ip = instance[:private_ip_address]
logger.info("Found server: #{hostname}(#{ip})")
enable_hostname ? hostname : ip
end
role(role, params) { host_list } if host_list
@@ -90,10 +86,12 @@
params.delete(:deployment)
params.delete(:name_prefix) if params.has_key?(:name_prefix)
host_list = srvs.map do |server|
hostname = server[:nickname]
+ hostname << ".#{_domain}" if _domain
+puts hostname
ip = server[:settings][:private_ip_address]
logger.info("Found server: #{hostname}(#{ip})")
enable_hostname ? hostname : ip
end
role(role, params) { host_list } if host_list
@@ -138,18 +136,34 @@
host_list = []
if found_ids.size > 0
host_list = srvs.select {|s| found_ids.include?(s[:href].match(/[0-9]+$/).to_s)}.map do |server|
hostname = server[:nickname]
+ hostname << ".#{_domain}" if _domain
ip = server[:settings][:private_ip_address]
- logger.info("Found server: #{server[:nickname]}(#{ip})")
+ logger.info("Found server: #{hostname}(#{ip})")
enable_hostname ? hostname : ip
end
role(role, params) { host_list } if host_list
end
puts "Time: #{Time.now - start}"
host_list || []
end
+
+ private
+ def enable_hostname
+ @use_nick ||= false
+ end
+
+ def _domain
+ @domain || nil
+ end
+
+ def check_role(role)
+ return false if ENV['HOSTS']
+ return false if ENV['ROLES'] && ENV['ROLES'].split(',').include?("#{role}") == false
+ return true
+ end
end
end
end