nirvdrum-rubber 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +146 -0
- data/COPYING +339 -0
- data/README +6 -0
- data/TODO +11 -0
- data/VERSION +1 -0
- data/bin/vulcanize +41 -0
- data/generators/vulcanize/USAGE +6 -0
- data/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +51 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/deflate.conf +10 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/expires.conf +9 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/headers.conf +6 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/monit-apache.conf +8 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/ports.conf +5 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/apache/setenvif.conf +52 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache-vhost.conf +66 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-apache.auth +7 -0
- data/generators/vulcanize/templates/apache/config/rubber/role/web_tools/tools-index.html +34 -0
- data/generators/vulcanize/templates/apache/config/rubber/rubber-apache.yml +6 -0
- data/generators/vulcanize/templates/apache/templates.yml +1 -0
- data/generators/vulcanize/templates/base/Capfile +14 -0
- data/generators/vulcanize/templates/base/config/deploy.rb +55 -0
- data/generators/vulcanize/templates/base/config/rubber/common/crontab +17 -0
- data/generators/vulcanize/templates/base/config/rubber/common/monit-postfix.conf +8 -0
- data/generators/vulcanize/templates/base/config/rubber/common/rubber.profile +14 -0
- data/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +84 -0
- data/generators/vulcanize/templates/base/config/rubber/rubber-dns.yml +79 -0
- data/generators/vulcanize/templates/base/config/rubber/rubber.yml +227 -0
- data/generators/vulcanize/templates/base/lib/tasks/rubber.rake +15 -0
- data/generators/vulcanize/templates/base/script/cron-rake +18 -0
- data/generators/vulcanize/templates/base/script/cron-runner +18 -0
- data/generators/vulcanize/templates/base/script/cron-sh +67 -0
- data/generators/vulcanize/templates/base/templates.yml +1 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/haproxy/haproxy-mongrel.conf +23 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/nginx/nginx-mongrel.conf +113 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/rubber-complete.yml +41 -0
- data/generators/vulcanize/templates/complete_mongrel_mysql/templates.yml +6 -0
- data/generators/vulcanize/templates/complete_passenger_mysql/config/rubber/role/haproxy/haproxy-passenger.conf +21 -0
- data/generators/vulcanize/templates/complete_passenger_mysql/config/rubber/rubber-complete.yml +40 -0
- data/generators/vulcanize/templates/complete_passenger_mysql/templates.yml +10 -0
- data/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +72 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/cruise +40 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/my.cnf +165 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/production.rb +8 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/site_config.rb +76 -0
- data/generators/vulcanize/templates/cruise/config/rubber/role/web_tools/cruise-nginx.conf +11 -0
- data/generators/vulcanize/templates/cruise/config/rubber/rubber-cruise.yml +18 -0
- data/generators/vulcanize/templates/cruise/templates.yml +1 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/deploy-haproxy.rb +45 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-base.conf +26 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-default.conf +8 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/monit-haproxy.conf +9 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslog-haproxy.conf +6 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslogd-default.conf +17 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/role/web_tools/haproxy-nginx.conf +10 -0
- data/generators/vulcanize/templates/haproxy/config/rubber/rubber-haproxy.yml +7 -0
- data/generators/vulcanize/templates/haproxy/templates.yml +1 -0
- data/generators/vulcanize/templates/jetty/config/rubber/deploy-jetty.rb +59 -0
- data/generators/vulcanize/templates/jetty/config/rubber/role/jetty/jetty.sh +589 -0
- data/generators/vulcanize/templates/jetty/config/rubber/role/jetty/jetty.xml +199 -0
- data/generators/vulcanize/templates/jetty/config/rubber/role/jetty/monit-jetty.conf +9 -0
- data/generators/vulcanize/templates/jetty/config/rubber/rubber-jetty.yml +10 -0
- data/generators/vulcanize/templates/jetty/templates.yml +1 -0
- data/generators/vulcanize/templates/memcached/config/memcached.yml +28 -0
- data/generators/vulcanize/templates/memcached/config/rubber/common/memcached.yml +14 -0
- data/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached.conf +52 -0
- data/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached_munin_plugin +249 -0
- data/generators/vulcanize/templates/memcached/config/rubber/rubber-memcached.yml +7 -0
- data/generators/vulcanize/templates/memcached/templates.yml +1 -0
- data/generators/vulcanize/templates/minimal_mysql/templates.yml +7 -0
- data/generators/vulcanize/templates/minimal_nodb/templates.yml +6 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/deploy-mongrel.rb +75 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/role/mongrel/mongrel_cluster.yml +12 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/role/mongrel/monit-mongrel.conf +20 -0
- data/generators/vulcanize/templates/mongrel/config/rubber/rubber-mongrel.yml +9 -0
- data/generators/vulcanize/templates/mongrel/templates.yml +1 -0
- data/generators/vulcanize/templates/monit/config/rubber/common/monit-default.conf +15 -0
- data/generators/vulcanize/templates/monit/config/rubber/common/monit.conf +251 -0
- data/generators/vulcanize/templates/monit/config/rubber/deploy-monit.rb +32 -0
- data/generators/vulcanize/templates/monit/config/rubber/role/web_tools/monit-admin-nginx.conf +10 -0
- data/generators/vulcanize/templates/monit/config/rubber/rubber-monit.yml +6 -0
- data/generators/vulcanize/templates/monit/templates.yml +1 -0
- data/generators/vulcanize/templates/munin/config/rubber/common/monit-munin.conf +8 -0
- data/generators/vulcanize/templates/munin/config/rubber/common/munin-node.conf +48 -0
- data/generators/vulcanize/templates/munin/config/rubber/common/munin-plugins.conf +9 -0
- data/generators/vulcanize/templates/munin/config/rubber/deploy-munin.rb +46 -0
- data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-nginx.conf +8 -0
- data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-plugins.conf +31 -0
- data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin.conf +80 -0
- data/generators/vulcanize/templates/munin/config/rubber/rubber-munin.yml +8 -0
- data/generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb +57 -0
- data/generators/vulcanize/templates/munin/script/munin/example_simple.rb +24 -0
- data/generators/vulcanize/templates/munin/templates.yml +1 -0
- data/generators/vulcanize/templates/mysql/config/rubber/common/database.yml +11 -0
- data/generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb +156 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/db/crontab +14 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/db/monit-mysql.cnf +10 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/db/my.cnf +167 -0
- data/generators/vulcanize/templates/mysql/config/rubber/role/mysql_slave/mysql_slave_munin_plugin +51 -0
- data/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +46 -0
- data/generators/vulcanize/templates/mysql/templates.yml +1 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/common/mysql_cluster_migrations.rb +13 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/deploy-mysql_cluster.rb +173 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_data/my.cnf +15 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_mgm/ndb_mgmd.cnf +39 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/monit-mysql_cluster_sql.cnf +10 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/my.cnf +23 -0
- data/generators/vulcanize/templates/mysql_cluster/config/rubber/rubber-mysql_cluster.yml +32 -0
- data/generators/vulcanize/templates/mysql_cluster/templates.yml +1 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/database.yml +16 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/monit-mysql_proxy.cnf +10 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy +153 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.conf +10 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.lua +5 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/deploy-mysql_proxy.rb +52 -0
- data/generators/vulcanize/templates/mysql_proxy/config/rubber/rubber-mysql_proxy.yml +11 -0
- data/generators/vulcanize/templates/mysql_proxy/templates.yml +1 -0
- data/generators/vulcanize/templates/nginx/config/rubber/deploy-nginx.rb +45 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/crontab +9 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/monit-nginx.conf +8 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/nginx/nginx.conf +42 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/nginx-tools.conf +55 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-index.html +30 -0
- data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-nginx.auth +7 -0
- data/generators/vulcanize/templates/nginx/config/rubber/rubber-nginx.yml +10 -0
- data/generators/vulcanize/templates/nginx/templates.yml +1 -0
- data/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +37 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-memory.conf +34 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-sudoers.conf +7 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger.conf +47 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger-apache-vhost.conf +46 -0
- data/generators/vulcanize/templates/passenger/config/rubber/role/passenger/passenger.conf +10 -0
- data/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +15 -0
- data/generators/vulcanize/templates/passenger/templates.yml +3 -0
- data/generators/vulcanize/templates/redis/config/rubber/deploy-redis.rb +36 -0
- data/generators/vulcanize/templates/redis/config/rubber/role/redis/crontab +8 -0
- data/generators/vulcanize/templates/redis/config/rubber/role/redis/monit-redis.conf +9 -0
- data/generators/vulcanize/templates/redis/config/rubber/role/redis/redis.conf +141 -0
- data/generators/vulcanize/templates/redis/config/rubber/rubber-redis.yml +4 -0
- data/generators/vulcanize/templates/redis/templates.yml +1 -0
- data/generators/vulcanize/templates/resque/config/rubber/deploy-resque-worker-default.rb +38 -0
- data/generators/vulcanize/templates/resque/config/rubber/deploy-resque.rb +39 -0
- data/generators/vulcanize/templates/resque/config/rubber/role/resque_worker_default/monit-resque_worker_default.conf +19 -0
- data/generators/vulcanize/templates/resque/config/rubber/rubber-resque.yml +10 -0
- data/generators/vulcanize/templates/resque/templates.yml +3 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/common/sphinx.yml +46 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +112 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/crontab +11 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf +10 -0
- data/generators/vulcanize/templates/sphinx/config/rubber/rubber-sphinx.yml +6 -0
- data/generators/vulcanize/templates/sphinx/templates.yml +1 -0
- data/generators/vulcanize/vulcanize_generator.rb +67 -0
- data/lib/capistrano/hostcmd.rb +12 -0
- data/lib/rubber.rb +38 -0
- data/lib/rubber/capistrano.rb +1 -0
- data/lib/rubber/cloud.rb +13 -0
- data/lib/rubber/cloud/aws.rb +334 -0
- data/lib/rubber/cloud/base.rb +16 -0
- data/lib/rubber/configuration.rb +47 -0
- data/lib/rubber/dns.rb +13 -0
- data/lib/rubber/dns/base.rb +84 -0
- data/lib/rubber/dns/dyndns.rb +78 -0
- data/lib/rubber/dns/nettica.rb +117 -0
- data/lib/rubber/dns/zerigo.rb +174 -0
- data/lib/rubber/environment.rb +169 -0
- data/lib/rubber/generator.rb +197 -0
- data/lib/rubber/instance.rb +166 -0
- data/lib/rubber/recipes/rubber.rb +89 -0
- data/lib/rubber/recipes/rubber/bundles.rb +28 -0
- data/lib/rubber/recipes/rubber/deploy.rb +90 -0
- data/lib/rubber/recipes/rubber/instances.rb +393 -0
- data/lib/rubber/recipes/rubber/load_balancers.rb +44 -0
- data/lib/rubber/recipes/rubber/security_groups.rb +189 -0
- data/lib/rubber/recipes/rubber/setup.rb +457 -0
- data/lib/rubber/recipes/rubber/spot_requests.rb +17 -0
- data/lib/rubber/recipes/rubber/static_ips.rb +107 -0
- data/lib/rubber/recipes/rubber/utils.rb +203 -0
- data/lib/rubber/recipes/rubber/volumes.rb +264 -0
- data/lib/rubber/tasks/rubber.rb +279 -0
- data/lib/rubber/util.rb +37 -0
- data/rails/init.rb +9 -0
- data/test/environment_test.rb +133 -0
- data/test/generator_test.rb +323 -0
- data/test/instance_test.rb +93 -0
- data/test/test_helper.rb +8 -0
- data/test/util_test.rb +16 -0
- metadata +298 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'rubber/environment'
|
3
|
+
require 'rubber/instance'
|
4
|
+
require 'rubber/generator'
|
5
|
+
|
6
|
+
module Rubber
|
7
|
+
module Configuration
|
8
|
+
|
9
|
+
@@configurations = {}
|
10
|
+
|
11
|
+
def self.get_configuration(env=nil, root=nil)
|
12
|
+
key = "#{env}-#{root}"
|
13
|
+
@@configurations[key] ||= ConfigHolder.new(env, root)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.rubber_env
|
17
|
+
raise "This convenience method needs RUBBER_ENV to be set" unless RUBBER_ENV
|
18
|
+
cfg = Rubber::Configuration.get_configuration(RUBBER_ENV)
|
19
|
+
host = cfg.environment.current_host
|
20
|
+
roles = cfg.instance[host].role_names rescue nil
|
21
|
+
cfg.environment.bind(roles, host)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.rubber_instances
|
25
|
+
raise "This convenience method needs RUBBER_ENV to be set" unless RUBBER_ENV
|
26
|
+
Rubber::Configuration.get_configuration(RUBBER_ENV).instance
|
27
|
+
end
|
28
|
+
|
29
|
+
class ConfigHolder
|
30
|
+
def initialize(env=nil, root=nil)
|
31
|
+
root = "#{RUBBER_ROOT}/config/rubber" unless root
|
32
|
+
instance_cfg = "#{root}/instance" + (env ? "-#{env}.yml" : ".yml")
|
33
|
+
@environment = Environment.new("#{root}")
|
34
|
+
@instance = Instance.new(instance_cfg)
|
35
|
+
end
|
36
|
+
|
37
|
+
def environment
|
38
|
+
@environment
|
39
|
+
end
|
40
|
+
|
41
|
+
def instance
|
42
|
+
@instance
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/rubber/dns.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Rubber
|
2
|
+
module Dns
|
3
|
+
|
4
|
+
class Base
|
5
|
+
|
6
|
+
attr_reader :env, :provider_env, :provider_name
|
7
|
+
|
8
|
+
def initialize(env, provider_name)
|
9
|
+
@env = env
|
10
|
+
@provider_name = provider_name
|
11
|
+
@provider_env = @env.dns_providers[provider_name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def update(host, ip)
|
15
|
+
if up_to_date(host, ip)
|
16
|
+
puts "IP has not changed for #{host}, not updating dynamic DNS"
|
17
|
+
else
|
18
|
+
if find_host_records(:host => host).size == 0
|
19
|
+
puts "Creating dynamic DNS: #{host} => #{ip}"
|
20
|
+
create_host_record(:host => host, :data => ip)
|
21
|
+
else
|
22
|
+
puts "Updating dynamic DNS: #{host} => #{ip}"
|
23
|
+
update_host_record({:host => host}, {:host => host, :data => ip})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def destroy(host)
|
29
|
+
if find_host_records(:host => host).size != 0
|
30
|
+
puts "Destroying dynamic DNS record: #{host}"
|
31
|
+
destroy_host_record(:host => host)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def up_to_date(host, ip)
|
36
|
+
find_host_records(:host => host).any? {|host| host[:data] == ip}
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_host_record(opts = {})
|
40
|
+
raise "create_host_record not implemented"
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_host_records(opts = {})
|
44
|
+
raise "find_host_records not implemented"
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_host_record(old_opts={}, new_opts={})
|
48
|
+
raise "update_host_record not implemented"
|
49
|
+
end
|
50
|
+
|
51
|
+
def destroy_host_record(opts = {})
|
52
|
+
raise "destroy_host_record not implemented"
|
53
|
+
end
|
54
|
+
|
55
|
+
def host_records_equal?(lhs_opts = {}, rhs_opts = {})
|
56
|
+
lhs = setup_opts(lhs_opts)
|
57
|
+
rhs = setup_opts(rhs_opts)
|
58
|
+
[lhs, rhs].each {|h| h.delete(:id); h.delete(:priority) if h[:priority] == 0}
|
59
|
+
lhs == rhs
|
60
|
+
end
|
61
|
+
|
62
|
+
def setup_opts(opts, required=[])
|
63
|
+
default_opts = {:domain => @env.domain,
|
64
|
+
:type => @provider_env['type'] || @provider_env.record_type || 'A',
|
65
|
+
:ttl => @provider_env.ttl || 300}
|
66
|
+
|
67
|
+
if opts.delete(:no_defaults)
|
68
|
+
actual_opts = Rubber::Util::symbolize_keys(opts)
|
69
|
+
else
|
70
|
+
actual_opts = default_opts.merge(Rubber::Util::symbolize_keys(opts))
|
71
|
+
end
|
72
|
+
|
73
|
+
required.each do |r|
|
74
|
+
raise "Missing required options: #{r}" unless actual_opts[r]
|
75
|
+
end
|
76
|
+
|
77
|
+
return actual_opts
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Rubber
|
2
|
+
module Dns
|
3
|
+
|
4
|
+
class Dyndns < Base
|
5
|
+
|
6
|
+
def initialize(env)
|
7
|
+
super(env, 'dyndns')
|
8
|
+
@user, @pass = provider_env.user, provider_env.password
|
9
|
+
@update_url = provider_env.update_url || 'https://members.dyndns.org/nic/update?hostname=%host%&myip=%ip%'
|
10
|
+
@update_url = @update_url.gsub(/%([^%]+)%/, '#{\1}')
|
11
|
+
end
|
12
|
+
|
13
|
+
def nameserver
|
14
|
+
"ns1.mydyndns.org"
|
15
|
+
end
|
16
|
+
|
17
|
+
def up_to_date(host, ip)
|
18
|
+
# This queries dns server directly instead of using hosts file
|
19
|
+
current_ip = nil
|
20
|
+
Resolv::DNS.open(:nameserver => [nameserver], :search => [], :ndots => 1) do |dns|
|
21
|
+
current_ip = dns.getaddress("#{host}.#{provider_env.domain}").to_s rescue nil
|
22
|
+
end
|
23
|
+
return ip == current_ip
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_host_records(opts={})
|
27
|
+
opts = setup_opts(opts, [:host, :domain])
|
28
|
+
hostname = "#{opts[:host]}.#{opts[:domain]}"
|
29
|
+
begin
|
30
|
+
Resolv::DNS.open(:nameserver => [nameserver], :search => [], :ndots => 1) do |dns|
|
31
|
+
r = dns.getresource(hostname, Resolv::DNS::Resource::IN::A)
|
32
|
+
result = [{:host =>host, :data => r.address}]
|
33
|
+
end
|
34
|
+
rescue
|
35
|
+
raise "Domain needs to exist in dyndns as an A record before record can be updated"
|
36
|
+
end
|
37
|
+
return true
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_host_record(opts={})
|
41
|
+
puts "WARNING: No create record available for dyndns, you need to do so manually"
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy_host_record(opts={})
|
45
|
+
puts "WARNING: No destroy record available for dyndns, you need to do so manually"
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_host_record(old_opts={}, new_opts={})
|
49
|
+
old_opts = setup_opts(opts, [:host, :domain])
|
50
|
+
new_opts = setup_opts(opts, [:data])
|
51
|
+
|
52
|
+
host = hostname(old_opts[:host])
|
53
|
+
ip = new_opts[:data]
|
54
|
+
update_url = eval('%Q{' + @update_url + '}')
|
55
|
+
|
56
|
+
# This header is required by dyndns.org
|
57
|
+
headers = {
|
58
|
+
"User-Agent" => "Capistrano - Rubber - 0.1"
|
59
|
+
}
|
60
|
+
|
61
|
+
uri = URI.parse(update_url)
|
62
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
63
|
+
# switch on SSL
|
64
|
+
http.use_ssl = true if uri.scheme == "https"
|
65
|
+
# suppress verification warning
|
66
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
67
|
+
req = Net::HTTP::Get.new(update_url.gsub(/.*:\/\/[^\/]*/, ''), headers)
|
68
|
+
# authentication details
|
69
|
+
req.basic_auth @user, @pass
|
70
|
+
resp = http.request(req)
|
71
|
+
# print out the response for the update
|
72
|
+
puts "DynDNS Update result: #{resp.body}"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'nettica/client'
|
2
|
+
module Rubber
|
3
|
+
module Dns
|
4
|
+
|
5
|
+
class Nettica < Base
|
6
|
+
|
7
|
+
def initialize(env)
|
8
|
+
super(env, "nettica")
|
9
|
+
@client = ::Nettica::Client.new(provider_env.user, provider_env.password)
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_status(response)
|
13
|
+
code = case
|
14
|
+
when response.respond_to?(:status)
|
15
|
+
response.status
|
16
|
+
when response.respond_to?(:result)
|
17
|
+
response.result.status
|
18
|
+
else
|
19
|
+
500
|
20
|
+
end
|
21
|
+
if code < 200 || code > 299
|
22
|
+
msg = "Failed to access nettica api (http_status=#{code})"
|
23
|
+
msg += ", check dns_providers.nettica.user/password in rubber.yml" if code == 401
|
24
|
+
raise msg
|
25
|
+
end
|
26
|
+
return response
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_host_records(opts = {})
|
30
|
+
opts = setup_opts(opts, [:host, :domain])
|
31
|
+
|
32
|
+
result = []
|
33
|
+
hn = opts[:host]
|
34
|
+
ht = opts[:type]
|
35
|
+
hd = opts[:data]
|
36
|
+
|
37
|
+
domain_info = find_or_create_zone(opts[:domain])
|
38
|
+
|
39
|
+
domain_info.record.each do |h|
|
40
|
+
keep = true
|
41
|
+
if hn && h.hostName != hn && hn != '*'
|
42
|
+
keep = false
|
43
|
+
end
|
44
|
+
if ht && h.recordType != ht && ht != '*'
|
45
|
+
keep = false
|
46
|
+
end
|
47
|
+
if hd && h.data != hd
|
48
|
+
keep = false
|
49
|
+
end
|
50
|
+
result << record_to_opts(h) if keep
|
51
|
+
end
|
52
|
+
|
53
|
+
return result
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_host_record(opts = {})
|
57
|
+
opts = setup_opts(opts, [:host, :data, :domain, :type, :ttl])
|
58
|
+
find_or_create_zone(opts[:domain])
|
59
|
+
record = opts_to_record(opts)
|
60
|
+
check_status @client.add_record(record)
|
61
|
+
end
|
62
|
+
|
63
|
+
def destroy_host_record(opts = {})
|
64
|
+
find_host_records(opts).each do |h|
|
65
|
+
record = opts_to_record(h)
|
66
|
+
check_status @client.delete_record(record)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def update_host_record(old_opts = {}, new_opts = {})
|
71
|
+
old_opts = setup_opts(old_opts, [:host, :domain])
|
72
|
+
new_opts = setup_opts(new_opts.merge(:no_defaults =>true), [])
|
73
|
+
find_host_records(old_opts).each do |h|
|
74
|
+
old_record = opts_to_record(h)
|
75
|
+
new_record = opts_to_record(h.merge(new_opts))
|
76
|
+
check_status @client.update_record(old_record, new_record)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def find_or_create_zone(domain)
|
83
|
+
domain_info = @client.list_domain(domain)
|
84
|
+
if domain_info.record
|
85
|
+
check_status domain_info
|
86
|
+
else
|
87
|
+
check_status @client.create_zone(domain)
|
88
|
+
domain_info = check_status @client.list_domain(domain)
|
89
|
+
raise "Could not create zone in nettica: #{domain}" unless domain_info.record
|
90
|
+
end
|
91
|
+
return domain_info
|
92
|
+
end
|
93
|
+
|
94
|
+
def opts_to_record(opts)
|
95
|
+
record = @client.create_domain_record(opts[:domain],
|
96
|
+
opts[:host],
|
97
|
+
opts[:type],
|
98
|
+
opts[:data],
|
99
|
+
opts[:ttl],
|
100
|
+
opts[:priority] || 0)
|
101
|
+
return record
|
102
|
+
end
|
103
|
+
|
104
|
+
def record_to_opts(record)
|
105
|
+
opts = {}
|
106
|
+
opts[:host] = record.hostName || ''
|
107
|
+
opts[:domain] = record.domainName
|
108
|
+
opts[:type] = record.recordType
|
109
|
+
opts[:data] = record.data if record.data
|
110
|
+
opts[:ttl] = record.tTL if record.tTL
|
111
|
+
opts[:priority] = record.priority if record.priority
|
112
|
+
return opts
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module Rubber
|
5
|
+
module Dns
|
6
|
+
|
7
|
+
|
8
|
+
class Zone
|
9
|
+
include HTTParty
|
10
|
+
format :xml
|
11
|
+
|
12
|
+
@@zones = {}
|
13
|
+
def self.get_zone(domain, provider_env)
|
14
|
+
@@zones[domain] ||= Zone.new(provider_env.customer_id, provider_env.email, provider_env.token, domain)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(customer_id, email, token, domain)
|
18
|
+
self.class.basic_auth email, token
|
19
|
+
self.class.base_uri "https://ns.zerigo.com/accounts/#{customer_id}"
|
20
|
+
@domain = domain
|
21
|
+
refresh()
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_status(response)
|
25
|
+
code = response.code
|
26
|
+
if code < 200 || code > 299
|
27
|
+
msg = "Failed to access zerigo api (http_status=#{code})"
|
28
|
+
msg += ", check dns_providers.zerigo.customer_id/email/token in rubber.yml" if code == 401
|
29
|
+
raise msg
|
30
|
+
end
|
31
|
+
return response
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_host(opts)
|
35
|
+
host = opts_to_host(opts, new_host())
|
36
|
+
check_status self.class.post("/zones/#{@zone['id']}/hosts.xml", :body => {:host => host})
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_host_records(opts={})
|
40
|
+
result = []
|
41
|
+
hn = opts[:host]
|
42
|
+
ht = opts[:type]
|
43
|
+
hd = opts[:data]
|
44
|
+
has_host = hn && hn != '*'
|
45
|
+
|
46
|
+
url = "/zones/#{@zone['id']}/hosts.xml"
|
47
|
+
if has_host
|
48
|
+
url << "?fqdn="
|
49
|
+
url << "#{hn}." if hn.strip.size > 0
|
50
|
+
url << "#{@domain}"
|
51
|
+
end
|
52
|
+
hosts = self.class.get(url)
|
53
|
+
|
54
|
+
# returns 404 on not found, so don't check status
|
55
|
+
hosts = check_status hosts unless has_host
|
56
|
+
|
57
|
+
hosts['hosts'].each do |h|
|
58
|
+
keep = true
|
59
|
+
if ht && h['host_type'] != ht && ht != '*'
|
60
|
+
keep = false
|
61
|
+
end
|
62
|
+
if hd && h['data'] != hd
|
63
|
+
keep = false
|
64
|
+
end
|
65
|
+
result << host_to_opts(h) if keep
|
66
|
+
end if hosts['hosts']
|
67
|
+
|
68
|
+
return result
|
69
|
+
end
|
70
|
+
|
71
|
+
def update_host(host_id, opts)
|
72
|
+
host = opts_to_host(opts, new_host())
|
73
|
+
check_status self.class.put("/zones/#{@zone['id']}/hosts/#{host_id}.xml", :body => {:host => host})
|
74
|
+
end
|
75
|
+
|
76
|
+
def delete_host(host_id)
|
77
|
+
check_status self.class.delete("/zones/#{@zone['id']}/hosts/#{host_id}.xml")
|
78
|
+
end
|
79
|
+
|
80
|
+
def refresh
|
81
|
+
zone_id = @zone['id'] rescue nil
|
82
|
+
if zone_id
|
83
|
+
@zone = check_status self.class.get("/zones/#{zone_id}.xml")
|
84
|
+
else
|
85
|
+
zones = check_status self.class.get('/zones.xml')
|
86
|
+
@zone = zones["zones"].find {|z| z["domain"] == @domain }
|
87
|
+
end
|
88
|
+
if ! @zone
|
89
|
+
zone = new_zone()
|
90
|
+
zone['domain'] = @domain
|
91
|
+
zones = check_status self.class.post('/zones.xml', :body => {:zone => zone})
|
92
|
+
@zone = zones['zone']
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def zone_record
|
97
|
+
return @zone
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def new_host
|
103
|
+
check_status(self.class.get("/zones/#{@zone['id']}/hosts/new.xml"))['host']
|
104
|
+
end
|
105
|
+
|
106
|
+
def new_zone
|
107
|
+
check_status(self.class.get("/zones/new.xml"))['zone']
|
108
|
+
end
|
109
|
+
|
110
|
+
def opts_to_host(opts, host={})
|
111
|
+
host['hostname'] = opts[:host]
|
112
|
+
host['host_type'] = opts[:type]
|
113
|
+
host['data'] = opts[:data] if opts[:data]
|
114
|
+
host['ttl'] = opts[:ttl] if opts[:ttl]
|
115
|
+
host['priority'] = opts[:priority] if opts[:priority]
|
116
|
+
return host
|
117
|
+
end
|
118
|
+
|
119
|
+
def host_to_opts(host)
|
120
|
+
opts = {}
|
121
|
+
opts[:id] = host['id']
|
122
|
+
opts[:domain] = @domain
|
123
|
+
opts[:host] = host['hostname'] || ''
|
124
|
+
opts[:type] = host['host_type']
|
125
|
+
opts[:data] = host['data'] if host['data']
|
126
|
+
opts[:ttl] = host['ttl'] if host['ttl']
|
127
|
+
opts[:priority] = host['priority'] if host['priority']
|
128
|
+
return opts
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class Zerigo < Base
|
133
|
+
|
134
|
+
def initialize(env)
|
135
|
+
super(env, "zerigo")
|
136
|
+
end
|
137
|
+
|
138
|
+
def find_host_records(opts = {})
|
139
|
+
opts = setup_opts(opts, [:host, :domain])
|
140
|
+
zone = Zone.get_zone(opts[:domain], provider_env)
|
141
|
+
|
142
|
+
zone.find_host_records(opts)
|
143
|
+
end
|
144
|
+
|
145
|
+
def create_host_record(opts = {})
|
146
|
+
opts = setup_opts(opts, [:host, :data, :domain, :type, :ttl])
|
147
|
+
zone = Zone.get_zone(opts[:domain], provider_env)
|
148
|
+
|
149
|
+
zone.create_host(opts)
|
150
|
+
end
|
151
|
+
|
152
|
+
def destroy_host_record(opts = {})
|
153
|
+
opts = setup_opts(opts, [:host, :domain])
|
154
|
+
zone = Zone.get_zone(opts[:domain], provider_env)
|
155
|
+
|
156
|
+
find_host_records(opts).each do |h|
|
157
|
+
zone.delete_host(h[:id])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def update_host_record(old_opts={}, new_opts={})
|
162
|
+
old_opts = setup_opts(old_opts, [:host, :domain])
|
163
|
+
new_opts = setup_opts(new_opts.merge(:no_defaults =>true), [])
|
164
|
+
zone = Zone.get_zone(old_opts[:domain], provider_env)
|
165
|
+
|
166
|
+
find_host_records(old_opts).each do |h|
|
167
|
+
zone.update_host(h[:id], h.merge(new_opts))
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|