-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRakefile
More file actions
316 lines (271 loc) · 11 KB
/
Rakefile
File metadata and controls
316 lines (271 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# frozen_string_literal:true
require 'bundler/setup'
if ENV['COV']
require 'simplecov'
SimpleCov.start
end
if RUBY_VERSION < '2.1'
puts 'This script requires ruby >= 2.1'
exit
end
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'refrepo'
G5K_PUPPET_DIR = (ENV['OUTPUTDIR'] ? ENV['OUTPUTDIR'] : "#{ENV['HOME']}/.gpuppet/repo".freeze)
PUPPET_ODIR = Dir.exist?(G5K_PUPPET_DIR) ? G5K_PUPPET_DIR : '/tmp/puppet'
DEFAULT_CONF_DIR = "#{G5K_PUPPET_DIR}/platforms/production/generators".freeze
CONF_DIR = ENV['CONFDIR'] || DEFAULT_CONF_DIR
GENERATED_MODULES_DIR = "#{PUPPET_ODIR}/platforms/production/modules/generated/files".freeze
G5K_SITES = RefRepo::Utils.get_sites
SITES = (ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES)
CLUSTERS = (ENV['CLUSTER'] ? ENV['CLUSTER'].split(',') : [])
VERBOSE = ENV['VERBOSE'] ? ENV['VERBOSE'].to_i : false
options = {
'sites': SITES,
'clusters': CLUSTERS,
'conf_dir': CONF_DIR,
'output_dir': PUPPET_ODIR,
'modules_dir': GENERATED_MODULES_DIR,
'verbose': VERBOSE
}
desc 'Import YAML files generated by g5k-checks to input/ dir -- parameters: SOURCEDIR=directory'
task 'g5k-checks-import' do
require 'refrepo/g5kchecks_importer'
sourcedir = ENV['SOURCEDIR']
if sourcedir.nil?
puts 'SOURCEDIR= needed. Exiting.'
exit(1)
end
g5kchecks_importer(sourcedir)
end
namespace :valid do
desc 'Run all base checks (homogeneity, duplicates, schema) -- parameters: [SITE={grenoble,..}] [CLUSTER={yeti,..}] [VERBOSE=1]'
task 'base' do
require 'refrepo/valid/homogeneity'
require 'refrepo/valid/input/duplicates'
require 'refrepo/valid/input/schema'
require 'refrepo/valid/duplicate_values'
puts '# Checking homogeneity ...'
ret1 = check_cluster_homogeneity(options)
puts '# Checking duplicates ...'
ret2 = yaml_input_find_duplicates(options)
puts '# Checking schema ...'
ret3 = yaml_input_schema_validator(options)
puts '# Checking duplicate values ...'
ret4 = check_duplicate_values
exit(ret1 && ret2 && ret3 && ret4)
end
desc 'Check homogeneity of clusters -- parameters: [SITE={grenoble,..}] [CLUSTER={yeti,..}] [VERBOSE=1]'
task 'homogeneity' do
require 'refrepo/valid/homogeneity'
ret = check_cluster_homogeneity(options)
exit(ret)
end
desc 'Check for duplicates fields in input -- parameters: [SITE={grenoble..}] [CLUSTER={yeti,...}] [VERBOSE=1]'
task 'duplicates' do
require 'refrepo/valid/input/duplicates'
ret = yaml_input_find_duplicates(options)
exit(ret)
end
desc 'Check for duplicates values in some fields that should be globally unique'
task 'duplicate-values' do
require 'refrepo/valid/duplicate_values'
ret = check_duplicate_values
exit(ret)
end
desc 'Check input data schema validity -- parameters: [SITE={grenoble,..}] [CLUSTER={yeti,..}]'
task 'schema' do
require 'refrepo/valid/input/schema'
ret = yaml_input_schema_validator(options)
exit(ret)
end
desc 'Check for required and unwanted files in input/'
task 'required-unwanted-files' do
require 'refrepo/valid/input/required_unwanted_files'
ret = yaml_input_required_unwanted_files(options)
exit(ret)
end
desc 'Check OAR properties -- parameters: [SITE={grenoble,...}] [CLUSTER={yeti,...}] [VERBOSE=1]'
task 'oar-properties' do
require 'refrepo/valid/oar-properties'
ret = RefRepo::Valid::OarProperties.check(options)
exit(ret)
end
desc 'Check network description -- parameters: [SITE={grenoble,...}] [VERBOSE=1] [GENERATE_DOT=1]'
task 'network' do
require 'refrepo/valid/network'
options[:dot] = true if ENV['GENERATE_DOT']
ret = 2
begin
ret = check_network_description(options)
rescue StandardError => e
puts e
puts e.backtrace
ret = 3
ensure
exit(ret)
end
end
end
namespace :gen do
desc 'Run wiki generator -- parameters: NAME={hardware,site_hardware,oar_properties,modules_list,...} SITE={global,grenoble,...} DO={diff,print,update} [CONFDIR=...]'
task 'wiki' do
require 'refrepo/gen/wiki'
# FIXME: global is not a Grid'5000 site.
# It's a word that means we want to generate a special page in the wiki.
# 'global' should be moved out of options[:sites]
options[:sites] = (ENV['SITE'] ? ENV['SITE'].split(',') : ['global'] + G5K_SITES)
if ENV['NAME']
options[:generators] = if ENV['NAME'] == 'all'
RefRepo::Gen::Wiki::GLOBAL_GENERATORS.keys
else
ENV['NAME'].split(',')
end
else
puts 'You must specify a generator name using NAME='
exit(1)
end
options[:diff] = false
options[:print] = false
options[:update] = false
if ENV['DO']
ENV['DO'].split(',').each do |t|
options[:diff] = true if t == 'diff'
options[:print] = true if t == 'print'
options[:update] = true if t == 'update'
end
else
puts 'You must specify something to do using DO='
exit(1)
end
ret = RefRepo::Gen::Wiki.wikigen(options)
exit(ret)
end
desc 'Generate OAR properties -- parameters: SITE=grenoble CLUSTER={yeti,...} DO={print,table,update,diff} [OAR_SERVER=192.168.37.10] [OAR_SERVER_USER=g5kadmin]'
task 'oar-properties' do
# Manage oar-properties for a given set of Grid'5000 cluster. The task takes the following parameters
# Params:
# +SITE+:: Grid'5000 site (Nantes, Nancy, ...).
# +CLUSTERS+:: a comma separated list of Grid'5000 clusters (econome, ecotype, ...). This argument is optional:
# if no clusters is provided, the script will be run on each cluster of the specified site.
# +Do+:: specify the action to execute:
# - print: computes a mapping (server, cpu, core, gpu) for the given clusters, and shows OAR shell commands
# that would be run on an OAR server to converge to this mapping. This action try to reuse existing OAR
# resource's IDs, by fetching the current state of the OAR database via the OAR REST API (see the
# OAR_API_SERVER and OAR_API_PORT arguments).
# - table: show an ASCII table that illustrates the mapping (server, cpu, core, gpu) computed via action
# "print"
# - update: apply the commands of computed with the "print" task, to a given OAR server (see the OAR_SERVER
# and OAR_SERVER_USER arguments).
# - diff: Compare the mapping (server, cpu, core, gpu) computed with action "print", with the existing mapping
# fetched from the OAR REST API (see the OAR_API_SERVER, OAR_API_PORT).
# +OAR_SERVER+:: IP address fo the OAR server that will serve as a target of the generator. The generator will
# connect via SSH to this server. By default, it targets the OAR server of the Grid'5000 site.
# +OAR_SERVER_USER+:: SSH user that may be used to connect to the OAR server. By default, it targets the OAR server of the Grid'5000 site.
# +OAR_API_SERVER+:: IP address fo the server that hosts the OAR API. The generator will use it to understand the
# existing (server, cpu, core, gpu) mapping.
# +OAR_API_PORT+:: HTTP port used to connect to the REST API
require 'refrepo/gen/oar-properties'
if ENV['OAR_SERVER']
options[:ssh] ||= {}
options[:ssh][:host] = ENV['OAR_SERVER']
end
if ENV['OAR_SERVER_USER']
options[:ssh] ||= {}
options[:ssh][:user] = ENV['OAR_SERVER_USER']
end
options[:print] = false
options[:diff] = false
options[:update] = false
options[:table] = false
if ENV['DO']
ENV['DO'].split(',').each do |t|
options[:table] = true if t == 'table'
options[:print] = true if t == 'print'
options[:update] = true if t == 'update'
options[:diff] = true if t == 'diff'
end
else
puts 'You must specify something to do using DO='
exit(1)
end
ret = generate_oar_properties(options)
exit(ret)
end
desc 'Generate accesses json'
task :accesses do
require 'refrepo/gen/accesses'
generate_accesses_ir(%i[json])
end
desc 'Generate accesses mode history'
task 'accesses-history' do
require 'refrepo/gen/accesses'
generate_accesses_ir(%i[json history])
end
namespace :puppet do
base_puppet_tasks = %i[bindg5k conmang5k dhcpg5k kadeployg5k lanpowerg5k refapi-subset
oarsub-simplifier-aliases clusters hieradata]
all_puppet_tasks = base_puppet_tasks + %i[kavlang5k kwollectg5k network_monitoring oxidizedg5k kavlanngg5k
stitcherg5k webfish]
all_puppet_tasks.each do |t|
generated_desc = t == :'refapi-subset' ? 'description' : 'configuration'
# tasks oxidizedg5k and stitcherg5K doesn't use the parameters
# SITE and VERBOSE. So we don't print them in the 'rake -T' for
# theses tasks.
parameters = "[OUTPUTDIR=(default: #{PUPPET_ODIR})] [CONFDIR=...]"
parameters = "[SITE={grenoble,...}] #{parameters} [VERBOSE=1]" unless %i[oxidizedg5k stitcherg5k].include? t
desc "Generate #{t} #{generated_desc} -- parameters: #{parameters}"
task t do
require "refrepo/gen/puppet/#{t}"
send("generate_puppet_#{t}".gsub(/-/, '_'), options)
end
end
desc "Launch base puppet generators (#{base_puppet_tasks.map(&:to_s)})"
task base: base_puppet_tasks
desc 'Launch all puppet generators'
task all: all_puppet_tasks
end
end
namespace :version do
desc 'Get bios, bmc and firmwares version -- parameters: MODEL={630,6420,...}'
task :get do
require 'refrepo/firmwares'
model = ENV['MODEL']
raise 'need MODEL=' if model.nil?
model_filter = nodes_by_model(model)
model_filter.sort_by { |node| node['uid'].to_s.split(/(\d+)/).map { |e| [e.to_i, e] } }.each do |node|
version = {}
version['bios'] = node['bios']['version']
version['bmc_version'] = node['bmc_version']
version['network_adapters'] = get_firmware_version(node['network_adapters'])
version['storage_devices'] = get_firmware_version(node['storage_devices'])
puts "#{node['uid']} : #{version}"
end
end
desc 'Build an HTML table with firmware versions'
task :table do
require 'refrepo/firmwares'
gen_firmwares_tables
end
end
desc 'Creates JSON data from inputs'
task 'reference-api' do
require 'refrepo/gen/reference-api'
generate_reference_api
end
desc 'Output sorted VLAN offsets table (to update the input YAML after modification)'
task 'sort-vlans-offsets' do
sorted_vlan_offsets
end
desc 'Retrieve Dell warranty and information using TechDirect API'
task 'gen:dell-product-data' do
require 'refrepo/gen/dell-product-data'
dell_product_data
end
# Hack rake: call only the first task and consider the rest as arguments to this task
current_task = Rake.application.top_level_tasks.first
task_names = Rake.application.tasks.map(&:name)
if task_names.include?(current_task)
Rake.application.instance_variable_set(:@top_level_tasks, [current_task])
ARGV.shift(ARGV.index(current_task) + 1)
$CMD_ARGS = ARGV.map { |arg| "'#{arg}'" }.join(' ')
end