[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Debian JP master SVN www commits (rev.1014)



=======================================================
Repository: /org/svn.debian.or.jp/repos
  Revision: 1014
  Commiter: yasu
      Date: 2010-03-07 08:46:30 +0900 (日, 07  3月 2010)
=======================================================
Log:

add gae-surrogate

=======================================================
Changed:

A   cdn/trunk/gae-surrogates.rb

Added: cdn/trunk/gae-surrogates.rb
===================================================================
--- cdn/trunk/gae-surrogates.rb	                        (rev 0)
+++ cdn/trunk/gae-surrogates.rb	2010-03-06 23:46:30 UTC (rev 1014)
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+#
+# = Script of gae-surrogates.rb
+#
+# This script gets Debian-CDN-Style JSON data to convert DnsBalance's address file (addr).
+#
+# Mainly for http://debiancdn.appspot.com/json/alive.
+#
+# = DEPENDENCY
+# 
+# rubygems, json, open-uri.
+#    You can install json by 'gem install json'.
+#
+# = SYNOPSIS
+#
+# == How to run this script
+# 
+# ruby gae-surrogates.rb http://localhost:8080/json/alive
+#   OR
+# ruby gae-surrogates.rb local_file.json
+#
+# Then, this script makes './addr'.
+
+require 'rubygems'
+require 'json'
+require 'open-uri'
+
+begin
+  if ARGV[0] =~ /^http/
+    json = open(ARGV[0]).read
+  else
+    f = ARGV[0] 
+    json = File.open(f, 'r').read
+  end
+rescue
+  p $!
+  
+end
+pj = JSON.parse(json)
+
+addr = Hash.new
+
+pj.each do |hs|
+  country = hs['country']
+  hostname = hs['hostname']
+  if addr[country]
+  else
+    addr[country] = Hash.new
+  end
+  
+  if addr[country][hostname]
+  else
+    addr[country][hostname] = Array.new
+  end
+  addr[country][hostname].push([hs['ip'].split('.').map{|x| x.to_i}, hs['preference']])
+end
+
+addrfile = File.open("addr", 'w')
+addrfile.puts "##" + Time.now.to_s
+addrfile.puts "##" + ARGV[0] + "\n\n"
+addrfile.puts '$addr_db = ' + addr.inspect
+addrfile.close
+