Commit 42251cd0 authored by Simon Delamare's avatar Simon Delamare
Browse files

[admin] Add network lookup functions (Florentin work)

parent 01a87cbe
......@@ -135,7 +135,60 @@ module G5K
raise ArgumentError, "Cannot fetch the values for '#{keys.inspect}' in the input file '#{filename}'. The config files you gave to me are: '#{config.keys.inspect}'."
end
end
# Build snmp_naming_pattern Example:
# '3 2 GigabitEthernet%LINECARD%/%PORT%' -> 'GigabitEthernet3/2'
def get_portname(lc_num,port_num,pattern)
return pattern.sub("%LINECARD%",lc_num.to_s).sub("%PORT%",port_num.to_s)
end
def net_switch_lookup(site, cluster, node_uid, interface='')
# Build the cluster_node_uid from argv1+argv2
if interface != ""
node_uid = node_uid+"-"+interface
end
Pathname.glob("generators/input/sites/#{site}/net-links/*.yaml").map { |i| i.basename.to_s.sub!(".yaml","") }.each do |equipment_name|
netlinks = File.open("generators/input/sites/#{site}/net-links/#{equipment_name}.yaml")
tab = YAML::load_stream ( netlinks )
tab[0][equipment_name]["linecards"].each do |(lc_num,lc_content)|
lc_content["ports"].each do |(port_num,port_content)|
if port_content.is_a?(Hash)
if port_content["uid"] == node_uid
return equipment_name
end
elsif port_content == node_uid
return equipment_name
end
end
end
end
return nil
end
# Parse network equipment description and print switch port connected to given node
def net_port_lookup(site, cluster, node_uid, interface='')
# Build the cluster_node_uid from argv1+argv2
if interface != ""
node_uid = node_uid+"-"+interface
end
Pathname.glob("generators/input/sites/#{site}/net-links/*.yaml").map { |i| i.basename.to_s.sub!(".yaml","") }.each do |equipment_name|
netlinks = File.open("generators/input/sites/#{site}/net-links/#{equipment_name}.yaml")
tab = YAML::load_stream ( netlinks )
tab[0][equipment_name]["linecards"].each do |(lc_num,lc_content)|
lc_content["ports"].each do |(port_num,port_content)|
if port_content.is_a?(Hash)
if port_content["uid"] == node_uid
return get_portname(lc_num,port_num,lc_content["snmp_pattern"])
end
elsif port_content == node_uid
return get_portname(lc_num,port_num,lc_content["snmp_pattern"])
end
end
end
end
return nil
end
# This method is used exclusivly for environments. Example:
# environment 'squeeze-x64-xen-0.8' do
# available_on %w{grenoble lille lyon nancy rennes sophia toulouse}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment