Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reference-repository
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
grid5000
reference-repository
Commits
f8dfba7f
Commit
f8dfba7f
authored
7 years ago
by
Jonathan Pastor
Browse files
Options
Downloads
Patches
Plain Diff
[yaml_find_duplicates] the script can take sites and clusters as parameters
parent
f9987521
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
generators/input-validators/yaml-input-find-duplicates.rb
+77
-18
77 additions, 18 deletions
generators/input-validators/yaml-input-find-duplicates.rb
with
77 additions
and
18 deletions
generators/input-validators/yaml-input-find-duplicates.rb
+
77
−
18
View file @
f8dfba7f
...
...
@@ -12,48 +12,107 @@ require '../lib/input_loader'
class
::
Hash
def
deep_merge
(
other_hash
)
# merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
merger
=
proc
{
|
key
,
v1
,
v2
|
if
Hash
===
v1
&&
Hash
===
v2
v1
.
merge
(
v2
,
&
merger
)
merger
=
proc
{
|
key
,
v1
,
v2
|
if
Hash
===
v1
&&
Hash
===
v2
v1
.
merge
(
v2
,
&
merger
)
else
v1
.
gsub!
(
'!duplicated: '
)
if
String
===
v1
v2
.
gsub!
(
'!duplicated: '
)
if
String
===
v2
if
Hash
===
v1
||
Hash
===
v2
# for example, this occurs if there are some empty entries on yaml files that need to be deleted (ex: parasilo-1 => {})
# return a hash because it is needed by expand_square_brackets
{
'v1'
=>
v1
,
'v2'
=>
v2
,
'error'
=>
"!duplicated:
#{
key
}
"
}
{
'v1'
=>
v1
,
'v2'
=>
v2
,
'error'
=>
"!duplicated:
#{
key
}
"
}
else
# remove the following 'if' if you want all the duplicated keys
#if v1 != v2
"!duplicated: '
#{
v1
}
' '
#{
v2
}
'"
"!duplicated: '
#{
v1
}
' '
#{
v2
}
'"
#else
# v2
#end
end
end
}
self
.
merge
(
other_hash
,
&
merger
)
end
end
global_hash
=
load_yaml_file_hierarchy
(
"../../input/grid5000/"
)
def
yaml_input_find_duplicates
(
refapi_hash
,
options
)
refapi_hash
[
"sites"
].
sort
.
each
do
|
site_uid
,
site
|
if
options
.
key?
(
:sites
)
&&
!
options
[
:sites
].
include?
(
site_uid
)
refapi_hash
[
"sites"
].
delete
(
site_uid
)
end
site
[
"clusters"
].
sort
.
each
do
|
cluster_uid
,
cluster
|
if
options
.
key?
(
:clusters
)
&&
!
options
[
:clusters
].
include?
(
cluster_uid
)
site
[
"clusters"
].
delete
(
cluster_uid
)
end
end
end
# remove entries that are not duplicate
global
_hash
.
deep_reject!
{
|
k
,
v
|
!
(
(
v
.
is_a?
(
Hash
)
&&
!
v
.
empty?
)
||
v
.
is_a?
(
String
)
&&
v
.
start_with?
(
'!duplicated:'
)
)
}
refapi
_hash
.
deep_reject!
{
|
k
,
v
|
!
(
(
v
.
is_a?
(
Hash
)
&&
!
v
.
empty?
)
||
v
.
is_a?
(
String
)
&&
v
.
start_with?
(
'!duplicated:'
)
)}
# remove ip, mac and mounted properties (as it can be use to bootstrap the installation of a cluster)
global_hash
.
deep_reject!
{
|
k
,
v
|
k
==
'ip'
||
k
==
'mac'
||
k
==
'mounted'
}
global_hash
.
deep_reject!
{
|
k
,
v
|
v
==
{}
}
refapi_hash
.
deep_reject!
{
|
k
,
v
|
k
==
'ip'
||
k
==
'mac'
||
k
==
'mounted'
}
refapi_hash
.
deep_reject!
{
|
k
,
v
|
v
==
{}}
if
refapi_hash
.
empty?
puts
"OK: no duplicate entries."
else
puts
refapi_hash
.
to_yaml
end
if
global_hash
.
empty?
puts
"OK: no duplicate entries."
else
puts
global_hash
.
to_yaml
end
if
__FILE__
==
$0
require
'optparse'
options
=
{}
options
[
:sites
]
=
%w{grenoble lille luxembourg lyon nancy nantes rennes sophia}
options
[
:api
]
=
{}
OptionParser
.
new
do
|
opts
|
opts
.
banner
=
"Usage: yaml-input-find-duplicates.rb [options]"
opts
.
separator
""
opts
.
separator
"Example: ruby yaml-input-find-duplicates.rb -v"
###
opts
.
separator
""
opts
.
separator
"Filters:"
opts
.
on
(
'-s'
,
'--sites a,b,c'
,
Array
,
'Select site(s)'
,
"Default: "
+
options
[
:sites
].
join
(
", "
))
do
|
s
|
raise
"Wrong argument for -s option."
unless
(
s
-
options
[
:sites
]).
empty?
options
[
:sites
]
=
s
end
opts
.
on
(
'-c'
,
'--clusters a,b,c'
,
Array
,
'Select clusters(s). Default: all'
)
do
|
s
|
options
[
:clusters
]
=
s
end
opts
.
separator
""
opts
.
separator
"Common options:"
opts
.
on
(
"-v"
,
"--[no-]verbose"
,
"Run verbosely"
)
do
|
v
|
options
[
:verbose
]
||=
0
options
[
:verbose
]
=
options
[
:verbose
]
+
1
end
# Print an options summary.
opts
.
on_tail
(
"-h"
,
"--help"
,
"Show this message"
)
do
puts
opts
exit
end
end
.
parse!
refapi_hash
=
load_yaml_file_hierarchy
(
"../../input/grid5000/"
)
yaml_input_find_duplicates
(
refapi_hash
,
options
)
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment