Class: Roadworker::HealthCheck
- Inherits:
-
Object
- Object
- Roadworker::HealthCheck
- Defined in:
- lib/roadworker/route53-health-check.rb
Class Method Summary collapse
- .config_to_hash(config) ⇒ Object
- .gc(route53, options = {}) ⇒ Object
- .health_checks(route53, options = {}) ⇒ Object
- .parse_url(url) ⇒ Object
Instance Method Summary collapse
- #gc(options = {}) ⇒ Object
- #health_checks(options = {}) ⇒ Object
-
#initialize(route53) ⇒ HealthCheck
constructor
of class method.
Constructor Details
#initialize(route53) ⇒ HealthCheck
of class method
52 53 54 |
# File 'lib/roadworker/route53-health-check.rb', line 52 def initialize(route53) @route53 = route53 end |
Class Method Details
.config_to_hash(config) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/roadworker/route53-health-check.rb', line 16 def config_to_hash(config) ipaddr = config[:ip_address] port = config[:port] type = config[:type].downcase path = config[:resource_path] fqdn = config[:fully_qualified_domain_name].downcase url = "#{type}://#{ipaddr}:#{port}" url << path if path && path != '/' {:url => url, :host_name => fqdn} end |
.gc(route53, options = {}) ⇒ Object
12 13 14 |
# File 'lib/roadworker/route53-health-check.rb', line 12 def gc(route53, = {}) self.new(route53).gc() end |
.health_checks(route53, options = {}) ⇒ Object
8 9 10 |
# File 'lib/roadworker/route53-health-check.rb', line 8 def health_checks(route53, = {}) self.new(route53).health_checks() end |
.parse_url(url) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/roadworker/route53-health-check.rb', line 29 def parse_url(url) url = URI.parse(url) path = url.path if path.nil? or path.empty? or path == '/' path = nil end config = {} { :ip_address => url.host, :port => url.port, :type => url.scheme.upcase, :resource_path => path, }.each {|key, value| config[key] = value if value } return config end |
Instance Method Details
#gc(options = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/roadworker/route53-health-check.rb', line 98 def gc( = {}) AWS.memoize { check_list = health_checks return if check_list.empty? if (logger = [:logger]) logger.info('Clean HealthChecks (pass `--no-health-check-gc` if you do not want to clean)') end @route53.hosted_zones.each do |zone| zone.rrsets.each do |record| check_list.delete(record.health_check_id) end end check_list.each do |health_check_id, config| @route53.client.delete_health_check(:health_check_id => health_check_id) end } end |
#health_checks(options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/roadworker/route53-health-check.rb', line 56 def health_checks( = {}) check_list = {} is_truncated = true next_marker = nil while is_truncated opts = next_marker ? {:marker => next_marker} : {} response = @route53.client.list_health_checks(opts) response[:health_checks].each do |check| check_list[check[:id]] = check[:health_check_config] end is_truncated = response[:is_truncated] next_marker = response[:next_marker] end if [:extended] check_list.instance_variable_set(:@route53, @route53) def check_list.find_or_create(attrs) health_check_id, config = self.find {|hcid, elems| elems == attrs } unless health_check_id response = @route53.client.create_health_check({ :caller_reference => UUID.new.generate, :health_check_config => attrs, }) health_check_id = response[:health_check][:id] config = response[:health_check][:health_check_config] self[health_check_id] = config end return health_check_id end end return check_list end |