lib/cap-rightscale/configuration/rightscale.rb in cap-rightscale-0.0.8 vs lib/cap-rightscale/configuration/rightscale.rb in cap-rightscale-0.0.9
- old
+ new
@@ -7,10 +7,19 @@
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)
+ @use_nick = bool
+ end
+
+ def enable_hostname
+ @use_nick ||= false
+ 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
@@ -44,16 +53,16 @@
logger.info("Deployment #{deployment_name}:")
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)
ip = instance[:private_ip_address]
- logger.info("Found server: #{instance[:nickname]}(#{ip})")
-# server(ip, role, params)
- ip
+ logger.info("Found server: #{hostname}(#{ip})")
+ enable_hostname ? hostname : ip
end
- role(role, host_list.join(','), params) if host_list
+ role(role, params) { host_list } if host_list
puts "Time: #{Time.now - start}"
host_list || []
end
# Get servers in deployment
@@ -80,16 +89,16 @@
# remove rightscale's parameters
params.delete(:deployment)
params.delete(:name_prefix) if params.has_key?(:name_prefix)
host_list = srvs.map do |server|
+ hostname = server[:nickname]
ip = server[:settings][:private_ip_address]
- logger.info("Found server: #{server[:nickname]}(#{ip})")
-# server(ip, role, params)
- ip
+ logger.info("Found server: #{hostname}(#{ip})")
+ enable_hostname ? hostname : ip
end
- role(role, host_list.join(','), params) if host_list
+ role(role, params) { host_list } if host_list
puts "Time: #{Time.now - start}"
host_list || []
end
# Get servers matching tags in deployment
@@ -128,16 +137,16 @@
params.delete(:tags)
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]
ip = server[:settings][:private_ip_address]
logger.info("Found server: #{server[:nickname]}(#{ip})")
- #server(ip, role, params)
- ip
+ enable_hostname ? hostname : ip
end
- role(role, host_list.join(','), params) if host_list
+ role(role, params) { host_list } if host_list
end
puts "Time: #{Time.now - start}"
host_list || []
end
end