Commit 96f0340f authored by Gaetan SIMO's avatar Gaetan SIMO
Browse files

[network-api] Fixing some bugs

parent 75ef44a6
......@@ -2,3 +2,4 @@ source :rubygems
gem 'json_pure', '~> 1.5'
gem 'net-ssh'
gem 'restfully','1.0.5'
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.8)
backports (2.5.1)
bond (0.4.2)
json (1.7.0)
json_pure (1.5.1)
mime-types (1.18)
net-ssh (2.1.0)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rb-readline (0.4.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rest-client-components (1.2.0)
rack (>= 1.0.1)
rest-client (>= 1.6.0, < 1.7.0)
restfully (1.0.5)
addressable
backports
json (~> 1.5)
rack-cache
rb-readline
rest-client (~> 1.6)
rest-client-components
ripl (= 0.6.1)
ripl-color_streams
ripl-multi_line
ripl-play (~> 0.2.1)
ripl-short_errors
ripl (0.6.1)
bond (~> 0.4.0)
ripl-color_streams (0.1.2)
ripl (>= 0.2.8)
ripl-multi_line (0.3.0)
ripl (>= 0.3.6)
ripl-play (0.2.1)
ripl (>= 0.3.0)
ripl-short_errors (0.1.0)
ripl (>= 0.2.8)
PLATFORMS
ruby
......@@ -10,3 +47,4 @@ PLATFORMS
DEPENDENCIES
json_pure (~> 1.5)
net-ssh
restfully (= 1.0.5)
......@@ -9,14 +9,13 @@ ROOT_DIR = File.expand_path File.dirname(__FILE__)
LIB_DIR = File.join(ROOT_DIR, "generators", "lib")
$LOAD_PATH.unshift(LIB_DIR) unless $LOAD_PATH.include?(LIB_DIR)
EXTRA_DIR = File.join(ROOT_DIR, "extras")
EXTRA_DIR_LIB = File.join(EXTRA_DIR, "lib")
$LOAD_PATH.unshift(EXTRA_DIR_LIB) unless $LOAD_PATH.include?(EXTRA_DIR_LIB)
EXTRA_DIR = File.join(ROOT_DIR, "extra", "lib")
$LOAD_PATH.unshift(EXTRA_DIR) unless $LOAD_PATH.include?(EXTRA_DIR)
Rake.application.options.trace = true
require 'grid5000'
require 'naming-pattern'
#require 'naming-pattern'
task :environment do
Dir.chdir(ROOT_DIR)
......@@ -71,13 +70,12 @@ namespace :netlinks do
# copy the 'extra' dir on the site,
# execute all the probing on all hosts
# retrieve the result from all hosts
extra_dir_basename = File.basename(EXTRA_DIR)
prober = "weathermap.#{site}.grid5000.fr"
sh "rsync -av #{EXTRA_DIR} #{prober}:"
sh "ssh #{prober} 'cd #{extra_dir_basename} && http_proxy=http://proxy:3128 bundle install'"
sh "rsync -av extra #{prober}:"
sh "ssh #{prober} 'cd extra && bundle install'"
probes.each do |info|
sh "ssh #{prober} 'cd #{extra_dir_basename} && ./bin/net-links.rb --host #{info[:uid]} --community #{info[:snmp_community]} --logger stdout:warn'"
sh "ssh #{prober} 'cd extra && ./bin/net-links.rb --host #{info[:uid]} --community #{info[:snmp_community]} --logger stdout:warn'"
end
probes.each do |info|
sh "rsync -av #{prober}:/tmp/#{info[:uid]}.yaml #{net_links_dir}/"
......@@ -104,16 +102,12 @@ namespace :netlinks do
end
def format_port(coord,raw_port,linecards)
# puts "#{coord.inspect} #{raw_port.inspect}"
neighbor,port,site = nil
neighbor,site = nil
if raw_port.has_key? :fqdn
neighbor,site = raw_port[:fqdn].scan(/([^.]+)\.([^.]+)\.grid5000\.fr/).flatten
elsif raw_port.has_key? :uid
if ((scan = raw_port[:uid].scan(/([^.]+)\.([^.]+)\.grid5000\.fr/)).size > 0)
neighbor,site = scan.flatten
else
neighbor = raw_port[:uid]
end
port = raw_port[:port]
neighbor,site = raw_port[:uid].scan(/([^.]+)\.([^.]+)\.grid5000\.fr/).flatten
neighbor = raw_port[:uid] if neighbor.nil?
end
return if neighbor.nil?
......@@ -122,17 +116,12 @@ namespace :netlinks do
linecards[l] = {"ports"=>{}} unless linecards.has_key? l
ports = linecards[l]["ports"]
formated_port = ports[p]
if formated_port.nil? and port.nil?
if formated_port.nil?
ports[p] = neighbor
elsif formated_port.is_a? Hash
ports[p]["uid"] = neighbor
ports[p]["port"] = port unless port.nil?
else
if port.nil?
ports[p] = neighbor
else
ports[p] = {"uid"=>neighbor,"port"=>port}
end
ports[p] = neighbor
end
end
def browse_naming_patterns(dico,patterns,&block)
......@@ -231,47 +220,6 @@ namespace :netlinks do
puts "+-#{"-" * message_size}-+"
end
end
task :net_links => [:environment,:hosts] do
host,site = @host.scan(/(\S+)\.(\S+)/).flatten
dirs = Dir.glob("generators/input/#{site}/")
if dirs.empty?
@logger.error "Failed to find a directory containing the net-links yaml file for your site '#{site}'"
next
end
@equipments = dirs.map do |dir|
site = File.basename(dir)
net_links_file = File.join(dir,"net-links.yaml")
net_links_dir = File.join(dir,"net-links")
net_links_orig = YAML::load_file(net_links_file)
net_links = net_links_orig.select do |uid,properties|
uid.match(Regexp.new(host.gsub(/\*/,'\S+'))) != nil
end
if net_links.empty?
@logger.warn "Failed to find any host described within the file #{net_links_file}."
else
{:net_links => net_links,:net_links_orig => net_links_orig,:net_links_file=>net_links_file}
end
end
end
desc "Manually modify net-links.yaml with custumized script."
task :manual => :net_links do
# puts @net_links.inspect
# gw.grenoble
gw = @equipments[0]
puts gw[:net_links]
linecards = gw[:net_links]["sbordeplage-2"]["linecards"][1]
linecards["ports"] = {} if linecards["ports"].nil?
ports = linecards["ports"]
11.upto(51) do |i|
ports[i-10] = "bordeplage-#{i}"
end
# When all net links in a site are formated, we write them in they file.
File.open(gw[:net_links_file],'w'){|f| YAML::dump(gw[:net_links_orig].merge(gw[:net_links]),f)}
puts "updated #{gw[:net_links_file]}"
end
desc "Update net-links.yaml with the kavlan like config file."
task :kavlan => [:environment,:hosts] do
config_file = ENV['CONF']
......@@ -288,31 +236,26 @@ namespace :netlinks do
net_links_file = File.join(dir,"net-links.yaml")
net_links_dir = File.join(dir,"net-links")
net_links_orig = YAML::load_file(net_links_file)
net_links = net_links_orig.select do |uid,properties|
net_links = YAML::load_file(net_links_file)
net_links.keep_if do |uid,properties|
uid.match(Regexp.new(host.gsub(/\*/,'\S+'))) != nil
end
if net_links.empty?
@logger.warn "Failed to find any host described within the file #{net_links_file}."
else
# parse the kavlan like config file
# #newservices 9/2 FastIron
config = {}
File.read(config_file).lines.each do |line|
if ((scan = line.strip.scan(/^([^.]+)\.([^.]+)\.grid5000\.fr\s+(\S+)\s+(\S+)$/)).size > 0)
uid,site,ifname,router = scan.flatten
router = router.downcase
config[router] = [] unless config.has_key? router
port = {:ifname=>ifname}
if ((scan = uid.scan(/^([^-]+)-([^-]+)-(\S+)$/)).size>0)
cluster,node_id,iface = scan.flatten
port[:uid] = "#{cluster}-#{node_id}"
port[:port] = iface
else
port[:uid] = uid
end
config[router].push(port)
# if ((scan = uid.scan(/^(\S+-\d+)-(\S+)$/)).size > 0)
# uid,port = scan.flatten
# config[router].push({:uid=>uid,:ifname=>ifname,:port=>port})
# else
config[router].push({:uid=>uid,:ifname=>ifname})
# end
end
end
......@@ -344,7 +287,7 @@ namespace :netlinks do
end
end
# When all net links in a site are formated, we write them in they file.
File.open(net_links_file,'w'){|f| YAML::dump(net_links_orig.merge(net_links),f)}
File.open(net_links_file,'w'){|f| YAML::dump(net_links,f)}
message.push "#{net_links_file} hosts=#{updated.inspect}"
end
end
......@@ -368,12 +311,14 @@ namespace :netlinks do
@logger.error "Failed to find a directory containing the net-links yaml file for your site '#{site}'"
next
end
generator = "#{File.join(ROOT_DIR, "generators", "grid5000")}"
net_link_generator = "#{File.join(ROOT_DIR, "generators", "input", "net-links-generator.rb")}"
dirs.each do |dir|
site = File.basename(dir)
net_links_file = File.expand_path(File.join(dir,"net-links.yaml"))
command = "#{generator} #{net_link_generator} #{net_links_file}"
site_file = File.expand_path(File.join(dir,"..","#{site}.rb"))
command = "#{generator} #{site_file} #{net_link_generator} #{net_links_file}"
command << " -s" if ENV['DRY'] && ENV['DRY'] != "0"
sh command
end
......
{
"compilation_server": false,
"description": "Grid5000 Bordeaux site",
"email_contact": "bordeaux-staff@lists.grid5000.fr",
"latitude": 44.833333,
"location": "Bordeaux, France",
"longitude": -0.566667,
"name": "Bordeaux",
"security_contact": "bordeaux-staff@lists.grid5000.fr",
"sys_admin_contact": "bordeaux-staff@lists.grid5000.fr",
"type": "site",
"uid": "bordeaux"
"uid": "bordeaux",
"user_support_contact": "bordeaux-staff@lists.grid5000.fr",
"web": "http://www.grid5000.fr/mediawiki/index.php/Bordeaux:Home"
}
\ No newline at end of file
{
"compilation_server": false,
"description": "Grid'5000 Grenoble site",
"email_contact": "grenoble-staff@lists.grid5000.fr",
"latitude": 45.1833,
"location": "Grenoble, France",
"longitude": 5.7167,
"name": "Grenoble",
"security_contact": "grenoble-staff@lists.grid5000.fr",
"sys_admin_contact": "grenoble-staff@lists.grid5000.fr",
"type": "site",
"uid": "grenoble"
"uid": "grenoble",
"user_support_contact": "grenoble-staff@lists.grid5000.fr",
"web": "http://www.grid5000.fr/mediawiki/index.php/Grenoble:Home"
}
\ No newline at end of file
{
"description": "",
"email_contact": null,
"latitude": 50.65,
"location": "Lille, France",
"longitude": 3.0833,
"name": "Lille",
"security_contact": null,
"sys_admin_contact": null,
"type": "site",
"uid": "lille"
"uid": "lille",
"user_support_contact": null,
"web": null
}
\ No newline at end of file
......@@ -12,96 +12,6 @@
},
{
<<<<<<< HEAD
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-1"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-23"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-2"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-24"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-3"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-25"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-4"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-26"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-5"
=======
},
{
......@@ -127,182 +37,11 @@
},
{
>>>>>>> network API generator scripts revisited and improved.
},
{
},
{
<<<<<<< HEAD
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-6"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-28"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-7"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-29"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-8"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-30"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-9"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-31"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-10"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-32"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-11"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-33"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-12"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-34"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-13"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-35"
},
{
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======
"rate": 1000000,
>>>>>>> [lille,lyon,nancy] First pass at a network equipment description.
"uid": "chinqchint-14"
=======
},
{
......@@ -352,162 +91,11 @@
},
{
>>>>>>> network API generator scripts revisited and improved.
},
{
},
{
<<<<<<< HEAD
"device": "eth0",
"kind": "node",
<<<<<<< HEAD
"rate": 1000000000,
=======