2016-01-31 17:52:11 +03:00
|
|
|
class ChefNodeNameBuilder
|
2016-02-20 17:39:02 +03:00
|
|
|
DEFAULT_MASK = '$project-$cfname-$env'
|
|
|
|
|
|
2016-01-31 17:52:11 +03:00
|
|
|
def initialize(server_info, project, env)
|
|
|
|
|
@server_info, @project, @env = server_info, project, env
|
2016-02-26 14:27:14 +03:00
|
|
|
@mask = server_info['tags']['cid:node-name-mask'] || DEFAULT_MASK
|
2016-01-31 17:52:11 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def build_node_name
|
2016-02-26 14:27:14 +03:00
|
|
|
result = @mask.dup
|
|
|
|
|
replace_dollar_variables!(result)
|
|
|
|
|
replace_colon_variables!(result)
|
|
|
|
|
result.gsub!('_', '-')
|
|
|
|
|
result
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def replace_dollar_variables!(result)
|
|
|
|
|
result.gsub!('$project', @project.id)
|
|
|
|
|
result.gsub!('$env', @env.identifier)
|
|
|
|
|
result.gsub!('$instanceid', @server_info['id'])
|
|
|
|
|
result.gsub!('$cfname', @server_info['tags']['Name'] || '')
|
|
|
|
|
result.gsub!('$time', Time.now.to_i.to_s)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def replace_colon_variables!(result)
|
|
|
|
|
result.gsub!(':project', @project.id)
|
|
|
|
|
result.gsub!(':env', @env.identifier)
|
|
|
|
|
result.gsub!(':instanceid', @server_info['id'])
|
|
|
|
|
result.gsub!(':cfname', @server_info['tags']['Name'] || '')
|
|
|
|
|
result.gsub!(':time', Time.now.to_i.to_s)
|
2016-01-31 17:52:11 +03:00
|
|
|
end
|
|
|
|
|
end
|