Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 31230546 authored by Lucas Nussbaum's avatar Lucas Nussbaum Committed by Teddy Valette
Browse files

[dev] Add allocation of IPv4 addresses

parent 6245f391
Branches
No related tags found
1 merge request!102Ipv4 second
---
ipv4:
base: 172.16.0.0
sites_offsets: |-
grenoble 0 0 16 0
lille 0 0 32 0
lyon 0 0 48 0
nancy 0 0 64 0
rennes 0 0 96 0
sophia 0 0 128 0
luxembourg 0 0 176 0
nantes 0 0 192 0
iface_offsets: |-
grenoble yeti eth0 0 0 3 0
grenoble dahu eth0 0 0 4 0
grenoble troll eth0 0 0 6 0
grenoble troll eth1 0 0 6 100
lille chifflot eth0 0 0 4 0
lille chifflot eth1 0 0 4 100
lille chetemi eth0 0 0 5 0
lille chetemi eth1 0 0 5 100
lille chifflet eth0 0 0 6 0
lille chifflet eth1 0 0 6 100
lille chiclet eth0 0 0 7 0
lille chiclet eth1 0 0 7 100
luxembourg granduc eth0 0 0 0 0
luxembourg granduc eth1 0 0 0 100
luxembourg granduc eth2 0 0 0 200
luxembourg petitprince eth0 0 0 1 0
luxembourg petitprince eth1 0 0 1 100
lyon sagittaire eth1 0 0 1 0
lyon taurus eth0 0 0 0 0
lyon orion eth0 0 0 2 0
lyon hercule eth1 0 0 3 0
lyon nova eth0 0 0 4 0
lyon gemini eth0 0 0 5 0
lyon pyxis eth0 0 0 6 0
nancy graffiti eth2 0 0 0 0
nancy gros eth0 0 0 2 0
nancy gros eth1 0 0 2 128
nancy graphique eth0 0 0 3 0
nancy graphite eth0 0 0 4 0
nancy graoully eth0 0 0 6 0
nancy grimoire eth0 0 0 7 0
nancy grimoire eth1 0 0 7 50
nancy grimoire eth2 0 0 7 100
nancy grimoire eth3 0 0 7 150
nancy grisou eth0 0 0 8 0
nancy grisou eth1 0 0 8 100
nancy grisou eth2 0 0 8 200
nancy grisou eth3 0 0 9 100
nancy grisou eth4 0 0 9 200
nancy grimani eth0 0 0 9 0
nancy grele eth0 0 0 10 0
nancy grcinq eth0 0 0 11 0
nancy grvingt eth0 0 0 12 0
nancy grue eth0 0 0 13 0
nantes econome eth0 0 0 0 0
nantes ecotype eth0 0 0 1 0
nantes ecotype eth1 0 0 2 0
rennes parapide eth0 0 0 2 0
rennes parapluie eth1 0 0 3 0
rennes paranoia eth0 0 0 4 0
rennes paranoia eth1 0 0 4 100
rennes paranoia eth2 0 0 4 200
rennes paravance eth0 0 0 0 0
rennes paravance eth1 0 0 0 100
rennes parasilo eth0 0 0 1 0
rennes parasilo eth1 0 0 1 100
sophia suno eth0 0 0 2 0
sophia uvb eth0 0 0 4 0
...@@ -111,11 +111,11 @@ def generate_reference_api ...@@ -111,11 +111,11 @@ def generate_reference_api
# remove kavlan information for now # remove kavlan information for now
global_hash.delete('vlans') global_hash.delete('vlans')
# remove software info
# also remove software info
global_hash.delete('software') global_hash.delete('software')
# remove ipv4 info
# also remove ipv6 info global_hash.delete('ipv4')
# remove ipv6 info
global_hash.delete('ipv6') global_hash.delete('ipv6')
grid_path = Pathname.new(refapi_path) grid_path = Pathname.new(refapi_path)
......
...@@ -50,7 +50,10 @@ def load_yaml_file_hierarchy(directory = File.expand_path("../../input/grid5000/ ...@@ -50,7 +50,10 @@ def load_yaml_file_hierarchy(directory = File.expand_path("../../input/grid5000/
# populate each node with its IPv6 # populate each node with its IPv6
add_ipv6(global_hash) add_ipv6(global_hash)
# populate each node with its kavlan IPs # populate each node with its IPv4 addresses
add_ipv4(global_hash)
# populate each node with its kavlan IPv4 IPs
add_kavlan_ips(global_hash) add_kavlan_ips(global_hash)
add_kavlan_ipv6s(global_hash) add_kavlan_ipv6s(global_hash)
...@@ -111,6 +114,34 @@ def add_kavlan_ips(h) ...@@ -111,6 +114,34 @@ def add_kavlan_ips(h)
end end
end end
def add_ipv4(h)
allocated = {}
base = IPAddress::IPv4::new(h['ipv4']['base']).to_u32
sites_offsets = h['ipv4']['sites_offsets'].split("\n").map { |l| l = l.split(/\s+/) ; [ l[0], l[1..-1].inject(0) { |a, b| (a << 8) + b.to_i } ] }.to_h
iface_offsets = h['ipv4']['iface_offsets'].split("\n").map { |l| l = l.split(/\s+/) ; [ l[0..2], l[3..-1].inject(0) { |a, b| (a << 8) + b.to_i } ] }.to_h
h['sites'].each_pair do |site_uid, hs|
hs['clusters'].each_pair do |cluster_uid, hc|
hc['nodes'].each_pair do |node_uid, hn|
raise "Node hash for #{node_uid} is nil" if hn.nil?
node_id = node_uid.split('-')[1].to_i
hn['network_adapters'].each_pair do |iface, v|
# only allocate mountable ethernet interfaces
next if not (v['mountable'] and v['interface'] == 'Ethernet')
k = [site_uid, cluster_uid, iface]
if not iface_offsets.has_key?(k)
raise "Missing IPv4 information for #{k}"
end
ip = IPAddress::IPv4::parse_u32(base + sites_offsets[site_uid] + iface_offsets[k] + node_id).to_s
a = [ site_uid, node_uid, iface ]
raise "IP already allocated: #{ip} (trying to add it to #{a} ; allocated to #{allocated[ip]})" if allocated[ip]
allocated[ip] = a
v['ip'] = ip
end
end
end
end
end
def add_ipv6(h) def add_ipv6(h)
# for each node # for each node
h['sites'].each_pair do |site_uid, hs| h['sites'].each_pair do |site_uid, hs|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment