Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a6065a3f authored by Jérémie Gaidamour's avatar Jérémie Gaidamour
Browse files

[dev] added various comments, minor edits

parent e4b8895c
Branches
No related tags found
No related merge requests found
.DS_Store .DS_Store
*.swp *.swp
*~ *~
*Gemfile.lock
\ No newline at end of file
...@@ -11,18 +11,19 @@ def deep_merge_entries(a, b) ...@@ -11,18 +11,19 @@ def deep_merge_entries(a, b)
end end
end end
def rec_sort(h)
case h
when Array
h.map{|v| rec_sort(v)}#.sort_by!{|v| (v.to_s rescue nil) }
when Hash
Hash[Hash[h.map{|k,v| [rec_sort(k),rec_sort(v)]}].sort_by{|k,v| [(k.to_s rescue nil), (v.to_s rescue nil)]}]
else
h
end
end
# Write pretty and sorted JSON files # Write pretty and sorted JSON files
def write_json(filepath, data) def write_json(filepath, data)
def rec_sort(h)
case h
when Array
h.map{|v| rec_sort(v)}#.sort_by!{|v| (v.to_s rescue nil) }
when Hash
Hash[Hash[h.map{|k,v| [rec_sort(k),rec_sort(v)]}].sort_by{|k,v| [(k.to_s rescue nil), (v.to_s rescue nil)]}]
else
h
end
end
File.open(filepath, 'w') do |f| File.open(filepath, 'w') do |f|
f.write(JSON.pretty_generate(rec_sort(data))) f.write(JSON.pretty_generate(rec_sort(data)))
end end
...@@ -30,16 +31,6 @@ end ...@@ -30,16 +31,6 @@ end
# Write sorted YAML files # Write sorted YAML files
def write_yaml(filepath, data) def write_yaml(filepath, data)
def rec_sort(h)
case h
when Array
h.map{|v| rec_sort(v)}#.sort_by!{|v| (v.to_s rescue nil) }
when Hash
Hash[Hash[h.map{|k,v| [rec_sort(k),rec_sort(v)]}].sort_by{|k,v| [(k.to_s rescue nil), (v.to_s rescue nil)]}]
else
h
end
end
File.open(filepath, 'w') do |f| File.open(filepath, 'w') do |f|
f.write(rec_sort(data).to_yaml) f.write(rec_sort(data).to_yaml)
end end
...@@ -118,7 +109,7 @@ class ::Hash ...@@ -118,7 +109,7 @@ class ::Hash
} }
end end
# sort a hash according to the position of the key in the array. # Sort a hash according to the position of the key in the array.
def sort_by_array(array) def sort_by_array(array)
Hash[sort_by{|key, _| array.index(key) || length}] Hash[sort_by{|key, _| array.index(key) || length}]
end end
...@@ -148,8 +139,19 @@ class ::Hash ...@@ -148,8 +139,19 @@ class ::Hash
} }
end end
def deep_copy(o) # Ex: { a: 1, b: nil, c: { d: nil, e: '' } }.deep_reject! { |k, v| v.blank? }
Marshal.load(Marshal.dump(o)) # ==> { a: 1 }
# Note: the blk delete condition is also applied to hash
# use { |k, v| !Hash === v } if you do not want this default behavior
def deep_reject!(&blk)
self.each do |k, v|
v.deep_reject!(&blk) if v.is_a?(Hash)
self.delete(k) if blk.call(k, v)
end
end end
end end
def deep_copy(o)
Marshal.load(Marshal.dump(o))
end
#!/usr/bin/ruby #!/usr/bin/ruby
# This script generates conmang5k/files/<site_uid>/conman.conf from input/ and conf/conman.yaml
require 'pp' require 'pp'
require 'erb' require 'erb'
require 'fileutils' require 'fileutils'
...@@ -7,12 +9,14 @@ require '../lib/input_loader' ...@@ -7,12 +9,14 @@ require '../lib/input_loader'
require '../lib/hash/hash.rb' require '../lib/hash/hash.rb'
global_hash = load_yaml_file_hierarchy("../input/grid5000/") global_hash = load_yaml_file_hierarchy("../input/grid5000/")
passwd_hash = YAML::load_file('./conman-password.yaml') output_dir = 'output'
passwd_hash = passwd_hash.expand_square_brackets()
conf_hash = YAML::load_file('./conf/conman-password.yaml')
conf_hash = conf_hash.expand_square_brackets()
def write_conman_file(site_uid, site, passwd) def write_conman_file(site_uid, site, passwd)
erb = ERB.new(File.read("templates/conman.erb")) erb = ERB.new(File.read("templates/conman.erb"))
output_file = File.join('output', 'conmang5k', 'files', site_uid, 'conman.conf') output_file = File.join(output_dir, 'conmang5k', 'files', site_uid, 'conman.conf')
# Create directory hierarchy # Create directory hierarchy
dirname = File.dirname(output_file) dirname = File.dirname(output_file)
...@@ -26,5 +30,5 @@ end ...@@ -26,5 +30,5 @@ end
# Loop over Grid'5000 sites # Loop over Grid'5000 sites
global_hash["sites"].each { |site_uid, site| global_hash["sites"].each { |site_uid, site|
write_conman_file(site_uid, site, passwd_hash[site_uid]) write_conman_file(site_uid, site, conf_hash[site_uid])
} }
#!/usr/bin/ruby #!/usr/bin/ruby
# This script generates:
# - kadeployg5k/files/<site_uid>/server_conf[_dev]/clusters.conf from input/
# - kadeployg5k/files/<site_uid>/server_conf[_dev]/<cluster_uid>-cluster.conf from conf/kadeployg5k.yaml and template/kadeployg5k.yaml.Erb
require 'pp' require 'pp'
require 'erb' require 'erb'
require 'fileutils' require 'fileutils'
...@@ -7,10 +11,7 @@ require '../lib/input_loader' ...@@ -7,10 +11,7 @@ require '../lib/input_loader'
require '../lib/hash/hash.rb' require '../lib/hash/hash.rb'
global_hash = load_yaml_file_hierarchy("../input/grid5000/") global_hash = load_yaml_file_hierarchy("../input/grid5000/")
output_dir = 'output'
template_hash = YAML::load_file('templates/kadeployg5k.yaml')
write_yaml('/tmp/test.yaml', template_hash)
# Compute cluster prefix # Compute cluster prefix
# input: cluster_list = ['graoully', 'graphene', 'griffon', ...] # input: cluster_list = ['graoully', 'graphene', 'griffon', ...]
...@@ -36,6 +37,7 @@ def cluster_prefix(cluster_list) ...@@ -36,6 +37,7 @@ def cluster_prefix(cluster_list)
end end
# Extract the node ip from the node hash
def get_ip(node) def get_ip(node)
node['network_adapters'].each { |device, network_adapter| node['network_adapters'].each { |device, network_adapter|
if network_adapter['mounted'] && /^eth[0-9]$/.match(device) if network_adapter['mounted'] && /^eth[0-9]$/.match(device)
...@@ -44,10 +46,15 @@ def get_ip(node) ...@@ -44,10 +46,15 @@ def get_ip(node)
} }
end end
# There is two kadeploy servers : kadeploy and kadeploy-dev
['', '-dev'].each {|suffix| ['', '-dev'].each {|suffix|
global_hash['sites'].each { |site_uid, site| global_hash['sites'].each { |site_uid, site|
next if site_uid != 'nancy'
#
# Generate site/<site_uid>/servers_conf[_dev]/clusters.conf
#
clusters_conf = { 'clusters'=> [] } # output clusters.conf clusters_conf = { 'clusters'=> [] } # output clusters.conf
prefix = cluster_prefix(site['clusters'].keys) prefix = cluster_prefix(site['clusters'].keys)
...@@ -107,8 +114,7 @@ end ...@@ -107,8 +114,7 @@ end
} # site['clusters'].each } # site['clusters'].each
output_file = File.join(output_dir, 'kadeployg5k', 'files', site_uid, "server_conf#{suffix.tr('-', '_')}", 'clusters.conf')
output_file = File.join('output', 'kadeployg5k', 'files', site_uid, "server_conf#{suffix.tr('-', '_')}", 'clusters.conf')
dirname = File.dirname(output_file) dirname = File.dirname(output_file)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname) FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment