Skip to content
GitLab
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
cf1af4a9
Commit
cf1af4a9
authored
Mar 02, 2016
by
Jérémie Gaidamour
Browse files
[dev] Custom iterators
parent
2a39dee9
Changes
4
Hide whitespace changes
Inline
Side-by-side
generators/bind/bind.rb
View file @
cf1af4a9
...
...
@@ -36,7 +36,7 @@ global_hash["sites"].each { |site_uid, site_hash|
site_hash
.
fetch
(
"clusters"
).
sort
.
each
{
|
cluster_uid
,
cluster_hash
|
cluster_hash
.
fetch
(
'nodes'
).
sort_by
{
|
item
|
item
.
to_s
.
split
(
/(\d+)/
).
map
{
|
e
|
[
e
.
to_i
,
e
]
}
}.
each
{
|
node_uid
,
node_hash
|
cluster_hash
.
fetch
(
'nodes'
).
each_
sort_by
_node_uid
{
|
node_uid
,
node_hash
|
network_interfaces
=
{}
node_hash
.
fetch
(
'network_interfaces'
).
each
{
|
net_uid
,
net_hash
|
...
...
generators/dhcp/templates/dhcp.erb
View file @
cf1af4a9
...
...
@@ -9,7 +9,7 @@
%>
group {
<%
data
.
fetch
(
'nodes'
).
sort_by
{
|
item
|
item
.
to_s
.
split
(
/(\d+)/
).
map
{
|
e
|
[
e
.
to_i
,
e
]
}
}.
each
{
|
node_uid
,
node_hash
|
data
.
fetch
(
'nodes'
).
each_
sort_by
_node_uid
{
|
node_uid
,
node_hash
|
network_interface
!=
'bmc'
?
node_uid_net
=
node_uid
:
node_uid_net
=
node_uid
+
'-bmc'
# Get ip and mac addresses
...
...
generators/lib/hash/hash.rb
View file @
cf1af4a9
...
...
@@ -90,4 +90,23 @@ class ::Hash
return
array
.
reverse
.
inject
(
value
)
{
|
a
,
n
|
{
n
=>
a
}
}
end
# Custom iterator. Same as "each" but it sorts keys by node_uid (ie. graphene-10 after graphene-9)
def
each_sort_by_node_uid
self
.
sort_by
{
|
item
|
item
.
to_s
.
split
(
/(\d+)/
).
map
{
|
e
|
[
e
.
to_i
,
e
]
}
}.
each
{
|
key
,
value
|
yield
key
,
value
}
end
# Custom iterator. Only consider entries corresponding to cluster_list and node_list. Sorted by node_uid.
def
each_filtered_node_uid
(
cluster_list
,
node_list
)
self
.
each_sort_by_node_uid
{
|
node_uid
,
properties
|
cluster_uid
=
node_uid
.
split
(
/-/
).
first
if
(
!
cluster_list
||
cluster_list
.
include?
(
cluster_uid
))
&&
(
!
node_list
||
node_list
.
include?
(
node_uid
))
yield
node_uid
,
properties
end
}
end
end
generators/oar-properties/oar-properties.rb
View file @
cf1af4a9
...
...
@@ -126,27 +126,21 @@ nodelist_properties["to_be_updated"] = {}
nodelist_properties
[
"ref"
].
each
{
|
site_uid
,
site_properties
|
site_properties
.
sort_by
{
|
item
|
item
.
to_s
.
split
(
/(\d+)/
).
map
{
|
e
|
[
e
.
to_i
,
e
]
}
}.
each
{
|
node_uid
,
node_properties_ref
|
cluster_uid
=
node_uid
.
split
(
/-/
).
first
if
(
!
options
[
:clusters
]
||
options
[
:clusters
].
include?
(
cluster_uid
))
&&
(
!
options
[
:nodes
]
||
options
[
:nodes
].
include?
(
node_uid
))
node_properties_oar
=
nodelist_properties
[
"oar"
][
site_uid
][
node_uid
]
site_properties
.
each_filtered_node_uid
(
options
[
:clusters
],
options
[
:nodes
])
{
|
node_uid
,
node_properties_ref
|
diff
=
diff_node_properties
(
node_properties_ref
,
node_properties_oar
)
diff_keys
=
diff
.
map
{
|
hashdiff_array
|
hashdiff_array
[
1
]
}
nodelist_properties
[
"to_be_updated"
][
node_uid
]
=
node_properties_ref
.
select
{
|
key
,
value
|
diff_keys
.
include?
(
key
)
}
node_properties_oar
=
nodelist_properties
[
"oar"
][
site_uid
][
node_uid
]
if
(
options
[
:verbose
])
#puts "#{node_uid}: #{diff}"
puts
"
#{
node_uid
}
:
#{
diff_keys
}
"
end
diff
=
diff_node_properties
(
node_properties_ref
,
node_properties_oar
)
diff_keys
=
diff
.
map
{
|
hashdiff_array
|
hashdiff_array
[
1
]
}
nodelist_properties
[
"to_be_updated"
][
node_uid
]
=
node_properties_ref
.
select
{
|
key
,
value
|
diff_keys
.
include?
(
key
)
}
if
(
options
[
:verbose
])
#puts "#{node_uid}: #{diff}"
puts
"
#{
node_uid
}
:
#{
diff_keys
}
"
end
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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