Class: OpenShift::BindPlugin
- Inherits:
-
DnsService
- Object
- DnsService
- OpenShift::BindPlugin
- Defined in:
- lib/openshift/bind_plugin.rb
Instance Attribute Summary collapse
- #keyname ⇒ Object readonly
- #keyvalue ⇒ Object readonly
- #port ⇒ Object readonly
- #server ⇒ Object readonly
Instance Method Summary collapse
- #close ⇒ Object
- #deregister_application(app_name, namespace) ⇒ Object
- #deregister_namespace(namespace) ⇒ Object
- #dns ⇒ Object
-
#initialize(access_info = nil) ⇒ BindPlugin
constructor
A new instance of BindPlugin.
- #modify_application(app_name, namespace, public_hostname) ⇒ Object
- #namespace_available?(namespace) ⇒ Boolean
- #publish ⇒ Object
- #register_application(app_name, namespace, public_hostname) ⇒ Object
- #register_namespace(namespace) ⇒ Object
Constructor Details
#initialize(access_info = nil) ⇒ BindPlugin
Returns a new instance of BindPlugin.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/openshift/bind_plugin.rb', line 17 def initialize(access_info = nil) if access_info != nil @domain_suffix = access_info[:domain_suffix] elsif defined? Rails # extract from Rails.application.config[dns,ss] access_info = Rails.application.config.dns @domain_suffix = Rails.application.config.openshift[:domain_suffix] else raise Exception.new("BIND DNS service is not initialized") end @server = access_info[:server] @port = access_info[:port].to_i @src_port = access_info[:src_port].to_i if access_info[:src_port].to_i @keyname = access_info[:keyname] @keyvalue = access_info[:keyvalue] @zone = access_info[:zone] end |
Instance Attribute Details
#keyname ⇒ Object (readonly)
15 16 17 |
# File 'lib/openshift/bind_plugin.rb', line 15 def keyname @keyname end |
#keyvalue ⇒ Object (readonly)
15 16 17 |
# File 'lib/openshift/bind_plugin.rb', line 15 def keyvalue @keyvalue end |
#port ⇒ Object (readonly)
15 16 17 |
# File 'lib/openshift/bind_plugin.rb', line 15 def port @port end |
#server ⇒ Object (readonly)
15 16 17 |
# File 'lib/openshift/bind_plugin.rb', line 15 def server @server end |
Instance Method Details
#close ⇒ Object
119 120 |
# File 'lib/openshift/bind_plugin.rb', line 119 def close end |
#deregister_application(app_name, namespace) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/openshift/bind_plugin.rb', line 90 def deregister_application(app_name, namespace) begin # delete the CNAME record for the application in the domain fqdn = "#{app_name}-#{namespace}.#{@domain_suffix}" # We know we only have one CNAME per app, so look it up # We need it for the delete # should be an error if there's not exactly one answer current = dns.query(fqdn, 'CNAME') cnamevalue = current.answer[0].rdata.to_s # enable updates with key dns.tsig = @keyname, @keyvalue update = Dnsruby::Update.new(@zone) update_response = update.delete(fqdn, 'CNAME', cnamevalue) send_response = dns.(update) rescue Dnsruby::NXDomain Rails.logger.debug "DEBUG: BIND: Could not find CNAME for #{fqdn} to delete" end end |
#deregister_namespace(namespace) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/openshift/bind_plugin.rb', line 68 def deregister_namespace(namespace) # create a TXT record for the namespace in the domain fqdn = "#{namespace}.#{@domain_suffix}" # enable updates with key dns.tsig = @keyname, @keyvalue update = Dnsruby::Update.new(@zone) update.delete(fqdn, 'TXT') dns.(update) end |
#dns ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/openshift/bind_plugin.rb', line 35 def dns if not @dns_con @dns_con = Dnsruby::Resolver.new(:nameserver => @server, :port => @port) @dns_con.src_port = @src_port if @src_port end @dns_con end |
#modify_application(app_name, namespace, public_hostname) ⇒ Object
111 112 113 114 |
# File 'lib/openshift/bind_plugin.rb', line 111 def modify_application(app_name, namespace, public_hostname) deregister_application(app_name, namespace) register_application(app_name, namespace, public_hostname) end |
#namespace_available?(namespace) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/openshift/bind_plugin.rb', line 43 def namespace_available?(namespace) fqdn = "#{namespace}.#{@domain_suffix}" # If we get a response, then the namespace is reserved # An exception means that it is available begin dns.query(fqdn, Dnsruby::Types::TXT) return false rescue Dnsruby::NXDomain return true end end |
#publish ⇒ Object
116 117 |
# File 'lib/openshift/bind_plugin.rb', line 116 def publish end |
#register_application(app_name, namespace, public_hostname) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/openshift/bind_plugin.rb', line 79 def register_application(app_name, namespace, public_hostname) # create an A record for the application in the domain fqdn = "#{app_name}-#{namespace}.#{@domain_suffix}" # enable updates with key dns.tsig = @keyname, @keyvalue update = Dnsruby::Update.new(@zone) update.add(fqdn, 'CNAME', 60, public_hostname) dns.(update) end |
#register_namespace(namespace) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/openshift/bind_plugin.rb', line 56 def register_namespace(namespace) # create a TXT record for the namespace in the domain fqdn = "#{namespace}.#{@domain_suffix}" # enable updates with key dns.tsig = @keyname, @keyvalue update = Dnsruby::Update.new(@zone) # update.absent(fqdn, 'TXT') update.add(fqdn, 'TXT', 60, "Text record for #{namespace}") dns.(update) end |