Commit 4f86ea0d authored by Lucas Nussbaum's avatar Lucas Nussbaum
Browse files

[dev] move of wiki generators to lib/refrepo/

parent 80754da2
if ENV['COV']
require 'simplecov'
SimpleCov.start
end
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'refrepo'
REFAPI_DIR = "./generators/reference-api"
PUPPET_DIR = "./generators/puppet"
......@@ -5,6 +12,9 @@ OAR_DIR = "./generators/oar-properties"
VALIDATORS_DIR = "./generators/input-validators"
WIKI_DIR = "./generators/wiki"
# Get the list of sites as the list of directories in input/grid5000/sites
G5K_SITES = (Dir::entries('input/grid5000/sites') - ['.', '..']).sort
namespace :puppet do
all_puppet_tasks = [:bindg5k, :conmang5k, :dhcpg5k, :kadeployg5k, :lanpowerg5k, :kavlang5k]
......@@ -43,13 +53,36 @@ namespace :validators do
end
end
desc "See info about wiki generators"
task "wiki" do
puts "Wikigenerators are in generators/wiki. See the 'wikigen' script."
puts " => generators/wiki/wikigen -h"
puts "Examples:"
puts " generators/wiki/wiki -g cpu_parameters -s global -d"
puts " generators/wiki/wiki -g site_hardware -s nancy -d"
namespace :gen do
desc "Run wiki generator. Parameter: NAME={hardware,site_hardware,...} SITE={global,grenoble,...} DO={diff,print,update}"
task "wiki" do
options = {}
if ENV['SITE']
options[:sites] = ENV['SITE'].split(',')
else
options[:sites] = ['global'] + G5K_SITES
end
if ENV['NAME']
options[:generators] = ENV['NAME'].split(',')
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
RefRepo::Gen::Wiki::wikigen(options)
end
end
desc "Creates json data from inputs"
......
#!/usr/bin/env ruby
=begin
require 'simplecov'
SimpleCov.start
=end
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'wiki_generator'
require 'generators/cpu_parameters'
require 'generators/disk_reservation'
require 'generators/hardware'
require 'generators/oar_properties'
require 'generators/site_hardware'
require 'generators/site_network'
GLOBAL_GENERATORS = {
'cpu_parameters' => {
:gen => CPUParametersGenerator,
:page => "Generated/CPUParameters"
},
'disk_reservation' => {
:gen => DiskReservationGenerator,
:page => 'Generated/DiskReservation'
},
'hardware' => {
:gen => G5KHardwareGenerator,
:page => 'Hardware'
},
'oar_properties' => {
:gen => OarPropertiesGenerator,
:page => 'OAR_Properties'
}
}
SITE_GENERATORS = {
'site_hardware' => {
:gen => SiteHardwareGenerator,
:page_suffix => ':Hardware'
},
'site_network' => {
:gen => SiteNetworkGenerator,
:page_suffix => ':GeneratedNetwork'
}
}
GENERATORS = GLOBAL_GENERATORS.merge(SITE_GENERATORS)
ret = true
options = WikiGenerator::parse_options
myopts = options.clone
options[:generators].each do |g|
myopts[:generators] = [g]
options[:sites].each do |s|
myopts[:sites] = [s]
if GLOBAL_GENERATORS.has_key?(g) and s == 'global'
ret &= GLOBAL_GENERATORS[g][:gen].new(GLOBAL_GENERATORS[g][:page]).exec(myopts)
elsif SITE_GENERATORS.has_key?(g) and s != 'global'
ret &= SITE_GENERATORS[g][:gen].new(s.capitalize + SITE_GENERATORS[g][:page_suffix], s).exec(myopts)
else
puts "Nothing to do: #{g}/#{s}"
end
end
end
exit(ret)
module RefRepo
end
module RefRepo::Gen
end
require 'refrepo/gen/wiki'
#!/usr/bin/env ruby
require 'refrepo/gen/wiki/wiki_generator'
require 'refrepo/gen/wiki/mw_utils'
require 'refrepo/gen/wiki/generators/cpu_parameters'
require 'refrepo/gen/wiki/generators/disk_reservation'
require 'refrepo/gen/wiki/generators/hardware'
require 'refrepo/gen/wiki/generators/oar_properties'
require 'refrepo/gen/wiki/generators/site_hardware'
require 'refrepo/gen/wiki/generators/site_network'
module RefRepo::Gen::Wiki
GLOBAL_GENERATORS = {
'cpu_parameters' => {
:gen => CPUParametersGenerator,
:page => "Generated/CPUParameters"
},
'disk_reservation' => {
:gen => DiskReservationGenerator,
:page => 'Generated/DiskReservation'
},
'hardware' => {
:gen => G5KHardwareGenerator,
:page => 'Hardware'
},
'oar_properties' => {
:gen => OarPropertiesGenerator,
:page => 'OAR_Properties'
}
}
SITE_GENERATORS = {
'site_hardware' => {
:gen => SiteHardwareGenerator,
:page_suffix => ':Hardware'
},
'site_network' => {
:gen => SiteNetworkGenerator,
:page_suffix => ':GeneratedNetwork'
}
}
GENERATORS = GLOBAL_GENERATORS.merge(SITE_GENERATORS)
def self.wikigen(options)
ret = true
myopts = options.clone
options[:generators].each do |g|
myopts[:generators] = [g]
options[:sites].each do |s|
myopts[:sites] = [s]
if GLOBAL_GENERATORS.has_key?(g) and s == 'global'
ret &= GLOBAL_GENERATORS[g][:gen].new(GLOBAL_GENERATORS[g][:page]).exec(myopts)
elsif SITE_GENERATORS.has_key?(g) and s != 'global'
ret &= SITE_GENERATORS[g][:gen].new(s.capitalize + SITE_GENERATORS[g][:page_suffix], s).exec(myopts)
else
puts "Nothing to do: #{g}/#{s}"
end
end
end
return ret
end
end
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'wiki_generator'
require 'refrepo/gen/wiki/wiki_generator'
class CPUParametersGenerator < WikiGenerator
......
# coding: utf-8
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'wiki_generator'
require 'refrepo/gen/wiki/wiki_generator'
class DiskReservationGenerator < WikiGenerator
......
# coding: utf-8
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'wiki_generator'
require 'refrepo/gen/wiki/wiki_generator'
require_relative './site_hardware.rb'
class G5KHardwareGenerator < WikiGenerator
......
# coding: utf-8
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'wiki_generator'
require 'refrepo/gen/wiki/wiki_generator'
require_relative '../../../oar-properties/lib/lib-oar-properties'
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../../../../generators/oar-properties/lib')))
require 'lib-oar-properties'
class OarPropertiesGenerator < WikiGenerator
......
# coding: utf-8
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'wiki_generator'
require 'refrepo/gen/wiki/wiki_generator'
class SiteHardwareGenerator < WikiGenerator
......
# coding: utf-8
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'wiki_generator'
require 'refrepo/gen/wiki/wiki_generator'
require_relative '../../../input-validators/check-network-description'
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../../../../generators')))
require 'input-validators/check-network-description'
# This class generates the network description of each site, in .dot
# and .png format
......
require 'active_support'
require 'active_support/core_ext/object/deep_dup'
require 'pp'
require 'open-uri'
require 'uri'
......@@ -5,11 +8,6 @@ require 'net/http'
require 'net/https'
require 'mediawiki_api'
# also add generators/lib to load path
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../lib')))
require 'input_loader'
#Adding method to mediawiki_api client
module MediawikiApi
......@@ -113,10 +111,10 @@ module G5K
@@global_hash = nil
def self.get_global_hash
if @@global_hash.nil?
@@global_hash = load_yaml_file_hierarchy(File.expand_path("../../../input/grid5000/", File.dirname(__FILE__)))
@@global_hash = load_yaml_file_hierarchy
end
# return a deep copy of global_hash
return Marshal.load(Marshal.dump(@@global_hash))
return @@global_hash.deep_dup
end
SITES = get_global_hash['sites'].keys.sort
......
# also add generators/lib to load path
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../lib')))
require 'input_loader'
require 'refrepo/input_loader'
require "optparse"
require "mediawiki_api"
require "diffy"
require "mw_utils"
require 'date'
require 'pp'
......
......@@ -2,9 +2,9 @@
require 'yaml'
require 'erb'
require_relative '../lib/hash/hash.rb'
require 'refrepo/hash/hash.rb'
def load_yaml_file_hierarchy(directory)
def load_yaml_file_hierarchy(directory = File.expand_path("../../input/grid5000/", File.dirname(__FILE__)))
global_hash = {} # the global data structure
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment