Sha256: befff50b6ec6d34d37a99231dc893c499a9391754b5e182714c2831358f709ff

Contents?: true

Size: 622 Bytes

Versions: 1

Compression:

Stored size: 622 Bytes

Contents

require 'json'

module Ring
class SQA

  class NodesJSON
    def get node
      json = (@nodes[node] or {})
      {
        name: json['hostname'],
        ip:   node,
        as:   json['asn'],
        cc:   json['countrycode'],
      }
    rescue
      {}
    end

    private

    def initialize
      @file = CFG.nodes_json
      @nodes = (load_json rescue {})
    end

    def load_json
      nodes = {}
      json = JSON.load File.read(@file)
      json['results']['nodes'].each do |node|
        addr = CFG.ipv6? ? node['ipv6'] : node['ipv4']
        nodes[addr] = node
      end
      nodes
    end
  end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ring-sqa-0.0.19 lib/ring/sqa/nodes_json.rb