Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
grid5000
reference-repository
Commits
42251cd0
Commit
42251cd0
authored
Jun 18, 2014
by
Simon Delamare
Browse files
[admin] Add network lookup functions (Florentin work)
parent
01a87cbe
Changes
1
Hide whitespace changes
Inline
Side-by-side
generators/lib/g5k_generator.rb
View file @
42251cd0
...
...
@@ -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}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment