Skip to content

Instantly share code, notes, and snippets.

@dsgh
Last active April 12, 2016 09:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsgh/6e45e8cccbb4d729d631 to your computer and use it in GitHub Desktop.
Save dsgh/6e45e8cccbb4d729d631 to your computer and use it in GitHub Desktop.
ey engineyard generate config for shuttle
#!/usr/bin/env ruby
def apps
%w(reviews seedrs_cluster)
end
def environments_cmd(app)
`ey environments -a #{app} | grep -v "(stopped)" | grep "^ " | awk '{print $1}'`
end
def servers_cmd(environment)
iname = "@servers_cmd_#{environment}"
instance_variable_get(iname) || instance_variable_set(iname, `ey servers -e #{environment} | grep -v "^Loading" | grep -v "^#" | awk '{print ""(NF>3?$3"-"$4:$3)" "$1""}'`)
end
def environments
apps.map{ |app| environments_cmd(app).strip.split("\n") }.flatten
end
def servers(environment)
servers_cmd(environment).strip.split("\n").map{ |s| s.split(" ") }
end
def servers_name_counts(environment)
iname = "@servers_name_counts_#{environment}"
instance_variable_get(iname) || instance_variable_set(iname, servers(environment).inject(Hash.new(0)){ |hash,(name,host)| hash[name] += 1; hash })
end
def servers_name_and_host(environment)
counts = Hash.new(0)
servers(environment).map do |(name,host)|
if servers_name_counts(environment)[name] > 1
counts[name] += 1
name = "#{name} #{counts[name]}"
end
{
:name => name,
:cmd => "ssh://deploy@#{host}"
}
end
end
def ey_hosts
environments.map do |environment|
{
environment.capitalize => servers_name_and_host(environment)
}
end
end
def local_hosts
[
{
"Lisbon" => [
{ :name => "fulla", :cmd => "ssh://db@fulla.lisbon" },
{ :name => "jenkins", :cmd => "ssh://jenkins@ci.lisbon" },
{ :name => "nanna", :cmd => "ssh://jenkins_slave@nanna.lisbon" }
]
}
]
end
def hosts
ey_hosts + local_hosts
end
def config
{
:terminal => "Terminal.app",
:launch_at_login => true,
:show_ssh_config_hosts => true,
:ssh_config_ignore_hosts => [],
:ssh_config_ignore_keywords => [],
:hosts => hosts
}
end
require "json"
puts JSON.pretty_generate(config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment