diff --git a/data/grid5000/sites/lyon/network_equipments/salome.json b/data/grid5000/sites/lyon/network_equipments/salome.json index 08c2e5dc47edf6e9bd29514a38a1b13c6571c286..e16786b8d89ca5f823e499face7b854793a09565 100644 --- a/data/grid5000/sites/lyon/network_equipments/salome.json +++ b/data/grid5000/sites/lyon/network_equipments/salome.json @@ -17,6 +17,7 @@ "kind": "router", "port": "0:24", "snmp_name": "GigabitEthernet1", + "ssh_name": "1", "uid": "gw" }, { @@ -63,24 +64,28 @@ "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet22", + "ssh_name": "22", "uid": "sagittaire-2" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet23", + "ssh_name": "23", "uid": "sagittaire-3" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet24", + "ssh_name": "24", "uid": "sagittaire-4" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet25", + "ssh_name": "25", "uid": "sagittaire-5" }, { @@ -91,36 +96,42 @@ "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet28", + "ssh_name": "28", "uid": "sagittaire-11" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet29", + "ssh_name": "29", "uid": "sagittaire-12" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet30", + "ssh_name": "30", "uid": "sagittaire-13" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet31", + "ssh_name": "31", "uid": "sagittaire-14" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet32", + "ssh_name": "32", "uid": "sagittaire-15" }, { "kind": "node", "port": "eth1", "snmp_name": "GigabitEthernet33", + "ssh_name": "33", "uid": "sagittaire-16" } ], diff --git a/data/grid5000/sites/rennes/network_equipments/gw.json b/data/grid5000/sites/rennes/network_equipments/gw.json index 5c4d050b26023b8c1a39d587a6cd91c7a92723fb..ca8c5cd3b34de6852362d3a64ea48e9a39342057 100644 --- a/data/grid5000/sites/rennes/network_equipments/gw.json +++ b/data/grid5000/sites/rennes/network_equipments/gw.json @@ -8,24 +8,28 @@ "kind": "switch", "port": "lag1", "rate": 200000000000, + "ssh_name": "lag 1", "uid": "sw-1" }, "lag2": { "kind": "server", "port": "lag2", "rate": 50000000000, + "ssh_name": "lag 2", "uid": "srv-data" }, "lag3": { "kind": "switch", "port": "port-channel286", "rate": 20000000000, + "ssh_name": "lag 3", "uid": "swcore-01-rba" }, "lag4": { "kind": "server", "port": "lag4", "rate": 50000000000, + "ssh_name": "lag 4", "uid": "srv-data2" } }, diff --git a/data/grid5000/sites/toulouse/network_equipments/gw.json b/data/grid5000/sites/toulouse/network_equipments/gw.json index 5c60ddb30893139022f2ad390315d26ebf038a85..6ae7e1099a8acb0c35721b1b7a1e1bc2b4f4d454 100644 --- a/data/grid5000/sites/toulouse/network_equipments/gw.json +++ b/data/grid5000/sites/toulouse/network_equipments/gw.json @@ -7,12 +7,14 @@ "kind": "server", "port": "port-channel1", "rate": 20000000000, + "ssh_name": "lag 1", "uid": "nfs" }, "lag2": { "kind": "switch", "port": "lacp key 1", "rate": 20000000000, + "ssh_name": "lag 2", "uid": "sw-estats" } }, diff --git a/lib/refrepo/gen/puppet/kavlanngg5k.rb b/lib/refrepo/gen/puppet/kavlanngg5k.rb index 4d59a4a0530bcec5a759caa7a75f00b5578ad381..8ece2ea077ad75aac149a8c6d1445b0ca4017dad 100644 --- a/lib/refrepo/gen/puppet/kavlanngg5k.rb +++ b/lib/refrepo/gen/puppet/kavlanngg5k.rb @@ -96,25 +96,14 @@ def gen_kavlanapi_g5k_desc(output_path, options) 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, # linecard, port, using refapi ssh/kavlan/snmp patterns (with # %LINECARD%, %PORT% substitutions), and interpolating the string for # ssh_pattern def get_port_name(_refapi, site_name, device_name, linecard_index, linecard, port_index, port) # try different possibilities, by order of precedence - if linecard.has_key?('ssh_pattern') - return get_port_pattern_interpolation(linecard['ssh_pattern'], linecard_index, port_index) + if port.has_key?('ssh_name') + return port['ssh_name'] elsif port.has_key?('snmp_name') return port['snmp_name'] elsif linecard.has_key?('kavlan_pattern') @@ -125,23 +114,12 @@ def get_port_name(_refapi, site_name, device_name, linecard_index, linecard, por 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, # using refapi channel_ssh_pattern (with %CHANNEL% substitution), and # interpolating the string -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') - return get_channel_pattern_interpolation(refapi['sites'][site_name]['network_equipments'][device_name]['channels_ssh_pattern'], channel_name) +def get_channel_name(_refapi, _site_name, _device_name, channel, channel_name) + if channel.has_key?('ssh_name') + return channel['ssh_name'] else return channel_name end diff --git a/lib/refrepo/input_loader.rb b/lib/refrepo/input_loader.rb index 7c5860d1665b3dda4828121a65858c7022c54175..ed1732ee73e2aff1a372792c181d2e84fccdf5e6 100644 --- a/lib/refrepo/input_loader.rb +++ b/lib/refrepo/input_loader.rb @@ -788,6 +788,28 @@ def add_gpu_information(h) 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) network["type"] = "network_equipment" network["uid"] = network_uid @@ -810,10 +832,16 @@ def complete_one_network_equipment(network_uid, network) port['snmp_pattern'] = linecard['snmp_pattern'] end if port['snmp_pattern'] - port['snmp_name'] = port['snmp_pattern'] - .sub('%LINECARD%',linecard_index.to_s).sub('%PORT%',port_index.to_s) + port['snmp_name'] = get_port_pattern_subst(port['snmp_pattern'], linecard_index, port_index) port.delete('snmp_pattern') 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? && port['kind'].nil? && linecard['kind'] == 'node') || @@ -830,6 +858,19 @@ def complete_one_network_equipment(network_uid, network) linecards_array[linecard_index] = linecard end 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 def complete_network_equipments(h) diff --git a/lib/refrepo/valid/input/schemas/schema-network_equipments.yaml b/lib/refrepo/valid/input/schemas/schema-network_equipments.yaml index f02f8bdae0951448d3232e00d7e7ee4a33d637c4..06567195f5bc665ffbb90b7dcfe647db2c5b7121 100644 --- a/lib/refrepo/valid/input/schemas/schema-network_equipments.yaml +++ b/lib/refrepo/valid/input/schemas/schema-network_equipments.yaml @@ -48,6 +48,7 @@ channels: kind: string rate: integer trunk: optional_boolean + ssh_name: optional_string metrics: optional_array uid: string type: string