Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 30183ea6 authored by IMBERT Matthieu's avatar IMBERT Matthieu
Browse files

move substitution and interpolation of ssh patterns to refapi generation

linecards' ssh_pattern and channels_ssh_pattern are transformed
into ssh_name into ports and channels
parent 8efadbca
No related branches found
No related tags found
No related merge requests found
Pipeline #1025953 failed
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"kind": "router", "kind": "router",
"port": "0:24", "port": "0:24",
"snmp_name": "GigabitEthernet1", "snmp_name": "GigabitEthernet1",
"ssh_name": "1",
"uid": "gw" "uid": "gw"
}, },
{ {
...@@ -63,24 +64,28 @@ ...@@ -63,24 +64,28 @@
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet22", "snmp_name": "GigabitEthernet22",
"ssh_name": "22",
"uid": "sagittaire-2" "uid": "sagittaire-2"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet23", "snmp_name": "GigabitEthernet23",
"ssh_name": "23",
"uid": "sagittaire-3" "uid": "sagittaire-3"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet24", "snmp_name": "GigabitEthernet24",
"ssh_name": "24",
"uid": "sagittaire-4" "uid": "sagittaire-4"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet25", "snmp_name": "GigabitEthernet25",
"ssh_name": "25",
"uid": "sagittaire-5" "uid": "sagittaire-5"
}, },
{ {
...@@ -91,36 +96,42 @@ ...@@ -91,36 +96,42 @@
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet28", "snmp_name": "GigabitEthernet28",
"ssh_name": "28",
"uid": "sagittaire-11" "uid": "sagittaire-11"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet29", "snmp_name": "GigabitEthernet29",
"ssh_name": "29",
"uid": "sagittaire-12" "uid": "sagittaire-12"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet30", "snmp_name": "GigabitEthernet30",
"ssh_name": "30",
"uid": "sagittaire-13" "uid": "sagittaire-13"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet31", "snmp_name": "GigabitEthernet31",
"ssh_name": "31",
"uid": "sagittaire-14" "uid": "sagittaire-14"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet32", "snmp_name": "GigabitEthernet32",
"ssh_name": "32",
"uid": "sagittaire-15" "uid": "sagittaire-15"
}, },
{ {
"kind": "node", "kind": "node",
"port": "eth1", "port": "eth1",
"snmp_name": "GigabitEthernet33", "snmp_name": "GigabitEthernet33",
"ssh_name": "33",
"uid": "sagittaire-16" "uid": "sagittaire-16"
} }
], ],
......
...@@ -8,24 +8,28 @@ ...@@ -8,24 +8,28 @@
"kind": "switch", "kind": "switch",
"port": "lag1", "port": "lag1",
"rate": 200000000000, "rate": 200000000000,
"ssh_name": "lag 1",
"uid": "sw-1" "uid": "sw-1"
}, },
"lag2": { "lag2": {
"kind": "server", "kind": "server",
"port": "lag2", "port": "lag2",
"rate": 50000000000, "rate": 50000000000,
"ssh_name": "lag 2",
"uid": "srv-data" "uid": "srv-data"
}, },
"lag3": { "lag3": {
"kind": "switch", "kind": "switch",
"port": "port-channel286", "port": "port-channel286",
"rate": 20000000000, "rate": 20000000000,
"ssh_name": "lag 3",
"uid": "swcore-01-rba" "uid": "swcore-01-rba"
}, },
"lag4": { "lag4": {
"kind": "server", "kind": "server",
"port": "lag4", "port": "lag4",
"rate": 50000000000, "rate": 50000000000,
"ssh_name": "lag 4",
"uid": "srv-data2" "uid": "srv-data2"
} }
}, },
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
"kind": "server", "kind": "server",
"port": "port-channel1", "port": "port-channel1",
"rate": 20000000000, "rate": 20000000000,
"ssh_name": "lag 1",
"uid": "nfs" "uid": "nfs"
}, },
"lag2": { "lag2": {
"kind": "switch", "kind": "switch",
"port": "lacp key 1", "port": "lacp key 1",
"rate": 20000000000, "rate": 20000000000,
"ssh_name": "lag 2",
"uid": "sw-estats" "uid": "sw-estats"
} }
}, },
......
...@@ -96,25 +96,14 @@ def gen_kavlanapi_g5k_desc(output_path, options) ...@@ -96,25 +96,14 @@ def gen_kavlanapi_g5k_desc(output_path, options)
end end
end end
def get_port_pattern_subst(pattern, linecard_index, port_index)
return pattern.gsub("%LINECARD%", linecard_index.to_s).sub("%PORT%", port_index.to_s)
end
def get_port_pattern_interpolation(pattern, linecard_index, port_index)
# reimplement with eval the ruby string interpolation mechanism (#{})
# WARNING: it means that code from the input yaml will be executed (thus input yamls may be used as attack vectors)
#return eval('"' + get_port_pattern_subst(pattern, linecard_index, port_index).gsub(/"/, '\"') + '"')
return eval('"' + get_port_pattern_subst(pattern, linecard_index, port_index) + '"')
end
# compute the port name for NGS ssh commands, based on device, # compute the port name for NGS ssh commands, based on device,
# linecard, port, using refapi ssh/kavlan/snmp patterns (with # linecard, port, using refapi ssh/kavlan/snmp patterns (with
# %LINECARD%, %PORT% substitutions), and interpolating the string for # %LINECARD%, %PORT% substitutions), and interpolating the string for
# ssh_pattern # ssh_pattern
def get_port_name(_refapi, site_name, device_name, linecard_index, linecard, port_index, port) def get_port_name(_refapi, site_name, device_name, linecard_index, linecard, port_index, port)
# try different possibilities, by order of precedence # try different possibilities, by order of precedence
if linecard.has_key?('ssh_pattern') if port.has_key?('ssh_name')
return get_port_pattern_interpolation(linecard['ssh_pattern'], linecard_index, port_index) return port['ssh_name']
elsif port.has_key?('snmp_name') elsif port.has_key?('snmp_name')
return port['snmp_name'] return port['snmp_name']
elsif linecard.has_key?('kavlan_pattern') elsif linecard.has_key?('kavlan_pattern')
...@@ -125,23 +114,12 @@ def get_port_name(_refapi, site_name, device_name, linecard_index, linecard, por ...@@ -125,23 +114,12 @@ def get_port_name(_refapi, site_name, device_name, linecard_index, linecard, por
end end
end end
def get_channel_pattern_subst(pattern, channel_name)
return pattern.gsub("%CHANNEL%", channel_name)
end
def get_channel_pattern_interpolation(pattern, channel_name)
# reimplement with eval the ruby string interpolation mechanism (#{})
# WARNING: it means that code from the input yaml will be executed (thus input yamls may be used as attack vectors)
#return eval('"' + get_channel_pattern_subst(pattern, channel_name).gsub(/"/, '\"') + '"')
return eval('"' + get_channel_pattern_subst(pattern, channel_name) + '"')
end
# compute the channel name for NGS ssh commands, based on device, # compute the channel name for NGS ssh commands, based on device,
# using refapi channel_ssh_pattern (with %CHANNEL% substitution), and # using refapi channel_ssh_pattern (with %CHANNEL% substitution), and
# interpolating the string # interpolating the string
def get_channel_name(refapi, site_name, device_name, _channel, channel_name) def get_channel_name(_refapi, _site_name, _device_name, channel, channel_name)
if refapi['sites'][site_name]['network_equipments'][device_name].has_key?('channels_ssh_pattern') if channel.has_key?('ssh_name')
return get_channel_pattern_interpolation(refapi['sites'][site_name]['network_equipments'][device_name]['channels_ssh_pattern'], channel_name) return channel['ssh_name']
else else
return channel_name return channel_name
end end
......
...@@ -788,6 +788,28 @@ def add_gpu_information(h) ...@@ -788,6 +788,28 @@ def add_gpu_information(h)
end end
end end
def get_port_pattern_subst(pattern, linecard_index, port_index)
return pattern.gsub("%LINECARD%", linecard_index.to_s).sub("%PORT%", port_index.to_s)
end
def get_port_pattern_interpolation(pattern, linecard_index, port_index)
# reimplement with eval the ruby string interpolation mechanism (#{})
# WARNING: it means that code from the input yaml will be executed (thus input yamls may be used as attack vectors)
#return eval('"' + get_port_pattern_subst(pattern, linecard_index, port_index).gsub(/"/, '\"') + '"')
return eval('"' + get_port_pattern_subst(pattern, linecard_index, port_index) + '"')
end
def get_channel_pattern_subst(pattern, channel_name)
return pattern.gsub("%CHANNEL%", channel_name)
end
def get_channel_pattern_interpolation(pattern, channel_name)
# reimplement with eval the ruby string interpolation mechanism (#{})
# WARNING: it means that code from the input yaml will be executed (thus input yamls may be used as attack vectors)
#return eval('"' + get_channel_pattern_subst(pattern, channel_name).gsub(/"/, '\"') + '"')
return eval('"' + get_channel_pattern_subst(pattern, channel_name) + '"')
end
def complete_one_network_equipment(network_uid, network) def complete_one_network_equipment(network_uid, network)
network["type"] = "network_equipment" network["type"] = "network_equipment"
network["uid"] = network_uid network["uid"] = network_uid
...@@ -810,10 +832,16 @@ def complete_one_network_equipment(network_uid, network) ...@@ -810,10 +832,16 @@ def complete_one_network_equipment(network_uid, network)
port['snmp_pattern'] = linecard['snmp_pattern'] port['snmp_pattern'] = linecard['snmp_pattern']
end end
if port['snmp_pattern'] if port['snmp_pattern']
port['snmp_name'] = port['snmp_pattern'] port['snmp_name'] = get_port_pattern_subst(port['snmp_pattern'], linecard_index, port_index)
.sub('%LINECARD%',linecard_index.to_s).sub('%PORT%',port_index.to_s)
port.delete('snmp_pattern') port.delete('snmp_pattern')
end end
if port['ssh_pattern'].nil? and linecard['ssh_pattern']
port['ssh_pattern'] = linecard['ssh_pattern']
end
if port['ssh_pattern']
port['ssh_name'] = get_port_pattern_interpolation(port['ssh_pattern'], linecard_index, port_index)
port.delete('ssh_pattern')
end
if ((!linecard['kind'].nil? && if ((!linecard['kind'].nil? &&
port['kind'].nil? && port['kind'].nil? &&
linecard['kind'] == 'node') || linecard['kind'] == 'node') ||
...@@ -830,6 +858,19 @@ def complete_one_network_equipment(network_uid, network) ...@@ -830,6 +858,19 @@ def complete_one_network_equipment(network_uid, network)
linecards_array[linecard_index] = linecard linecards_array[linecard_index] = linecard
end end
network["linecards"] = linecards_array.map{|l| l || {}} network["linecards"] = linecards_array.map{|l| l || {}}
# Channels
if network.key?('channels')
network['channels'].each do |channel_name, channel|
if channel['ssh_pattern'].nil? and network['channels_ssh_pattern']
channel['ssh_pattern'] = network['channels_ssh_pattern']
end
if channel['ssh_pattern']
channel['ssh_name'] = get_channel_pattern_interpolation(channel['ssh_pattern'], channel_name)
channel.delete('ssh_pattern')
end
end
end
end end
def complete_network_equipments(h) def complete_network_equipments(h)
......
...@@ -48,6 +48,7 @@ channels: ...@@ -48,6 +48,7 @@ channels:
kind: string kind: string
rate: integer rate: integer
trunk: optional_boolean trunk: optional_boolean
ssh_name: optional_string
metrics: optional_array metrics: optional_array
uid: string uid: string
type: string type: string
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment