diff --git a/bin/kaconsole3 b/bin/kaconsole3 index 5c3e8349112ca19876669ceee1823c5922fb894a..e0a2ff54cc6162cd29a5e6214f59d6d31eb31f69 100755 --- a/bin/kaconsole3 +++ b/bin/kaconsole3 @@ -21,27 +21,27 @@ $interactive = false module Kadeploy class KaconsoleClient < Client - ESCAPE_SEQ="\x1b\x1b\x1b\x1b" + ESCAPE_SEQ = "\x1b\x1b\x1b\x1b" - def initialize(name,server,port,secure,auth_headers_prefix,nodes=nil) - super(name,server,port,secure,auth_headers_prefix,nodes) + def initialize(name, server, port, secure, auth_headers_prefix, nodes = nil) + super(name, server, port, secure, auth_headers_prefix, nodes) @wid = nil @resources = nil end - def api_path(path=nil,kind=nil,*args) + def api_path(path = nil, kind = nil, *args) if @resources if @resources[path] @resources[path] else if path - File.join(@resources['resource'],path,*args) + File.join(@resources['resource'], path, *args) else - File.join(@resources['resource'],*args) + File.join(@resources['resource'], *args) end end else - super(path,kind,*args) + super(path, kind, *args) end end @@ -68,9 +68,9 @@ class KaconsoleClient < Client end def self.parse_options() - global_parse_options() do |opt,options| + global_parse_options() do |opt, options| opt.separator "General options:" - parse_machine(opt,options) + parse_machine(opt, options) end end @@ -94,8 +94,8 @@ class KaconsoleClient < Client params end - def run(_options,params) - ret = post(api_path(),params) + def run(_options, params) + ret = post(api_path(), params) @wid = ret['wid'] @resources = ret['resources'] @@ -103,7 +103,7 @@ class KaconsoleClient < Client sock = nil begin - sock = TCPSocket.new(uri.host,uri.port) + sock = TCPSocket.new(uri.host, uri.port) sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) rescue StandardError => e error("Fail to connect to remote console #{uri} "\ @@ -121,7 +121,7 @@ class KaconsoleClient < Client buf = String.new until done do begin - sock.sysread(4096,buf) + sock.sysread(4096, buf) $stdout.write(buf) $stdout.flush rescue EOFError @@ -164,7 +164,7 @@ class KaconsoleClient < Client loop do sleep SLEEP_PITCH - done = true if !done and get(api_path('resource'),params)['error'] + done = true if !done and get(api_path('resource'), params)['error'] break if done end @@ -181,17 +181,17 @@ class KaconsoleClient < Client @resources = nil # disable api_path magic # check that workflow stil exists (do not clean if already cleaned) - consoles = get(api_path(nil,:console),params) + consoles = get(api_path(nil, :console), params) if consoles.select{|v| v['id'] == @wid}.empty? @wid = nil else @resources = tmp end - get(api_path('resource'),params) if @wid + get(api_path('resource'), params) if @wid end - def result(_options,ret) + def result(_options, ret) if @wid get(api_path('error')) if ret['error'] delete(api_path()) diff --git a/bin/kadeploy3 b/bin/kadeploy3 index 7b981386dae690978a70e7c1290ba58f169f82b4..bdcbd78a2212c27617af1e84ea32a5cfd9533d28 100755 --- a/bin/kadeploy3 +++ b/bin/kadeploy3 @@ -25,8 +25,8 @@ class KadeployClient < ClientWorkflow :env_desc => {}, :env_user => nil, :env_name => '', - :env_version => nil, #By default we load the latest version - :env_arch => nil, #By default we automatically select the arch + :env_version => nil, # By default we load the latest version + :env_arch => nil, # By default we automatically select the arch :block_device => nil, :deploy_part => nil, :boot_part => nil, @@ -51,51 +51,51 @@ class KadeployClient < ClientWorkflow end def self.parse_options() - global_parse_options() do |opt,options| + global_parse_options() do |opt, options| opt.separator "General options:" - add_opt(opt,"-a", "--env-file ENVFILE", "File containing the environment description") { |f| + add_opt(opt, "-a", "--env-file ENVFILE", "File containing the environment description") { |f| options[:env_kind] = :anonymous - load_envfile(options[:env_desc],f) + load_envfile(options[:env_desc], f) } - parse_block_device(opt,options) - add_opt(opt,"-c", "--boot-partition NUMBER", /^\d+$/, "Specify the number of the partition to boot on (use 0 to boot on the MBR)") { |c| + parse_block_device(opt, options) + add_opt(opt, "-c", "--boot-partition NUMBER", /^\d+$/, "Specify the number of the partition to boot on (use 0 to boot on the MBR)") { |c| options[:boot_part] = c.to_i } - parse_env_name(opt,options){ options[:env_kind] = :database } - parse_keyfile(opt,options) - parse_deploy_part(opt,options) - add_opt(opt,"-r", "--reformat-tmp FSTYPE", "Reformat the /tmp partition with the given filesystem type (this filesystem need to be supported by the deployment environment)") { |t| + parse_env_name(opt, options){ options[:env_kind] = :database } + parse_keyfile(opt, options) + parse_deploy_part(opt, options) + add_opt(opt, "-r", "--reformat-tmp FSTYPE", "Reformat the /tmp partition with the given filesystem type (this filesystem need to be supported by the deployment environment)") { |t| options[:reformat_tmp] = t } - parse_env_user(opt,options) - parse_vlan(opt,options) - parse_pxe_profile(opt,options) - parse_pxe_pattern(opt,options) - parse_pxe_files(opt,options) - parse_env_version(opt,options) - parse_env_arch(opt,options) + parse_env_user(opt, options) + parse_vlan(opt, options) + parse_pxe_profile(opt, options) + parse_pxe_pattern(opt, options) + parse_pxe_files(opt, options) + parse_env_version(opt, options) + parse_env_arch(opt, options) opt.separator "" opt.separator "Advanced options:" - add_opt(opt,"--no-kexec", "Disable kexec from the deployment kernel to the deployed environment") { + add_opt(opt, "--no-kexec", "Disable kexec from the deployment kernel to the deployed environment") { options[:disable_kexec] = true } - add_opt(opt,"--force-untrust-current-env", "Never trust the current environment. It will disable kexec to the deployment kernel") { + add_opt(opt, "--force-untrust-current-env", "Never trust the current environment. It will disable kexec to the deployment kernel") { options[:dont_trust_env] = true } - add_opt(opt,"--force-trust-current-env", "Always trust the current environment. Kadeploy will try to use kexec to the deployment kernel regardless of the current environment") { + add_opt(opt, "--force-trust-current-env", "Always trust the current environment. Kadeploy will try to use kexec to the deployment kernel regardless of the current environment") { options[:always_trust_env] = true } - add_opt(opt,"--disable-bootloader-install", "Disable the automatic installation of a bootloader for a Linux based environment") { + add_opt(opt, "--disable-bootloader-install", "Disable the automatic installation of a bootloader for a Linux based environment") { options[:disable_bootloader_install] = true } - add_opt(opt,"--disable-disk-partitioning", "Disable the disk partitioning") { + add_opt(opt, "--disable-disk-partitioning", "Disable the disk partitioning") { options[:disable_disk_partitioning] = true } - parse_timeout_reboot(opt,options) - add_opt(opt,"--reboot-kexec-timeout VALUE", "Overload the default timeout for kexec reboots (a ruby expression can be used, 'n' will be replaced by the number of nodes)") { |t| + parse_timeout_reboot(opt, options) + add_opt(opt, "--reboot-kexec-timeout VALUE", "Overload the default timeout for kexec reboots (a ruby expression can be used, 'n' will be replaced by the number of nodes)") { |t| options[:reboot_kexec_timeout] = t } - add_opt(opt,"--force-steps STRING", /^SetDeploymentEnv\|(?:\w+:\d+:\d+,?)+&BroadcastEnv\|(?:\w+:\d+:\d+,?)+&BootNewEnv\|(?:\w+:\d+:\d+,?)+$/,"Undocumented, for administration purpose only") { |s| + add_opt(opt, "--force-steps STRING", /^SetDeploymentEnv\|(?:\w+:\d+:\d+,?)+&BroadcastEnv\|(?:\w+:\d+:\d+,?)+&BootNewEnv\|(?:\w+:\d+:\d+,?)+$/, "Undocumented, for administration purpose only") { |s| options[:automata] = {} s.split("&").each do |macrostep| macroname = macrostep.split("|")[0] @@ -110,7 +110,7 @@ class KadeployClient < ClientWorkflow end end } - parse_secure(opt,options) + parse_secure(opt, options) end end @@ -171,16 +171,16 @@ class KadeployClient < ClientWorkflow tmp[:name] = envname if envname && !envname.empty? tmp[:version] = envversion if envversion tmp[:arch] = envarch if envarch - envs = get2(options,api_path("/",:envs),tmp) + envs = get2(options, api_path("/", :envs), tmp) error("Environment '#{tmp[:name]}' for #{tmp[:arch]} does not exist") if envs.empty? - #if env_user is not defined, own environments are selected if available + # if env_user is not defined, own environments are selected if available if options[:env_user].nil? list = envs.select { |e| e["user"] == USER } list = envs if list.empty? else list = envs end - #List should not have a size > 1 when only one user is allowed to publish public environments + # List should not have a size > 1 when only one user is allowed to publish public environments env = list.first params[:environment][:user] = env['user'] diff --git a/bin/kaenv3 b/bin/kaenv3 index 9c01969182441c0d7d51635bc1c77872105cf0ad..bf1868526d9e84f11c9a18d02262d04c6cda897a 100755 --- a/bin/kaenv3 +++ b/bin/kaenv3 @@ -14,9 +14,9 @@ module Kadeploy class KaenvsClient < Client - def print_env_in_array(envs, text="") + def print_env_in_array(envs, text = "") env_array = [] - env_array << ['Name','Version','Arch','Description'] + env_array << ['Name', 'Version', 'Arch', 'Description'] envs.each do |env| env_array << [env['name'], env['version'], env['arch'], env['description']] end @@ -39,14 +39,14 @@ class KaenvsClient < Client debug "\n" end - def print_summary_env_in_array(envs, text="") + def print_summary_env_in_array(envs, text = "") env_array = [] # sort by occurence all_archs = envs.map{|x| x['arch']}.group_by(&:itself).transform_values(&:count).sort_by{|x| -x.last}.map(&:first) - envs.group_by{|x| [x['name'],x['version'],x['user']]}.each do |k,v| + envs.group_by{|x| [x['name'], x['version'], x['user']]}.each do |k, v| env_array << [k[0], k[1], all_archs.map{|a| v.map{|e| e['arch']}.include?(a) ? a : ' ' * a.length}.join(' ')] end - env_array.unshift(['Name','Version','Archs']) + env_array.unshift(['Name', 'Version', 'Archs']) column_sizes = env_array.reduce([]) do |lengths, row| row.each_with_index.map{|iterand, index| [lengths[index] || 0, iterand.to_s.length].max} end @@ -66,7 +66,7 @@ class KaenvsClient < Client debug "\n" end - def print_full(env, type=:yaml) + def print_full(env, type = :yaml) if type == :yaml # yaml outpout is used as input and the user should not be specify in # this case @@ -105,79 +105,79 @@ class KaenvsClient < Client end def self.parse_options() - global_parse_options() do |opt,options| + global_parse_options() do |opt, options| opt.separator "General options:" - add_opt(opt,"--summary [ENVNAME]", "Short list of environments with the environment name pattern (% is the wildcard).") { |n| + add_opt(opt, "--summary [ENVNAME]", "Short list of environments with the environment name pattern (% is the wildcard).") { |n| options[:operation] = :summary options[:env_name] = n if n } - add_opt(opt,"-l","--list [ENVNAME]", "List environments with the environment name pattern (% is the wildcard).") { |n| + add_opt(opt, "-l", "--list [ENVNAME]", "List environments with the environment name pattern (% is the wildcard).") { |n| options[:operation] = :list options[:env_name] = n if n } - add_opt(opt,"-p", "--print ENVNAME", "Print an environment") { |n| + add_opt(opt, "-p", "--print ENVNAME", "Print an environment") { |n| options[:env_name] = n options[:operation] = :print } - add_opt(opt,"-a", "--add ENVFILE", "Add an environment") { |f| + add_opt(opt, "-a", "--add ENVFILE", "Add an environment") { |f| options[:operation] = :add - load_envfile(options[:env_desc],f) + load_envfile(options[:env_desc], f) } - add_opt(opt,"-d", "--delete ENVNAME", "Delete an environment") { |n| + add_opt(opt, "-d", "--delete ENVNAME", "Delete an environment") { |n| options[:env_name] = n options[:operation] = :delete } - add_opt(opt,"--json", "print the env info as json (only available with when printing or listing environment)") { + add_opt(opt, "--json", "print the env info as json (only available with when printing or listing environment)") { options[:type] = :json } - add_opt(opt,"-s", "--all-versions", "Apply the operation on all the versions of the environment") { + add_opt(opt, "-s", "--all-versions", "Apply the operation on all the versions of the environment") { options[:all_versions] = true } - parse_env_user(opt,options) - parse_env_version(opt,options) - parse_env_arch(opt,options) + parse_env_user(opt, options) + parse_env_version(opt, options) + parse_env_arch(opt, options) opt.separator "" opt.separator "Advanced options:" - add_opt(opt,"--yes", "Do not prompt for environment deletion") { + add_opt(opt, "--yes", "Do not prompt for environment deletion") { options[:interactive] = false } - add_opt(opt,"--toggle-destructive-tag ENVNAME", "Toggle the destructive tag on an environment") { |n| + add_opt(opt, "--toggle-destructive-tag ENVNAME", "Toggle the destructive tag on an environment") { |n| options[:env_name] = n options[:operation] = :'toggle-destructive-tag' } - add_opt(opt,"--set-visibility-tag ENVNAME", "Set the visibility tag on an environment") { |n| + add_opt(opt, "--set-visibility-tag ENVNAME", "Set the visibility tag on an environment") { |n| options[:env_name] = n options[:operation] = :'set-visibility-tag' } - add_opt(opt,"-t", "--visibility-tag TAG", ['public','private','shared'], "Set the visibility tag (private, shared, public)") { |v| + add_opt(opt, "-t", "--visibility-tag TAG", ['public', 'private', 'shared'], "Set the visibility tag (private, shared, public)") { |v| options[:visibility_tag] = v } - add_opt(opt,"--set-arch ENVNAME", "Set the architecture of the environment") { |n| + add_opt(opt, "--set-arch ENVNAME", "Set the architecture of the environment") { |n| options[:env_name] = n options[:operation] = :'set-arch' } - add_opt(opt,"--new-arch ARCH", "Set the new architecture") { |a| + add_opt(opt, "--new-arch ARCH", "Set the new architecture") { |a| options[:'new_arch'] = a } - add_opt(opt,"--update-image-checksum ENVNAME", "Update the checksum of the environment image") { |n| + add_opt(opt, "--update-image-checksum ENVNAME", "Update the checksum of the environment image") { |n| options[:env_name] = n options[:operation] = :'update-image-checksum' } - add_opt(opt,"--update-preinstall-checksum ENVNAME", "Update the checksum of the environment preinstall") { |n| + add_opt(opt, "--update-preinstall-checksum ENVNAME", "Update the checksum of the environment preinstall") { |n| options[:env_name] = n options[:operation] = :'update-preinstall-checksum' } - add_opt(opt,"--update-postinstalls-checksum ENVNAME", "Update the checksum of the environment postinstalls") { |n| + add_opt(opt, "--update-postinstalls-checksum ENVNAME", "Update the checksum of the environment postinstalls") { |n| options[:env_name] = n options[:operation] = :'update-postinstalls-checksum' } - add_opt(opt,"--move-files", "Move the files of the environments (for administrators only)") { + add_opt(opt, "--move-files", "Move the files of the environments (for administrators only)") { options[:operation] = :'move-files' } - add_opt(opt,"-m", "--files-to-move FILES", "Files to move (src1::dst1,src2::dst2,...)") { |f| + add_opt(opt, "-m", "--files-to-move FILES", "Files to move (src1::dst1,src2::dst2,...)") { |f| if /\A.+::.+(,.+::.+)*\Z/ =~f then f.split(",").each do |src_dst| - tmp = src_dst.split("::",2) + tmp = src_dst.split("::", 2) options[:files_to_move][tmp[0]] = tmp[1] end else @@ -185,7 +185,7 @@ class KaenvsClient < Client return false end } - parse_secure(opt,options) + parse_secure(opt, options) end end @@ -251,11 +251,11 @@ class KaenvsClient < Client if options[:operation] == :delete && options[:interactive] tmp = params.dup - tmp[:username] = options[:env_user]||USER + tmp[:username] = options[:env_user] || USER tmp[:name] = options[:env_name] tmp[:arch] = options[:env_arch] if options[:env_arch] && !options[:env_arch].empty? tmp[:last] = true unless options[:env_version] || options[:all_versions] - envs = get2(options,api_path("/",:envs),tmp) + envs = get2(options, api_path("/", :envs), tmp) error("No environment found") if envs.size <= 0 debug "The following environments will be deleted:" envs.each do |e| @@ -263,9 +263,9 @@ class KaenvsClient < Client end print("\n Proceed with deletion? [y/N] ") yesno = gets.downcase.chomp - exit(1) unless ['yes','y'].include?(yesno) + exit(1) unless ['yes', 'y'].include?(yesno) end - if [:add, :'update-image-checksum',:'update-postinstalls-checksum',:'update-preinstall-checksum',:'move-files',:'set-arch'].include?(options[:operation]) + if [:add, :'update-image-checksum', :'update-postinstalls-checksum', :'update-preinstall-checksum', :'move-files', :'set-arch'].include?(options[:operation]) # Check if the environment contains local files desc = nil case options[:operation] @@ -284,7 +284,7 @@ class KaenvsClient < Client tmp[:name] = envname if envname && !envname.empty? tmp[:version] = envversion if envversion && !envversion.nil? tmp[:arch] = envarch if envarch && !envarch.empty? - envs = get2(options,api_path("/",:envs),tmp) + envs = get2(options, api_path("/", :envs), tmp) error("The environment '#{envname}' does not exist") if envs.size <= 0 error("Multiple environments '#{envname}' exists. Be more specific by specifying the architecture or user of the environement.") if envs.size > 1 desc = envs.first @@ -319,23 +319,23 @@ class KaenvsClient < Client params end - def run(options,params) + def run(options, params) # set path path = api_path() if ![:add, :'move-files'].include?(options[:operation]) - if [:print,:list,:summary].include?(options[:operation]) + if [:print, :list, :summary].include?(options[:operation]) if options[:env_user] && !options[:env_user].empty? params[:username] = options[:env_user] end - params[:version] = options[:env_version] if options[:env_version] + params[:version] = options[:env_version] if options[:env_version] params[:arch] = options[:env_arch] if options[:env_arch] && !options[:env_arch].empty? params[:name] = options[:env_name] if options[:env_name] && !options[:env_name].empty? else - path = File.join(path,URI.encode_www_form_component(options[:env_user]||USER)) - path = File.join(path,URI.encode_www_form_component(options[:env_name])) if options[:env_name] - path = File.join(path,URI.encode_www_form_component(options[:env_arch])) if options[:env_arch] && !options[:env_arch].empty? - path = File.join(path,options[:env_version].to_s) if options[:env_version] + path = File.join(path, URI.encode_www_form_component(options[:env_user] || USER)) + path = File.join(path, URI.encode_www_form_component(options[:env_name])) if options[:env_name] + path = File.join(path, URI.encode_www_form_component(options[:env_arch])) if options[:env_arch] && !options[:env_arch].empty? + path = File.join(path, options[:env_version].to_s) if options[:env_version] end end @@ -344,11 +344,11 @@ class KaenvsClient < Client case options[:operation] when :add method = :POST - when :list,:print,:summary + when :list, :print, :summary method = :GET when :delete method = :DELETE - when :'update-image-checksum',:'update-postinstalls-checksum',:'update-preinstall-checksum',:'set-visibility-tag',:'toggle-destructive-tag',:'set-arch',:'move-files' + when :'update-image-checksum', :'update-postinstalls-checksum', :'update-preinstall-checksum', :'set-visibility-tag', :'toggle-destructive-tag', :'set-arch', :'move-files' method = :PUT else raise @@ -356,21 +356,21 @@ class KaenvsClient < Client case method when :GET - get(path,params) + get(path, params) when :POST - post(path,params) + post(path, params) when :PUT - put(path,params) + put(path, params) when :DELETE - delete(path,params) + delete(path, params) else raise end end - def result(options,ret) + def result(options, ret) case options[:operation] - when :list,:summary + when :list, :summary if ret.empty? && options[:type] != :json debug 'No environment has been found' elsif options[:type] == :json @@ -395,7 +395,7 @@ class KaenvsClient < Client if ret.empty? debug 'No environment has been found' else - #if env_user is not defined, own environments are selected if available + # if env_user is not defined, own environments are selected if available if options[:env_user].nil? list = ret.select { |e| e["user"] == USER } list = ret if list.empty? @@ -410,7 +410,7 @@ class KaenvsClient < Client ret.each{|env| debug "#{env['name']} v#{env['version']}"} when :delete debug 'Environment deleted' - when :'update-image-checksum',:'update-postinstalls-checksum',:'update-preinstall-checksum',:'set-arch' + when :'update-image-checksum', :'update-postinstalls-checksum', :'update-preinstall-checksum', :'set-arch' debug 'Environment updated' end end diff --git a/bin/kanodes3 b/bin/kanodes3 index cab235f1328fdd94ca6d63b8a0f0b1925c3c76d7..eacfaf09edd06e3d1fd57013049501e067371ebb 100755 --- a/bin/kanodes3 +++ b/bin/kanodes3 @@ -28,29 +28,29 @@ class KanodesClient < Client end def self.parse_options() - global_parse_options() do |opt,options| + global_parse_options() do |opt, options| opt.separator "General options:" - add_opt(opt,"-s", "--get-nodes-state", "Get the deployment state of the nodes") { + add_opt(opt, "-s", "--get-nodes-state", "Get the deployment state of the nodes") { options[:operation] = :get_state } - add_opt(opt,"-d", "--get-deployments-status", "Get the status of running deployments") { + add_opt(opt, "-d", "--get-deployments-status", "Get the status of running deployments") { options[:operation] = :get_status_deploy } - add_opt(opt,"-r", "--get-reboots-status", "Get the status of running reboot operations") { + add_opt(opt, "-r", "--get-reboots-status", "Get the status of running reboot operations") { options[:operation] = :get_status_reboot } - add_opt(opt,"-p", "--get-powers-status", "Get the status of running power operations") { + add_opt(opt, "-p", "--get-powers-status", "Get the status of running power operations") { options[:operation] = :get_status_power } - add_opt(opt,"-c", "--get-consoles-status", "Get the status of open consoles") { + add_opt(opt, "-c", "--get-consoles-status", "Get the status of open consoles") { options[:operation] = :get_status_console } - add_opt(opt,"-a", "--get-all-status", "Get the status of all running operations") { + add_opt(opt, "-a", "--get-all-status", "Get the status of all running operations") { options[:operation] = :get_status_all } - parse_machinefile(opt,options) - parse_machine(opt,options) - add_opt(opt,"-w", "--workflow-id WID", "Specify a workflow id (to be used with the get_status option). If no wid is specified, the information of all the running deployments will be returned.") { |w| + parse_machinefile(opt, options) + parse_machine(opt, options) + add_opt(opt, "-w", "--workflow-id WID", "Specify a workflow id (to be used with the get_status option). If no wid is specified, the information of all the running deployments will be returned.") { |w| options[:wid] = w } add_opt(opt, "--json", "use json output instead of yaml") { @@ -60,13 +60,13 @@ class KanodesClient < Client end def self.check_options(options) - unless [:get_state,:get_status_deploy,:get_status_reboot,:get_status_power,:get_status_console,:get_status_all].include?(options[:operation]) + unless [:get_state, :get_status_deploy, :get_status_reboot, :get_status_power, :get_status_console, :get_status_all].include?(options[:operation]) error("You must choose an operation") return false end case options[:operation] - when :get_status_deploy,:get_status_reboot,:get_status_power,:get_status_console,:get_status_all + when :get_status_deploy, :get_status_reboot, :get_status_power, :get_status_console, :get_status_all if !options[:nodes].empty? error('Node list is useless when gathering deployment statuses') return false @@ -80,10 +80,10 @@ class KanodesClient < Client true end - #def self.prepare(options) - #end + # def self.prepare(options) + # end - def run(options,params) + def run(options, params) params[:nodes] = nodes() if nodes() path = nil @@ -91,19 +91,19 @@ class KanodesClient < Client when :get_state path = api_path() when :get_status_deploy - path = api_path(options[:wid],:deploy) + path = api_path(options[:wid], :deploy) when :get_status_reboot - path = api_path(options[:wid],:reboot) + path = api_path(options[:wid], :reboot) when :get_status_power - path = api_path(options[:wid],:power) + path = api_path(options[:wid], :power) when :get_status_console - path = api_path(options[:wid],:console) + path = api_path(options[:wid], :console) when :get_status_all path = [] - path << api_path(options[:wid],:deploy) - path << api_path(options[:wid],:reboot) - path << api_path(options[:wid],:power) - path << api_path(options[:wid],:console) + path << api_path(options[:wid], :deploy) + path << api_path(options[:wid], :reboot) + path << api_path(options[:wid], :power) + path << api_path(options[:wid], :console) else raise end @@ -111,7 +111,7 @@ class KanodesClient < Client if path.is_a?(Array) ret = [] path.each do |p| - ret += get(p,params) + ret += get(p, params) end if options[:type] == :yaml ret.to_yaml @@ -121,11 +121,11 @@ class KanodesClient < Client raise end else - get(path,params,options[:type], false) + get(path, params, options[:type], false) end end - def result(_options,ret) + def result(_options, ret) debug ret if ret end end diff --git a/bin/kapower3 b/bin/kapower3 index 500c7df9be0340017d6094f885ccb3daedc539e1..5675faaed37b21e8d1124408674d2da167471e2d 100755 --- a/bin/kapower3 +++ b/bin/kapower3 @@ -26,16 +26,16 @@ class KapowerClient < ClientWorkflow end def self.parse_options() - global_parse_options() do |opt,options| + global_parse_options() do |opt, options| opt.separator "General options:" - parse_op_level(opt,options) - add_opt(opt,"--off", "Shutdown the nodes") { + parse_op_level(opt, options) + add_opt(opt, "--off", "Shutdown the nodes") { options[:operation] = :off } - add_opt(opt,"--on", "Power on the nodes") { + add_opt(opt, "--on", "Power on the nodes") { options[:operation] = :on } - add_opt(opt,"--status", "Get the status of the nodes") { + add_opt(opt, "--status", "Get the status of the nodes") { options[:operation] = :status } end @@ -49,7 +49,7 @@ class KapowerClient < ClientWorkflow return false end - unless [:on,:off,:status].include?(options[:operation]) + unless [:on, :off, :status].include?(options[:operation]) error("Invalid operation #{options[:operation]}") return false end @@ -78,12 +78,12 @@ class KapowerClient < ClientWorkflow params end - def run(options,params) + def run(options, params) case options[:operation] when :on, :off - run_workflow(options,params,:put) + run_workflow(options, params, :put) when :status - run_workflow(options,params,:get) + run_workflow(options, params, :get) else raise end diff --git a/bin/kareboot3 b/bin/kareboot3 index c4aca63c1ba1f1d7edbd8e7a425a5c7316104368..9f8a28e4a6327ce7e403924410724f8f4ad98502 100755 --- a/bin/kareboot3 +++ b/bin/kareboot3 @@ -22,8 +22,8 @@ class KarebootClient < ClientWorkflow { :operation => :simple, :env_name => nil, - :env_version => nil, #By default we load the latest version - :env_arch => nil, #By default we automatically choose the arch + :env_version => nil, # By default we load the latest version + :env_arch => nil, # By default we automatically choose the arch :check_demolishing => false, :block_device => nil, :deploy_part => nil, @@ -40,28 +40,28 @@ class KarebootClient < ClientWorkflow end def self.parse_options() - global_parse_options() do |opt,options| + global_parse_options() do |opt, options| opt.separator "General options:" - parse_block_device(opt,options) - add_opt(opt,"-c", "--check-destructive-tag", "Check if some nodes was deployed with an environment that have the destructive tag") { + parse_block_device(opt, options) + add_opt(opt, "-c", "--check-destructive-tag", "Check if some nodes was deployed with an environment that have the destructive tag") { options[:check_demolishing] = true } - parse_env_name(opt,options){ options[:env_kind] = :database } - parse_keyfile(opt,options) - parse_op_level(opt,options) - parse_deploy_part(opt,options) - add_opt(opt,"-r", "--reboot-kind REBOOT_KIND", ['set_pxe', 'simple', 'deploy_env', 'recorded_env'], "Specify the reboot kind (set_pxe, simple, deploy_env, recorded_env)") { |k| + parse_env_name(opt, options){ options[:env_kind] = :database } + parse_keyfile(opt, options) + parse_op_level(opt, options) + parse_deploy_part(opt, options) + add_opt(opt, "-r", "--reboot-kind REBOOT_KIND", ['set_pxe', 'simple', 'deploy_env', 'recorded_env'], "Specify the reboot kind (set_pxe, simple, deploy_env, recorded_env)") { |k| options[:operation] = k.strip.downcase.to_sym } - parse_env_user(opt,options) - parse_vlan(opt,options) - parse_pxe_profile(opt,options) - parse_pxe_pattern(opt,options) - parse_pxe_files(opt,options) - parse_env_version(opt,options) - parse_env_arch(opt,options) - parse_timeout_reboot(opt,options) - parse_secure(opt,options) + parse_env_user(opt, options) + parse_vlan(opt, options) + parse_pxe_profile(opt, options) + parse_pxe_pattern(opt, options) + parse_pxe_files(opt, options) + parse_env_version(opt, options) + parse_env_arch(opt, options) + parse_timeout_reboot(opt, options) + parse_secure(opt, options) end end @@ -73,7 +73,7 @@ class KarebootClient < ClientWorkflow return false end - error("invalid operation #{options[:operation]}") unless [:set_pxe,:simple,:deploy_env,:recorded_env].include?(options[:operation]) + error("invalid operation #{options[:operation]}") unless [:set_pxe, :simple, :deploy_env, :recorded_env].include?(options[:operation]) case options[:operation] when :set_pxe @@ -143,7 +143,7 @@ class KarebootClient < ClientWorkflow tmp[:username] = username if username && !username.empty? tmp[:name] = envname if envname && !envname.empty? tmp[:version] = envversion if envversion - envs = get2(options,api_path("/",:envs),tmp) + envs = get2(options, api_path("/", :envs), tmp) error("The environment '#{options[:env_name]}' does not exist") if envs.size <= 0 env = envs.first diff --git a/bin/kastat3 b/bin/kastat3 index b21ea8cdb5f891787bb85941fc776031912f7838..aef7b91b78b573064179bfb2a98dafbdb67082a3 100755 --- a/bin/kastat3 +++ b/bin/kastat3 @@ -13,7 +13,7 @@ require 'optparse/time' module Kadeploy class KastatClient < Client - FIELDS = ['wid','user','hostname','step1','step2','step3','timeout_step1','timeout_step2','timeout_step3','retry_step1','retry_step2','retry_step3','start','step1_duration','step2_duration','step3_duration','env','md5','success','error'] + FIELDS = ['wid', 'user', 'hostname', 'step1', 'step2', 'step3', 'timeout_step1', 'timeout_step2', 'timeout_step3', 'retry_step1', 'retry_step2', 'retry_step3', 'start', 'step1_duration', 'step2_duration', 'step3_duration', 'env', 'md5', 'success', 'error'] def self.operation() 'Stats operation' @@ -37,42 +37,42 @@ class KastatClient < Client end def self.parse_options() - global_parse_options() do |opt,options| + global_parse_options() do |opt, options| opt.separator "General options:" - add_opt(opt,"-a", "--all", "Print all the information") { + add_opt(opt, "-a", "--all", "Print all the information") { options[:kind] = :all } - add_opt(opt,"-b", "--failure-rate [RATE]", /^0?\.\d+|1(?:\.0)?$/, "Print the nodes which have a minimum failure-rate of RATE 1 (0 <= RATE <= 1)") { |r| + add_opt(opt, "-b", "--failure-rate [RATE]", /^0?\.\d+|1(?:\.0)?$/, "Print the nodes which have a minimum failure-rate of RATE 1 (0 <= RATE <= 1)") { |r| options[:kind] = :failure_rates options[:min_failure_rate] = r.to_f if r } - parse_machinefile(opt,options) - add_opt(opt,"-F", "--fields FIELDS", Array, "Only print the selected fields (#{FIELDS.join(', ')})") { |f| + parse_machinefile(opt, options) + add_opt(opt, "-F", "--fields FIELDS", Array, "Only print the selected fields (#{FIELDS.join(', ')})") { |f| options[:fields] = f } - parse_machine(opt,options) - add_opt(opt,"-o", "--operation OP", ['deploy','reboot','power'], "Only print statistics about a specific operation") { |n| + parse_machine(opt, options) + add_opt(opt, "-o", "--operation OP", ['deploy', 'reboot', 'power'], "Only print statistics about a specific operation") { |n| options[:operation] = n } - add_opt(opt,"-r", "--min-retries NB", /^\d+$/, "Print the statistics about the nodes that need at least NB attempts to perform specific steps") { |n| + add_opt(opt, "-r", "--min-retries NB", /^\d+$/, "Print the statistics about the nodes that need at least NB attempts to perform specific steps") { |n| options[:min_retries] = n.to_i } - add_opt(opt,"-s", "--retry-steps STEPS", Array, "Apply the retry filter on the given steps (1, 2 or 3)") { |s| + add_opt(opt, "-s", "--retry-steps STEPS", Array, "Apply the retry filter on the given steps (1, 2 or 3)") { |s| options[:step_retries] = s } - add_opt(opt,"-w", "--workflow-id ID", "Get the stats of a specific workflow") { |w| + add_opt(opt, "-w", "--workflow-id ID", "Get the stats of a specific workflow") { |w| options[:wid] = w } - add_opt(opt,"-x", "--date-min TIME", Time, "Get the stats from this date (yyyy-mm-dd hh:mm:ss)") { |d| + add_opt(opt, "-x", "--date-min TIME", Time, "Get the stats from this date (yyyy-mm-dd hh:mm:ss)") { |d| options[:date_min] = d } - add_opt(opt,"-y", "--date-max TIME", Time, "Get the stats to this date (yyyy-mm-dd hh:mm:ss)") { |d| + add_opt(opt, "-y", "--date-max TIME", Time, "Get the stats to this date (yyyy-mm-dd hh:mm:ss)") { |d| options[:date_max] = d } - add_opt(opt,"--limit N", /^\d+$/, "Print a maximal number of N results") {|n| + add_opt(opt, "--limit N", /^\d+$/, "Print a maximal number of N results") {|n| options[:limit] = n } - add_opt(opt,"--sort VALS", Array, "Sort the result on some specific fields (default: start)") { |s| + add_opt(opt, "--sort VALS", Array, "Sort the result on some specific fields (default: start)") { |s| options[:sort] = s } end @@ -104,17 +104,17 @@ class KastatClient < Client params end - def run(options,params) + def run(options, params) path = api_path() - path = File.join(path,options[:operation]) if options[:operation] + path = File.join(path, options[:operation]) if options[:operation] - get(path,params) + get(path, params) end - def result(options,ret) + def result(options, ret) case options[:kind] when :failure_rates - ret.each_pair do |host,rate| + ret.each_pair do |host, rate| debug "#{host}: #{rate}" end else diff --git a/lib/kadeploy3/client/client.rb b/lib/kadeploy3/client/client.rb index 39472cd7127cb55481eedd55f5968e9595caec81..8df4ae7411d91103e099d19d4cd1d27b4d13fe29 100644 --- a/lib/kadeploy3/client/client.rb +++ b/lib/kadeploy3/client/client.rb @@ -1,4 +1,4 @@ -$kadeploy_confdir=ENV['KADEPLOY3_CONFIG_DIR']||'/etc/kadeploy3' +$kadeploy_confdir = ENV['KADEPLOY3_CONFIG_DIR'] || '/etc/kadeploy3' $kadeploy_logdir = nil $files = [] @@ -37,7 +37,7 @@ class Client @@terminal_width = nil attr_reader :name, :nodes - def initialize(name,server,port,secure,auth_headers_prefix,nodes=nil) + def initialize(name, server, port, secure, auth_headers_prefix, nodes = nil) @name = name @server = server @port = port @@ -49,35 +49,35 @@ class Client def kill end - def self.api_path(path=nil,kind=nil,*args) + def self.api_path(path = nil, kind = nil, *args) API.ppath( - kind||service_name.downcase.gsub(/^ka/,'').to_sym,'', - path||'', + kind || service_name.downcase.gsub(/^ka/, '').to_sym, '', + path || '', *args ) end - def api_path(path=nil,kind=nil,*args) + def api_path(path = nil, kind = nil, *args) API.ppath( - kind||self.class.service_name.downcase.gsub(/^ka/,'').to_sym, - File.join("#{(@secure ? 'https' : 'http')}://","#{@server}:#{@port}"), - path||'', + kind || self.class.service_name.downcase.gsub(/^ka/, '').to_sym, + File.join("#{(@secure ? 'https' : 'http')}://", "#{@server}:#{@port}"), + path || '', *args ) end - def self.error(msg='',code=1) + def self.error(msg = '', code = 1) unless $killing $stdin.cooked! if $stdin.respond_to?(:cooked!) and STDIN.tty? and !STDIN.closed? $stderr.puts msg if msg and !msg.empty? self.kill - exit!(code||1) + exit!(code || 1) end raise end - def error(msg='',code=1) - self.class.error(debug(msg,false),code) + def error(msg = '', code = 1) + self.class.error(debug(msg, false), code) end def self.kill() @@ -85,7 +85,7 @@ class Client $killing = true $threads.each do |thread| thread.kill unless thread == Thread.current - #thread.join + # thread.join end $clients.each do |client| @@ -123,17 +123,17 @@ class Client servers = {} cp = Configuration::Parser.new(config) - cp.parse('servers',true,Array) do - tmp = cp.value('auth_headers_prefix',String,'') + cp.parse('servers', true, Array) do + tmp = cp.value('auth_headers_prefix', String, '') tmp = nil if tmp.empty? - servers[cp.value('name',String)] = [ - cp.value('hostname',String), + servers[cp.value('name', String)] = [ + cp.value('hostname', String), cp.value('port', Integer), - cp.value('secure',[TrueClass,FalseClass],true), + cp.value('secure', [TrueClass, FalseClass], true), tmp ] end - servers['default'] = cp.value('default',String,nil,servers.keys) + servers['default'] = cp.value('default', String, nil, servers.keys) rescue ArgumentError => ae error("Error(#{configfile}) #{ae.message}") end @@ -145,7 +145,7 @@ class Client def self.load_outputfile(file) begin - File.open(file,'w'){} + File.open(file, 'w'){} rescue error("Cannot create the file '#{file}'") return false @@ -155,21 +155,21 @@ class Client def self.load_inputfile(file) if file.is_a?(IO) or check_file(file) file = File.new(file) unless file.is_a?(IO) - file.readlines.collect{|v|v.chomp}.delete_if{|v|v=~/^\s*#.*$/ or v.empty?} + file.readlines.collect{|v|v.chomp}.delete_if{|v|v =~ /^\s*#.*$/ or v.empty?} else return false end end - def self.load_envfile(envfile,srcfile) + def self.load_envfile(envfile, srcfile) tmpfile = Tempfile.new("env_file") begin uri = URI(srcfile) if uri.scheme.nil? or uri.scheme.empty? - uri.send(:set_scheme,'server') - uri.send(:set_path,File.absolute_path(srcfile)) + uri.send(:set_scheme, 'server') + uri.send(:set_path, File.absolute_path(srcfile)) end - FetchFile[uri.to_s,true].grab(tmpfile.path) + FetchFile[uri.to_s, true].grab(tmpfile.path) tmpfile.close rescue KadeployError => ke tmpfile.unlink @@ -184,10 +184,10 @@ class Client begin ret = YAML.load_file(tmpfile.path) rescue Psych::SyntaxError => se - error("Invalid YAML file '#{srcfile}'\n#{se.message.gsub(tmpfile.path,srcfile)}") + error("Invalid YAML file '#{srcfile}'\n#{se.message.gsub(tmpfile.path, srcfile)}") tmpfile.unlink rescue ArgumentError => ae - error("Invalid YAML file '#{srcfile}' (#{ae.message.gsub(tmpfile.path,srcfile)})") + error("Invalid YAML file '#{srcfile}' (#{ae.message.gsub(tmpfile.path, srcfile)})") tmpfile.unlink rescue Errno::ENOENT tmpfile.unlink @@ -197,7 +197,7 @@ class Client tmpfile.unlink begin - Environment.new.load_from_desc(Marshal.load(Marshal.dump(ret)),[],USER,nil,false,$stdout) + Environment.new.load_from_desc(Marshal.load(Marshal.dump(ret)), [], USER, nil, false, $stdout) rescue KadeployError => ke msg = KadeployError.to_msg(ke.errno) || '' msg = "#{msg} (error ##{ke.errno})\n" if msg and !msg.empty? @@ -228,7 +228,7 @@ class Client if (machines = load_inputfile(file)) machines.each do |hostname| - load_machine(nodelist,hostname) + load_machine(nodelist, hostname) end else return false @@ -257,52 +257,52 @@ class Client config end - def self.parse_machinefile(opt,options) - add_opt(opt,"-f", "--file MACHINELIST", "A file containing a list of nodes (- means stdin)") { |f| + def self.parse_machinefile(opt, options) + add_opt(opt, "-f", "--file MACHINELIST", "A file containing a list of nodes (- means stdin)") { |f| load_machinefile(options[:nodes], f) } end - def self.parse_machine(opt,options) - add_opt(opt,"-m", "--machine MACHINE", "The node to run on") { |m| + def self.parse_machine(opt, options) + add_opt(opt, "-m", "--machine MACHINE", "The node to run on") { |m| load_machine(options[:nodes], m) } end - def self.parse_env_user(opt,options) - add_opt(opt,"-u", "--env-user USERNAME", /^\w+$/, "Specify the user that own the recorded environment") { |u| + def self.parse_env_user(opt, options) + add_opt(opt, "-u", "--env-user USERNAME", /^\w+$/, "Specify the user that own the recorded environment") { |u| options[:env_user] = u } end - def self.parse_user(opt,options) - add_opt(opt,"-u", "--user USERNAME", /^\w+$/, "Specify the user") { |u| + def self.parse_user(opt, options) + add_opt(opt, "-u", "--user USERNAME", /^\w+$/, "Specify the user") { |u| options[:user] = u } end - def self.parse_env_name(opt,options) - add_opt(opt,"-e", "--env-name ENVNAME", "Name of the recorded environment") { |n| + def self.parse_env_name(opt, options) + add_opt(opt, "-e", "--env-name ENVNAME", "Name of the recorded environment") { |n| options[:env_name] = n yield(n) } end - def self.parse_env_arch(opt,options) - add_opt(opt,"-A", "--env-arch ARCH", "Architecture of the recorded environment") { |n| + def self.parse_env_arch(opt, options) + add_opt(opt, "-A", "--env-arch ARCH", "Architecture of the recorded environment") { |n| options[:env_arch] = n } end - def self.parse_env_version(opt,options) - add_opt(opt,"--env-version NUMBER", /^\d+$/, "Version number of the recorded environment") { |n| + def self.parse_env_version(opt, options) + add_opt(opt, "--env-version NUMBER", /^\d+$/, "Version number of the recorded environment") { |n| options[:env_version] = n.to_i } end - def self.parse_secure(opt,options) - add_opt(opt,"--[no-]secure", "Use a secure connection to export files to the server") { |v| + def self.parse_secure(opt, options) + add_opt(opt, "--[no-]secure", "Use a secure connection to export files to the server") { |v| options[:secure] = v } end @@ -327,9 +327,9 @@ class Client # Check if servers specified in the config file are reachable if options[:multi_server] unreachables = [] - options[:servers].each_pair do |server,inf| + options[:servers].each_pair do |server, inf| next if server.downcase == "default" - unless test_get(inf[0],inf[1],'/version',inf[2]) + unless test_get(inf[0], inf[1], '/version', inf[2]) debug("The #{server} server is unreachable") unreachables << server end @@ -338,7 +338,7 @@ class Client else info = options[:servers][options[:chosen_server]] error("Unknown server #{info[0]}") unless info - error("The #{info[0]} server is unreachable") unless test_get(info[0],info[1],'/version',info[2]) + error("The #{info[0]} server is unreachable") unless test_get(info[0], info[1], '/version', info[2]) end return true end @@ -346,17 +346,17 @@ class Client # Treatment of -v/--version option def self.do_version(options) if options[:get_version] - print = Proc.new do |res,prefix| + print = Proc.new do |res, prefix| $stdout.puts "#{prefix if prefix}Kadeploy version: #{res.strip}" end if options[:multi_server] - options[:servers].each_pair do |server,inf| + options[:servers].each_pair do |server, inf| next if server.downcase == "default" - print.call(get(inf[0],inf[1],'/version',inf[2]),"(#{inf[0]}) ") + print.call(get(inf[0], inf[1], '/version', inf[2]), "(#{inf[0]}) ") end else info = options[:servers][options[:chosen_server]] - print.call(get(info[0],info[1],'/version',info[2])) + print.call(get(info[0], info[1], '/version', info[2])) end exit 0 end @@ -365,47 +365,47 @@ class Client # Treatment of -i/--server-info option def self.do_info(options) if options[:get_users_info] - print = Proc.new do |res,prefix| + print = Proc.new do |res, prefix| $stdout.puts "#{prefix if prefix}Kadeploy server configuration:" $stdout.puts "#{prefix if prefix} Custom PXE boot method: #{res['pxe']}" $stdout.puts "#{prefix if prefix} Automata configuration:" - res['automata'].each_pair do |clname,macros| + res['automata'].each_pair do |clname, macros| $stdout.puts "#{prefix if prefix} #{clname}:" - macros.each_pair do |name,steps| + macros.each_pair do |name, steps| $stdout.puts "#{prefix if prefix} #{name}: #{steps.collect{|s| s.values.join(',')}.join('; ')}" end end $stdout.puts "#{prefix if prefix} Deployment environment:" $stdout.puts "#{prefix if prefix} Supported file systems:" - res['supported_fs'].each_pair do |clname,fslist| + res['supported_fs'].each_pair do |clname, fslist| $stdout.puts "#{prefix if prefix} #{clname}: #{fslist.join(',')}" end $stdout.puts "#{prefix if prefix} Variables exported to custom scripts:" - $stdout.puts print_arraystr(res['vars'],"#{prefix if prefix} ") + $stdout.puts print_arraystr(res['vars'], "#{prefix if prefix} ") end if options[:multi_server] - options[:servers].each_pair do |server,inf| + options[:servers].each_pair do |server, inf| next if server.downcase == "default" - print.call(get(inf[0],inf[1],'/info',inf[2]),"(#{inf[0]}) ") + print.call(get(inf[0], inf[1], '/info', inf[2]), "(#{inf[0]}) ") end else info = options[:servers][options[:chosen_server]] - print.call(get(info[0],info[1],'/info',info[2])) + print.call(get(info[0], info[1], '/info', info[2])) end exit 0 end end - def self.debug(msg='',io=$stdout) + def self.debug(msg = '', io = $stdout) io.puts msg end - def debug(msg='',print=true,io=$stdout) + def debug(msg = '', print = true, io = $stdout) if @name tmp = '' msg.each_line do |line| - tmp << sprintf("%-10s%s","[#{@name}] ",line) + tmp << sprintf("%-10s%s", "[#{@name}] ", line) end msg = tmp end @@ -441,7 +441,7 @@ class Client error("Cannot read file '#{file}'") unless File.readable?(file) if File.directory?(file) Dir.foreach(file) do |fi| - $files << File.new(File.join(file,fi)) unless ['.','..'].include?(fi) + $files << File.new(File.join(file, fi)) unless ['.', '..'].include?(fi) end else $files << File.new(file) @@ -462,7 +462,7 @@ class Client end # Serve files throught HTTP(s) - def self.http_export_files(secure=false) + def self.http_export_files(secure = false) return if !$files or $files.empty? httpd_init(secure) httpd_bind_files() @@ -471,23 +471,23 @@ class Client end def self.service_name - name.split('::').last.gsub(/Client$/,'') + name.split('::').last.gsub(/Client$/, '') end def self.parse_uri(uri) uri = URI.parse(uri) - [uri.host,uri.port,uri.path,uri.query] + [uri.host, uri.port, uri.path, uri.query] end def parse_uri(uri) self.class.parse_uri(uri) end - def self.get(host,port,path,secure,headers=nil) + def self.get(host, port, path, secure, headers = nil) ret = nil begin Timeout.timeout(32) do - ret = HTTP::Client::get(host,port,path,secure,nil,nil,nil,headers) + ret = HTTP::Client::get(host, port, path, secure, nil, nil, nil, headers) end rescue Timeout::Error error("Request timeout: cannot GET #{path} on #{host}:#{port}") @@ -499,10 +499,10 @@ class Client ret end - def self.test_get(host,port,path,secure,headers=nil) + def self.test_get(host, port, path, secure, headers = nil) begin Timeout.timeout(5) do - HTTP::Client::get(host,port,path,secure,nil,nil,nil,headers) + HTTP::Client::get(host, port, path, secure, nil, nil, nil, headers) return true end rescue StandardError @@ -510,92 +510,92 @@ class Client end end - def self.get2(options,path,params=nil) - host,port,path,query = parse_uri(path) + def self.get2(options, path, params = nil) + host, port, path, query = parse_uri(path) if query path = "#{path}?#{query}" elsif params - path = HTTP::Client.path_params(path,params) + path = HTTP::Client.path_params(path, params) end host = options[:server_host] unless host port = options[:server_port] unless port headers = {"#{options[:server_auth_http_prefix]}User" => USER} begin - HTTP::Client::get(host,port,path,options[:server_secure],nil,nil,nil,headers) + HTTP::Client::get(host, port, path, options[:server_secure], nil, nil, nil, headers) rescue HTTP::ClientError => e - error(e.message,e.code) + error(e.message, e.code) end end - def get(uri,params=nil,accept_type=nil,parse=nil) - host,port,path,query = parse_uri(uri) + def get(uri, params = nil, accept_type = nil, parse = nil) + host, port, path, query = parse_uri(uri) if query path = "#{path}?#{query}" elsif params - path = HTTP::Client.path_params(path,params) + path = HTTP::Client.path_params(path, params) end host = @server unless host port = @port unless port headers = {"#{@auth_headers_prefix}User" => USER} begin - HTTP::Client::get(host,port,path,@secure,nil,accept_type,parse,headers) + HTTP::Client::get(host, port, path, @secure, nil, accept_type, parse, headers) rescue HTTP::ClientError => e - error(e.message,e.code) + error(e.message, e.code) end end - def post(uri,data,content_type=nil,accept_type=nil,parse=nil) - host,port,path,query = parse_uri(uri) + def post(uri, data, content_type = nil, accept_type = nil, parse = nil) + host, port, path, query = parse_uri(uri) path = "#{path}?#{query}" if query host = @server unless host port = @port unless port headers = {"#{@auth_headers_prefix}User" => USER} begin - HTTP::Client::post(host,port,path,data,@secure,content_type,accept_type,parse,headers) + HTTP::Client::post(host, port, path, data, @secure, content_type, accept_type, parse, headers) rescue HTTP::ClientError => e - error(e.message,e.code) + error(e.message, e.code) end end - def put(uri,data,content_type=nil,accept_type=nil,parse=nil) - host,port,path,query = parse_uri(uri) + def put(uri, data, content_type = nil, accept_type = nil, parse = nil) + host, port, path, query = parse_uri(uri) path = "#{path}?#{query}" if query host = @server unless host port = @port unless port headers = {"#{@auth_headers_prefix}User" => USER} begin - HTTP::Client::put(host,port,path,data,@secure,content_type,accept_type,parse,headers) + HTTP::Client::put(host, port, path, data, @secure, content_type, accept_type, parse, headers) rescue HTTP::ClientError => e - error(e.message,e.code) + error(e.message, e.code) end end - def delete(uri,data={},content_type=nil,accept_type=nil,parse=nil) - host,port,path,query = parse_uri(uri) + def delete(uri, data = {}, content_type = nil, accept_type = nil, parse = nil) + host, port, path, query = parse_uri(uri) path = "#{path}?#{query}" if query host = @server unless host port = @port unless port headers = {"#{@auth_headers_prefix}User" => USER} begin - HTTP::Client::delete(host,port,path,data,@secure,content_type,accept_type,parse,headers) + HTTP::Client::delete(host, port, path, data, @secure, content_type, accept_type, parse, headers) rescue HTTP::ClientError => e - error(e.message,e.code) + error(e.message, e.code) end end - def self.get_auth_headers_prefix(server,port,secure=true) - tmp = get(server,port,'/auth_headers_prefix',secure) + def self.get_auth_headers_prefix(server, port, secure = true) + tmp = get(server, port, '/auth_headers_prefix', secure) tmp.strip if tmp end - def self.get_nodelist(server,port,secure,auth_headers_prefix) - path = HTTP::Client.path_params('/nodes',{:user => USER,:list=>true}) - get(server,port,path,secure,{"#{auth_headers_prefix}User"=>USER}) + def self.get_nodelist(server, port, secure, auth_headers_prefix) + path = HTTP::Client.path_params('/nodes', {:user => USER, :list => true}) + get(server, port, path, secure, {"#{auth_headers_prefix}User" => USER}) end - def self.get_nodearch(server,port,secure,auth_headers_prefix, nodes=[]) - path = HTTP::Client.path_params('/nodes',{:user => USER,:arch=>true,:nodes=> nodes}) - get(server,port,path,secure,{"#{auth_headers_prefix}User"=>USER}) + def self.get_nodearch(server, port, secure, auth_headers_prefix, nodes = []) + path = HTTP::Client.path_params('/nodes', {:user => USER, :arch => true, :nodes => nodes}) + get(server, port, path, secure, {"#{auth_headers_prefix}User" => USER}) end def self.term_size() @@ -615,7 +615,7 @@ class Client @@terminal_width end - def self.print_optdesc(str,indentsize) + def self.print_optdesc(str, indentsize) return str.dup if term_size() <= 0 ret = '' tmp = nil @@ -624,7 +624,7 @@ class Client tmp = val elsif tmp.size + val.size + indentsize + 1 > term_size() ret << tmp - ret << "\n#{([' ']*indentsize).join}" + ret << "\n#{([' '] * indentsize).join}" tmp = val else tmp << " #{val}" @@ -634,10 +634,10 @@ class Client ret end - def self.print_arraystr(arr,prefix=nil) + def self.print_arraystr(arr, prefix = nil) ret = '' prefix = prefix || '' - colsize = (ENV['COLUMNS']||80).to_i + colsize = (ENV['COLUMNS'] || 80).to_i tmp = nil arr.each do |val| if tmp.nil? @@ -656,13 +656,13 @@ class Client ret end - def self.httpd_init(secure=false) - $httpd = HTTPd::Server.new(nil,nil,secure) + def self.httpd_init(secure = false) + $httpd = HTTPd::Server.new(nil, nil, secure) end def self.httpd_bind_files() $files.each do |file| - $httpd.bind([:HEAD,:GET],"/#{Base64.urlsafe_encode64(file.path)}",:file,file) + $httpd.bind([:HEAD, :GET], "/#{Base64.urlsafe_encode64(file.path)}", :file, file) end end @@ -688,12 +688,12 @@ class Client } end - def self.add_opt(opt,*args,&block) + def self.add_opt(opt, *args, &block) desc = args.last - tmp = print_optdesc(desc,opt.summary_width+opt.summary_indent.size+1) - desc.clear rescue desc.gsub!(/.*/,'') + tmp = print_optdesc(desc, opt.summary_width + opt.summary_indent.size + 1) + desc.clear rescue desc.gsub!(/.*/, '') desc << tmp - opt.on(*args,&block) + opt.on(*args, &block) end def self.global_parse_options() @@ -709,27 +709,27 @@ class Client puts opts exit 0 end - add_opt(opt,"-v", "--version", "Get the server's version") { + add_opt(opt, "-v", "--version", "Get the server's version") { options[:get_version] = true } - add_opt(opt,"-I", "--server-info", "Get information about the server's configuration") { + add_opt(opt, "-I", "--server-info", "Get information about the server's configuration") { options[:get_users_info] = true } - add_opt(opt,"-M","--multi-server", "Activate the multi-server mode") { + add_opt(opt, "-M", "--multi-server", "Activate the multi-server mode") { options[:multi_server] = true } - add_opt(opt,"-H", "--[no-]debug-http", "Debug HTTP communications with the server (can be redirected to the fd #4)") { |v| + add_opt(opt, "-H", "--[no-]debug-http", "Debug HTTP communications with the server (can be redirected to the fd #4)") { |v| if v $debug_http = IO.new(4) rescue $stdout unless $debug_http end } - add_opt(opt,"-S","--server STRING", "Specify the Kadeploy server to use") { |s| + add_opt(opt, "-S", "--server STRING", "Specify the Kadeploy server to use") { |s| options[:chosen_server] = s } - add_opt(opt,"--[no-]dry-run", "Perform a dry run") { |v| + add_opt(opt, "--[no-]dry-run", "Perform a dry run") { |v| options[:dry_run] = v } - add_opt(opt,"--password [PASSWORD]", "Provide a password for HTTP Basic authentication (read from STDIN if not specified)") { |p| + add_opt(opt, "--password [PASSWORD]", "Provide a password for HTTP Basic authentication (read from STDIN if not specified)") { |p| unless p error("Error: no password specified and invalid STDIN") if !STDIN.tty? or STDIN.closed? $stdout.write('Password: ') @@ -745,7 +745,7 @@ class Client $http_password = p.dup.freeze } opt.separator "" - yield(opt,options) + yield(opt, options) end begin @@ -813,13 +813,13 @@ class Client # Sort nodes from the list by server (if multiserver option is specified) nodes = nil if options[:multi_server] - options[:servers].each_pair do |server,inf| + options[:servers].each_pair do |server, inf| next if server.downcase == 'default' - inf[3] = get_auth_headers_prefix(inf[0],inf[1],inf[2]) unless inf[3] + inf[3] = get_auth_headers_prefix(inf[0], inf[1], inf[2]) unless inf[3] if options[:nodes] - nodelist = get_nodelist(inf[0],inf[1],inf[2],inf[3]) + nodelist = get_nodelist(inf[0], inf[1], inf[2], inf[3]) unless nodelist # Just in case a server give an empty answer - error("Ignoring the server #{inf[0]} (empty answer)",false) + error("Ignoring the server #{inf[0]} (empty answer)", false) next end # Strict check when working on multi-server @@ -827,14 +827,14 @@ class Client next if nodes.empty? # it's useless to contact this server treated += nodes end - $clients << self.new(server,inf[0],inf[1],inf[2],inf[3],nodes) + $clients << self.new(server, inf[0], inf[1], inf[2], inf[3], nodes) break if options[:nodes] and treated.sort == options[:nodes].sort end else info = options[:servers][options[:chosen_server]] - info[3] = get_auth_headers_prefix(info[0],info[1],info[2]) unless info[3] + info[3] = get_auth_headers_prefix(info[0], info[1], info[2]) unless info[3] if options[:nodes] - nodelist = get_nodelist(info[0],info[1],info[2],info[3]) + nodelist = get_nodelist(info[0], info[1], info[2], info[3]) # Lazy check when not working on multi-server nodes = options[:nodes] options[:nodes].each do |node| @@ -845,7 +845,7 @@ class Client end end end - $clients << self.new(nil,info[0],info[1],info[2],info[3],nodes) + $clients << self.new(nil, info[0], info[1], info[2], info[3], nodes) end options[:server_auth_http_prefix] = options[:servers][options[:chosen_server]][3] @@ -853,21 +853,21 @@ class Client error("The nodes #{(options[:nodes] - treated).join(", ")} does not belongs to any server") if options[:nodes] and treated.sort != options[:nodes].sort unless options[:env_arch] || nodes.nil? - default_arch = get_nodearch(info[0],info[1],info[2],info[3],nodes).values.uniq + default_arch = get_nodearch(info[0], info[1], info[2], info[3], nodes).values.uniq error("All nodes do not have a same default architecture. You must give the architecture to use with --env-arch") if default_arch.count != 1 options[:env_arch] = default_arch.first end # Prepare parameters params = self.prepare(options) - params = self.check_params(options,params) + params = self.check_params(options, params) # Launch the deployment $clients.each do |client| $threads << Thread.new do Thread.current[:client] = client - ret = client.run(options,params) - client.result(options,ret) if ret and !options[:dry_run] + ret = client.run(options, params) + client.result(options, ret) if ret and !options[:dry_run] end end @@ -924,15 +924,15 @@ class Client def self.check_options(options) end - def self.check_params(_options,params) + def self.check_params(_options, params) params end - def run(_options,_params) + def run(_options, _params) raise end - def result(options,ret) + def result(options, ret) end def self.operation() @@ -943,26 +943,26 @@ end class ClientWorkflow < Client attr_reader :wid - def initialize(name,server,port,secure,auth_headers_prefix,nodes=nil) - super(name,server,port,secure,auth_headers_prefix,nodes) + def initialize(name, server, port, secure, auth_headers_prefix, nodes = nil) + super(name, server, port, secure, auth_headers_prefix, nodes) @wid = nil @resources = nil @start_time = nil end - def api_path(path=nil,kind=nil,*args) + def api_path(path = nil, kind = nil, *args) if @resources if @resources[path] @resources[path] else if path - File.join(@resources['resource'],path,*args) + File.join(@resources['resource'], path, *args) else - File.join(@resources['resource'],*args) + File.join(@resources['resource'], *args) end end else - super(path,kind,*args) + super(path, kind, *args) end end @@ -976,7 +976,7 @@ class ClientWorkflow < Client end def self.load_file(file) - kind = (URI.parse(file).scheme||'local') + kind = (URI.parse(file).scheme || 'local') case kind when 'local' if check_file(file) @@ -986,7 +986,7 @@ class ClientWorkflow < Client end when 'server' file - when 'http','https' + when 'http', 'https' file else error("Invalid protocol '#{kind}'") @@ -994,7 +994,7 @@ class ClientWorkflow < Client end end - def self.load_keyfile(file,val) + def self.load_keyfile(file, val) if file and !file.empty? unless (val << load_file(file)) return false @@ -1009,35 +1009,35 @@ class ClientWorkflow < Client end end - def self.parse_okfile(opt,options) - add_opt(opt,"-o", "--output-ok-nodes FILENAME", "File that will contain the nodes on which the operation has been correctly performed") { |f| + def self.parse_okfile(opt, options) + add_opt(opt, "-o", "--output-ok-nodes FILENAME", "File that will contain the nodes on which the operation has been correctly performed") { |f| options[:nodes_ok_file] = f load_outputfile(f) } end - def self.parse_kofile(opt,options) - add_opt(opt,"-n", "--output-ko-nodes FILENAME", "File that will contain the nodes on which the operation has not been correctly performed") { |f| + def self.parse_kofile(opt, options) + add_opt(opt, "-n", "--output-ko-nodes FILENAME", "File that will contain the nodes on which the operation has not been correctly performed") { |f| options[:nodes_ko_file] = f load_outputfile(f) } end - def self.parse_keyfile(opt,options) - add_opt(opt,"-k", "--key [FILE]", "Public key to copy in the root's authorized_keys, if no argument is specified, use ~/.ssh/authorized_keys") { |f| - options[:key] = '' - load_keyfile(f,options[:key]) + def self.parse_keyfile(opt, options) + add_opt(opt, "-k", "--key [FILE]", "Public key to copy in the root's authorized_keys, if no argument is specified, use ~/.ssh/authorized_keys") { |f| + options[:key] = '' + load_keyfile(f, options[:key]) } end - def self.parse_op_level(opt,options) - add_opt(opt,"-l", "--op-level VALUE", ['soft','hard','very_hard'], "Operation\'s level (soft, hard, very_hard)") { |l| + def self.parse_op_level(opt, options) + add_opt(opt, "-l", "--op-level VALUE", ['soft', 'hard', 'very_hard'], "Operation\'s level (soft, hard, very_hard)") { |l| options[:level] = l.downcase } end - def self.parse_debug(opt,options) - add_opt(opt,"-d", "--[no-]debug-mode", "Activate the debug mode (can be redirected to the fd #3)") { |v| + def self.parse_debug(opt, options) + add_opt(opt, "-d", "--[no-]debug-mode", "Activate the debug mode (can be redirected to the fd #3)") { |v| options[:debug] = v if v $debug_mode = IO.new(3) rescue $stdout unless $debug_mode @@ -1045,33 +1045,33 @@ class ClientWorkflow < Client } end - def self.parse_verbose(opt,options) - add_opt(opt,"-V", "--verbose-level VALUE", /^[0-5]$/, "Verbose level (between 0 to 5)") { |d| + def self.parse_verbose(opt, options) + add_opt(opt, "-V", "--verbose-level VALUE", /^[0-5]$/, "Verbose level (between 0 to 5)") { |d| options[:verbose_level] = d.to_i } end - def self.parse_block_device(opt,options) - add_opt(opt,"-b", "--block-device BLOCKDEVICE", /^[\w\/]+$/, "Specify the block device to use") { |b| + def self.parse_block_device(opt, options) + add_opt(opt, "-b", "--block-device BLOCKDEVICE", /^[\w\/]+$/, "Specify the block device to use") { |b| options[:block_device] = b options[:deploy_part] = '' unless options[:deploy_part] } end - def self.parse_deploy_part(opt,options) - add_opt(opt,"-p", "--partition-number LABEL", "--partition-label LABEL", "Specify the partition label to use") { |p| + def self.parse_deploy_part(opt, options) + add_opt(opt, "-p", "--partition-number LABEL", "--partition-label LABEL", "Specify the partition label to use") { |p| options[:deploy_part] = p } end - def self.parse_vlan(opt,options) - add_opt(opt,"--vlan VLANID", "Set the VLAN") { |id| + def self.parse_vlan(opt, options) + add_opt(opt, "--vlan VLANID", "Set the VLAN") { |id| options[:vlan] = id } end - def self.parse_pxe_profile(opt,options) - add_opt(opt,"-w", "--set-pxe-profile FILE", "Set the PXE profile (use with caution)") { |f| + def self.parse_pxe_profile(opt, options) + add_opt(opt, "-w", "--set-pxe-profile FILE", "Set the PXE profile (use with caution)") { |f| if check_file(f) options[:pxe_profile] = File.read(f) else @@ -1080,8 +1080,8 @@ class ClientWorkflow < Client } end - def self.parse_pxe_pattern(opt,options) - add_opt(opt,"--set-pxe-pattern FILE", "Specify a file containing the substitution of a pattern for each node in the PXE profile (the NODE_SINGULARITY pattern must be used in the PXE profile)") { |f| + def self.parse_pxe_pattern(opt, options) + add_opt(opt, "--set-pxe-pattern FILE", "Specify a file containing the substitution of a pattern for each node in the PXE profile (the NODE_SINGULARITY pattern must be used in the PXE profile)") { |f| if (lines = load_inputfile(f)) options[:pxe_profile_singularities] = {} lines.each do |line| @@ -1094,8 +1094,8 @@ class ClientWorkflow < Client } end - def self.parse_pxe_files(opt,options) - add_opt(opt,"-x", "--upload-pxe-files FILES", Array, "Upload a list of files (file1,file2,file3) to the PXE repository. Those files will then be available with the prefix FILES_PREFIX-- ") { |fs| + def self.parse_pxe_files(opt, options) + add_opt(opt, "-x", "--upload-pxe-files FILES", Array, "Upload a list of files (file1,file2,file3) to the PXE repository. Those files will then be available with the prefix FILES_PREFIX-- ") { |fs| fs.each do |file| return false unless (filename = load_file(File.expand_path(file))) options[:pxe_files] << filename @@ -1103,15 +1103,15 @@ class ClientWorkflow < Client } end - def self.parse_wid(opt,options) - add_opt(opt,"--write-workflow-id FILE", "Write the workflow id in a file") { |f| + def self.parse_wid(opt, options) + add_opt(opt, "--write-workflow-id FILE", "Write the workflow id in a file") { |f| options[:wid_file] = f load_outputfile(f) } end - def self.parse_scriptfile(opt,options) - add_opt(opt,"-s", "--script FILE", "Execute a script at the end of the operation") { |f| + def self.parse_scriptfile(opt, options) + add_opt(opt, "-s", "--script FILE", "Execute a script at the end of the operation") { |f| if check_file(f) if File.stat(f).executable? options[:script] = File.expand_path(f) @@ -1125,39 +1125,39 @@ class ClientWorkflow < Client } end - def self.parse_timeout_reboot(opt,options) - add_opt(opt,"--reboot-classical-timeout VALUE", "Overload the default timeout for classical reboots (a ruby expression can be used, 'n' will be replaced by the number of nodes)") { |t| + def self.parse_timeout_reboot(opt, options) + add_opt(opt, "--reboot-classical-timeout VALUE", "Overload the default timeout for classical reboots (a ruby expression can be used, 'n' will be replaced by the number of nodes)") { |t| options[:reboot_classical_timeout] = t } end - def self.parse_wait(opt,options) - add_opt(opt,"--[no-]wait", "Wait the end of the operation, set by default") { |v| + def self.parse_wait(opt, options) + add_opt(opt, "--[no-]wait", "Wait the end of the operation, set by default") { |v| options[:wait] = v } end - def self.parse_force(opt,options) - add_opt(opt,"--[no-]force", "Allow to deploy even on the nodes tagged as currently used (use this only if you know what you do)") { + def self.parse_force(opt, options) + add_opt(opt, "--[no-]force", "Allow to deploy even on the nodes tagged as currently used (use this only if you know what you do)") { options[:force] = true } end - def self.parse_breakpoint(opt,options) - add_opt(opt,"--breakpoint STEP", /^\w+(?::\w+)?$/, "Set a breakpoint just before lauching the given micro-step, the syntax is macrostep:microstep (use this only if you know what you do)") { |s| + def self.parse_breakpoint(opt, options) + add_opt(opt, "--breakpoint STEP", /^\w+(?::\w+)?$/, "Set a breakpoint just before lauching the given micro-step, the syntax is macrostep:microstep (use this only if you know what you do)") { |s| options[:breakpoint] = s } end - def self.parse_custom_ops(opt,options) - add_opt(opt,"--custom-steps FILE", "Add some custom operations defined in a file") { |file| + def self.parse_custom_ops(opt, options) + add_opt(opt, "--custom-steps FILE", "Add some custom operations defined in a file") { |file| options[:custom_operations] = load_custom_file(file) return false unless options[:custom_operations] } end - def self.parse_hook(opt,options) - add_opt(opt,"--[no-]hook", "Launch server's hook at the end of operation, disabled by default") { |h| + def self.parse_hook(opt, options) + add_opt(opt, "--[no-]hook", "Launch server's hook at the end of operation, disabled by default") { |h| options[:hook] = h } end @@ -1180,24 +1180,24 @@ class ClientWorkflow < Client end def self.global_parse_options() - super do |opt,options| - #opt.separator "" - #opt.separator "Workflow options:" - parse_debug(opt,options) - parse_machinefile(opt,options) - parse_machine(opt,options) - parse_kofile(opt,options) - parse_okfile(opt,options) - parse_scriptfile(opt,options) - parse_verbose(opt,options) - parse_wid(opt,options) - parse_wait(opt,options) - parse_force(opt,options) - parse_breakpoint(opt,options) - parse_custom_ops(opt,options) - parse_hook(opt,options) + super do |opt, options| + # opt.separator "" + # opt.separator "Workflow options:" + parse_debug(opt, options) + parse_machinefile(opt, options) + parse_machine(opt, options) + parse_kofile(opt, options) + parse_okfile(opt, options) + parse_scriptfile(opt, options) + parse_verbose(opt, options) + parse_wid(opt, options) + parse_wait(opt, options) + parse_force(opt, options) + parse_breakpoint(opt, options) + parse_custom_ops(opt, options) + parse_hook(opt, options) opt.separator "" - yield(opt,options) + yield(opt, options) end end @@ -1257,8 +1257,8 @@ class ClientWorkflow < Client params end - def self.check_params(options,params) - params = super(options,params) + def self.check_params(options, params) + params = super(options, params) # Serve local files throught HTTP(s) params[:client] = http_export_files(options[:secure]) unless $files.empty? @@ -1271,22 +1271,22 @@ class ClientWorkflow < Client params end - def run(options,params) + def run(options, params) # Launch the workflow - run_workflow(options,params) + run_workflow(options, params) end - def run_workflow(options,params,submit_method=:post) + def run_workflow(options, params, submit_method = :post) params[:nodes] = nodes() # Launch the operation - ret = send(submit_method,api_path(),params) + ret = send(submit_method, api_path(), params) return if options[:dry_run] @wid = ret['wid'] @resources = ret['resources'] @start_time = Time.now.to_i - File.open(options[:wid_file],'w'){|f| f.write @wid} if options[:wid_file] + File.open(options[:wid_file], 'w'){|f| f.write @wid} if options[:wid_file] if options[:wait] debug "#{self.class.operation()}#{" ##{@wid}" if @wid} started\n" @@ -1313,18 +1313,18 @@ class ClientWorkflow < Client if $debug_mode and $debug_mode != $stdout dbg.sort_by!{|line| (line.split("|")[0] rescue '0').to_f} dbg.collect!{|line| line.split("|")[1] rescue line } - debug(dbg.join("\n"),true,$debug_mode) + debug(dbg.join("\n"), true, $debug_mode) else out += dbg end - dbg.clear rescue dbg.gsub!(/.*/,'') + dbg.clear rescue dbg.gsub!(/.*/, '') end unless out.empty? out.sort_by!{|line| (line.split("|")[0] rescue '0').to_f} out.collect!{|line| line.split("|")[1] rescue line } debug out.join("\n") - out.clear rescue out.gsub!(/.*/,'') + out.clear rescue out.gsub!(/.*/, '') end sleep SLEEP_PITCH @@ -1339,21 +1339,21 @@ class ClientWorkflow < Client delete(api_path()) if @wid @resources = nil - [ res, states ] + [res, states] else debug "#{@wid} #{@resources['resource']}\n" nil end end - def result(options,ret) - res,states = ret + def result(options, ret) + res, states = ret unless res['error'] # Success if res['nodes']['ok'] and !res['nodes']['ok'].empty? debug "The #{self.class.operation().downcase} is successful on nodes" debug res['nodes']['ok'].join("\n") - File.open(options[:nodes_ok_file],'a+') do |f| + File.open(options[:nodes_ok_file], 'a+') do |f| f.puts res['nodes']['ok'].join("\n") end if options[:nodes_ok_file] end @@ -1364,19 +1364,19 @@ class ClientWorkflow < Client res['nodes']['ko'].each do |node| debug "#{node} (#{states[node]['error'] if states[node]})\n" end - File.open(options[:nodes_ko_file],'a+') do |f| + File.open(options[:nodes_ko_file], 'a+') do |f| f.puts res['nodes']['ko'].join("\n") end if options[:nodes_ko_file] end end end - def display_status_cluster(stat,prefix='') - stat.each_pair do |macro,micros| + def display_status_cluster(stat, prefix = '') + stat.each_pair do |macro, micros| if micros.is_a?(Hash) - micros.each_pair do |micro,status| + micros.each_pair do |micro, status| if status.is_a?(Hash) - status['nodes'].each_pair do |state,nodes| + status['nodes'].each_pair do |state, nodes| unless nodes.empty? debug "#{prefix} [#{macro}-#{micro}] ~#{status['time']}s (#{state})" debug "#{prefix} #{nodes.join("\n#{prefix} ")}" @@ -1410,9 +1410,9 @@ class ClientWorkflow < Client if stats.size == 1 display_status_cluster(stats[stats.keys[0]]) else - stats.each_pair do |clname,stat| + stats.each_pair do |clname, stat| debug " [#{clname}]" - display_status_cluster(stat,' ') + display_status_cluster(stat, ' ') end end end diff --git a/lib/kadeploy3/common/api.rb b/lib/kadeploy3/common/api.rb index 0e0038b4bdbb7f73766750f60a561a5b99616722..d34244b94f59a5736d0749176b10b9a70a195bc4 100644 --- a/lib/kadeploy3/common/api.rb +++ b/lib/kadeploy3/common/api.rb @@ -24,12 +24,12 @@ module API end end - def self.path(kind,*args) - File.join(base(kind),*args) + def self.path(kind, *args) + File.join(base(kind), *args) end - def self.ppath(kind,prefix,*args) - File.join(prefix,base(kind),*args) + def self.ppath(kind, prefix, *args) + File.join(prefix, base(kind), *args) end def self.wid_prefix(kind) diff --git a/lib/kadeploy3/common/compat.rb b/lib/kadeploy3/common/compat.rb index 5a0ad39b6fac8310dde9b6395521e801162daa95..5a5e10440433671789a75dfe9536116fde6ba68b 100644 --- a/lib/kadeploy3/common/compat.rb +++ b/lib/kadeploy3/common/compat.rb @@ -7,12 +7,12 @@ if RUBY_VERSION < '1.9' end class Array - def select!(*args,&block) - replace(select(*args,&block)) + def select!(*args, &block) + replace(select(*args, &block)) end - def sort_by!(*args,&block) - replace(sort_by(*args,&block)) + def sort_by!(*args, &block) + replace(sort_by(*args, &block)) end end @@ -49,7 +49,7 @@ if RUBY_VERSION < '1.9' end def self.strict_encode64(bin) - encode64(bin).gsub("\n",'') + encode64(bin).gsub("\n", '') end def self.strict_decode64(str) @@ -58,12 +58,12 @@ if RUBY_VERSION < '1.9' end module URI - def self.encode_www_form_component(str,*) + def self.encode_www_form_component(str, *) encode(str.to_s) end def self.encode_www_form(enum) - enum.map do |k,v| + enum.map do |k, v| if v.nil? encode_www_form_component(k) elsif v.respond_to?(:to_ary) @@ -82,7 +82,7 @@ if RUBY_VERSION < '1.9' end.join('&') end - def self.decode_www_form_component(str,*) + def self.decode_www_form_component(str, *) decode(str) end diff --git a/lib/kadeploy3/common/configparser.rb b/lib/kadeploy3/common/configparser.rb index 6b0efaa53679c66d8a0fae843fd76302b3903612..c963f7a8e7dbb08b1227e4a630384169026e460a 100644 --- a/lib/kadeploy3/common/configparser.rb +++ b/lib/kadeploy3/common/configparser.rb @@ -77,12 +77,12 @@ module Configuration @val = confighash end - def push(fieldname, val=nil) + def push(fieldname, val = nil) @path.push(fieldname) @val = (val.nil? ? curval() : val) end - def pop(val=nil) + def pop(val = nil) @path.pop @val = (val.nil? ? curval() : val) end @@ -91,7 +91,7 @@ module Configuration @path.size end - def path(val=nil) + def path(val = nil) self.class.pathstr(@path + [val]) end @@ -114,7 +114,7 @@ module Configuration ret end - def self.errmsg(field,message) + def self.errmsg(field, message) "#{message} [field: #{field}]" end @@ -122,7 +122,7 @@ module Configuration array.compact.join(PATH_SEPARATOR) end - def check_field(fieldname,mandatory,type) + def check_field(fieldname, mandatory, type) begin if @val.is_a?(Hash) if !@val[fieldname].nil? @@ -138,11 +138,11 @@ module Configuration end if typeok - yield(@val[fieldname],true) + yield(@val[fieldname], true) else - $,=',' + $, = ',' typename = type.to_s - $,=nil + $, = nil raise ParserError.new( "The field should have the type #{typename}" ) @@ -150,7 +150,7 @@ module Configuration elsif mandatory raise ParserError.new("The field is mandatory") else - yield(nil,@val.has_key?(fieldname)) + yield(nil, @val.has_key?(fieldname)) end elsif mandatory if @val.nil? @@ -159,11 +159,11 @@ module Configuration raise ParserError.new("The field has to be a Hash") end else - yield(nil,false) + yield(nil, false) end rescue ParserError => pe raise ArgumentError.new( - self.class.errmsg(path(fieldname),pe.message) + self.class.errmsg(path(fieldname), pe.message) ) end end @@ -181,7 +181,7 @@ module Configuration def check_hash(val, hash, fieldname) val = val.clone if hash[:const] - self.send("customcheck_#{hash[:type].downcase}".to_sym,val,fieldname,hash) + self.send("customcheck_#{hash[:type].downcase}".to_sym, val, fieldname, hash) end def check_range(val, range, fieldname) @@ -247,7 +247,7 @@ module Configuration def customcheck_file(val, _fieldname, args) return if args[:disable] if args[:command] - val = val.split(/\s+/).first||'' + val = val.split(/\s+/).first || '' if !val.empty? and !Pathname.new(val).absolute? # Since the command is launched in a shell and can be a script, # if the command cannot be found, skip further checkings @@ -258,9 +258,9 @@ module Configuration if args[:prefix] tmp = Pathname.new(val) - val.gsub!(val,File.join(args[:prefix],val)) if !tmp.absolute? and !val.empty? + val.gsub!(val, File.join(args[:prefix], val)) if !tmp.absolute? and !val.empty? end - val.gsub!(val,File.join(val,args[:suffix])) if args[:suffix] + val.gsub!(val, File.join(val, args[:suffix])) if args[:suffix] if File.exist?(val) if File.file?(val) if args[:writable] @@ -302,8 +302,8 @@ module Configuration def customcheck_dir(val, _fieldname, args) return if args[:disable] - val = File.join(args[:prefix],val) if args[:prefix] and !val.empty? - val = File.join(val,args[:suffix]) if args[:suffix] and !val.empty? + val = File.join(args[:prefix], val) if args[:prefix] and !val.empty? + val = File.join(val, args[:suffix]) if args[:suffix] and !val.empty? if File.exist?(val) if File.directory?(val) if args[:writable] @@ -336,8 +336,8 @@ module Configuration end - def parse(fieldname, mandatory=false, type=Hash,warns_if_empty=true) - check_field(fieldname,mandatory,type) do |curval,provided| + def parse(fieldname, mandatory = false, type = Hash, warns_if_empty = true) + check_field(fieldname, mandatory, type) do |curval, provided| oldval = @val push(fieldname, curval) @@ -370,16 +370,16 @@ module Configuration end # if no defaultvalue defined, field is mandatory - def value(fieldname,type,defaultvalue=nil,expected=nil) + def value(fieldname, type, defaultvalue = nil, expected = nil) ret = nil - check_field(fieldname,defaultvalue.nil?,type) do |val,_| + check_field(fieldname, defaultvalue.nil?, type) do |val, _| if val.nil? ret = defaultvalue else ret = val @val.delete(fieldname) end - #ret = (val.nil? ? defaultvalue : val) + # ret = (val.nil? ? defaultvalue : val) if expected classname = ( @@ -396,17 +396,17 @@ module Configuration ret end - def unused(result = [],curval=nil,curpath=nil) + def unused(result = [], curval = nil, curpath = nil) curval = @basehash if curval.nil? curpath = [] unless curpath if curval.is_a?(Hash) - curval.each do |key,value| + curval.each do |key, value| curpath << key if value.nil? result << self.class.pathstr(curpath) else - unused(result,value,curpath) + unused(result, value, curpath) end curpath.pop end @@ -416,7 +416,7 @@ module Configuration if curval[i].nil? result << self.class.pathstr(curpath) else - unused(result,curval[i],curpath) + unused(result, curval[i], curpath) end curpath.pop end diff --git a/lib/kadeploy3/common/environment.rb b/lib/kadeploy3/common/environment.rb index 79ad17fbd199bb864b85d5bf8bae4144a0f02bc5..6329d42f6cc04a1cb5c2131fab2003d281772d23 100644 --- a/lib/kadeploy3/common/environment.rb +++ b/lib/kadeploy3/common/environment.rb @@ -23,7 +23,7 @@ class Environment 'zstd', ] - def self.image_type_short(kind,compression) + def self.image_type_short(kind, compression) case kind when 'tar' case compression @@ -55,23 +55,23 @@ class Environment def self.image_type_long(type) case type when 'tgz' - [ 'tar', 'gzip' ] + ['tar', 'gzip'] when 'tbz2' - [ 'tar', 'bzip2' ] + ['tar', 'bzip2'] when 'txz' - [ 'tar', 'xz' ] + ['tar', 'xz'] when 'tzstd' - [ 'tar', 'zstd' ] + ['tar', 'zstd'] when 'ddgz' - [ 'dd', 'gzip' ] + ['dd', 'gzip'] when 'ddbz2' - [ 'dd', 'bzip2' ] + ['dd', 'bzip2'] when 'ddxz' - [ 'dd', 'xz' ] + ['dd', 'xz'] when 'ddzstd' - [ 'dd', 'zstd' ] + ['dd', 'zstd'] when /^fsa(\d+)$/ - [ 'fsa', $1 ] + ['fsa', $1] end end @@ -148,8 +148,8 @@ class Environment @recorded = nil end - def error(errno,msg) - raise KadeployError.new(errno,nil,msg) + def error(errno, msg) + raise KadeployError.new(errno, nil, msg) end def check_os_values() @@ -169,10 +169,10 @@ class Environment mandatory.each do |name| val = self.instance_variable_get(name) if val.nil? or val.empty? - return [false,"The field '#{name.to_s[1..-1]}' is mandatory for OS #{@environment_kind} with the '#{@image[:kind]}' image kind"] + return [false, "The field '#{name.to_s[1..-1]}' is mandatory for OS #{@environment_kind} with the '#{@image[:kind]}' image kind"] end end - return [true,''] + return [true, ''] end def recorded? @@ -191,7 +191,7 @@ class Environment # * user: true user # Output # * returns true if the environment can be loaded correctly, false otherwise - def load_from_desc(description, _almighty_env_users, user, client=nil, get_checksum=true,output=nil) + def load_from_desc(description, _almighty_env_users, user, client = nil, get_checksum = true, output = nil) @recorded = false @user = user @preinstall = nil @@ -209,24 +209,23 @@ class Environment @visibility = cp.value('visibility',String,'private',['public','private','shared']) @demolishing_env = cp.value('destructive',[TrueClass,FalseClass],false) @environment_kind = cp.value('os',String,nil,OS_KIND) - - cp.parse('image',true) do - file = cp.value('file',String) - kind = cp.value('kind',String,nil,IMAGE_KIND) + cp.parse('image', true) do + file = cp.value('file', String) + kind = cp.value('kind', String, nil, IMAGE_KIND) compress = nil if kind == 'fsa' - compress = cp.value('compression',Integer,0,Array(0..9)).to_s + compress = cp.value('compression', Integer, 0, Array(0..9)).to_s else - compress = cp.value('compression',String,nil,IMAGE_COMPRESSION) + compress = cp.value('compression', String, nil, IMAGE_COMPRESSION) end md5 = nil if get_checksum - md5 = FetchFile[file,client].checksum() + md5 = FetchFile[file, client].checksum() else md5 = '' end - shortkind = self.class.image_type_short(kind,compress) + shortkind = self.class.image_type_short(kind, compress) @tarball = { 'kind' => shortkind, 'file' => file, @@ -240,15 +239,15 @@ class Environment :md5 => md5, } end - if (@image[:compression] == 'gzip' && ['zstd','std','tzstd'].include?(@image[:file].split('.').last)) || (@image[:compression] == 'zstd' && ['tgz','gz','zip'].include?(@image[:file].split('.').last)) + if (@image[:compression] == 'gzip' && ['zstd', 'std', 'tzstd'].include?(@image[:file].split('.').last)) || (@image[:compression] == 'zstd' && ['tgz', 'gz', 'zip'].include?(@image[:file].split('.').last)) output.puts "Warning[env_desc]: Mismatch between image file name \"#{@image[:file]}\" and the compression \"#{@image[:compression]}\"" end cp.parse('preinstall') do |info| unless info[:empty] - file = cp.value('archive',String) + file = cp.value('archive', String) md5 = nil if get_checksum - md5 = FetchFile[file,client].checksum() + md5 = FetchFile[file, client].checksum() else md5 = '' end @@ -256,47 +255,47 @@ class Environment 'file' => file, 'kind' => self.class.image_type_short( 'tar', - cp.value('compression',String,nil,IMAGE_COMPRESSION) + cp.value('compression', String, nil, IMAGE_COMPRESSION) ), 'md5' => md5, - 'script' => cp.value('script',String,'none'), + 'script' => cp.value('script', String, 'none'), } end end - cp.parse('postinstalls',false,Array) do |info| + cp.parse('postinstalls', false, Array) do |info| unless info[:empty] - file = cp.value('archive',String) + file = cp.value('archive', String) md5 = nil if get_checksum - md5 = FetchFile[file,client].checksum() + md5 = FetchFile[file, client].checksum() else md5 = '' end @postinstall << { 'kind' => self.class.image_type_short( 'tar', - cp.value('compression',String,nil,IMAGE_COMPRESSION) + cp.value('compression', String, nil, IMAGE_COMPRESSION) ), 'file' => file, 'md5' => md5, - 'script' => cp.value('script',String,'none'), + 'script' => cp.value('script', String, 'none'), } end end - @filesystem = cp.value('filesystem',String,'') - @fdisk_type = cp.value('partition_type',Integer,0).to_s(16) #numeric or hexa - @multipart = cp.value('multipart',[TrueClass,FalseClass],false) + @filesystem = cp.value('filesystem', String, '') + @fdisk_type = cp.value('partition_type', Integer, 0).to_s(16) # numeric or hexa + @multipart = cp.value('multipart', [TrueClass, FalseClass], false) @options = {} - cp.parse('options',@multipart) do |info| + cp.parse('options', @multipart) do |info| unless info[:empty] @options['partitions'] = [] - cp.parse('partitions',@multipart,Array) do |info2| + cp.parse('partitions', @multipart, Array) do |info2| unless info2[:empty] tmp = { 'id' => cp.value('id', Integer), - 'device' => cp.value('device',String), + 'device' => cp.value('device', String), } # Check if 'id' already defined for another partition unless @options['partitions'].select{ |part| @@ -328,20 +327,20 @@ class Environment "on the deployment partition" ) end - @options['kexec'] = cp.value('kexec',[TrueClass,FalseClass],true) - @options['trust_env'] = cp.value('trust_previous_env', [TrueClass,FalseClass,nil],nil) + @options['kexec'] = cp.value('kexec', [TrueClass, FalseClass], true) + @options['trust_env'] = cp.value('trust_previous_env', [TrueClass, FalseClass, nil], nil) end end cp.parse('boot') do - @kernel = cp.value('kernel',String,'',Pathname) - @initrd = cp.value('initrd',String,'',Pathname) - @kernel_params = cp.value('kernel_params',String,'') - @hypervisor = cp.value('hypervisor',String,'',Pathname) - @hypervisor_params = cp.value('hypervisor_params',String,'') + @kernel = cp.value('kernel', String, '', Pathname) + @initrd = cp.value('initrd', String, '', Pathname) + @kernel_params = cp.value('kernel_params', String, '') + @hypervisor = cp.value('hypervisor', String, '', Pathname) + @hypervisor_params = cp.value('hypervisor_params', String, '') if @multipart - @options['block_device'] = cp.value('block_device',String) - @options['deploy_part'] = cp.value('partition',String) + @options['block_device'] = cp.value('block_device', String) + @options['deploy_part'] = cp.value('partition', String) end end @@ -356,7 +355,7 @@ class Environment end ret = check_os_values() - error(APIError::INVALID_ENVIRONMENT,ret[1]) unless ret[0] + error(APIError::INVALID_ENVIRONMENT, ret[1]) unless ret[0] return ret[0] end @@ -385,10 +384,10 @@ class Environment # * Public environments are returned if: # * owner_user is nil or empty # * no environment belongs to owner_user - def self.get_from_db_context(dbh,name,version,arch,owner_user,context_user,almighty_users) + def self.get_from_db_context(dbh, name, version, arch, owner_user, context_user, almighty_users) is_almighty = almighty_users.include?(context_user) - user2 = (owner_user.nil? || owner_user.empty?) && !is_almighty ? context_user : owner_user + user2 = (owner_user.nil? || owner_user.empty?) && !is_almighty ? context_user : owner_user get_from_db( dbh, @@ -401,19 +400,19 @@ class Environment ) end - def self.add_cond(args,condition,sql,value) + def self.add_cond(args, condition, sql, value) if value && !value.empty? - args<<value + args << value condition += sql end condition end - def self.get_from_db(dbh, name, version, arch, user, private_envs=false, public_envs=false) + def self.get_from_db(dbh, name, version, arch, user, private_envs = false, public_envs = false) version = version.to_s if version.is_a?(Integer) args = [] last_version = false - sort='' + sort = '' conditions = "WHERE true " if name && !name.empty? args << name @@ -434,7 +433,7 @@ class Environment end if version == true - sort=', version desc' + sort = ', version desc' elsif version and !version.empty? conditions += " AND version = ?" args << version @@ -484,7 +483,7 @@ class Environment if envs and !envs.empty? env = envs[0] query = "DELETE FROM environments WHERE name=? AND user=?" - args = [env.name,env.user] + args = [env.name, env.user] if (version and version != true and !version.empty?) or version.nil? query << ' AND version=?' args << env.version @@ -493,7 +492,7 @@ class Environment query << ' AND arch LIKE ?' args << env.arch end - res = dbh.run_query(query,*args) + res = dbh.run_query(query, *args) if res.affected_rows == 0 return false else @@ -504,7 +503,7 @@ class Environment end end - def self.update_to_db(dbh, name, version, arch, user, private_envs, fields, env=nil) + def self.update_to_db(dbh, name, version, arch, user, private_envs, fields, env = nil) if fields and !fields.empty? # check if the fields to update exists tmp = Environment.new @@ -531,7 +530,7 @@ class Environment args = [] dbfields = [] nbtoup = 0 - fields.each_pair do |fieldname,val| + fields.each_pair do |fieldname, val| unless env.send(fieldname.to_sym) == val dbfields << "#{fieldname}=?" args << val @@ -552,7 +551,7 @@ class Environment ) # Update the object - fields.each_pair do |fieldname,val| + fields.each_pair do |fieldname, val| if env.send(fieldname.to_sym) != val and env.respond_to?("#{fieldname}=".to_sym) case fieldname when 'demolishing_env' @@ -562,15 +561,15 @@ class Environment env.demolishing_env = true end when 'tarball' - env.tarball = self.expand_tarball(val,true) + env.tarball = self.expand_tarball(val, true) env.image[:file] = env.tarball['file'] env.image[:md5] = env.tarball['md5'] when 'preinstall' - env.preinstall = self.expand_preinstall(val,true) + env.preinstall = self.expand_preinstall(val, true) when 'postinstall' - env.postinstall = self.expand_postinstall(val,true) + env.postinstall = self.expand_postinstall(val, true) else - env.send("#{fieldname}=".to_sym,val) + env.send("#{fieldname}=".to_sym, val) end end end @@ -614,20 +613,20 @@ class Environment self end - def load_from_db_context(dbh,name,version,arch,user,context_user,almighty_users) - ret = self.class.get_from_db_context(dbh,name,version,arch,user,context_user,almighty_users) - #if user is not defined, own environments are selected if available + def load_from_db_context(dbh, name, version, arch, user, context_user, almighty_users) + ret = self.class.get_from_db_context(dbh, name, version, arch, user, context_user, almighty_users) + # if user is not defined, own environments are selected if available if !ret.nil? && user.nil? list = ret.select { |env| env.user == context_user } list = ret if list.empty? else list = ret end - #list should not contain more than one element when only one user is allowed to publish public environments + # list should not contain more than one element when only one user is allowed to publish public environments load_from_env(list.first) if ret end - def load_from_db(dbh, name, version, arch, user, private_env=false, public_env=false) + def load_from_db(dbh, name, version, arch, user, private_env = false, public_env = false) ret = self.class.get_from_db( dbh, name, @@ -657,7 +656,7 @@ class Environment @visibility = hash['visibility'] @demolishing_env = (hash['demolishing_env'] == 0 ? false : true) @environment_kind = hash['environment_kind'] - @tarball = self.class.expand_image(hash['tarball'],true) + @tarball = self.class.expand_image(hash['tarball'], true) tmp = self.class.image_type_long(@tarball['kind']) @image = { :file => @tarball['file'], @@ -666,8 +665,8 @@ class Environment :shortkind => @tarball['kind'], :md5 => @tarball['md5'], } - @preinstall = self.class.expand_preinstall(hash['preinstall'],true) - @postinstall = self.class.expand_postinstall(hash['postinstall'],true) + @preinstall = self.class.expand_preinstall(hash['preinstall'], true) + @postinstall = self.class.expand_postinstall(hash['postinstall'], true) @kernel = hash['kernel'] @kernel_params = hash['kernel_params'] @initrd = hash['initrd'] @@ -687,9 +686,9 @@ class Environment # returns true if it worked, the already existing environments if it doesnt def save_to_db(dbh) - if (envs = self.class.get_from_db(dbh,@name,@version,@arch,@user,true,false)) + if (envs = self.class.get_from_db(dbh, @name, @version, @arch, @user, true, false)) envs - elsif (@alias && !@alias.empty? && (envs = self.class.get_from_db(dbh,@alias,@version,@arch,@user,true,false))) + elsif (@alias && !@alias.empty? && (envs = self.class.get_from_db(dbh, @alias, @version, @arch, @user, true, false))) envs else dbh.run_query( @@ -723,9 +722,9 @@ class Environment @alias, @description, @author, - self.class.flatten_image(@tarball,true), - self.class.flatten_preinstall(@preinstall,true), - self.class.flatten_postinstall(@postinstall,true), + self.class.flatten_image(@tarball, true), + self.class.flatten_preinstall(@preinstall, true), + self.class.flatten_postinstall(@postinstall, true), @kernel, @kernel_params, @initrd, @@ -773,7 +772,7 @@ class Environment unless @preinstall.nil? ret['preinstall'] = {} ret['preinstall']['archive'] = @preinstall['file'] - _,ret['preinstall']['compression'] = + _, ret['preinstall']['compression'] = self.class.image_type_long(@preinstall['kind']) ret['preinstall']['script'] = @preinstall['script'] end @@ -783,7 +782,7 @@ class Environment @postinstall.each do |post| tmp = {} tmp['archive'] = post['file'] - _,tmp['compression'] = + _, tmp['compression'] = self.class.image_type_long(post['kind']) tmp['script'] = post['script'] ret['postinstalls'] << tmp @@ -815,33 +814,33 @@ class Environment ret end - def self.flatten_image(img,md5=false) - "#{img['file']}|#{img['kind']}#{(md5 ? '|'+img['md5'] : '')}" + def self.flatten_image(img, md5 = false) + "#{img['file']}|#{img['kind']}#{(md5 ? '|' + img['md5'] : '')}" end - def self.expand_image(img,md5=false) + def self.expand_image(img, md5 = false) ret = {} - tmp=img.split('|') - ret['file'],ret['kind'] = tmp + tmp = img.split('|') + ret['file'], ret['kind'] = tmp ret['md5'] = tmp[2] if md5 ret end - def self.flatten_preinstall(pre,md5=false) + def self.flatten_preinstall(pre, md5 = false) if !pre.nil? and !pre.empty? - "#{pre['file']}|#{pre['kind']}#{(md5 ? '|'+pre['md5'] : '')}|#{pre['script']}" + "#{pre['file']}|#{pre['kind']}#{(md5 ? '|' + pre['md5'] : '')}|#{pre['script']}" else '' end end - def self.expand_preinstall(pre,md5=false) + def self.expand_preinstall(pre, md5 = false) if pre.nil? or pre.empty? nil else ret = {} tmp = pre.split('|') - ret['file'],ret['kind'] = tmp + ret['file'], ret['kind'] = tmp if md5 ret['md5'] = tmp[2] ret['script'] = tmp[3] @@ -852,17 +851,17 @@ class Environment end end - def self.flatten_postinstall(post,md5=false) + def self.flatten_postinstall(post, md5 = false) if !post.nil? and !post.empty? post.collect do |p| - "#{p['file']}|#{p['kind']}#{(md5 ? '|'+p['md5'] : '')}|#{p['script']}" + "#{p['file']}|#{p['kind']}#{(md5 ? '|' + p['md5'] : '')}|#{p['script']}" end.join(',') else '' end end - def self.expand_postinstall(post,md5=false) + def self.expand_postinstall(post, md5 = false) if post.nil? or post.empty? [] else @@ -870,7 +869,7 @@ class Environment post.split(',').each do |p| val = {} tmp = p.split('|') - val['file'],val['kind'] = tmp + val['file'], val['kind'] = tmp if md5 val['md5'] = tmp[2] val['script'] = tmp[3] diff --git a/lib/kadeploy3/common/error.rb b/lib/kadeploy3/common/error.rb index a11cebbd0b5412eac0d764de7f7097c899ef1d8e..e780b5893c07e58834ea3bad7331dbfe8d8de17a 100644 --- a/lib/kadeploy3/common/error.rb +++ b/lib/kadeploy3/common/error.rb @@ -3,7 +3,7 @@ module Kadeploy class KadeployError < RuntimeError attr_reader :errno, :context attr_writer :context - def initialize(errno,context={},msg='') + def initialize(errno, context = {}, msg = '') super(msg) @errno = errno @context = context @@ -62,7 +62,7 @@ end class KadeployExecuteError < KadeployError def initialize(msg) - super(APIError::EXECUTE_ERROR,nil,msg) + super(APIError::EXECUTE_ERROR, nil, msg) end end diff --git a/lib/kadeploy3/common/execute.rb b/lib/kadeploy3/common/execute.rb index 2a5155c9f838449eb01d64065e7ef36291453142..461ee523a1314b20563bc4dc36f8e1f5bb093e81 100644 --- a/lib/kadeploy3/common/execute.rb +++ b/lib/kadeploy3/common/execute.rb @@ -3,7 +3,7 @@ module Kadeploy # To be used as you're using Open3.popen3 in ruby 1.9.2 class Execute require 'fcntl' - attr_reader :command, :exec_pid, :stdout, :stderr, :status,:emptypipes + attr_reader :command, :exec_pid, :stdout, :stderr, :status, :emptypipes @@forkmutex = Mutex.new def initialize(*cmd) @@ -23,31 +23,31 @@ module Kadeploy @emptypipes = false end - #Free the command, stdout stderr string. + # Free the command, stdout stderr string. def free @command = nil @stdout = nil @stderr = nil end - #Same as new function + # Same as new function def self.[](*cmd) self.new(*cmd) end - #Initialize the pipes and return one array for parent and one array for child. - def self.init_ios(opts={:stdin => false}) + # Initialize the pipes and return one array for parent and one array for child. + def self.init_ios(opts = {:stdin => false}) if opts[:stdin] in_r, in_w = IO::pipe in_w.sync = true else - in_r, in_w = [nil,nil] + in_r, in_w = [nil, nil] end - out_r, out_w = opts[:stdout] == false ? [nil,nil] : IO::pipe - err_r, err_w = opts[:stderr] == false ? [nil,nil] : IO::pipe + out_r, out_w = opts[:stdout] == false ? [nil, nil] : IO::pipe + err_r, err_w = opts[:stderr] == false ? [nil, nil] : IO::pipe - [ [in_r,out_w,err_w], [in_w,out_r,err_r] ] + [[in_r, out_w, err_w], [in_w, out_r, err_r]] end # Launch the command provided by the constructor @@ -56,13 +56,13 @@ module Kadeploy # opts: hash # :stdin, :stdout, :stderr boolean to enable or disable pipe in respectively stdin,stdout and stderr. # :stdout_size, :stderr_size is number to limit the number of byte read by execute respectively on stdout or stderr. - def run(opts={:stdin => false}) + def run(opts = {:stdin => false}) @lock.synchronize do if @run_thread raise "Already launched" else begin - ensure #We can't interrupt this process here before run was launched. + ensure # We can't interrupt this process here before run was launched. @child_io, @parent_io = Execute.init_ios(opts) @@forkmutex.synchronize do @exec_pid = fork do @@ -76,8 +76,8 @@ module Kadeploy @child_io = nil emptypipes = true - @stdout,emptypipes = read_parent_io(1,opts[:stdout_size],emptypipes) - @stderr,emptypipes = read_parent_io(2,opts[:stderr_size],emptypipes) + @stdout, emptypipes = read_parent_io(1, opts[:stdout_size], emptypipes) + @stderr, emptypipes = read_parent_io(2, opts[:stderr_size], emptypipes) _, @status = Process.wait2(@exec_pid) @exec_pid = nil @@ -95,8 +95,8 @@ module Kadeploy [@exec_pid, *@parent_io] end - #Write to stdin - #Argument: + # Write to stdin + # Argument: # String passed to process stdin. def write_stdin(str) @lock.synchronize do @@ -121,7 +121,7 @@ module Kadeploy # Run the command and return the Execute object. # Arguments: # Opts see bellow - def run!(opts={:stdin => false}) + def run!(opts = {:stdin => false}) run(opts) self end @@ -134,12 +134,12 @@ module Kadeploy # # Output # Array ( Process::Status, stdout String, stderr String, emptypipe). - def wait(opts={:checkstatus => true}) + def wait(opts = {:checkstatus => true}) begin - wkilled=true + wkilled = true close_stdin() @run_thread.join - wkilled=false + wkilled = false ensure @lock.synchronize do if wkilled && !@killed @@ -155,7 +155,7 @@ module Kadeploy ) if opts[:checkstatus] and !@status.success? end end - [ @status, @stdout, @stderr, @emptypipes ] + [@status, @stdout, @stderr, @emptypipes] end EXECDEBUG = false @@ -168,7 +168,7 @@ module Kadeploy # SIGSTOPs the process to avoid it creating new children begin - Process.kill('STOP',pid) + Process.kill('STOP', pid) rescue Errno::ESRCH # "no such process". The process was already killed, return. puts "got ESRCH on STOP" if EXECDEBUG return @@ -185,14 +185,14 @@ module Kadeploy end if children begin - Process.kill('KILL',pid) + Process.kill('KILL', pid) rescue Errno::ESRCH # "no such process". The process was already killed, return. puts "got ESRCH on KILL" if EXECDEBUG return end end - #Kill the launched process. + # Kill the launched process. def kill() @lock.synchronize{ kill! } end @@ -200,8 +200,8 @@ module Kadeploy private - #Launch kill_recurcive if in launched and it not already killed - #@killed becomes true. + # Launch kill_recurcive if in launched and it not already killed + # @killed becomes true. def kill!() if @exec_pid && !@killed @killed = true @@ -210,15 +210,15 @@ module Kadeploy end end - #Read pipe and return out and boolean which indicate if pipe are empty. - #Arguments: + # Read pipe and return out and boolean which indicate if pipe are empty. + # Arguments: # +num : number of file descriptor # +size : Maximum number of bytes must be read 0 is unlimited. # +emptypipes: Previous value of emptypipe the new value was obtained with logical and. - #Output: + # Output: # Array (output: String, emptypipes: Boolean) - def read_parent_io(num,size,emptypipes) - out='' + def read_parent_io(num, size, emptypipes) + out = '' if @parent_io and @parent_io[num] if size and size > 0 out = @parent_io[num].read(size) unless @parent_io[num].closed? @@ -230,7 +230,7 @@ module Kadeploy out = @parent_io[num].read unless @parent_io[num].closed? end end - [out,emptypipes] + [out, emptypipes] end # This function is made by children. # It redirect the stdin,stdout,stderr @@ -238,13 +238,13 @@ module Kadeploy # And launch the command with exec. def run_fork() begin - #stdin + # stdin STDIN.reopen(@child_io[0] || '/dev/null') - #stdout + # stdout STDOUT.reopen(@child_io[1] || '/dev/null') - #stderr + # stderr STDERR.reopen(@child_io[2] || '/dev/null') @@ -255,14 +255,14 @@ module Kadeploy if RUBY_VERSION < "2.0" Dir.foreach('/proc/self/fd') do |opened_fd| begin - fd=opened_fd.to_i - if fd>2 - f_IO=IO.new(fd) + fd = opened_fd.to_i + if fd > 2 + f_IO = IO.new(fd) f_IO.close if !f_IO.closed? end rescue StandardError - #Some file descriptor are reserved for the rubyVM. - #So the function 'IO.new' raises an exception. We ignore that. + # Some file descriptor are reserved for the rubyVM. + # So the function 'IO.new' raises an exception. We ignore that. end end end diff --git a/lib/kadeploy3/common/fetchfile.rb b/lib/kadeploy3/common/fetchfile.rb index c6d7b08895057b82df4c449c48df8b11f78fb490..7b5c9fa647fc92c4da78f6a39e0c0630b15d1453 100644 --- a/lib/kadeploy3/common/fetchfile.rb +++ b/lib/kadeploy3/common/fetchfile.rb @@ -8,35 +8,35 @@ module Kadeploy class FetchFile attr_reader :origin_uri - def initialize(origin_uri,client=nil) + def initialize(origin_uri, client = nil) @origin_uri = origin_uri @client = client end - def self.[](origin_uri,client=nil) + def self.[](origin_uri, client = nil) uri = URI.parse(origin_uri) kind = uri.scheme || 'local' case kind when 'local' - fetcher = LocalFetchFile.new(uri.path,client) + fetcher = LocalFetchFile.new(uri.path, client) when 'server' - fetcher = ServerFetchFile.new(uri.path,client) - when 'http','https' - fetcher = HTTPFetchFile.new(origin_uri,client) + fetcher = ServerFetchFile.new(uri.path, client) + when 'http', 'https' + fetcher = HTTPFetchFile.new(origin_uri, client) else raise KadeployError.new( - APIError::INVALID_FILE,nil, + APIError::INVALID_FILE, nil, "Unable to grab the file '#{origin_uri}', unknown protocol #{kind}" ) end fetcher end - def error(msg,errno=nil) - raise KadeployError.new(errno||APIError::INVALID_FILE,nil,msg) + def error(msg, errno = nil) + raise KadeployError.new(errno || APIError::INVALID_FILE, nil, msg) end - def uptodate?(fchecksum,fmtime=nil) + def uptodate?(fchecksum, fmtime = nil) !((mtime > fmtime) and (checksum != fchecksum)) end @@ -52,7 +52,7 @@ class FetchFile raise 'Should be reimplemented' end - def grab(_dest,_dir=nil) + def grab(_dest, _dir = nil) raise 'Should be reimplemented' end end @@ -82,10 +82,10 @@ class ServerFetchFile < FetchFile end end - def grab(dest,_dir=nil) + def grab(dest, _dir = nil) if File.readable?(@origin_uri) begin - Execute['cp',@origin_uri,dest].run!.wait + Execute['cp', @origin_uri, dest].run!.wait rescue StandardError => e error("Unable to grab the file #{@origin_uri} (#{e.message})") end @@ -96,12 +96,12 @@ class ServerFetchFile < FetchFile end class HTTPFetchFile < FetchFile - def initialize(origin_uri,client=nil) - super(origin_uri,client) + def initialize(origin_uri, client = nil) + super(origin_uri, client) @file_status = nil end - #Get file status when at first time. + # Get file status when at first time. def get_file_status(uri) if @file_status @file_status @@ -149,9 +149,9 @@ class HTTPFetchFile < FetchFile end end - def grab(dest,_dir=nil) + def grab(dest, _dir = nil) begin - HTTP.fetch_file(@origin_uri,dest) + HTTP.fetch_file(@origin_uri, dest) nil rescue KadeployHTTPError => k error("Unable to get the mtime of #{@origin_uri} (http error ##{k.errno})") @@ -166,16 +166,16 @@ class HTTPFetchFile < FetchFile end class LocalFetchFile < HTTPFetchFile - def initialize(origin_uri,client=nil) - super(origin_uri,client) - raise KadeployError.new(APIError::INVALID_CLIENT,nil,"There is no way to retrieve #{origin_uri} from the Kadeploy server. Consider using a server:// or a http:// URL") unless @client + def initialize(origin_uri, client = nil) + super(origin_uri, client) + raise KadeployError.new(APIError::INVALID_CLIENT, nil, "There is no way to retrieve #{origin_uri} from the Kadeploy server. Consider using a server:// or a http:// URL") unless @client - @origin_uri = File.join(@client.to_s,Base64.urlsafe_encode64(@origin_uri)) + @origin_uri = File.join(@client.to_s, Base64.urlsafe_encode64(@origin_uri)) begin URI.parse(@origin_uri) nil rescue - raise KadeployError.new(APIError::INVALID_CLIENT,nil,'Invalid client origin_uri') + raise KadeployError.new(APIError::INVALID_CLIENT, nil, 'Invalid client origin_uri') end end end diff --git a/lib/kadeploy3/common/http.rb b/lib/kadeploy3/common/http.rb index 5aaeb2ce13608cbcd7c94e3832c5056797f67938..a980e60632597bbd02c851f477682e01e263e284 100644 --- a/lib/kadeploy3/common/http.rb +++ b/lib/kadeploy3/common/http.rb @@ -22,18 +22,18 @@ module HTTP # * etag: ETag of the file (http_response is -1 if Tempfiles cannot be created) # Output # * return http_response and ETag - def self.fetch_file(uri,destfile) + def self.fetch_file(uri, destfile) ret = nil url = URI.parse(uri) http = Net::HTTP.new(url.host, url.port) http.use_ssl = url.is_a?(URI::HTTPS) http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.start - http.request_get(url.path,{}) do |resp| + http.request_get(url.path, {}) do |resp| raise KadeployHTTPError.new(resp.code) if !resp.is_a?(Net::HTTPSuccess) and !resp.is_a?(Net::HTTPNotModified) ret = resp.to_hash - File.open(destfile,'w+') do |f| + File.open(destfile, 'w+') do |f| resp.read_body do |chunk| f.write chunk nil @@ -50,7 +50,7 @@ module HTTP http.use_ssl = url.is_a?(URI::HTTPS) http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.start - resp = http.head(url.path,{}) + resp = http.head(url.path, {}) raise KadeployHTTPError.new(resp.code) if !resp.is_a?(Net::HTTPSuccess) and !resp.is_a?(Net::HTTPNotModified) return resp.to_hash end @@ -72,23 +72,23 @@ module HTTP class ClientError < RuntimeError attr_reader :code - def initialize(msg,code=nil) + def initialize(msg, code = nil) super(msg) @code = code end end class Client - def self.error(msg='',code=nil) - raise ClientError.new(msg,code) + def self.error(msg = '', code = nil) + raise ClientError.new(msg, code) end - def self.path_params(path,params) + def self.path_params(path, params) path = path[0..-2] if path[-1] == '/' "#{path}?#{URI.encode_www_form(params)}" end - def self.connect(server,port,secure=true) + def self.connect(server, port, secure = true) begin client = Net::HTTP.new(server, port) if secure @@ -103,10 +103,10 @@ module HTTP end end - def self.request(server,port,secure=true,request=nil,parse=nil) + def self.request(server, port, secure = true, request = nil, parse = nil) parse = true if parse.nil? res = nil - connect(server,port,secure) do |client| + connect(server, port, secure) do |client| begin request = yield(client) unless request raise unless request.is_a?(Net::HTTPRequest) @@ -117,7 +117,7 @@ module HTTP body = nil if response.content_length and response.content_length > 0 and response['Content-Encoding'] == 'gzip' - sio = StringIO.new(response.body,'rb') + sio = StringIO.new(response.body, 'rb') gzr = Zlib::GzipReader.new(sio) body = gzr.read gzr.close @@ -158,15 +158,15 @@ module HTTP (response['X-Application-Error-Code'].to_i rescue 1)) else error("#{body.strip}\n"\ - "[HTTP Error ##{response.code} on #{request.method} #{request.path}]",2) + "[HTTP Error ##{response.code} on #{request.method} #{request.path}]", 2) end when 404 error("Resource not found #{request.path.split('?').first}") when 500 - error("[Internal Server Error]\n#{body.strip}",3) + error("[Internal Server Error]\n#{body.strip}", 3) else error("#{body.strip}\n"\ - "[HTTP Error ##{response.code} on #{request.method} #{request.path}]",2) + "[HTTP Error ##{response.code} on #{request.method} #{request.path}]", 2) end end end @@ -184,7 +184,7 @@ module HTTP end end - def self.content_cast(kind,obj) + def self.content_cast(kind, obj) case kind when :json obj.to_json @@ -195,13 +195,13 @@ module HTTP end end - def self.gen_request(kind,path,data=nil,content_type=nil,accept_type=nil,headers=nil) + def self.gen_request(kind, path, data = nil, content_type = nil, accept_type = nil, headers = nil) content_type ||= :json accept_type ||= :json header = { 'Accept' => content_type(accept_type) } if data - data = content_cast(content_type,data) + data = content_cast(content_type, data) header['Content-Type'] = content_type(content_type) header['Content-Length'] = data.size.to_s end @@ -210,39 +210,39 @@ module HTTP ret = nil case kind when :GET - ret = Net::HTTP::Get.new(path,header) + ret = Net::HTTP::Get.new(path, header) when :HEAD - ret = Net::HTTP::Head.new(path,header) + ret = Net::HTTP::Head.new(path, header) when :POST - ret = Net::HTTP::Post.new(path,header) + ret = Net::HTTP::Post.new(path, header) when :PUT - ret = Net::HTTP::Put.new(path,header) + ret = Net::HTTP::Put.new(path, header) when :DELETE - ret = Net::HTTP::Delete.new(path,header) + ret = Net::HTTP::Delete.new(path, header) else raise end ret.body = data if data - ret.basic_auth($http_user,$http_password) if $http_user and $http_password + ret.basic_auth($http_user, $http_password) if $http_user and $http_password ret end - def self.get(server,port,path,secure=true,_content_type=nil,accept_type=nil,parse=nil,headers=nil) - request(server,port,secure,gen_request(:GET,path,nil,nil,accept_type,headers),parse) + def self.get(server, port, path, secure = true, _content_type = nil, accept_type = nil, parse = nil, headers = nil) + request(server, port, secure, gen_request(:GET, path, nil, nil, accept_type, headers), parse) end - def self.post(server,port,path,data,secure=true,content_type=nil,accept_type=nil,parse=nil,headers=nil) - request(server,port,secure,gen_request(:POST,path,data,content_type,accept_type,headers),parse) + def self.post(server, port, path, data, secure = true, content_type = nil, accept_type = nil, parse = nil, headers = nil) + request(server, port, secure, gen_request(:POST, path, data, content_type, accept_type, headers), parse) end - def self.put(server,port,path,data,secure=true,content_type=nil,accept_type=nil,parse=nil,headers=nil) - request(server,port,secure,gen_request(:PUT,path,data,content_type,accept_type,headers),parse) + def self.put(server, port, path, data, secure = true, content_type = nil, accept_type = nil, parse = nil, headers = nil) + request(server, port, secure, gen_request(:PUT, path, data, content_type, accept_type, headers), parse) end - def self.delete(server,port,path,data,secure=true,content_type=nil,accept_type=nil,parse=nil,headers=nil) - request(server,port,secure,gen_request(:DELETE,path,data,content_type,accept_type,headers),parse) + def self.delete(server, port, path, data, secure = true, content_type = nil, accept_type = nil, parse = nil, headers = nil) + request(server, port, secure, gen_request(:DELETE, path, data, content_type, accept_type, headers), parse) end end end diff --git a/lib/kadeploy3/common/httpd.rb b/lib/kadeploy3/common/httpd.rb index b056cfcdae7f0ab4a6cc33e36f42a2baed7094d5..2b63093cb3e08d345799dbadbe5dab28ee8479a8 100644 --- a/lib/kadeploy3/common/httpd.rb +++ b/lib/kadeploy3/common/httpd.rb @@ -27,21 +27,21 @@ end class WEBrick::HTTPRequest # avoid warning about constant redefining remove_const :MAX_URI_LENGTH - MAX_URI_LENGTH=100000 + MAX_URI_LENGTH = 100000 end module Kadeploy module HTTPd - LOGFILE_HTTPD='httpd.log' - LOGFILE_ACCESS='access.log' + LOGFILE_HTTPD = 'httpd.log' + LOGFILE_ACCESS = 'access.log' MAX_CLIENTS = 1000 MAX_CONTENT_SIZE = 1048576 # 1 MB - SERVLET_TIMEOUT = 600 #10 min + SERVLET_TIMEOUT = 600 # 10 min class HTTPError < RuntimeError - attr_reader :code,:headers - def initialize(code,name,msg=nil,headers=nil) + attr_reader :code, :headers + def initialize(code, name, msg = nil, headers = nil) super(msg) @code = code @name = name @@ -54,39 +54,39 @@ module HTTPd end end class InvalidError < HTTPError - def initialize(msg=nil,headers=nil) - super(405,'Method Not Allowed',msg,headers) + def initialize(msg = nil, headers = nil) + super(405, 'Method Not Allowed', msg, headers) end end class NotFoundError < HTTPError - def initialize(msg=nil,headers=nil) - super(404,'File Not Found',msg,headers) + def initialize(msg = nil, headers = nil) + super(404, 'File Not Found', msg, headers) end end class UnauthorizedError < HTTPError - def initialize(msg=nil,headers=nil) - super(401,'Unauthorized',msg,headers) + def initialize(msg = nil, headers = nil) + super(401, 'Unauthorized', msg, headers) end end class ForbiddenError < HTTPError - def initialize(msg=nil,headers=nil) - super(403,'Forbidden',msg,headers) + def initialize(msg = nil, headers = nil) + super(403, 'Forbidden', msg, headers) end end class UnsupportedError < HTTPError - def initialize(msg=nil,headers=nil) - super(415,'Unsupported Media Type',msg,headers) + def initialize(msg = nil, headers = nil) + super(415, 'Unsupported Media Type', msg, headers) end end class UnavailableError < HTTPError - def initialize(msg=nil,headers=nil) - super(503,'Service Unavailable',msg,headers) + def initialize(msg = nil, headers = nil) + super(503, 'Service Unavailable', msg, headers) end end class ServletTimeout < RuntimeError def set_backtrace(array) - time=Time.now() + time = Time.now() $stderr.puts("[#{time}] Servlet execution is timed out") $stderr.puts("[#{time}] #{array.join("\n[#{time}] ")}") $stderr.puts("[#{time}] === End of trace ===") @@ -117,7 +117,7 @@ module HTTPd @encoding = self.class.parse_header_list(@request['Accept-Encoding']) if @accept and (@accept & TYPES.values).empty? - raise HTTPError.new(406,'Not Acceptable',@accept.join(', ')) + raise HTTPError.new(406, 'Not Acceptable', @accept.join(', ')) end end @@ -132,7 +132,7 @@ module HTTPd def self.parse_header_list(val) if val and !val.strip.empty? ret = val.split(',').collect{|v| v.split(';').first.strip.downcase} - if (ret & ['*','*/*']).empty? + if (ret & ['*', '*/*']).empty? ret else nil @@ -152,17 +152,17 @@ module HTTPd begin length = @request['Content-Length'].to_i rescue - raise HTTPError.new(411,'Length Required', + raise HTTPError.new(411, 'Length Required', "The Content-Length HTTP header has to be an integer") end if length > MAX_CONTENT_SIZE - raise HTTPError.new(413,'Request Entity Too Large', + raise HTTPError.new(413, 'Request Entity Too Large', "The content in the request's body cannot be greater than "\ "#{MAX_CONTENT_SIZE} bytes") end else - raise HTTPError.new(411,'Length Required', + raise HTTPError.new(411, 'Length Required', "The Content-Length HTTP header has to be sed") end @@ -197,13 +197,13 @@ module HTTPd # Parse HTTP request's query string if @uri.query and @uri.query.size > MAX_CONTENT_SIZE - raise HTTPError.new(414,'Request-URI Too Long', + raise HTTPError.new(414, 'Request-URI Too Long', "The the request's query size cannot be greater than "\ "#{MAX_CONTENT_SIZE} chars") end # CGI.parse do decode_www_form - CGI.parse(@uri.query||'').each do |key,val| + CGI.parse(@uri.query || '').each do |key, val| if val.is_a?(Array) if val.size > 1 res[key] = val @@ -226,14 +226,14 @@ module HTTPd if @accept case (@accept & TYPES.values)[0] when TYPES[:json] - type,content = [ TYPES[:json], JSON.pretty_generate(obj) ] + type, content = [TYPES[:json], JSON.pretty_generate(obj)] when TYPES[:yaml] - type,content = [ TYPES[:yaml], obj.to_yaml ] + type, content = [TYPES[:yaml], obj.to_yaml] else - raise HTTPError.new(406,'Not Acceptable',@accept.join(', ')) + raise HTTPError.new(406, 'Not Acceptable', @accept.join(', ')) end else - type,content = [ TYPES[:json], JSON.pretty_generate(obj) ] + type, content = [TYPES[:json], JSON.pretty_generate(obj)] end type = type.dup @@ -245,7 +245,7 @@ module HTTPd gzw.write(content) gzw.close content = sio.string - #sio.close + # sio.close [type, 'gzip', content] else [type, nil, content] @@ -265,7 +265,7 @@ module HTTPd # class_eval "alias :\"do_#{m.to_s.upcase}\", :do_METHOD" end - #This function override the inspect function of Object class and it avoids a recursive inspection by webrick + # This function override the inspect function of Object class and it avoids a recursive inspection by webrick def inspect() self.class.name end @@ -282,7 +282,7 @@ module HTTPd Thread.current[:run_thr].kill if Thread.current[:run_thr] end - def treatment(req,resp) + def treatment(req, resp) # # = A client disconnection kills the handle thread. # The handle thread can allocate some resources (ex : refs token in cache or compressedCSV) and be killed @@ -324,8 +324,8 @@ module HTTPd Timeout.timeout(SERVLET_TIMEOUT, ServletTimeout) do request_handler = RequestHandler.new(req) - ret = handle(req,resp,request_handler) - return [ret,request_handler] + ret = handle(req, resp, request_handler) + return [ret, request_handler] end end @@ -333,7 +333,7 @@ module HTTPd ret = nil if @allowed.include?(get_method(request)) begin - ret,request_handler = treatment(request,response) + ret, request_handler = treatment(request, response) res = ret # No caching @@ -353,10 +353,10 @@ module HTTPd elsif ret.is_a?(File) # Ugly hack since Webrick filehandler automatically closes files ret.close unless ret.closed? - ret = res = open(ret.path,'rb') + ret = res = open(ret.path, 'rb') st = ret.stat - response['ETag'] = sprintf("\"%x-%x-%x\"",st.ino,st.size, + response['ETag'] = sprintf("\"%x-%x-%x\"", st.ino, st.size, st.mtime.to_i) response['Last-Modified'] = st.mtime.httpdate response['Content-Type'] = 'application/octet-stream' @@ -369,17 +369,17 @@ module HTTPd res = ret.file else ret.free - raise HTTPError.new(406,'Not Acceptable','Content-Encoding: gzip') + raise HTTPError.new(406, 'Not Acceptable', 'Content-Encoding: gzip') end else - response['Content-Type'],response['Content-Encoding'],res = \ + response['Content-Type'], response['Content-Encoding'], res = \ request_handler.output(ret) end request_handler.free rescue HTTPError => e res = e.message response.status = e.code - e.headers.each_pair{|k,v| response[k] = v} if e.headers + e.headers.each_pair{|k, v| response[k] = v} if e.headers response['Content-Type'] = 'text/plain' if e.is_a?(InvalidError) response['Allow'] = @allowed.collect{|m|m.to_s}.join(',') @@ -400,7 +400,7 @@ module HTTPd "---- Stack trace ----\n"\ "#{e.backtrace.join("\n")}\n"\ "---------------------" - #Write the error in stderr + # Write the error in stderr $stderr.puts("[#{Time.now}] Internal Server Error #{res}") $stderr.flush response.status = 500 @@ -436,19 +436,19 @@ module HTTPd end class ProcedureHandler < HTTPdHandler - def initialize(allowed_methods,proc) + def initialize(allowed_methods, proc) super(allowed_methods) @proc = proc end def handle(request, _response, _request_handler) - @proc.call(get_method(request),request) + @proc.call(get_method(request), request) end end class MethodHandler < HTTPdHandler # Call a method with static or dynamic args - def initialize(allowed_methods,obj,method,args=nil,blocks=nil) + def initialize(allowed_methods, obj, method, args = nil, blocks = nil) super(allowed_methods) @obj = obj @method = method @@ -456,7 +456,7 @@ module HTTPd @blocks = blocks end - def handle(request, _response, request_handler, args=nil, params={}) + def handle(request, _response, request_handler, args = nil, params = {}) args = @args.dup if args.nil? and !@args.nil? args = args[get_method(request)] if args.is_a?(ContentBinding) args = [] if args.nil? @@ -474,7 +474,7 @@ module HTTPd params[:params] = request_handler.params begin - return @obj.send(name,params,*args)#,&proc{request}) + return @obj.send(name, params, *args)# ,&proc{request}) rescue ArgumentError => e # if the problem is that the method is called with the wrong nb of args if e.backtrace[0].split(/\s+/)[-1] =~ /#{name}/ \ @@ -496,8 +496,8 @@ module HTTPd end class MethodFilterHandler < MethodHandler - def initialize(allowed_methods,obj,method,filter,names=nil,static=nil) - super(allowed_methods,obj,method,nil) + def initialize(allowed_methods, obj, method, filter, names = nil, static = nil) + super(allowed_methods, obj, method, nil) @obj = obj @filter = filter @names = names @@ -512,7 +512,7 @@ module HTTPd filter = nil if @filter.is_a?(ContentBinding) filter = @filter[get_method(request)] - #elsif @filter.is_a?(Hash) + # elsif @filter.is_a?(Hash) # filter = @filter[:dynamic] || [] # @args += @filter[:static] if @filter[:static] else @@ -535,29 +535,29 @@ module HTTPd end names = [] unless names - #prefix = nil - #if @method_prefix.is_a?(ContentBinding) + # prefix = nil + # if @method_prefix.is_a?(ContentBinding) # prefix = @method_prefix[get_method(request)] - #else + # else # prefix = @method_prefix - #end + # end fields = request.request_uri.path.split('/')[1..-1] args += fields.values_at(*filter).compact.collect{|v| URI.decode_www_form_component(v)} params[:names] = fields.values_at(*names).compact params[:names] = nil if params[:names].empty? - #if suffix.empty? + # if suffix.empty? # @method = prefix.to_sym - #else + # else # @method = (prefix.to_s + '_' + suffix.join('_')).to_sym - #end + # end return super(request, response, request_handler, args, params) end end class ContentHandler < HTTPdHandler - def initialize(allowed_methods,content) + def initialize(allowed_methods, content) super(allowed_methods) @content = content end @@ -577,7 +577,7 @@ module HTTPd class Server attr_reader :host, :port, :logs - def initialize(host='',port=0,secure=true,local=false,cert=nil,private_key=nil,dh_seeds={},httpd_logfile=nil) + def initialize(host = '', port = 0, secure = true, local = false, cert = nil, private_key = nil, dh_seeds = {}, httpd_logfile = nil) raise if cert and !private_key @host = host || '' @port = port || 0 @@ -590,31 +590,31 @@ module HTTPd @logs = {} if httpd_logfile - if !File.writable?(File.join(httpd_logfile,LOGFILE_HTTPD)) \ + if !File.writable?(File.join(httpd_logfile, LOGFILE_HTTPD)) \ and !File.writable?(File.dirname(httpd_logfile)) self.class.error("Log directory '#{httpd_logfile}' not writable") end - @logs[:httpd] = File.open(File.join(httpd_logfile),'a+') + @logs[:httpd] = File.open(File.join(httpd_logfile), 'a+') elsif $kadeploy_logdir unless File.directory?($kadeploy_logdir) self.class.error("Log directory '#{$kadeploy_logdir}' does not exists") end - if !File.writable?(File.join($kadeploy_logdir,LOGFILE_HTTPD)) \ + if !File.writable?(File.join($kadeploy_logdir, LOGFILE_HTTPD)) \ and !File.writable?($kadeploy_logdir) self.class.error("Log directory '#{$kadeploy_logdir}' not writable") end - @logs[:httpd] = File.open(File.join($kadeploy_logdir,LOGFILE_HTTPD),'a+') + @logs[:httpd] = File.open(File.join($kadeploy_logdir, LOGFILE_HTTPD), 'a+') end if $kadeploy_logdir unless File.directory?($kadeploy_logdir) self.class.error("Log directory '#{$kadeploy_logdir}' does not exists") end - if !File.writable?(File.join($kadeploy_logdir,LOGFILE_ACCESS)) \ + if !File.writable?(File.join($kadeploy_logdir, LOGFILE_ACCESS)) \ and !File.writable?($kadeploy_logdir) self.class.error("Log directory '#{$kadeploy_logdir}' not writable") end - @logs[:access] = File.open(File.join($kadeploy_logdir,LOGFILE_ACCESS),'a+') + @logs[:access] = File.open(File.join($kadeploy_logdir, LOGFILE_ACCESS), 'a+') @logs[:access].sync = true end @@ -658,14 +658,14 @@ module HTTPd @dh_seeds[1024] = OpenSSL::PKey::DH.new(1024) unless @dh_seeds[1024] # Do not threat ciphers instructions (export) - opts[:SSLTmpDhCallback] = proc{|_,_,len| @dh_seeds[len] || (@dh_seeds[len] = OpenSSL::PKey::DH.new(len))} + opts[:SSLTmpDhCallback] = proc{|_, _, len| @dh_seeds[len] || (@dh_seeds[len] = OpenSSL::PKey::DH.new(len))} end if @cert opts[:SSLCertificate] = @cert opts[:SSLPrivateKey] = @private_key else - opts[:SSLCertName] = [['CN',@host]] + opts[:SSLCertName] = [['CN', @host]] end # TODO: load a CA certificate to identify clients @@ -677,7 +677,7 @@ module HTTPd @port = @server.config[:Port] if @port == 0 end - def self.error(msg='',abrt = true) + def self.error(msg = '', abrt = true) $stderr.puts msg if msg and !msg.empty? exit 1 if abrt end @@ -696,24 +696,24 @@ module HTTPd # :object, args and method => :method_name or { :GET => :method1, :POST => :method2 } # :content :value => {},123,[],... or { :GET => 123, :POST => 'abc' } - def bind(methods,path,kind=:proc,params={},&block) + def bind(methods, path, kind = :proc, params = {}, &block) methods = [methods] if methods.is_a?(Symbol) case kind when :method raise unless params.is_a?(Hash) and params[:object] and params[:method] - @server.mount(path,MethodHandler.new(methods,params[:object],params[:method],params[:args])) + @server.mount(path, MethodHandler.new(methods, params[:object], params[:method], params[:args])) when :filter raise unless params.is_a?(Hash) and params[:object] and params[:method] and params[:args] - @server.mount(path,MethodFilterHandler.new(methods,params[:object],params[:method],params[:args],params[:name],params[:static])) + @server.mount(path, MethodFilterHandler.new(methods, params[:object], params[:method], params[:args], params[:name], params[:static])) when :content - @server.mount(path,ContentHandler.new(methods,params)) + @server.mount(path, ContentHandler.new(methods, params)) when :file - @server.mount(path,ContentHandler.new(methods,params)) + @server.mount(path, ContentHandler.new(methods, params)) when :proc if block_given? - @server.mount(path,ProcedureHandler.new(methods,block)) + @server.mount(path, ProcedureHandler.new(methods, block)) else - @server.mount(path,ProcedureHandler.new(methods,params)) + @server.mount(path, ProcedureHandler.new(methods, params)) end else raise diff --git a/lib/kadeploy3/common/nodes.rb b/lib/kadeploy3/common/nodes.rb index d8de156d548e9e58abe596aad21be9073b373a3d..211b4eff40847438aa068b6424c4bfba9d6c25d6 100644 --- a/lib/kadeploy3/common/nodes.rb +++ b/lib/kadeploy3/common/nodes.rb @@ -13,7 +13,7 @@ module Nodes end end - def self.get_states(db,nodes) + def self.get_states(db, nodes) where = nil args = nil if nodes @@ -27,17 +27,17 @@ module Nodes query = "SELECT nodes.hostname, nodes.state, nodes.user, environments.name as env_name, environments.version as env_version, environments.user as env_user, nodes.deploy_part \ FROM nodes \ LEFT JOIN environments ON nodes.env_id = environments.id" - #If no node list is given, we print everything + # If no node list is given, we print everything query += " WHERE #{where}" unless where.empty? query += " ORDER BY nodes.hostname" - res = db.run_query(query,*args).to_hash + res = db.run_query(query, *args).to_hash ret = {} res.each do |node| hostname = node['hostname'] node.delete('hostname') node['environment'] = {} - node.each_pair do |k,v| + node.each_pair do |k, v| if k =~ /^env_(.*)$/ node['environment'][Regexp.last_match(1)] = v node.delete(k) @@ -89,7 +89,7 @@ module Nodes @power_status = nil end - def self.generate(cmd,node) + def self.generate(cmd, node) if cmd ret = cmd.dup ret.gsub!('HOSTNAME_FQDN', node.hostname) @@ -100,10 +100,10 @@ module Nodes end class Node - attr_accessor :hostname #fqdn - attr_accessor :ip #aaa.bbb.ccc.ddd + attr_accessor :hostname # fqdn + attr_accessor :ip # aaa.bbb.ccc.ddd attr_accessor :cluster - attr_accessor :state #OK,KO + attr_accessor :state # OK,KO attr_accessor :current_step attr_accessor :last_cmd_exit_status attr_accessor :last_cmd_stdout @@ -140,7 +140,7 @@ module Nodes # * return a string that contains the information def to_s(show_out = false, show_err = false) s = String.new - s = "stdout: #{@last_cmd_stdout.chomp}" if (show_out) && (last_cmd_stdout != nil) && (last_cmd_stdout != '') + s = "stdout: #{@last_cmd_stdout.chomp}" if (show_out) && (last_cmd_stdout != nil) && (last_cmd_stdout != '') if (show_err) && (last_cmd_stderr != nil) && (last_cmd_stderr != '') then if (s == "") then s = "stderr: #{@last_cmd_stderr.chomp}" @@ -272,7 +272,7 @@ module Nodes # Output # * returns array of numbers def NodeSet::develop_interval(interval) - numbers_array =[] + numbers_array = [] if /(\d+)-(\d+)/ =~ interval content = Regexp.last_match if content[1].length == content[2].length @@ -294,7 +294,7 @@ module Nodes # # Output # * return false if it is too remote - def NodeSet::cmp_hosts(hostname1,hostname2) + def NodeSet::cmp_hosts(hostname1, hostname2) close = true i = 0 j = 0 @@ -304,9 +304,9 @@ module Nodes while close == true && i < array_host1.length if array_host1[i] != array_host2[i] j += 1 - close = false if (array_host1[i] =~ /[a-zA-Z\-\.]+/ || array_host2[i] =~ /[a-zA-Z\-\.]+/ || j>1) + close = false if (array_host1[i] =~ /[a-zA-Z\-\.]+/ || array_host2[i] =~ /[a-zA-Z\-\.]+/ || j > 1) end - i+=1 + i += 1 end else close = false @@ -351,7 +351,7 @@ module Nodes def NodeSet::make_array_of_figures(numbers_list) numbers_array = [] if numbers_list.include? ?, - patterns=numbers_list.split(",") + patterns = numbers_list.split(",") patterns.each{|pattern| numbers_array += NodeSet::develop_interval(pattern) } @@ -370,7 +370,7 @@ module Nodes # # Output # * returns array of hostname - def NodeSet::make_array_of_hostnames(numbers_array,head_host,tail_host) + def NodeSet::make_array_of_hostnames(numbers_array, head_host, tail_host) hosts_array = [] numbers_array.each{|n| hosts_array += [head_host + n.to_s + tail_host] @@ -392,7 +392,7 @@ module Nodes res = [] for i in (0 ... letter.length) res += [letter[i]] - res += [number[i+1]] + res += [number[i + 1]] end res.delete(nil) return res @@ -407,7 +407,7 @@ module Nodes # Output # * return array : # * [ the beginning of the hostname , the end of the hostname, [number1] , [number2] ] - def NodeSet::diff_hosts(hostname1,hostname2) + def NodeSet::diff_hosts(hostname1, hostname2) similar_array = [] diff_array = [] head = "" @@ -416,7 +416,7 @@ module Nodes if array_host1.length == array_host2.length for i in (0 ... array_host1.length) if array_host1[i] == array_host2[i] - similar_array += [ array_host1[i] ] + similar_array += [array_host1[i]] else if array_host1[i] =~ /[0-9]+/ && array_host2[i] =~ /[0-9]+/ diff_array += [[array_host1[i]] + [array_host2[i]]] @@ -439,15 +439,15 @@ module Nodes # # Output # * returns array of folded hostnames - def NodeSet::remote_host_find(name_array,i) + def NodeSet::remote_host_find(name_array, i) case i when 1 - array = name_array[i-1] - when name_array.length-1 + array = name_array[i - 1] + when name_array.length - 1 array = name_array[i] else - if cmp_hosts(name_array[i-2],name_array[i-1]) == false - array = name_array[i-1] + if cmp_hosts(name_array[i - 2], name_array[i - 1]) == false + array = name_array[i - 1] end end return [array] @@ -462,25 +462,25 @@ module Nodes # Output # * return list of numbers def NodeSet::numbers_fold(numbers_array) - fold="" - i=1 - numbers_array=numbers_array.sort { |a,b| + fold = "" + i = 1 + numbers_array = numbers_array.sort { |a, b| a.to_i <=> b.to_i } while i < numbers_array.length - fold += numbers_array[i-1] - if (numbers_array[i].to_i - numbers_array[i-1].to_i != 1) + fold += numbers_array[i - 1] + if (numbers_array[i].to_i - numbers_array[i - 1].to_i != 1) fold += "," - fold +=numbers_array[i] if i == numbers_array.length-1 - i+=1 + fold += numbers_array[i] if i == numbers_array.length - 1 + i += 1 else - while (numbers_array[i].to_i - numbers_array[i-1].to_i == 1) - if (fold[fold.length-1,1] != '-') + while (numbers_array[i].to_i - numbers_array[i - 1].to_i == 1) + if (fold[fold.length - 1, 1] != '-') fold += "-" end - i+=1 - if (numbers_array[i].to_i - numbers_array[i-1].to_i != 1 && i == numbers_array.length) - fold += numbers_array[i-1] + i += 1 + if (numbers_array[i].to_i - numbers_array[i - 1].to_i != 1 && i == numbers_array.length) + fold += numbers_array[i - 1] end end end @@ -498,7 +498,7 @@ module Nodes # Output # * return list of group nodes # * eg: cors[001-128].ocre.cea.fr - def NodeSet::nodes_group_list_fold(numbers_array,head,tail) + def NodeSet::nodes_group_list_fold(numbers_array, head, tail) list_number = numbers_fold(numbers_array) return head + "[" + list_number + "]" + tail end @@ -527,7 +527,7 @@ module Nodes end end array_figures = make_array_of_figures(numbers_list) - return make_array_of_hostnames(array_figures,head,tail) + return make_array_of_hostnames(array_figures, head, tail) end def method_missing(method_sym, *) @@ -544,30 +544,30 @@ module Nodes def to_s_fold() name_array = make_array_of_hostname() array = [] - i=1 - j=0 + i = 1 + j = 0 if name_array.length != 1 name_array = sort_host(name_array) while i < name_array.length temp = [] # creation of list folds - while (i < name_array.length && NodeSet::cmp_hosts(name_array[i-1],name_array[i]) != false) - u = NodeSet::diff_hosts(name_array[i-1],name_array[i]) + while (i < name_array.length && NodeSet::cmp_hosts(name_array[i - 1], name_array[i]) != false) + u = NodeSet::diff_hosts(name_array[i - 1], name_array[i]) # addition of head and tail hostname: - if (temp[j] != u[0][0] || temp[j+1] != u[0][1]) + if (temp[j] != u[0][0] || temp[j + 1] != u[0][1]) temp += [u[0][0]] temp += [u[0][1]] - j = temp.length-2 + j = temp.length - 2 end # addition of the list of numbers: - temp += [u[0][2][0]] if temp[temp.length-1]!= u[0][2][0] + temp += [u[0][2][0]] if temp[temp.length - 1] != u[0][2][0] temp += [u[0][2][1]] i += 1 end - array += [NodeSet::nodes_group_list_fold(temp[2,temp.length-2],temp[0],temp[1])] if temp != [] + array += [NodeSet::nodes_group_list_fold(temp[2, temp.length - 2], temp[0], temp[1])] if temp != [] # addition of remote hosts (depend on the position in the array) - array += NodeSet::remote_host_find(name_array,i) - i+=1 + array += NodeSet::remote_host_find(name_array, i) + i += 1 end else array += [name_array] @@ -627,7 +627,7 @@ module Nodes dest.push(node) end } - #dest.id = @id + # dest.id = @id end # Duplicate a NodeSet @@ -745,7 +745,7 @@ module Nodes # * nothing # Output # * nothing - def free(recursive=true) + def free(recursive = true) @set.each { |node| node.free } if recursive @set = nil @id = nil @@ -786,9 +786,9 @@ module Nodes # Output # * return a sorted array of nodes def make_sorted_array_of_nodes - return @set.sort { |str_x,str_y| - x = str_x.hostname.gsub(/[a-zA-Z\-\.]/,"").to_i - y = str_y.hostname.gsub(/[a-zA-Z\-\.]/,"").to_i + return @set.sort { |str_x, str_y| + x = str_x.hostname.gsub(/[a-zA-Z\-\.]/, "").to_i + y = str_y.hostname.gsub(/[a-zA-Z\-\.]/, "").to_i x <=> y } end @@ -943,7 +943,7 @@ module Nodes # * return an array that contains two NodeSet ([0] is the good nodes set and [1] is the bad nodes set) def check_nodes_used(db, purge) bad_nodes = NodeSet.new - args,nodelist = generic_where_nodelist() + args, nodelist = generic_where_nodelist() args << (Time.now.to_i - purge) res = db.run_query( @@ -973,38 +973,38 @@ module Nodes # * return true if the state has been correctly modified, false otherwise def set_state(state, env_id, db, user, deploy_part = nil) return if @set.empty? - args,nodelist = generic_where_nodelist() + args, nodelist = generic_where_nodelist() date = Time.now.to_i env_id = env_id || -1 case state - when 'deploying','rebooting','powering' - db.run_query("DELETE FROM nodes WHERE #{nodelist}",*args) + when 'deploying', 'rebooting', 'powering' + db.run_query("DELETE FROM nodes WHERE #{nodelist}", *args) @set.each { |node| db.run_query( "INSERT INTO nodes (hostname, state, env_id, date, user, deploy_part) VALUES (?,'#{state}',?,?,?,?)", - node.hostname,env_id,date,user,deploy_part + node.hostname, env_id, date, user, deploy_part ) } - when 'deployed','rebooted','powered' - db.run_query("UPDATE nodes SET state='#{state}' WHERE #{nodelist}",*args) unless args.empty? - when 'deploy_failed','reboot_failed','power_failed' - db.run_query("UPDATE nodes SET state='#{state}' WHERE #{nodelist}",*args) unless args.empty? + when 'deployed', 'rebooted', 'powered' + db.run_query("UPDATE nodes SET state='#{state}' WHERE #{nodelist}", *args) unless args.empty? + when 'deploy_failed', 'reboot_failed', 'power_failed' + db.run_query("UPDATE nodes SET state='#{state}' WHERE #{nodelist}", *args) unless args.empty? when "recorded_env" - db.run_query("UPDATE nodes SET state='recorded_env' WHERE #{nodelist}",*args) unless args.empty? + db.run_query("UPDATE nodes SET state='recorded_env' WHERE #{nodelist}", *args) unless args.empty? when "deploy_env" - args = [ user, date ] + args - db.run_query("UPDATE nodes SET state='deploy_env', user=?, env_id=\"-1\", date=? WHERE #{nodelist}",*args) + args = [user, date] + args + db.run_query("UPDATE nodes SET state='deploy_env', user=?, env_id=\"-1\", date=? WHERE #{nodelist}", *args) when "aborted" - db.run_query("DELETE FROM nodes WHERE #{nodelist}",*args) + db.run_query("DELETE FROM nodes WHERE #{nodelist}", *args) @set.each { |node| db.run_query( "INSERT INTO nodes (hostname, state, env_id, date, user, deploy_part) VALUES (?,'aborted',?,?,?,?)", - node.hostname,env_id,date,user,deploy_part + node.hostname, env_id, date, user, deploy_part ) } - #db.run_query("UPDATE nodes SET state='aborted' WHERE #{nodelist}",*args) unless args.empty? + # db.run_query("UPDATE nodes SET state='aborted' WHERE #{nodelist}",*args) unless args.empty? else raise end @@ -1019,7 +1019,7 @@ module Nodes # Output # * return true if at least one node has been deployed with a demolishing environment def check_demolishing_env(db) - args,nodelist = generic_where_nodelist() + args, nodelist = generic_where_nodelist() res = db.run_query( "SELECT hostname FROM nodes \ INNER JOIN environments ON nodes.env_id = environments.id \ @@ -1029,7 +1029,7 @@ module Nodes return (res.num_rows > 0) end - def generic_where_nodelist(field='hostname', sep=' OR ') + def generic_where_nodelist(field = 'hostname', sep = ' OR ') ret = [] @set.each do |node| if node.is_a?(Nodes::Node) @@ -1039,7 +1039,7 @@ module Nodes end end nodelist = "(#{(["#{field} = ?"] * ret.size).join(sep)})" - return [ ret, nodelist ] + return [ret, nodelist] end end @@ -1054,7 +1054,7 @@ module Nodes @states = nil end - def set(hostname, macro='', micro='', state='', error='', out='') + def set(hostname, macro = '', micro = '', state = '', error = '', out = '') @states[hostname] = {} unless @states[hostname] @states[hostname][:macro] = macro if macro and !macro.empty? @states[hostname][:micro] = micro if micro and !micro.empty? @@ -1074,7 +1074,7 @@ module Nodes end end class NodeSetId - def initialize(i=0) + def initialize(i = 0) @mutex = Mutex.new @i = i end @@ -1084,9 +1084,9 @@ module Nodes def to_s() @i.to_s() end - def inc(i=1) + def inc(i = 1) @mutex.synchronize do - @i +=i + @i += i end end end diff --git a/lib/kadeploy3/server/authentication.rb b/lib/kadeploy3/server/authentication.rb index 24e00b024909fe85eb55f847fe601acf8d2782dd..a3cb3c0af03c2a0cdee844c8fd24c1dcff6c1635 100644 --- a/lib/kadeploy3/server/authentication.rb +++ b/lib/kadeploy3/server/authentication.rb @@ -7,8 +7,8 @@ require 'webrick' module Kadeploy class Authentication - UNTRUSTED_SOURCE='Trying to authenticate from an untrusted source' - INVALID_PARAMS='Invalid authentication credentials' + UNTRUSTED_SOURCE = 'Trying to authenticate from an untrusted source' + INVALID_PARAMS = 'Invalid authentication credentials' attr_reader :whitelist @@ -46,14 +46,14 @@ class Authentication end end - def auth!(_source_sock,_params={}) + def auth!(_source_sock, _params = {}) raise end end class ACLAuthentication < Authentication - def auth!(source_sock,_params={}) - return [check_host?(source_sock),UNTRUSTED_SOURCE] + def auth!(source_sock, _params = {}) + return [check_host?(source_sock), UNTRUSTED_SOURCE] end def ==(auth) @@ -68,7 +68,7 @@ end class HTTPBasicAuthentication < Authentication attr_reader :realm - def initialize(dbfile,realm) + def initialize(dbfile, realm) super() @dbfile = dbfile @realm = realm.freeze @@ -79,17 +79,17 @@ class HTTPBasicAuthentication < Authentication }) end - def auth!(source_sock,params={}) - return [false,UNTRUSTED_SOURCE] unless check_host?(source_sock) + def auth!(source_sock, params = {}) + return [false, UNTRUSTED_SOURCE] unless check_host?(source_sock) ret = nil begin - @authenticator.authenticate(params[:req],{}) + @authenticator.authenticate(params[:req], {}) ret = true rescue ret = false end - [ret,INVALID_PARAMS] + [ret, INVALID_PARAMS] end def ==(auth) @@ -107,27 +107,27 @@ class CertificateAuthentication < Authentication @public_key = ca_public_key end - def auth!(source_sock,params={}) - return [false,UNTRUSTED_SOURCE] unless check_host?(source_sock) + def auth!(source_sock, params = {}) + return [false, UNTRUSTED_SOURCE] unless check_host?(source_sock) cert = nil begin cert = OpenSSL::X509::Certificate.new(params[:cert]) rescue StandardError => e - return [false,"Invalid x509 certificate (#{e.message})"] + return [false, "Invalid x509 certificate (#{e.message})"] end cns = nil if cert.verify(@public_key) cns = cert.subject.to_a.select{|v| v[0] == 'CN'}.collect{|v| v[1]} else - return [false,"The certificate was not signed by the trusted CA"] + return [false, "The certificate was not signed by the trusted CA"] end if params[:user] - [cns.include?(params[:user]),'Specified user does not match with the certificate\'s CN'] + [cns.include?(params[:user]), 'Specified user does not match with the certificate\'s CN'] else - [cns.first,nil] + [cns.first, nil] end end @@ -141,20 +141,20 @@ class CertificateAuthentication < Authentication end class IdentAuthentication < Authentication - def auth!(source_sock,params={}) - return [false,UNTRUSTED_SOURCE] unless check_host?(source_sock) + def auth!(source_sock, params = {}) + return [false, UNTRUSTED_SOURCE] unless check_host?(source_sock) user = nil begin - user = Ident.userid(source_sock,params[:port]) + user = Ident.userid(source_sock, params[:port]) rescue IdentError => ie return [false, ie.message] end if params[:user] - [user == params[:user],'Specified user does not match with the one given by the ident service'] + [user == params[:user], 'Specified user does not match with the one given by the ident service'] else - [user,nil] + [user, nil] end end diff --git a/lib/kadeploy3/server/automata.rb b/lib/kadeploy3/server/automata.rb index b9924815971bc3170cd53c87ee73982c70f3d3af..ff710f3359ea8761a11140f674fe4a18c2b25fd6 100644 --- a/lib/kadeploy3/server/automata.rb +++ b/lib/kadeploy3/server/automata.rb @@ -54,7 +54,7 @@ module Automata raise 'Should be reimplemented' end - def kill(_dofree=true) + def kill(_dofree = true) raise 'Should be reimplemented' end @@ -70,7 +70,7 @@ module Automata raise 'Should be reimplemented' end - def raise_nodes(nodeset,status,nodesetid=nil) + def raise_nodes(nodeset, status, nodesetid = nil) # Nodes of this nodeset are not threated by this task anymore nodeset.set.each do |node| nodes().remove(node) @@ -128,11 +128,11 @@ module Automata @context = nil @params = nil @mutex = nil - #@nodes_brk.free(false) if @nodes_brk + # @nodes_brk.free(false) if @nodes_brk @nodes_brk = nil - #@nodes_ok.free(false) if @nodes_ok + # @nodes_ok.free(false) if @nodes_ok @nodes_ok = nil - #@nodes_ko.free(false) if @nodes_ko + # @nodes_ko.free(false) if @nodes_ko @nodes_ko = nil end @@ -145,17 +145,17 @@ module Automata attr_reader :nodes, :nodes_done, :static_context, :cleaner TIMER_CKECK_PITCH = 0.5 - #QUEUE_CKECK_PITCH = 0.3 + # QUEUE_CKECK_PITCH = 0.3 CLEAN_THREADS_PITCH = 5 - def initialize(nodeset,static_context = {},config = {}) + def initialize(nodeset, static_context = {}, config = {}) raise if nodeset.nil? @config = config @static_context = static_context @queue = Queue.new @threads = {} @threads_lock = Mutex.new - @nodes = nodeset #all nodes + @nodes = nodeset # all nodes @nodes_done = Nodes::NodeSet.new(@nodes.id) @runthread = nil @cleaner = nil @@ -180,13 +180,13 @@ module Automata end @threads_lock = nil @nodes = nil - #@nodes_done.free(false) if @nodes_done + # @nodes_done.free(false) if @nodes_done @nodes_done = nil @runthread = nil @cleaner = nil end - def create_task(_idx,_subidx,_nodes,_nsid,_context) + def create_task(_idx, _subidx, _nodes, _nsid, _context) raise 'Should be reimplemented' end @@ -198,29 +198,29 @@ module Automata raise 'Should be reimplemented' end - def custom(_task,_operation) + def custom(_task, _operation) raise 'Should be reimplemented' end - def break!(_task,_nodeset) + def break!(_task, _nodeset) end - def success!(_task,_nodeset) + def success!(_task, _nodeset) end - def fail!(_task,_nodeset) + def fail!(_task, _nodeset) end - def display_fail_message(_task,_nodeset) + def display_fail_message(_task, _nodeset) end def timeout!(_task) end - def retry!(_task,_nodeset) + def retry!(_task, _nodeset) end - def split!(_nsid0,_nsid1,_ns1,_nsid2,_ns2) + def split!(_nsid0, _nsid1, _ns1, _nsid2, _ns2) end def kill!() @@ -238,7 +238,7 @@ module Automata @queue.push({ :nodes => nodeset, :nsid => nsid() }) end - def init_context(task=nil) + def init_context(task = nil) if task ret = task.context ret[:local] = task.context[:local].dup @@ -259,7 +259,7 @@ module Automata end tasks.size.times do |idx| - if multi_task?(idx,tasks) + if multi_task?(idx, tasks) tasks[idx].size.times do |subidx| proc_init.call(tasks[idx][subidx][0]) end @@ -277,8 +277,8 @@ module Automata # To be used at runtine def config(config) unless config.nil? - config.each_pair do |taskname,taskconf| - conf_task(taskname,taskconf) + config.each_pair do |taskname, taskconf| + conf_task(taskname, taskconf) end end self @@ -323,33 +323,33 @@ module Automata def load_tasks end - def done_task(_task,nodeset) + def done_task(_task, nodeset) @nodes_done.add(nodeset) end - def break_task(task,nodeset) - done_task(task,nodeset) + def break_task(task, nodeset) + done_task(task, nodeset) nodeset.linked_copy(nodes_brk()) - break!(task,nodeset) + break!(task, nodeset) end - def success_task(task,nodeset,_rnsid=nil) - done_task(task,nodeset) + def success_task(task, nodeset, _rnsid = nil) + done_task(task, nodeset) nodeset.linked_copy(nodes_ok()) - success!(task,nodeset) + success!(task, nodeset) end - def fail_task(task,nodeset,_rnsid=nil) - done_task(task,nodeset) + def fail_task(task, nodeset, _rnsid = nil) + done_task(task, nodeset) nodeset.linked_copy(nodes_ko()) - fail!(task,nodeset) + fail!(task, nodeset) end - def get_task(idx,subidx) + def get_task(idx, subidx) ret = nil tasks = tasks() - if multi_task?(idx,tasks) + if multi_task?(idx, tasks) ret = tasks[idx][subidx] else ret = tasks[idx] @@ -358,7 +358,7 @@ module Automata return ret end - def multi_task?(idx,tasks=nil) + def multi_task?(idx, tasks = nil) tasks = tasks() unless tasks tasks[idx][0].is_a?(Array) @@ -368,11 +368,11 @@ module Automata ok_nsid = context[:nodesets_id].inc ko_nsid = context[:nodesets_id].inc - split!(task.nsid,ok_nsid,task.nodes_ok,ko_nsid,task.nodes_ko) - [ok_nsid,ko_nsid] + split!(task.nsid, ok_nsid, task.nodes_ok, ko_nsid, task.nodes_ko) + [ok_nsid, ko_nsid] end - def clean_nodeset(nodeset,exclude=nil) + def clean_nodeset(nodeset, exclude = nil) # gathering nodes that are not present in @nodes and removing them tmpset = nodeset.diff(@nodes) tmpset.set.each do |node| @@ -399,9 +399,9 @@ module Automata def clean_threads # To be called with the threads lock return unless @threads to_delete = [] - @threads.each_pair do |task,threads| + @threads.each_pair do |task, threads| to_delete2 = [] - threads.each_pair do |key,thread| + threads.each_pair do |key, thread| unless thread.alive? thread.join to_delete2 << key @@ -426,9 +426,9 @@ module Automata def join_threads # To be called with the threads lock to_delete = [] - @threads.each_pair do |task,threads| + @threads.each_pair do |task, threads| to_delete2 = [] - threads.each_pair do |key,thread| + threads.each_pair do |key, thread| thread.join to_delete2 << key end @@ -489,10 +489,10 @@ module Automata treated = Nodes::NodeSet.new unless task.nodes_ko.empty? # some nodes failed - display_fail_message(task,task.nodes_ko) + display_fail_message(task, task.nodes_ko) unless task.nodes_ok.empty? # some nodes didn't fail, we need to split - ok_nsid,ko_nsid = split_nodeset(task) + ok_nsid, ko_nsid = split_nodeset(task) end clean_nodeset(task.nodes_ko) @@ -502,7 +502,7 @@ module Automata unless task.nodes_ok.empty? # by default if nodes are present in nodes_ok and nodes_ko, # consider them as KO - clean_nodeset(task.nodes_ok,treated) + clean_nodeset(task.nodes_ok, treated) task.nodes_ok.linked_copy(treated) nodes = Nodes::NodeSet.new(task.nodes_ok.id) task.nodes_ok.linked_copy(nodes) @@ -563,14 +563,14 @@ module Automata until (done?) query = nil begin - #sleep(QUEUE_CKECK_PITCH) + # sleep(QUEUE_CKECK_PITCH) query = @queue.pop rescue ThreadError retry unless done? end @threads_lock.synchronize do - #clean_threads() + # clean_threads() # Don't do anything if the nodes was already treated clean_nodeset(query[:nodes]) @@ -589,8 +589,8 @@ module Automata if query[:status] and curtask if query[:status] == :BRK - break_task(curtask,query[:nodes]) - #break!(curtask,query[:nodes]) + break_task(curtask, query[:nodes]) + # break!(curtask,query[:nodes]) continue = false elsif query[:status] == :OK if (curtask.idx + 1) < tasks().length @@ -598,8 +598,8 @@ module Automata newtask[:context][:local][:retries] = 0 else curtask.mutex.synchronize do - success_task(curtask,query[:nodes],query[:nsid]) - #success!(curtask,query[:nodes]) + success_task(curtask, query[:nodes], query[:nsid]) + # success!(curtask,query[:nodes]) curtask.clean_nodes(query[:nodes]) end continue = false @@ -609,19 +609,19 @@ module Automata newtask[:idx] = curtask.idx newtask[:subidx] = curtask.subidx newtask[:context][:local][:retries] += 1 - retry!(curtask,query[:nodes]) + retry!(curtask, query[:nodes]) else tasks = tasks() - if multi_task?(curtask.idx,tasks) \ + if multi_task?(curtask.idx, tasks) \ and curtask.subidx < (tasks[curtask.idx].size - 1) newtask[:idx] = curtask.idx newtask[:subidx] = curtask.subidx + 1 newtask[:context][:local][:retries] = 0 - retry!(curtask,query[:nodes]) + retry!(curtask, query[:nodes]) else curtask.mutex.synchronize do - fail_task(curtask,query[:nodes],query[:nsid]) - #fail!(curtask,query[:nodes]) + fail_task(curtask, query[:nodes], query[:nsid]) + # fail!(curtask,query[:nodes]) curtask.clean_nodes(query[:nodes]) end continue = false @@ -666,7 +666,7 @@ module Automata curtask end - def kill(dofree=true) + def kill(dofree = true) @threads_lock.synchronize{ clean_threads() } if @threads unless @runthread.nil? @@ -685,7 +685,7 @@ module Automata if @threads @threads_lock.synchronize do - @threads.each_pair do |task,threads| + @threads.each_pair do |task, threads| task.kill(false) threads.each_value do |thread| thread.kill if thread.alive? @@ -715,7 +715,7 @@ module Automata attr_reader :name, :nodes, :nsid, :idx, :subidx, :nodes_brk, :nodes_ok, :nodes_ko, :mqueue, :mutex, :cleaner - def initialize(name, idx, subidx, nodes, nsid, manager_queue, context = {}, config={}, params = []) + def initialize(name, idx, subidx, nodes, nsid, manager_queue, context = {}, config = {}, params = []) @nsid = nsid @config = {} if config and !config.empty? @@ -723,7 +723,7 @@ module Automata config(config) load_config() end - super(nodes,context,@config) + super(nodes, context, @config) @name = name.to_sym @idx = idx @subidx = subidx @@ -744,11 +744,11 @@ module Automata @mqueue = nil @params = nil @mutex = nil - #@nodes_brk.free(false) if @nodes_brk + # @nodes_brk.free(false) if @nodes_brk @nodes_brk = nil - #@nodes_ok.free(false) if @nodes_ok + # @nodes_ok.free(false) if @nodes_ok @nodes_ok = nil - #@nodes_ko.free(false) if @nodes_ko + # @nodes_ko.free(false) if @nodes_ko @nodes_ko = nil end @@ -756,50 +756,50 @@ module Automata @static_context end - def break_task(task,nodeset) - super(task,nodeset) - raise_nodes(@nodes_brk,:BRK) + def break_task(task, nodeset) + super(task, nodeset) + raise_nodes(@nodes_brk, :BRK) end def split_nodeset(task) - ok_nsid,ko_nsid = super(task) + ok_nsid, ko_nsid = super(task) @nsid = ok_nsid - [ok_nsid,ko_nsid] + [ok_nsid, ko_nsid] end - def success_task(task,nodeset,rnsid=nil) + def success_task(task, nodeset, rnsid = nil) @nsid = task.nsid - super(task,nodeset) + super(task, nodeset) if @config[task.name][:raisable] new_nsid = nil if rnsid != task.nsid new_nsid = rnsid elsif !task.nodes.equal?(task.nodes_ok) - _,new_nsid = split_nodeset(task) + _, new_nsid = split_nodeset(task) else new_nsid = task.nsid end - #task.nsid = new_nsid - raise_nodes(@nodes_ok,:OK,new_nsid) + # task.nsid = new_nsid + raise_nodes(@nodes_ok, :OK, new_nsid) end end - def fail_task(task,nodeset,rnsid=nil) + def fail_task(task, nodeset, rnsid = nil) @nsid = task.nsid - super(task,nodeset) + super(task, nodeset) if @config[task.name][:raisable] new_nsid = nil if rnsid != task.nsid new_nsid = rnsid elsif !task.nodes.equal?(task.nodes_ko) - _,new_nsid = split_nodeset(task) + _, new_nsid = split_nodeset(task) else new_nsid = task.nsid end - #task.nsid = new_nsid - raise_nodes(@nodes_ko,:KO,new_nsid) + # task.nsid = new_nsid + raise_nodes(@nodes_ko, :KO, new_nsid) end end @@ -821,7 +821,7 @@ module Automata return true end - def kill(dofree=true) + def kill(dofree = true) __kill__(false) @nodes_ok.clean() @nodes.linked_copy(@nodes_ko) diff --git a/lib/kadeploy3/server/bittorrent.rb b/lib/kadeploy3/server/bittorrent.rb index f7ad8fdc1c087e9384c61359c9c3a900df1ae675..ac2821980cfaee6fec60aa730d1a06bb8abf4b14 100644 --- a/lib/kadeploy3/server/bittorrent.rb +++ b/lib/kadeploy3/server/bittorrent.rb @@ -26,9 +26,9 @@ module Bittorrent # Output # * return the number of remaining leechers or -1 if something went wrong def Bittorrent::get_remaining_download(torrent_hash, tracker_ip, tracker_port) - #first, we get a temporary file + # first, we get a temporary file temp = Tempfile.new("bttrack_wget") - #then, we grab the HTML output of bttrack + # then, we grab the HTML output of bttrack cmd = "wget --quiet -O #{temp.path} http://#{tracker_ip}:#{tracker_port} ; grep #{torrent_hash} #{temp.path} | sed 's/\"//g'" html_output = `#{cmd}` temp.unlink @@ -50,9 +50,9 @@ module Bittorrent # Output # * return the number of completed downloads or -1 if something went wrong def Bittorrent::get_downloaded(torrent_hash, tracker_ip, tracker_port) - #first, we get a temporary file + # first, we get a temporary file temp = Tempfile.new("bttrack_wget") - #then, we grab the HTML output of bttrack + # then, we grab the HTML output of bttrack cmd = "wget --quiet -O #{temp.path} http://#{tracker_ip}:#{tracker_port} ; grep #{torrent_hash} #{temp.path} | sed 's/\"//g'" html_output = `#{cmd}` temp.unlink diff --git a/lib/kadeploy3/server/cache.rb b/lib/kadeploy3/server/cache.rb index 00859d6fe0d511aad6e3369303bcdf9c8e16beb7..54d51f70f301e074d72cc9d2f5d07e0371f76851 100644 --- a/lib/kadeploy3/server/cache.rb +++ b/lib/kadeploy3/server/cache.rb @@ -8,21 +8,21 @@ require 'set' module Kadeploy - #Used for environments + # Used for environments class CacheIndexPVHash def self.name(params) if params[:tag] - "#{params[:tag]}-#{params[:version]}-#{params[:origin_uri]}".gsub(/\W/,'_')+".data" + "#{params[:tag]}-#{params[:version]}-#{params[:origin_uri]}".gsub(/\W/, '_') + ".data" else - "#{params[:version]}-#{params[:origin_uri]}".gsub(/\W/,'_')+".data" + "#{params[:version]}-#{params[:origin_uri]}".gsub(/\W/, '_') + ".data" end end end - #Used for user file boot + # Used for user file boot class CacheIndexPath def self.name(params) - raise KadeployError.new(APIError::CACHE_ERROR,nil,"In CacheIndexPath the file_in_cache must be provided") if params[:file_in_cache].nil? + raise KadeployError.new(APIError::CACHE_ERROR, nil, "In CacheIndexPath the file_in_cache must be provided") if params[:file_in_cache].nil? params[:file_in_cache] end end @@ -32,15 +32,15 @@ module Kadeploy EXT_META = 'meta' EXT_FILE = 'data' - MODE=0640 + MODE = 0640 - #This function checks if a file is readable. - #It raises an exception if the file is not readable. + # This function checks if a file is readable. + # It raises an exception if the file is not readable. def self.readable?(file) - raise KadeployError.new(APIError::CACHE_ERROR,nil,"File '#{file}' is not readable") if !File.file?(file) or !File.readable?(file) or !File.readable_real?(file) + raise KadeployError.new(APIError::CACHE_ERROR, nil, "File '#{file}' is not readable") if !File.file?(file) or !File.readable?(file) or !File.readable_real?(file) end - #Load CacheFile from meta_file. + # Load CacheFile from meta_file. def self.load(meta_file) readable?(meta_file) meta = YAML.load_file(meta_file) @@ -49,16 +49,16 @@ module Kadeploy meta[:file_in_cache], meta[:user], nil, - false #this avoids to create a new meta file, this parameter will be overridden by the next lines. + false # this avoids to create a new meta file, this parameter will be overridden by the next lines. ) - meta.each_pair do |key,value| + meta.each_pair do |key, value| ret.instance_variable_set("@#{key}", value) end ret end attr_reader :user, :priority, :origin_uri , :version, :tag, :md5, :size - attr_reader :mtime, :lock, :refs, :fetched, :fetch_error,:file_in_cache,:meta + attr_reader :mtime, :lock, :refs, :fetched, :fetch_error, :file_in_cache, :meta # file_in_cache: is the filename in a cache this parameter could not be nil. @@ -67,7 +67,7 @@ module Kadeploy # +user: user who stores the file # +directory: directory where the meta will be stored # +save_meta: boolean which enables or disables the meta file writing - def initialize(file_in_cache, user, directory, save_meta=false) + def initialize(file_in_cache, user, directory, save_meta = false) @lock = Mutex.new #: Lock of file @user = user.clone #: The user who has cached the file @version = nil #: The version of the file @@ -100,32 +100,32 @@ module Kadeploy # +tag is the tag of file # +block is the block to fetch file. # block has four parameters : origin_uri, file_in_cache,size and md5 which are the parameter of this function - def fetch(user,origin_uri,priority,version,size,md5,mtime,tag,&block) + def fetch(user, origin_uri, priority, version, size, md5, mtime, tag, &block) @lock.synchronize do if @fetched # File has already been fetched - if ( mtime != @mtime || ( size > 0 && size != @size) || version != @version || md5 != @md5 ) #Update - raise KadeployError.new(APIError::CACHE_ERROR,nil,"File #{origin_uri} is already in use, it can't be updated !\nPlease try again later.") if @refs.size > 1 - get_file(user,origin_uri,priority,version,size,md5,mtime,tag,&block) # We assume that an update can dammage a file. + if ( mtime != @mtime || ( size > 0 && size != @size) || version != @version || md5 != @md5 ) # Update + raise KadeployError.new(APIError::CACHE_ERROR, nil, "File #{origin_uri} is already in use, it can't be updated !\nPlease try again later.") if @refs.size > 1 + get_file(user, origin_uri, priority, version, size, md5, mtime, tag, &block) # We assume that an update can dammage a file. end else - get_file(user,origin_uri,priority,version,size,md5,mtime,tag,&block) + get_file(user, origin_uri, priority, version, size, md5, mtime, tag, &block) end end end - #Update size if it changed. - #If the file is already in use it raise an exception. + # Update size if it changed. + # If the file is already in use it raise an exception. def update_size(size) @lock.synchronize do if @size != size - raise KadeployError.new(APIError::CACHE_ERROR,nil,"File #{origin_uri} is already in use, it can't be updated !\nPlease try again later.") if @refs.size > 1 + raise KadeployError.new(APIError::CACHE_ERROR, nil, "File #{origin_uri} is already in use, it can't be updated !\nPlease try again later.") if @refs.size > 1 @size = size @fetched = false end end end - #Return true if file is used false otherwise + # Return true if file is used false otherwise def used?() if @lock.try_lock ret = used!() @@ -136,12 +136,12 @@ module Kadeploy end end - #Update the virtual access time - #and return the @file_in_cache + # Update the virtual access time + # and return the @file_in_cache def file() - raise KadeployError.new(APIError::CACHE_ERROR,nil,"This file has been freed!") if is_freed?() - raise KadeployError.new(APIError::CACHE_ERROR,nil,"This file has not been fetched") if !@fetched - raise KadeployError.new(APIError::CACHE_ERROR,nil,"An error occurs when it was fetched! #{@fetched_error}") if @fetch_error + raise KadeployError.new(APIError::CACHE_ERROR, nil, "This file has been freed!") if is_freed?() + raise KadeployError.new(APIError::CACHE_ERROR, nil, "This file has not been fetched") if !@fetched + raise KadeployError.new(APIError::CACHE_ERROR, nil, "An error occurs when it was fetched! #{@fetched_error}") if @fetch_error update_atime() @file_in_cache end @@ -160,23 +160,23 @@ module Kadeploy end end - #Update virtual access time, this replaces FS atime + # Update virtual access time, this replaces FS atime def update_atime() @atime_virt = Time.now.to_i self end - #Get access time. Relying on the FS information might not be reliable (noatime mount option for instance) + # Get access time. Relying on the FS information might not be reliable (noatime mount option for instance) def atime() @atime_virt end - #Try to free the file + # Try to free the file # Output: # - file_in_cache path if the operation was a success # - nil else def try_free() - locked=false + locked = false begin locked = @lock.try_lock if locked @@ -195,12 +195,12 @@ module Kadeploy nil end - #Check if the file is freed or not. + # Check if the file is freed or not. def is_freed?() @file_in_cache.nil? end - #Return hash of structure (for testing purpose) + # Return hash of structure (for testing purpose) def to_hash() @lock.synchronize do to_hash!() @@ -209,9 +209,9 @@ module Kadeploy private - #Generate the path to store the meta file + # Generate the path to store the meta file def meta_file(directory) - File.join(directory,File.basename(@file_in_cache,"."+EXT_FILE)) + "."+EXT_META + File.join(directory, File.basename(@file_in_cache, "." + EXT_FILE)) + "." + EXT_META ## ## If CacheIndexPath is used and if the cache saves the meta data then a conflict of meta file name is possible ## since the meta file is named according to the filename only. For example if /toto/example.txt and /titi/example.txt @@ -226,12 +226,12 @@ module Kadeploy # ret end - #Check if file is still used + # Check if file is still used def used!() (@refs.size > 0) end - #Transform variables to hash format + # Transform variables to hash format def to_hash!() ret = {} instance_variables.each do |instvar| @@ -242,35 +242,35 @@ module Kadeploy ret end - #Save the object field in @meta file in hash format + # Save the object field in @meta file in hash format # # !!! Be careful, use lock def save!() return unless @meta content = to_hash!() - File.open(@meta,"w") do |f| + File.open(@meta, "w") do |f| f.write(content.to_yaml) end self end - #Put file into the cache and update the data structure - #Arguments: see the fetch function - def get_file(user,origin_uri,priority,version,size,md5,mtime,tag,&_block) + # Put file into the cache and update the data structure + # Arguments: see the fetch function + def get_file(user, origin_uri, priority, version, size, md5, mtime, tag, &_block) begin @user = user @priority = priority @version = version @tag = tag if block_given? - yield(origin_uri,@file_in_cache,size,md5) + yield(origin_uri, @file_in_cache, size, md5) else - raise KadeployError.new(APIError::CACHE_ERROR,nil,"File size mistmatch") if size > 0 && size != File.size(origin_uri) + raise KadeployError.new(APIError::CACHE_ERROR, nil, "File size mistmatch") if size > 0 && size != File.size(origin_uri) raise KadeployError.new(APIError::INVALID_FILE, ("Checksum of the file '#{origin_uri}' does not match "\ "(an update is necessary)")) if md5 && md5 != Digest::MD5.file(origin_uri).hexdigest! - FileUtils.cp(origin_uri,@file_in_cache) + FileUtils.cp(origin_uri, @file_in_cache) end - #update all parameters if fetch raise nothing + # update all parameters if fetch raise nothing @origin_uri = origin_uri @mtime = mtime @size = File.size(@file_in_cache) @@ -281,7 +281,7 @@ module Kadeploy save!() rescue StandardError => ex @fetched = false - @fetched_error=ex + @fetched_error = ex FileUtils.rm_f(@file_in_cache) if @file_in_cache && File.exist?(@file_in_cache) raise ex end @@ -355,10 +355,10 @@ module Kadeploy # +naming_meth is object which contains name function with all parameter of cache and it gives the path where file will be stored # +emptycache is a boolean the cache is cleaned at start if true and loaded from finded meta file in directory at start # +same_meta boolean which enable or disable the meta saving. - def initialize(directory, max_size, concurrency_level, naming_meth, emptycache=true, save_meta=false) - raise KadeployError.new(APIError::CACHE_ERROR,nil,"#{directory} is not a directory") if directory && !File.directory?(directory) - raise KadeployError.new(APIError::CACHE_ERROR,nil,"Save meta without directory is not allowed") if save_meta && directory.nil? - raise KadeployError.new(APIError::CACHE_ERROR,nil,"Invalid cache size '#{max_size}'") if !(max_size.is_a?(Integer)) or max_size <= 0 + def initialize(directory, max_size, concurrency_level, naming_meth, emptycache = true, save_meta = false) + raise KadeployError.new(APIError::CACHE_ERROR, nil, "#{directory} is not a directory") if directory && !File.directory?(directory) + raise KadeployError.new(APIError::CACHE_ERROR, nil, "Save meta without directory is not allowed") if save_meta && directory.nil? + raise KadeployError.new(APIError::CACHE_ERROR, nil, "Invalid cache size '#{max_size}'") if !(max_size.is_a?(Integer)) or max_size <= 0 @directory = directory @max_size = max_size # Bytes @@ -396,7 +396,7 @@ module Kadeploy # Output: # FileCache # This function take a token that have to be released after a deployment - def cache(origin_uri,version,user,priority,tag,size,wid,file_in_cache=nil,md5=nil,mtime=nil,&block) + def cache(origin_uri, version, user, priority, tag, size, wid, file_in_cache = nil, md5 = nil, mtime = nil, &block) raise("The priority argument is nil in cache call") if priority.nil? fentry = absolute_path(@naming_meth.name({ :origin_uri => origin_uri, @@ -417,14 +417,14 @@ module Kadeploy @lock.synchronize do file = @files[fentry] if !file - file = CacheFile.new(fentry,user,@directory,@save_meta) + file = CacheFile.new(fentry, user, @directory, @save_meta) @files[fentry] = file end file.acquire(wid) - check_space_and_clean!(size-file.size,origin_uri) + check_space_and_clean!(size - file.size, origin_uri) file.update_size(size) end - file.fetch(user,origin_uri,priority,version,size,md5,mtime,tag,&block) + file.fetch(user, origin_uri, priority, version, size, md5, mtime, tag, &block) end rescue StandardError => ex @lock.synchronize do @@ -438,34 +438,34 @@ module Kadeploy file end - #Transform path into absolute path. + # Transform path into absolute path. # Argument: # +path # Output # Absolute path of path def absolute_path(file) begin - file = File.expand_path(file,@directory) + file = File.expand_path(file, @directory) rescue ArgumentError - raise KadeployError.new(APIError::CACHE_ERROR,nil,"Invalid path '#{file}'") + raise KadeployError.new(APIError::CACHE_ERROR, nil, "Invalid path '#{file}'") end file end - #Return the number of files + # Return the number of files def nb_files() @files.size end # Clean clean the cached files that are releasable and have a priority lower or equal to max_priority # if max_priority is negative, it tries to free all files. - def clean(max_priority=0) + def clean(max_priority = 0) @lock.synchronize do - to_del=[] + to_del = [] @files.each_value do |file| - if file.priority <= max_priority or max_priority<0 + if file.priority <= max_priority or max_priority < 0 if (fentry = file.try_free) - to_del<<fentry + to_del << fentry end end end @@ -485,7 +485,7 @@ module Kadeploy end - #Load cache with different policy: + # Load cache with different policy: # -if @directory == nil: do nothing # -if empty_cache == true : erase files in directory # -else all meta file inside @directory are loaded @@ -493,9 +493,9 @@ module Kadeploy return if @directory.nil? # No directory is provided if emptycache debug("Cleaning cache #{@directory} ...") - exclude = [ '.', '..' ] + exclude = ['.', '..'] Dir.entries(@directory).sort.each do |file| - rfile = File.join(@directory,file) + rfile = File.join(@directory, file) if !exclude.include?(rfile) if File.file?(rfile) debug("Delete file #{rfile} from cache") @@ -506,10 +506,10 @@ module Kadeploy debug("Cache #{@directory} cleaned") else debug("Loading cache #{@directory} ...") - exclude = [ '.', '..' ] + exclude = ['.', '..'] @lock.synchronize do Dir.entries(@directory).sort.each do |file| - rfile = File.join(@directory,file) + rfile = File.join(@directory, file) if !exclude.include?(file) && file.split('.').last == CacheFile::EXT_META begin fc = CacheFile.load(rfile) @@ -525,8 +525,8 @@ module Kadeploy end end - #Free all resources - #Raise an exception if there is a file still used ! + # Free all resources + # Raise an exception if there is a file still used ! def free() clean(-1) if @files.size > 0 @@ -550,19 +550,19 @@ module Kadeploy def check_space_and_clean!(size, origin_uri) return if size <= 0 # If a size is given, clean the cache before grabbing the new file - unfreeable,used_space = compute_space!() + unfreeable, used_space = compute_space!() if size > @max_size - unfreeable raise KadeployError.new( - APIError::CACHE_FULL,nil, + APIError::CACHE_FULL, nil, "Cache is full: impossible to cache the file '#{origin_uri}'. Too many deployments are probably running concurrently." ) end free_space!(size - (@max_size - used_space)) end - #Compute the releasable and the used cache space - #Output: + # Compute the releasable and the used cache space + # Output: # Array[ file cache used in byte, total of file cache in byte ] def compute_space!() unfreeable_space = 0 @@ -571,17 +571,17 @@ module Kadeploy unfreeable_space += file.size if file.used? used_space += file.size end - [unfreeable_space,used_space] + [unfreeable_space, used_space] end - #This function removes low priority elements until having enough free space (need_to_free) + # This function removes low priority elements until having enough free space (need_to_free) def free_space!(need_to_free) return true if need_to_free <= 0 # Delete elements depending on their priority and according to an LRU policy begin ensure - @files.values.sort_by{|v| [v.priority,v.atime]}.each do |file| + @files.values.sort_by{|v| [v.priority, v.atime]}.each do |file| size = file.size fid = file.try_free if fid diff --git a/lib/kadeploy3/server/config.rb b/lib/kadeploy3/server/config.rb index 5e63eb29485ed80fad52304e6cd1ee6eb22ea331..cc8b80077d35c0a574332f29447f05e9e2861b6d 100644 --- a/lib/kadeploy3/server/config.rb +++ b/lib/kadeploy3/server/config.rb @@ -27,7 +27,7 @@ module Configuration next if obj.hash == hash() obj.free if obj.respond_to?(:free) obj.clear if obj.respond_to?(:clear) - self.instance_variable_set(v,nil) + self.instance_variable_set(v, nil) end if self.respond_to?(:each) self.each do |obj| @@ -53,7 +53,7 @@ module Configuration attr_reader :common, :clusters, :caches, :static - def initialize(config=nil,caches=nil) + def initialize(config = nil, caches = nil) if config.nil? sanity_check() @@ -87,7 +87,7 @@ module Configuration @static.freeze @caches.freeze if @caches else - raise KadeployError.new(APIError::BAD_CONFIGURATION,nil, + raise KadeployError.new(APIError::BAD_CONFIGURATION, nil, "Problem in configuration") end else @@ -135,7 +135,7 @@ module Configuration files.each do |file| unless File.readable?(file) $stderr.puts "The #{file} file cannot be read" - raise KadeployError.new(APIError::BAD_CONFIGURATION,nil, + raise KadeployError.new(APIError::BAD_CONFIGURATION, nil, "Unsane configuration") end end @@ -148,7 +148,7 @@ module Configuration @static[:caches][:global][:directory], @static[:caches][:global][:size], @static[:caches][:global][:concurrency_level], - CacheIndexPVHash,true,true + CacheIndexPVHash, true, true ) end @@ -157,7 +157,7 @@ module Configuration @static[:caches][:netboot][:directory], @static[:caches][:netboot][:size], @static[:caches][:netboot][:concurrency_level], - CacheIndexPath,false,false + CacheIndexPath, false, false ) end @@ -231,7 +231,7 @@ module Configuration # * nothing # Output # * nothing - def initialize(version=nil) + def initialize(version = nil) @version = version @nodes = Nodes::NodeSet.new @cache = {} @@ -259,16 +259,16 @@ module Configuration static = {} cp = Parser.new(config) - cp.parse('database',true) do - @db_kind = cp.value('kind',String,nil,'mysql') - @deploy_db_host = cp.value('host',String) - @deploy_db_name = cp.value('name',String) - @deploy_db_login = cp.value('login',String) - @deploy_db_passwd = cp.value('passwd',String) + cp.parse('database', true) do + @db_kind = cp.value('kind', String, nil, 'mysql') + @deploy_db_host = cp.value('host', String) + @deploy_db_name = cp.value('name', String) + @deploy_db_login = cp.value('login', String) + @deploy_db_passwd = cp.value('passwd', String) end cp.parse('rights') do - @rights_kind = cp.value('kind',String,'db',['db','dummy']) + @rights_kind = cp.value('kind', String, 'db', ['db', 'dummy']) @almighty_env_users = cp.value( 'almighty_users', String, 'root' ).split(",").collect! { |v| v.strip } @@ -276,12 +276,12 @@ module Configuration 'purge_deployment_timer', Integer, 900 ) end - @archs_list = cp.value('archs_list',String,nil).split(',').collect{ |v| v.strip }.uniq - cp.parse('network',false) do + @archs_list = cp.value('archs_list', String, nil).split(',').collect{ |v| v.strip }.uniq + cp.parse('network', false) do cp.parse('vlan') do - @vlan_hostname_suffix = cp.value('hostname_suffix',String,'') - @allow_vlan_failure = cp.value('allow_failure',[TrueClass, FalseClass],true) - @set_vlan_cmd = cp.value('set_cmd',String,'',{ + @vlan_hostname_suffix = cp.value('hostname_suffix', String, '') + @allow_vlan_failure = cp.value('allow_failure', [TrueClass, FalseClass], true) + @set_vlan_cmd = cp.value('set_cmd', String, '', { :type => 'file', :command => true, :readable => true, :executable => true }) @@ -290,9 +290,9 @@ module Configuration cp.parse('ports') do static[:port] = cp.value( - 'kadeploy_server', Integer,KADEPLOY_PORT + 'kadeploy_server', Integer, KADEPLOY_PORT ) - @ssh_port = cp.value('ssh', Integer,22) + @ssh_port = cp.value('ssh', Integer, 22) @test_deploy_env_port = cp.value( 'test_deploy_env', Integer, KADEPLOY_PORT ) @@ -301,21 +301,21 @@ module Configuration @kadeploy_tcp_buffer_size = cp.value( 'tcp_buffer_size', Integer, 8192 ) - static[:host] = cp.value('server_hostname',String,Socket.gethostname) + static[:host] = cp.value('server_hostname', String, Socket.gethostname) end cp.parse('security') do |info| static[:secure] = cp.value('secure_server', - [TrueClass,FalseClass],true) + [TrueClass, FalseClass], true) static[:local] = cp.value('local_only', - [TrueClass,FalseClass],false) + [TrueClass, FalseClass], false) - cp.parse('private_key',false) do |inf| + cp.parse('private_key', false) do |inf| next if inf[:empty] - file = cp.value('file',String,'', + file = cp.value('file', String, '', { :type => 'file', :readable => true, :prefix => Config.dir()}) - kind = cp.value('algorithm',String,nil,['RSA','DSA','EC']) + kind = cp.value('algorithm', String, nil, ['RSA', 'DSA', 'EC']) next if file.empty? begin case kind @@ -329,30 +329,30 @@ module Configuration raise end rescue StandardError => e - raise ArgumentError.new(Parser.errmsg(inf[:path],"Unable to load #{kind} private key: #{e.message}")) + raise ArgumentError.new(Parser.errmsg(inf[:path], "Unable to load #{kind} private key: #{e.message}")) end end - cert = cp.value('certificate',String,'', + cert = cp.value('certificate', String, '', { :type => 'file', :readable => true, :prefix => Config.dir()}) if cert and !cert.empty? begin static[:cert] = OpenSSL::X509::Certificate.new(File.read(cert)) rescue StandardError => e - raise ArgumentError.new(Parser.errmsg(info[:path],"Unable to load x509 cert file: #{e.message}")) + raise ArgumentError.new(Parser.errmsg(info[:path], "Unable to load x509 cert file: #{e.message}")) end end if static[:cert] unless static[:private_key] - raise ArgumentError.new(Parser.errmsg(info[:path],"You have to specify the private key associated with the x509 certificate")) + raise ArgumentError.new(Parser.errmsg(info[:path], "You have to specify the private key associated with the x509 certificate")) end unless static[:cert].check_private_key(static[:private_key]) - raise ArgumentError.new(Parser.errmsg(info[:path],"The private key does not match with the x509 certificate")) + raise ArgumentError.new(Parser.errmsg(info[:path], "The private key does not match with the x509 certificate")) end end @secure_client = cp.value('force_secure_client', - [TrueClass,FalseClass],false) + [TrueClass, FalseClass], false) end cp.parse('authentication') do |nfo| @@ -360,7 +360,7 @@ module Configuration # 192.168.0.0/24 # domain.tld # /^.*\.domain.tld$/ - parse_hostname = Proc.new do |hostname,path| + parse_hostname = Proc.new do |hostname, path| addr = nil begin # Check if IP address @@ -371,7 +371,7 @@ module Configuration begin addr = Regexp.new(Regexp.last_match(1)) rescue - raise ArgumentError.new(Parser.errmsg(path,"Invalid regexp #{hostname}")) + raise ArgumentError.new(Parser.errmsg(path, "Invalid regexp #{hostname}")) end end end @@ -380,37 +380,37 @@ module Configuration begin addr = IPAddr.new(Resolv.getaddress(hostname)) rescue Resolv::ResolvError - raise ArgumentError.new(Parser.errmsg(path,"Cannot resolv hostname #{hostname}")) + raise ArgumentError.new(Parser.errmsg(path, "Cannot resolv hostname #{hostname}")) rescue StandardError => e - raise ArgumentError.new(Parser.errmsg(path,"Invalid hostname #{hostname.inspect} (#{e.message})")) + raise ArgumentError.new(Parser.errmsg(path, "Invalid hostname #{hostname.inspect} (#{e.message})")) end end addr end - cp.parse('global',false) do - static[:auth_headers_prefix] = cp.value('headers_prefix',String,'X-Kadeploy-') + cp.parse('global', false) do + static[:auth_headers_prefix] = cp.value('headers_prefix', String, 'X-Kadeploy-') end - cp.parse('acl',false) do |inf| + cp.parse('acl', false) do |inf| next if inf[:empty] static[:auth] = {} unless static[:auth] static[:auth][:acl] = ACLAuthentication.new() - cp.parse('whitelist',true,Array) do |info| + cp.parse('whitelist', true, Array) do |info| next if info[:empty] - static[:auth][:acl].whitelist << parse_hostname.call(info[:val][info[:iter]],info[:path]) + static[:auth][:acl].whitelist << parse_hostname.call(info[:val][info[:iter]], info[:path]) end end - cp.parse('certificate',false) do |inf| + cp.parse('certificate', false) do |inf| next if inf[:empty] public_key = nil - cp.parse('ca_public_key',false) do |info| + cp.parse('ca_public_key', false) do |info| next if info[:empty] - file = cp.value('file',String,'', + file = cp.value('file', String, '', { :type => 'file', :readable => true, :prefix => Config.dir()}) next if file.empty? - kind = cp.value('algorithm',String,nil,['RSA','DSA','EC']) + kind = cp.value('algorithm', String, nil, ['RSA', 'DSA', 'EC']) begin case kind when 'RSA' @@ -423,21 +423,21 @@ module Configuration raise end rescue StandardError => e - raise ArgumentError.new(Parser.errmsg(nfo[:path],"Unable to load #{kind} public key: #{e.message}")) + raise ArgumentError.new(Parser.errmsg(nfo[:path], "Unable to load #{kind} public key: #{e.message}")) end end unless public_key - cert = cp.value('ca_cert',String,'', + cert = cp.value('ca_cert', String, '', { :type => 'file', :readable => true, :prefix => Config.dir()}) if cert.empty? - raise ArgumentError.new(Parser.errmsg(nfo[:path],"At least a certificate or a public key have to be specified")) + raise ArgumentError.new(Parser.errmsg(nfo[:path], "At least a certificate or a public key have to be specified")) else begin cert = OpenSSL::X509::Certificate.new(File.read(cert)) public_key = cert.public_key rescue StandardError => e - raise ArgumentError.new(Parser.errmsg(nfo[:path],"Unable to load x509 cert file: #{e.message}")) + raise ArgumentError.new(Parser.errmsg(nfo[:path], "Unable to load x509 cert file: #{e.message}")) end end end @@ -445,82 +445,82 @@ module Configuration static[:auth] = {} unless static[:auth] static[:auth][:cert] = CertificateAuthentication.new(public_key) if static[:local] - static[:auth][:cert].whitelist << parse_hostname.call('localhost',inf[:path]) + static[:auth][:cert].whitelist << parse_hostname.call('localhost', inf[:path]) else - cp.parse('whitelist',false,Array) do |info| + cp.parse('whitelist', false, Array) do |info| next if info[:empty] - static[:auth][:cert].whitelist << parse_hostname.call(info[:val][info[:iter]],info[:path]) + static[:auth][:cert].whitelist << parse_hostname.call(info[:val][info[:iter]], info[:path]) end end end - cp.parse('http_basic',false) do |inf| + cp.parse('http_basic', false) do |inf| next if inf[:empty] static[:auth] = {} unless static[:auth] - dbfile = cp.value('dbfile',String,nil, + dbfile = cp.value('dbfile', String, nil, { :type => 'file', :readable => true, :prefix => Config.dir()}) begin dbfile = WEBrick::HTTPAuth::Htpasswd.new(dbfile) rescue StandardError => e - raise ArgumentError.new(Parser.errmsg(inf[:path],"Unable to load htpasswd file: #{e.message}")) + raise ArgumentError.new(Parser.errmsg(inf[:path], "Unable to load htpasswd file: #{e.message}")) end static[:auth][:http_basic] = HTTPBasicAuthentication.new(dbfile, - cp.value('realm',String,"http#{'s' if static[:secure]}://#{static[:host]}:#{static[:port]}")) + cp.value('realm', String, "http#{'s' if static[:secure]}://#{static[:host]}:#{static[:port]}")) if static[:local] - static[:auth][:http_basic].whitelist << parse_hostname.call('localhost',inf[:path]) + static[:auth][:http_basic].whitelist << parse_hostname.call('localhost', inf[:path]) else - cp.parse('whitelist',false,Array) do |info| + cp.parse('whitelist', false, Array) do |info| next if info[:empty] - static[:auth][:http_basic].whitelist << parse_hostname.call(info[:val][info[:iter]],info[:path]) + static[:auth][:http_basic].whitelist << parse_hostname.call(info[:val][info[:iter]], info[:path]) end end end - cp.parse('ident',false,Hash,false) do |info_ident| + cp.parse('ident', false, Hash, false) do |info_ident| next unless info_ident[:provided] static[:auth] = {} unless static[:auth] static[:auth][:ident] = IdentAuthentication.new if static[:local] - static[:auth][:ident].whitelist << parse_hostname.call('localhost',info_ident[:path]) + static[:auth][:ident].whitelist << parse_hostname.call('localhost', info_ident[:path]) else - cp.parse('whitelist',true,Array) do |info_white| + cp.parse('whitelist', true, Array) do |info_white| next if info_white[:empty] - static[:auth][:ident].whitelist << parse_hostname.call(info_white[:val][info_white[:iter]],info_white[:path]) + static[:auth][:ident].whitelist << parse_hostname.call(info_white[:val][info_white[:iter]], info_white[:path]) end end end if !static[:auth] or static[:auth].empty? - raise ArgumentError.new(Parser.errmsg(nfo[:path],"You must set at least one authentication method")) + raise ArgumentError.new(Parser.errmsg(nfo[:path], "You must set at least one authentication method")) end end - static[:ssh_private_key] = cp.value('ssh_private_key',String, File.join($kadeploy_confdir,'keys','id_deploy'), + static[:ssh_private_key] = cp.value('ssh_private_key', String, File.join($kadeploy_confdir, 'keys', 'id_deploy'), { :type => 'file', :readable => true, :prefix => Config.dir()}) cp.parse('logs') do static[:logfile] = cp.value( - 'logfile',String,'', + 'logfile', String, '', { :type => 'file', :writable => true, :create => true } ) static[:logfile] = nil if static[:logfile].empty? - @log_to_db = cp.value('database',[TrueClass,FalseClass],true) + @log_to_db = cp.value('database', [TrueClass, FalseClass], true) @dbg_to_file = cp.value( - 'debugfile',String,'', + 'debugfile', String, '', { :type => 'file', :writable => true, :create => true } ) @dbg_to_file = nil if @dbg_to_file.empty? end cp.parse('verbosity') do - @dbg_to_file_level = cp.value('logs', Integer,3,(0..4)) - @verbose_level = cp.value('clients', Integer,3,(0..4)) + @dbg_to_file_level = cp.value('logs', Integer, 3, (0..4)) + @verbose_level = cp.value('clients', Integer, 3, (0..4)) end - cp.parse('cache',true) do + cp.parse('cache', true) do static[:caches] = {} unless static[:caches] static[:caches][:global] = {} - static[:caches][:global][:directory] = cp.value('directory',String,'/tmp', + static[:caches][:global][:directory] = cp.value('directory', String, '/tmp', { :type => 'dir', :readable => true, @@ -529,123 +529,123 @@ module Configuration :mode => 0700 } ) - static[:caches][:global][:size] = cp.value('size', Integer)*1024*1024 + static[:caches][:global][:size] = cp.value('size', Integer) * 1024 * 1024 static[:caches][:global][:concurrency_level] = cp.value('concurrency_level', Integer, 10) end cp.parse('windows') do cp.parse('reboot') do - static[:reboot_window] = cp.value('size', Integer,50) - static[:reboot_window_sleep_time] = cp.value('sleep_time', Integer,10) + static[:reboot_window] = cp.value('size', Integer, 50) + static[:reboot_window_sleep_time] = cp.value('sleep_time', Integer, 10) end cp.parse('check') do - static[:nodes_check_window] = cp.value('size', Integer,50) + static[:nodes_check_window] = cp.value('size', Integer, 50) end end cp.parse('environments') do cp.parse('deployment') do @environment_extraction_dir = cp.value( - 'extraction_dir',String,'/mnt/dest',Pathname + 'extraction_dir', String, '/mnt/dest', Pathname ) - @rambin_path = cp.value('rambin_dir',String,'/rambin',Pathname) + @rambin_path = cp.value('rambin_dir', String, '/rambin', Pathname) @tarball_dest_dir = cp.value( - 'tarball_dir',String,'/tmp',Pathname + 'tarball_dir', String, '/tmp', Pathname ) end @max_preinstall_size = - cp.value('max_preinstall_size', Integer,20) *1024 * 1024 + cp.value('max_preinstall_size', Integer, 20) * 1024 * 1024 @max_postinstall_size = - cp.value('max_postinstall_size', Integer,20) * 1024 * 1024 + cp.value('max_postinstall_size', Integer, 20) * 1024 * 1024 @env_name_regex = cp.value('allowed_name_regex', String, nil) end - cp.parse('pxe',true) do + cp.parse('pxe', true) do chain = nil - cp.parse('dhcp',true) do |info| - chain = pxemethod(:dhcp,info,cp,static) + cp.parse('dhcp', true) do |info| + chain = pxemethod(:dhcp, info, cp, static) end cp.parse('localboot') do |info| - pxemethod(:local,info,cp,static,chain) + pxemethod(:local, info, cp, static, chain) end @pxe[:local] = chain unless @pxe[:local] cp.parse('networkboot') do |info| - pxemethod(:network,info,cp,static,chain) + pxemethod(:network, info, cp, static, chain) end @pxe[:network] = chain unless @pxe[:network] end cp.parse('hooks') do - @end_of_deploy_hook = cp.value('end_of_deployment',String,'',{ + @end_of_deploy_hook = cp.value('end_of_deployment', String, '', { :type => 'file', :command => true, :readable => true, :executable => true }) @end_of_deploy_hook = nil if @end_of_deploy_hook.empty? - @end_of_reboot_hook = cp.value('end_of_reboot',String,'',{ + @end_of_reboot_hook = cp.value('end_of_reboot', String, '', { :type => 'file', :command => true, :readable => true, :executable => true }) @end_of_reboot_hook = nil if @end_of_reboot_hook.empty? - @end_of_power_hook = cp.value('end_of_power',String,'',{ + @end_of_power_hook = cp.value('end_of_power', String, '', { :type => 'file', :command => true, :readable => true, :executable => true }) @end_of_power_hook = nil if @end_of_power_hook.empty? end - @autoclean_threshold = cp.value('autoclean_threshold', Integer,60*6).abs * 60 # 6h by default + @autoclean_threshold = cp.value('autoclean_threshold', Integer, 60 * 6).abs * 60 # 6h by default cp.parse('external') do - @cmd_ext[:default_connector] = cp.value('default_connector',String,'ssh -A -l root -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=publickey -o BatchMode=yes') + @cmd_ext[:default_connector] = cp.value('default_connector', String, 'ssh -A -l root -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=publickey -o BatchMode=yes') cp.parse('taktuk') do - @taktuk_connector = cp.value('connector',String,'DEFAULT_CONNECTOR') - @taktuk_connector.gsub!('DEFAULT_CONNECTOR',@cmd_ext[:default_connector]) + @taktuk_connector = cp.value('connector', String, 'DEFAULT_CONNECTOR') + @taktuk_connector.gsub!('DEFAULT_CONNECTOR', @cmd_ext[:default_connector]) - @taktuk_tree_arity = cp.value('tree_arity', Integer,0) + @taktuk_tree_arity = cp.value('tree_arity', Integer, 0) @taktuk_auto_propagate = cp.value( - 'auto_propagate',[TrueClass,FalseClass],true + 'auto_propagate', [TrueClass, FalseClass], true ) - @taktuk_outputs_size = cp.value('outputs_size', Integer,20000) + @taktuk_outputs_size = cp.value('outputs_size', Integer, 20000) end cp.parse('bittorrent') do |info| unless info[:empty] @bt_tracker_ip = cp.value( - 'tracker_ip',String,nil,/\A\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\Z/ + 'tracker_ip', String, nil, /\A\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\Z/ ) @bt_download_timeout = cp.value('download_timeout', Integer) end end cp.parse('kastafior') do - @kastafior = cp.value('binary',String,'kastafior') + @kastafior = cp.value('binary', String, 'kastafior') end cp.parse('kascade') do - @kascade = cp.value('binary',String,'kascade') - @kascade_options = cp.value('args',String,'') + @kascade = cp.value('binary', String, 'kascade') + @kascade_options = cp.value('args', String, '') end @mkfs_options = Hash.new - cp.parse('mkfs',false,Array) do |info| + cp.parse('mkfs', false, Array) do |info| unless info[:empty] - @mkfs_options[cp.value('fstype',String)] = - cp.value('args',String) + @mkfs_options[cp.value('fstype', String)] = + cp.value('args', String) end end @compression_options = Hash.new - cp.parse('compression_options',false,Array) do |info| + cp.parse('compression_options', false, Array) do |info| unless info[:empty] - @compression_options[cp.value('type',String, '', Environment::IMAGE_COMPRESSION)] = - cp.value('args',String) + @compression_options[cp.value('type', String, '', Environment::IMAGE_COMPRESSION)] = + cp.value('args', String) end end - @tar_options = cp.value('tar',String,'') + @tar_options = cp.value('tar', String, '') end rescue ArgumentError => ae @@ -662,36 +662,36 @@ module Configuration end # Parse pxe part to build NetBoot object - def pxemethod(name,info,cp,static,chain = nil) + def pxemethod(name, info, cp, static, chain = nil) unless info[:empty] args = {} - args[:kind] = cp.value('method',String,'PXElinux', - ['PXElinux','LPXElinux','IPXE','GrubPXE'] + args[:kind] = cp.value('method', String, 'PXElinux', + ['PXElinux', 'LPXElinux', 'IPXE', 'GrubPXE'] ) - args[:repository_dir] = cp.value('repository',String,nil,Dir) + args[:repository_dir] = cp.value('repository', String, nil, Dir) if name == :dhcp args[:binary] = 'DHCP_PXEBIN' else - args[:binary] = cp.value('binary',String,nil, + args[:binary] = cp.value('binary', String, nil, {:type => 'file', :prefix => args[:repository_dir], :const => true} ) end cp.parse('export') do - args[:export_kind] = cp.value('kind',String,'tftp',['http','ftp','tftp','auto']).to_sym - args[:export_server] = cp.value('server',String,'LOCAL_IP') + args[:export_kind] = cp.value('kind', String, 'tftp', ['http', 'ftp', 'tftp', 'auto']).to_sym + args[:export_server] = cp.value('server', String, 'LOCAL_IP') end if name == :dhcp - cp.parse('userfiles',true) do - args[:custom_dir] = cp.value('directory',String,nil, + cp.parse('userfiles', true) do + args[:custom_dir] = cp.value('directory', String, nil, {:type => 'dir', :prefix => args[:repository_dir]} ) static[:caches] = {} unless static[:caches] static[:caches][:netboot] = {} - static[:caches][:netboot][:directory] = File.join(args[:repository_dir],args[:custom_dir]) - static[:caches][:netboot][:size] = cp.value('max_size', Integer)*1024*1024 + static[:caches][:netboot][:directory] = File.join(args[:repository_dir], args[:custom_dir]) + static[:caches][:netboot][:size] = cp.value('max_size', Integer) * 1024 * 1024 static[:caches][:netboot][:concurrency_level] = cp.value('concurrency_level', Integer, 10) end else @@ -699,18 +699,18 @@ module Configuration end cp.parse('profiles') do - #TODO : check profile config for example : pxelinuix => pxelinux.cfg,ip_hex another=> another - args[:profiles_dir] = cp.value('directory',String,'pxelinux.cfg') + # TODO : check profile config for example : pxelinuix => pxelinux.cfg,ip_hex another=> another + args[:profiles_dir] = cp.value('directory', String, 'pxelinux.cfg') if args[:profiles_dir].empty? args[:profiles_dir] = args[:repository_dir] elsif !Pathname.new(args[:profiles_dir]).absolute? - args[:profiles_dir] = File.join(args[:repository_dir],args[:profiles_dir]) + args[:profiles_dir] = File.join(args[:repository_dir], args[:profiles_dir]) end if !File.exist?(args[:profiles_dir]) or !File.directory?(args[:profiles_dir]) - raise ArgumentError.new(Parser.errmsg(info[:path],"The directory '#{args[:profiles_dir]}' does not exist")) + raise ArgumentError.new(Parser.errmsg(info[:path], "The directory '#{args[:profiles_dir]}' does not exist")) end - args[:profiles_kind] = cp.value('filename',String,'ip_hex', - ['ip','ip_hex','hostname','hostname_short'] + args[:profiles_kind] = cp.value('filename', String, 'ip_hex', + ['ip', 'ip_hex', 'hostname', 'hostname_short'] ) end @@ -718,7 +718,7 @@ module Configuration @pxe[name] = NetBoot.Factory(args[:kind], args[:binary], args[:export_kind], args[:export_server], args[:repository_dir], args[:custom_dir], args[:profiles_dir], args[:profiles_kind], chain) rescue NetBoot::Exception => nbe - raise ArgumentError.new(Parser.errmsg(info[:path],nbe.message)) + raise ArgumentError.new(Parser.errmsg(info[:path], nbe.message)) end end end @@ -753,25 +753,25 @@ module Configuration cp = Parser.new(config) - cp.parse('clusters',true,Array) do - clname = cp.value('name',String) + cp.parse('clusters', true, Array) do + clname = cp.value('name', String) if self.keys.include?(clname) raise ArgumentError.new("Cluster \"#{clname}\" is already defined") end clfile = cp.value( - 'conf_file',String,nil,{ + 'conf_file', String, nil, { :type => 'file', :readable => true, :prefix => Config.dir()}) conf = self[clname] = ClusterSpecificConfig.new( - cp.value('prefix',String,''),commonconfig) - return false unless conf.load(clname,clfile) + cp.value('prefix', String, ''), commonconfig) + return false unless conf.load(clname, clfile) - cp.parse('nodes',true,Array) do |info| - name = cp.value('name',String) - address = cp.value('address',String) + cp.parse('nodes', true, Array) do |info| + name = cp.value('name', String) + address = cp.value('address', String) if name =~ Nodes::REGEXP_NODELIST and address =~ Nodes::REGEXP_IPLIST hostnames = Nodes::NodeSet::nodes_list_expand(name) @@ -786,7 +786,7 @@ module Configuration end else raise ArgumentError.new(Parser.errmsg( - info[:path],"Incoherent number of hostnames and IP addresses" + info[:path], "Incoherent number of hostnames and IP addresses" ) ) end @@ -799,7 +799,7 @@ module Configuration )) rescue ArgumentError raise ArgumentError.new(Parser.errmsg( - info[:path],"Invalid address" + info[:path], "Invalid address" ) ) end @@ -838,7 +838,7 @@ module Configuration attr_reader :deploy_part attr_reader :default_arch attr_reader :supported_arch - attr_reader :workflow_steps #Array of MacroStep + attr_reader :workflow_steps # Array of MacroStep attr_reader :timeout_reboot_classical attr_reader :timeout_reboot_kexec attr_reader :cmd_reboot_soft @@ -854,7 +854,7 @@ module Configuration attr_reader :cmd_power_status attr_reader :cmd_sendenv attr_reader :decompress_environment - attr_reader :group_of_nodes #Hashtable (key is a command name) + attr_reader :group_of_nodes # Hashtable (key is a command name) attr_reader :partitioning_script attr_reader :formating_script attr_reader :kexec_server_precmd @@ -882,7 +882,7 @@ module Configuration # * nothing # Output # * nothing - def initialize(prefix=nil,global_conf) + def initialize(prefix = nil, global_conf) @prefix = prefix @workflow_steps = [] @deploy_kernel_args = "" @@ -895,7 +895,7 @@ module Configuration @cmd_ext = global_conf.cmd_ext.clone end - def handle_cmd_priority(obj,conf_path,cp,cluster=null,limit=3) + def handle_cmd_priority(obj, conf_path, cp, cluster = null, limit = 3) begin raise "This is not an array, please check the documentation." unless obj.is_a? Array raise "This version accepts only #{limit} commands." if obj.size > limit @@ -903,7 +903,7 @@ module Configuration output = [] obj.each do |element| idx = @level_name.index(element['name']) - raise "the '#{element['name']}' is not a valid name." if idx<0 + raise "the '#{element['name']}' is not a valid name." if idx < 0 output[idx] = element['cmd'] group = element['group'] add_group_of_nodes("#{name}_reboot", group, cluster) unless group.nil? || cluster.nil? @@ -914,8 +914,8 @@ module Configuration cmd = obj[idx] if cmd raise "The provided command is not a string." unless cmd.is_a? String - obj[idx] = cmd.gsub!('DEFAULT_CONNECTOR',@cmd_ext[:default_connector]) || obj[idx] - cp.customcheck_file(cmd,nil,{ + obj[idx] = cmd.gsub!('DEFAULT_CONNECTOR', @cmd_ext[:default_connector]) || obj[idx] + cp.customcheck_file(cmd, nil, { :type => 'file', :command => true, :readable => true, :executable => true }) @@ -944,29 +944,29 @@ module Configuration raise ArgumentError.new("Invalid file format'#{configfile}'") end - #The method to add default automata is ugly, but it is readable. + # The method to add default automata is ugly, but it is readable. unless config['automata'] - add={'automata'=>{ - 'macrosteps'=>{ - 'SetDeploymentEnv'=> [{ - 'timeout'=> 200, - 'type'=>'Untrusted', - 'retries'=> 2, + add = {'automata' => { + 'macrosteps' => { + 'SetDeploymentEnv' => [{ + 'timeout' => 200, + 'type' => 'Untrusted', + 'retries' => 2, }], - 'BroadcastEnv'=> [{ - 'timeout'=> 300, - 'type'=>'Kascade', - 'retries'=> 2, + 'BroadcastEnv' => [{ + 'timeout' => 300, + 'type' => 'Kascade', + 'retries' => 2, }], - 'BootNewEnv'=> [ + 'BootNewEnv' => [ { - 'timeout'=> 150, - 'type'=>'Classical', - 'retries'=> 0, - },{ - 'timeout'=> 120, - 'type'=>'HardReboot', - 'retries'=> 1 + 'timeout' => 150, + 'type' => 'Classical', + 'retries' => 0, + }, { + 'timeout' => 120, + 'type' => 'HardReboot', + 'retries' => 1 } ], } @@ -974,93 +974,93 @@ module Configuration } config.merge!(add) end - #end of ugly + # end of ugly @name = cluster cp = Parser.new(config) - cp.parse('partitioning',true) do - @block_device = cp.value('block_device',String,nil,Pathname) - @tmp_part = cp.value('tmp_label',String,'TMP') - @swap_part = cp.value('swap_label',String,'SWAP') - @deploy_part = cp.value('deploy_label',String,'DEPLOY') + cp.parse('partitioning', true) do + @block_device = cp.value('block_device', String, nil, Pathname) + @tmp_part = cp.value('tmp_label', String, 'TMP') + @swap_part = cp.value('swap_label', String, 'SWAP') + @deploy_part = cp.value('deploy_label', String, 'DEPLOY') - @swap_disabled = cp.value('disable_swap',[TrueClass,FalseClass],false) - @partitioning_script = cp.value('script',String,nil, + @swap_disabled = cp.value('disable_swap', [TrueClass, FalseClass], false) + @partitioning_script = cp.value('script', String, nil, { :type => 'file', :readable => true, :prefix => Config.dir() }) - @formating_script = cp.value('formating_script',String,'', + @formating_script = cp.value('formating_script', String, '', { :type => 'file', :readable => true, :prefix => Config.dir() }) - @disk_path = cp.value('disk_path',Hash,{}) + @disk_path = cp.value('disk_path', Hash, {}) end cp.parse('kexec', true) do - @kexec_server_precmd = cp.value('server_precmd',String,"") - @kexec_script = cp.value('script',String,nil, + @kexec_server_precmd = cp.value('server_precmd', String, "") + @kexec_script = cp.value('script', String, nil, { :type => 'file', :readable => true, :prefix => Config.dir() }) end - cp.parse('trusted_deployment',false) do - @trusted_deployment_user = cp.value('user',String,"") - @trusted_deployment_partition = cp.value('partition',String,"") + cp.parse('trusted_deployment', false) do + @trusted_deployment_user = cp.value('user', String, "") + @trusted_deployment_partition = cp.value('partition', String, "") @trusted_envs = [] cp.parse('envs', false, Array) do |info| unless info[:empty] - n = cp.value('name',String,nil) - u = cp.value('user',String,nil) - v = cp.value('version',String,"") + n = cp.value('name', String, nil) + u = cp.value('user', String, nil) + v = cp.value('version', String, "") @trusted_envs << {name:n, user: u, version: v} end end end - cp.parse('arch',true) do - @default_arch = cp.value('default',String,nil,@archs_list) - @supported_arch = cp.value('supported',String,nil).split(',').collect{ |v| v.strip }.uniq + cp.parse('arch', true) do + @default_arch = cp.value('default', String, nil, @archs_list) + @supported_arch = cp.value('supported', String, nil).split(',').collect{ |v| v.strip }.uniq raise ArgumentError.new("arch/supported must contain arch/default") unless @supported_arch.include?(@default_arch) unknown_arch = @supported_arch - @archs_list raise ArgumentError.new("Unknown arch #{unknown_arch.join(',')} in arch/supported") unless unknown_arch.empty? end - cp.parse('boot',true) do - @sleep_time_before_ping = cp.value('sleep_time_before_ping',Integer,20) - @bootloader_script = cp.value('install_bootloader',String,nil, + cp.parse('boot', true) do + @sleep_time_before_ping = cp.value('sleep_time_before_ping', Integer, 20) + @bootloader_script = cp.value('install_bootloader', String, nil, { :type => 'file', :readable => true, :prefix => Config.dir() }) - cp.parse('kernels',true) do + cp.parse('kernels', true) do cp.parse('user') do - @kernel_params = cp.value('params',String,'') + @kernel_params = cp.value('params', String, '') end - cp.parse('deploy',true) do - @deploy_kernel = cp.value('vmlinuz',String) - @deploy_initrd = cp.value('initrd',String) - @deploy_kernel_args = cp.value('params',String,'') + cp.parse('deploy', true) do + @deploy_kernel = cp.value('vmlinuz', String) + @deploy_initrd = cp.value('initrd', String) + @deploy_kernel_args = cp.value('params', String, '') @drivers = cp.value( - 'drivers',String,'' + 'drivers', String, '' ).split(',').collect{ |v| v.strip } @deploy_supported_fs = cp.value( - 'supported_fs',String,'ext2, ext3, ext4, vfat' + 'supported_fs', String, 'ext2, ext3, ext4, vfat' ).split(',').collect{ |v| v.strip } end cp.parse('nfsroot') do - @nfsroot_kernel = cp.value('vmlinuz',String,'') - @nfsroot_params = cp.value('params',String,'') + @nfsroot_kernel = cp.value('vmlinuz', String, '') + @nfsroot_params = cp.value('params', String, '') end end end - cp.parse('remoteops',true) do |remoteops_info| - @level_name = cp.value('level_name',Array,['soft','hard','very_hard']) - level_symbols = [:soft,:hard,:very_hard] + cp.parse('remoteops', true) do |remoteops_info| + @level_name = cp.value('level_name', Array, ['soft', 'hard', 'very_hard']) + level_symbols = [:soft, :hard, :very_hard] - [:power_off,:power_on,:reboot].each do |symb| - @cmd_ext[symb]=handle_cmd_priority(cp.value(symb.to_s,Array,[]),remoteops_info[:path],cp,cluster) - 0.upto(level_symbols.length-1) do |idx| - self.instance_variable_set("@cmd_#{symb}_#{level_symbols[idx]}".to_sym,@cmd_ext[symb][idx]) + [:power_off, :power_on, :reboot].each do |symb| + @cmd_ext[symb] = handle_cmd_priority(cp.value(symb.to_s, Array, []), remoteops_info[:path], cp, cluster) + 0.upto(level_symbols.length - 1) do |idx| + self.instance_variable_set("@cmd_#{symb}_#{level_symbols[idx]}".to_sym, @cmd_ext[symb][idx]) end end - @cmd_ext[:power_status] = handle_cmd_priority(cp.value('power_status',Array,[]),remoteops_info[:path],cp,nil,1) + @cmd_ext[:power_status] = handle_cmd_priority(cp.value('power_status', Array, []), remoteops_info[:path], cp, nil, 1) @cmd_power_status = @cmd_ext[:power_status][0] - @cmd_ext[:console] = handle_cmd_priority(cp.value('console',Array,[]),remoteops_info[:path],cp,nil,1) + @cmd_ext[:console] = handle_cmd_priority(cp.value('console', Array, []), remoteops_info[:path], cp, nil, 1) @cmd_console = @cmd_ext[:console][0] end @@ -1068,24 +1068,24 @@ module Configuration cp.parse('localops') do |info| cp.parse('broadcastenv') do unless info[:empty] - @cmd_sendenv = cp.value('cmd',String,'',{ + @cmd_sendenv = cp.value('cmd', String, '', { :type => 'file', :command => true, :readable => true, :executable => true }) @cmd_sendenv = nil if @cmd_sendenv.empty? - @decompress_environment = !(cp.value('decompress',[TrueClass,FalseClass],true)) + @decompress_environment = !(cp.value('decompress', [TrueClass, FalseClass], true)) end end end cp.parse('preinstall') do |info| - cp.parse('files',false,Array) do + cp.parse('files', false, Array) do unless info[:empty] @admin_pre_install = Array.new if info[:iter] == 0 tmp = {} - tmp['file'] = cp.value('file',String,nil,File) - tmp['kind'] = cp.value('format',String,nil,['tgz','tbz2','txz','tzstd']) - tmp['script'] = cp.value('script',String,nil,Pathname) + tmp['file'] = cp.value('file', String, nil, File) + tmp['kind'] = cp.value('format', String, nil, ['tgz', 'tbz2', 'txz', 'tzstd']) + tmp['script'] = cp.value('script', String, nil, Pathname) @admin_pre_install.push(tmp) end @@ -1093,50 +1093,50 @@ module Configuration end cp.parse('postinstall') do |info| - cp.parse('files',false,Array) do + cp.parse('files', false, Array) do unless info[:empty] @admin_post_install = Array.new if info[:iter] == 0 tmp = {} - tmp['file'] = cp.value('file',String,nil,File) - tmp['kind'] = cp.value('format',String,nil,['tgz','tbz2','txz','tzstd']) - tmp['script'] = cp.value('script',String,nil,Pathname) + tmp['file'] = cp.value('file', String, nil, File) + tmp['kind'] = cp.value('format', String, nil, ['tgz', 'tbz2', 'txz', 'tzstd']) + tmp['script'] = cp.value('script', String, nil, Pathname) @admin_post_install.push(tmp) end end end - cp.parse('automata',true) do - cp.parse('macrosteps',true) do + cp.parse('automata', true) do + cp.parse('macrosteps', true) do microsteps = Microstep.instance_methods.select{ |name| name =~ /^ms_/ } - microsteps.collect!{ |name| name.to_s.sub(/^ms_/,'') } + microsteps.collect!{ |name| name.to_s.sub(/^ms_/, '') } - treatcustom = Proc.new do |info,microname,ret| + treatcustom = Proc.new do |info, microname, ret| unless info[:empty] op = { - :name => "#{microname}-#{cp.value('name',String)}", - :action => cp.value('action',String,nil,['exec','send','run']) + :name => "#{microname}-#{cp.value('name', String)}", + :action => cp.value('action', String, nil, ['exec', 'send', 'run']) } case op[:action] when 'exec' - op[:command] = cp.value('command',String) - op[:timeout] = cp.value('timeout', Integer,0) - op[:retries] = cp.value('retries', Integer,0) - op[:scattering] = cp.value('scattering',String,:tree) + op[:command] = cp.value('command', String) + op[:timeout] = cp.value('timeout', Integer, 0) + op[:retries] = cp.value('retries', Integer, 0) + op[:scattering] = cp.value('scattering', String, :tree) when 'send' - op[:file] = cp.value('file',String,nil, + op[:file] = cp.value('file', String, nil, { :type => 'file', :readable => true, :prefix => Config.dir() }) - op[:destination] = cp.value('destination',String) - op[:timeout] = cp.value('timeout', Integer,0) - op[:retries] = cp.value('retries', Integer,0) - op[:scattering] = cp.value('scattering',String,:tree) + op[:destination] = cp.value('destination', String) + op[:timeout] = cp.value('timeout', Integer, 0) + op[:retries] = cp.value('retries', Integer, 0) + op[:scattering] = cp.value('scattering', String, :tree) when 'run' - op[:file] = cp.value('file',String,nil, + op[:file] = cp.value('file', String, nil, { :type => 'file', :readable => true, :prefix => Config.dir() }) - op[:params] = cp.value('params',String,'') - op[:timeout] = cp.value('timeout', Integer,0) - op[:retries] = cp.value('retries', Integer,0) - op[:scattering] = cp.value('scattering',String,:tree) + op[:params] = cp.value('params', String, '') + op[:timeout] = cp.value('timeout', Integer, 0) + op[:retries] = cp.value('retries', Integer, 0) + op[:scattering] = cp.value('scattering', String, :tree) end op[:action] = op[:action].to_sym ret << op @@ -1147,43 +1147,43 @@ module Configuration insts = ObjectSpace.each_object(Class).select { |klass| klass.ancestors.include?(Macrostep.const_get("Deploy#{macroname}")) } unless macroname.empty? - insts.collect!{ |klass| klass.name.sub(/^Kadeploy::Macrostep::Deploy#{macroname}/,'') } + insts.collect!{ |klass| klass.name.sub(/^Kadeploy::Macrostep::Deploy#{macroname}/, '') } macroinsts = [] - cp.parse(macroname,true,Array) do |info| + cp.parse(macroname, true, Array) do |info| unless info[:empty] microconf = nil - cp.parse('microsteps',false,Array) do |info2| + cp.parse('microsteps', false, Array) do |info2| unless info2[:empty] microconf = {} unless microconf - microname = cp.value('name',String,nil,microsteps) + microname = cp.value('name', String, nil, microsteps) custom_sub = [] - cp.parse('substitute',false,Array) do |info3| - treatcustom.call(info3,microname,custom_sub) + cp.parse('substitute', false, Array) do |info3| + treatcustom.call(info3, microname, custom_sub) end custom_sub = nil if custom_sub.empty? custom_pre = [] - cp.parse('pre-ops',false,Array) do |info3| - treatcustom.call(info3,microname,custom_pre) + cp.parse('pre-ops', false, Array) do |info3| + treatcustom.call(info3, microname, custom_pre) end custom_pre = nil if custom_pre.empty? custom_post = [] - cp.parse('post-ops',false,Array) do |info3| - treatcustom.call(info3,microname,custom_post) + cp.parse('post-ops', false, Array) do |info3| + treatcustom.call(info3, microname, custom_post) end custom_post = nil if custom_post.empty? microconf[microname.to_sym] = { - :timeout => cp.value('timeout', Integer,0), + :timeout => cp.value('timeout', Integer, 0), :raisable => cp.value( - 'raisable',[TrueClass,FalseClass],true + 'raisable', [TrueClass, FalseClass], true ), :breakpoint => cp.value( - 'breakpoint',[TrueClass,FalseClass],false + 'breakpoint', [TrueClass, FalseClass], false ), - :retries => cp.value('retries', Integer,0), + :retries => cp.value('retries', Integer, 0), :custom_sub => custom_sub, :custom_pre => custom_pre, :custom_post => custom_post, @@ -1192,16 +1192,16 @@ module Configuration end macroinsts << [ - macroname + cp.value('type',String,nil,insts), - cp.value('retries', Integer,0), - cp.value('timeout', Integer,0), - cp.value('raisable',[TrueClass,FalseClass],true), - cp.value('breakpoint',[TrueClass,FalseClass],false), + macroname + cp.value('type', String, nil, insts), + cp.value('retries', Integer, 0), + cp.value('timeout', Integer, 0), + cp.value('raisable', [TrueClass, FalseClass], true), + cp.value('breakpoint', [TrueClass, FalseClass], false), microconf, ] end end - @workflow_steps << MacroStep.new(macroname,macroinsts) + @workflow_steps << MacroStep.new(macroname, macroinsts) end treatmacro.call('SetDeploymentEnv') @@ -1211,14 +1211,14 @@ module Configuration end cp.parse('timeouts') do |info| - code = cp.value('reboot',Object,120, + code = cp.value('reboot', Object, 120, { :type => 'code', :prefix => 'n=1;' } ).to_s begin code.to_i rescue raise ArgumentError.new(Parser.errmsg( - info[:path],"Expression evaluation is not an integer" + info[:path], "Expression evaluation is not an integer" ) ) end @@ -1231,7 +1231,7 @@ module Configuration ].include?(macroinst[0]) and tmptime > macroinst[2] then raise ArgumentError.new(Parser.errmsg( - info[:path],"Global reboot timeout is greater than the timeout of the macrostep #{macroinst[0]}" + info[:path], "Global reboot timeout is greater than the timeout of the macrostep #{macroinst[0]}" ) ) end @@ -1243,31 +1243,31 @@ module Configuration ].include?(macroinst[0]) and tmptime > macroinst[2] then raise ArgumentError.new(Parser.errmsg( - info[:path],"Global reboot timeout is greater than the timeout of the macrostep #{macroinst[0]}" + info[:path], "Global reboot timeout is greater than the timeout of the macrostep #{macroinst[0]}" ) ) end end @timeout_reboot_classical = code - code = cp.value('kexec',Object,60, + code = cp.value('kexec', Object, 60, { :type => 'code', :prefix => 'n=1;' } ).to_s begin code.to_i rescue raise ArgumentError.new(Parser.errmsg( - info[:path],"Expression evaluation is not an integer" + info[:path], "Expression evaluation is not an integer" ) ) end tmptime = eval(code) @workflow_steps[0].to_a.each do |macroinst| - if ['SetDeploymentEnvKexec','SetDeploymentEnvTrusted'].include?(macroinst[0]) && tmptime > macroinst[2] + if ['SetDeploymentEnvKexec', 'SetDeploymentEnvTrusted'].include?(macroinst[0]) && tmptime > macroinst[2] then raise ArgumentError.new(Parser.errmsg( - info[:path],"Global kexec timeout is greater than the timeout of the macrostep #{macroinst[0]}" + info[:path], "Global kexec timeout is greater than the timeout of the macrostep #{macroinst[0]}" ) ) end @@ -1276,7 +1276,7 @@ module Configuration if macroinst[0] == 'BootNewEnvKexec' && tmptime > macroinst[2] then raise ArgumentError.new(Parser.errmsg( - info[:path],"Global kexec timeout is greater than the timeout of the macrostep #{macroinst[0]}" + info[:path], "Global kexec timeout is greater than the timeout of the macrostep #{macroinst[0]}" ) ) end @@ -1286,21 +1286,21 @@ module Configuration cp.parse('kexec') do @kexec_repository = cp.value( - 'repository',String,'/dev/shm/kexec_repository',Pathname + 'repository', String, '/dev/shm/kexec_repository', Pathname ) end cp.parse('pxe') do cp.parse('headers') do - @pxe_header[:chain] = cp.value('dhcp',String,'') - @pxe_header[:local] = cp.value('localboot',String,'') - @pxe_header[:network] = cp.value('networkboot',String,'') + @pxe_header[:chain] = cp.value('dhcp', String, '') + @pxe_header[:local] = cp.value('localboot', String, '') + @pxe_header[:network] = cp.value('networkboot', String, '') end end cp.parse('hooks') do @use_ip_to_deploy = cp.value( - 'use_ip_to_deploy',[TrueClass,FalseClass],false + 'use_ip_to_deploy', [TrueClass, FalseClass], false ) end @@ -1314,7 +1314,7 @@ module Configuration $stderr.puts "Warning(#{configfile}) Unused field '#{path}'" end - #self.instance_variables.each{|v| self.class.send(:attr_accessor,v)} + # self.instance_variables.each{|v| self.class.send(:attr_accessor,v)} return true end @@ -1334,7 +1334,7 @@ module Configuration @group_of_nodes[command].push(line.strip.split(",")) end else - raise ArgumentError.new(Parser.errmsg(info[:path],"Unable to read group of node '#{file}'")) + raise ArgumentError.new(Parser.errmsg(info[:path], "Unable to read group of node '#{file}'")) end end end @@ -1369,11 +1369,11 @@ module Configuration return false end - config.each_pair do |nodename,commands| + config.each_pair do |nodename, commands| node = common.nodes.get_node_by_host(nodename) if (node != nil) then - commands.each_pair do |kind,val| + commands.each_pair do |kind, val| if (node.cmd.instance_variable_defined?("@#{kind}")) then node.cmd.instance_variable_set("@#{kind}", val) else @@ -1402,10 +1402,10 @@ module Configuration end end - def self.parse_custom_operation(cp,microname,opts={}) + def self.parse_custom_operation(cp, microname, opts = {}) ret = { - :name => "#{microname}-#{cp.value('name',String)}", - :action => cp.value('action',String,nil,['exec','send','run']) + :name => "#{microname}-#{cp.value('name', String)}", + :action => cp.value('action', String, nil, ['exec', 'send', 'run']) } fileopts = nil if opts[:check_files] @@ -1414,85 +1414,85 @@ module Configuration case ret[:action] when 'exec' - ret[:command] = cp.value('command',String) - ret[:timeout] = cp.value('timeout', Integer,0) - ret[:retries] = cp.value('retries', Integer,0) - ret[:scattering] = cp.value('scattering',String,:tree) + ret[:command] = cp.value('command', String) + ret[:timeout] = cp.value('timeout', Integer, 0) + ret[:retries] = cp.value('retries', Integer, 0) + ret[:scattering] = cp.value('scattering', String, :tree) when 'send' - ret[:file] = cp.value('file',String,nil,fileopts) - ret[:destination] = cp.value('destination',String) - ret[:timeout] = cp.value('timeout', Integer,0) - ret[:retries] = cp.value('retries', Integer,0) - ret[:scattering] = cp.value('scattering',String,:tree) + ret[:file] = cp.value('file', String, nil, fileopts) + ret[:destination] = cp.value('destination', String) + ret[:timeout] = cp.value('timeout', Integer, 0) + ret[:retries] = cp.value('retries', Integer, 0) + ret[:scattering] = cp.value('scattering', String, :tree) when 'run' - ret[:file] = cp.value('file',String,nil,fileopts) - ret[:params] = cp.value('params',String,'') - ret[:timeout] = cp.value('timeout', Integer,0) - ret[:retries] = cp.value('retries', Integer,0) - ret[:scattering] = cp.value('scattering',String,:tree) + ret[:file] = cp.value('file', String, nil, fileopts) + ret[:params] = cp.value('params', String, '') + ret[:timeout] = cp.value('timeout', Integer, 0) + ret[:retries] = cp.value('retries', Integer, 0) + ret[:scattering] = cp.value('scattering', String, :tree) end ret[:action] = ret[:action].to_sym ret end - def self.parse_custom_operations(cp,microname,opts={}) - ret = { :sub=>[], :pre=>[], :post=>[], :over=>nil } + def self.parse_custom_operations(cp, microname, opts = {}) + ret = { :sub => [], :pre => [], :post => [], :over => nil } - cp.parse('substitute',false,Array) do |info| + cp.parse('substitute', false, Array) do |info| unless info[:empty] - val = parse_custom_operation(cp,microname,opts) + val = parse_custom_operation(cp, microname, opts) val[:target] = :sub if opts[:set_target] ret[:sub] << val end end ret[:sub] = nil if ret[:sub].empty? - cp.parse('pre-ops',false,Array) do |info| + cp.parse('pre-ops', false, Array) do |info| unless info[:empty] - val = parse_custom_operation(cp,microname,opts) + val = parse_custom_operation(cp, microname, opts) val[:target] = :'pre-ops' if opts[:set_target] ret[:pre] << val end end ret[:pre] = nil if ret[:pre].empty? - cp.parse('post-ops',false,Array) do |info| + cp.parse('post-ops', false, Array) do |info| unless info[:empty] - val = parse_custom_operation(cp,microname,opts) + val = parse_custom_operation(cp, microname, opts) val[:target] = :'post-ops' if opts[:set_target] ret[:post] << val end end ret[:post] = nil if ret[:post].empty? - ret[:over] = cp.value('override',[TrueClass,FalseClass],false) + ret[:over] = cp.value('override', [TrueClass, FalseClass], false) ret end - def self.parse_custom_macrostep(cp,macrobase,_opts={}) + def self.parse_custom_macrostep(cp, macrobase, _opts = {}) ret = [] - cp.parse(macrobase,true,Array) do - name = cp.value('name',String) + cp.parse(macrobase, true, Array) do + name = cp.value('name', String) raise ArgumentError.new("Unknown macrostep name '#{name}'") \ - unless check_macrostep_instance(name,:deploy) + unless check_macrostep_instance(name, :deploy) ret << [ name, - cp.value('retries', Integer,0), - cp.value('timeout', Integer,0), + cp.value('retries', Integer, 0), + cp.value('timeout', Integer, 0), ] end ret end - def self.parse_custom_macrosteps(cp,opts={}) + def self.parse_custom_macrosteps(cp, opts = {}) ret = [] parse_macro = Proc.new do |macrobase| - ret << MacroStep.new(macrobase, parse_custom_macrostep(cp,macrobase,opts)) + ret << MacroStep.new(macrobase, parse_custom_macrostep(cp, macrobase, opts)) end parse_macro.call('SetDeploymentEnv') @@ -1502,18 +1502,18 @@ module Configuration ret end - def self.check_macrostep_interface(name,kind) + def self.check_macrostep_interface(name, kind) kind = kind.to_s.capitalize klassbase = ::Kadeploy::Macrostep.const_get(kind) macrointerfaces = ObjectSpace.each_object(Class).select { |klass| klass.superclass == klassbase } - macrointerfaces.collect!{ |klass| klass.name.split('::').last.gsub(/^#{kind}/,'') } + macrointerfaces.collect!{ |klass| klass.name.split('::').last.gsub(/^#{kind}/, '') } return macrointerfaces.include?(name) end - def self.check_macrostep_instance(name,kind) + def self.check_macrostep_instance(name, kind) # Gathering a list of availables macrosteps klassbase = ::Kadeploy::Macrostep.const_get(kind.to_s.capitalize) macrosteps = ObjectSpace.each_object(Class).select { |klass| @@ -1540,7 +1540,7 @@ module Configuration microsteps = Microstep.instance_methods.select{ |microname| microname =~ /^ms_/ } - microsteps.collect!{ |microname| microname.to_s.sub(/^ms_/,'') } + microsteps.collect!{ |microname| microname.to_s.sub(/^ms_/, '') } return microsteps.include?(name) end diff --git a/lib/kadeploy3/server/csv.rb b/lib/kadeploy3/server/csv.rb index 729f93545b215a679b9be95bcd70c976f73d7847..c99ecf42b8162a8e712b4f274b74c3b3e41226a1 100644 --- a/lib/kadeploy3/server/csv.rb +++ b/lib/kadeploy3/server/csv.rb @@ -5,7 +5,7 @@ module Kadeploy class CompressedCSV attr_reader :file, :gz, :algorithm - def initialize(buffer_size=100000) + def initialize(buffer_size = 100000) @filepath = Tempfile.new('csv') @gz = Zlib::GzipWriter.new(@filepath) @file = nil @@ -18,7 +18,7 @@ class CompressedCSV @gz.write(@buffer) if !@gz.closed? and !@buffer.empty? @buffer.clear @gz.close unless @gz.closed? - @file = File.open(@filepath,'r+') + @file = File.open(@filepath, 'r+') end def closed?() diff --git a/lib/kadeploy3/server/db.rb b/lib/kadeploy3/server/db.rb index cc6e20b2c680bcc6573e1b8c50e8456909033351..c6d9c994adf409fb4aade0b0021fff5bb119d61c 100644 --- a/lib/kadeploy3/server/db.rb +++ b/lib/kadeploy3/server/db.rb @@ -4,7 +4,7 @@ require 'timeout' module Kadeploy module Database - def self.where_nodelist(nodes,field='node') + def self.where_nodelist(nodes, field = 'node') ["(#{(["(#{field} = ? )"] * nodes.size).join(' OR ')})", nodes] if nodes and !nodes.empty? end @@ -29,7 +29,7 @@ module Database class Db attr_accessor :dbh - #Constructor of Db + # Constructor of Db # # Arguments # * nothing @@ -193,23 +193,23 @@ module Database content = [] res.each do |r| rescontent = [] - r.each do |_,row| + r.each do |_, row| rescontent << row end content << rescontent end end - result = DbResult.new(fields,content,st.affected_rows) + result = DbResult.new(fields, content, st.affected_rows) st.close rescue Mysql2::Error => e - $stderr.puts "MySQL query: #{query.gsub(/\s+/," ").strip}" if query + $stderr.puts "MySQL query: #{query.gsub(/\s+/, " ").strip}" if query $stderr.puts "MySQL args: #{args.inspect}" if args $stderr.puts "MySQL error (code): #{e.errno}" $stderr.puts "MySQL error (message): #{e.error}" $stderr.puts e.backtrace - raise KadeployError.new(APIError::DATABASE_ERROR,nil, - "MySQL error ##{e.errno}: #{e.error.gsub(/\s+/," ").strip}") + raise KadeployError.new(APIError::DATABASE_ERROR, nil, + "MySQL error ##{e.errno}: #{e.error.gsub(/\s+/, " ").strip}") end return result end diff --git a/lib/kadeploy3/server/debug.rb b/lib/kadeploy3/server/debug.rb index 22226f7375652f57f6810f5fbfbe704c4acf96ad..0d4d31256bdbeb8f98dcebb21a3bd18c11322cc0 100644 --- a/lib/kadeploy3/server/debug.rb +++ b/lib/kadeploy3/server/debug.rb @@ -1,7 +1,7 @@ module Kadeploy module Debug - def self.prefix(clid,nsid=nil) + def self.prefix(clid, nsid = nil) ns = nsid if !nsid.nil? and nsid > 0 if !clid.nil? and !clid.empty? @@ -19,7 +19,7 @@ module Debug class FileOutput attr_accessor :prefix - def initialize(file,verbose_level=0,prefix='') + def initialize(file, verbose_level = 0, prefix = '') @file = file @verbose_level = verbose_level @prefix = prefix @@ -33,7 +33,7 @@ module Debug @lock = nil end - def write(msg,lvl=-1) + def write(msg, lvl = -1) if lvl <= @verbose_level @lock.synchronize do f = File.new(@file, File::CREAT | File::APPEND | File::WRONLY, 0644) @@ -60,7 +60,7 @@ module Debug # * debug: boolean user to know if the extra debug must be used or not # Output # * nothing - def initialize(verbose_level, file = nil, cluster_id=nil) + def initialize(verbose_level, file = nil, cluster_id = nil) @verbose_level = verbose_level @output = '' @file = file @@ -84,11 +84,11 @@ module Debug # * nodeset: print with this NodeSet id # Output # * prints the message on the server and on the client - def push(lvl, msg, nsid=nil, print_prefix = true) + def push(lvl, msg, nsid = nil, print_prefix = true) @lock.synchronize do - msg = "#{Debug.prefix(@cluster_id,nsid)}#{msg}" if print_prefix + msg = "#{Debug.prefix(@cluster_id, nsid)}#{msg}" if print_prefix @output << Debug.format("#{msg}\n") if lvl <= @verbose_level - @file.write(msg,lvl) if @file + @file.write(msg, lvl) if @file end end @@ -124,7 +124,7 @@ module Debug @lock = nil end - def push(cmd, nodeset, stdout=nil, stderr=nil, status=nil) + def push(cmd, nodeset, stdout = nil, stderr = nil, status = nil) return unless nodeset out = nil @@ -162,7 +162,7 @@ module Debug end end - def pop(node=nil) + def pop(node = nil) @lock.synchronize do if node ret = @debug[node] @@ -207,7 +207,7 @@ module Debug # * anonymous_env: anonymous environment or not # Output # * nothing - def initialize(nodes, user, wid, start, env, anonymous_env, file=nil, db=nil) + def initialize(nodes, user, wid, start, env, anonymous_env, file = nil, db = nil) @nodes = {} nodes.each do |node| @nodes[node] = create_node_infos(user, wid, start, env, anonymous_env) @@ -249,7 +249,7 @@ module Debug "step1_duration" => 0, "step2_duration" => 0, "step3_duration" => 0, - "env" => env||'', + "env" => env || '', "anonymous_env" => anonymous_env, "md5" => String.new, "success" => false, @@ -283,11 +283,11 @@ module Debug # * node_set: Array of nodes # Output # * nothing - def error(nodeset,states) + def error(nodeset, states) nodeset.set.each do |node| state = states.get(node.hostname) node.last_cmd_stderr = "#{state[:macro]}-#{state[:micro]}: #{node.last_cmd_stderr}" - states.set(node.hostname,nil,nil,'ko',node.last_cmd_stderr) + states.set(node.hostname, nil, nil, 'ko', node.last_cmd_stderr) @nodes[node.hostname]["error"] = node.last_cmd_stderr end end @@ -389,9 +389,9 @@ module Debug out = [] @nodes.each_pair do |hostname, node_infos| str = node_infos["wid"].to_s + "," + hostname + "," + node_infos["user"] + "," - str += node_infos["step1"] + "," + node_infos["step2"] + "," + node_infos["step3"] + "," + str += node_infos["step1"] + "," + node_infos["step2"] + "," + node_infos["step3"] + "," str += node_infos["timeout_step1"].to_s + "," + node_infos["timeout_step2"].to_s + "," + node_infos["timeout_step3"].to_s + "," - str += node_infos["retry_step1"].to_s + "," + node_infos["retry_step2"].to_s + "," + node_infos["retry_step3"].to_s + "," + str += node_infos["retry_step1"].to_s + "," + node_infos["retry_step2"].to_s + "," + node_infos["retry_step3"].to_s + "," str += node_infos["start"].to_i.to_s + "," str += node_infos["step1_duration"].to_s + "," + node_infos["step2_duration"].to_s + "," + node_infos["step3_duration"].to_s + "," str += node_infos["env"] + "," + node_infos["anonymous_env"].to_s + "," + node_infos["md5"] + "," @@ -405,17 +405,17 @@ end module Printer - def debug(level,msg,nodesetid=nil,_opts={}) + def debug(level, msg, nodesetid = nil, _opts = {}) return unless output() - output().push(level,msg,nodesetid) + output().push(level, msg, nodesetid) end - def log(operation,value=nil,nodeset=nil,opts={}) + def log(operation, value = nil, nodeset = nil, opts = {}) return unless logger() if opts[:increment] logger().increment(operation, nodeset) else - logger().set(operation,value,nodeset) + logger().set(operation, value, nodeset) end end end diff --git a/lib/kadeploy3/server/dump.rb b/lib/kadeploy3/server/dump.rb index c5496719daef4ed1577a303fc381193414c690b0..bd4ee3181779ce0750072217b3a189f3309ac5b3 100644 --- a/lib/kadeploy3/server/dump.rb +++ b/lib/kadeploy3/server/dump.rb @@ -8,7 +8,7 @@ class Mutex end module Kadeploy - def self.dump(width=80) + def self.dump(width = 80) file = STDERR GC.start @@ -17,25 +17,25 @@ module Kadeploy objects[Object] = total file.puts("--- Objects by number ---") - PP.pp(Hash[objects.select{|_,v| v > 4}.sort_by{|_,v| -v}],file,width) + PP.pp(Hash[objects.select{|_, v| v > 4}.sort_by{|_, v| -v}], file, width) file.puts("\n--- Objects by name ---") - PP.pp(Hash[objects.sort_by{|k,_| k.name || ''}],file,width) + PP.pp(Hash[objects.sort_by{|k, _| k.name || ''}], file, width) objects = nil if ObjectSpace.respond_to?(:count_objects) file.puts("\n--- Raw objects ---") - PP.pp(ObjectSpace.count_objects,file,width) + PP.pp(ObjectSpace.count_objects, file, width) end if GC.respond_to?(:stat) file.puts("\n--- GC stats ---") - PP.pp(GC.stat,file,width) + PP.pp(GC.stat, file, width) end if $kadeploy file.puts("\n--- Kadeploy structures ---") - PP.pp($kadeploy,file,width) + PP.pp($kadeploy, file, width) end file.flush diff --git a/lib/kadeploy3/server/grabfile.rb b/lib/kadeploy3/server/grabfile.rb index 58ca3043b64310c0398e397ee08c50516d06c479..18d86bc1f0baf1f9db1aeb0f70e30addf622f3ee 100644 --- a/lib/kadeploy3/server/grabfile.rb +++ b/lib/kadeploy3/server/grabfile.rb @@ -11,7 +11,7 @@ class GrabFile attr_accessor :files attr_reader :output - def initialize(cache, files, lock, output, mode=0640, client = nil) + def initialize(cache, files, lock, output, mode = 0640, client = nil) @cache = cache @files = files @lock = lock @@ -20,15 +20,15 @@ class GrabFile @client = client end - def error(errno,msg) + def error(errno, msg) # If something is going wrong, the will be cleaned by kaworkflow - raise KadeployError.new(errno,nil,msg) + raise KadeployError.new(errno, nil, msg) end - def grab(origin_uri,version,user,priority,tag,wid,checksum=nil,opts={}) + def grab(origin_uri, version, user, priority, tag, wid, checksum = nil, opts = {}) return nil if !origin_uri or origin_uri.empty? cf = nil - fetcher = FetchFile[origin_uri,@client] + fetcher = FetchFile[origin_uri, @client] unless @cache error(APIError::CACHE_ERROR, @@ -43,20 +43,20 @@ class GrabFile if opts[:maxsize] and fetcher.size > opts[:maxsize] error(APIError::INVALID_FILE, "The #{tag} file '#{origin_uri}' is too big "\ - "(#{opts[:maxsize]/(1024*1024)} MB is the max allowed size)" + "(#{opts[:maxsize] / (1024 * 1024)} MB is the max allowed size)" ) end - fmtime = checksum ? nil : fetcher.mtime #does not use the mtime if checksum is provided - fchecksum = checksum ? checksum : nil #use checksum if it provided. + fmtime = checksum ? nil : fetcher.mtime # does not use the mtime if checksum is provided + fchecksum = checksum ? checksum : nil # use checksum if it provided. cf = @cache.cache( - origin_uri,version,user,priority,tag,fetcher.size, - wid,opts[:file],fchecksum,fmtime - ) do |source,destination,_size,md5| + origin_uri, version, user, priority, tag, fetcher.size, + wid, opts[:file], fchecksum, fmtime + ) do |source, destination, _size, md5| if md5 && fetcher.checksum && md5 != fetcher.checksum # fetcher provides the checksum - error(APIError::INVALID_FILE,"Checksum of the file '#{source}' does not match "\ + error(APIError::INVALID_FILE, "Checksum of the file '#{source}' does not match "\ "(an update is necessary)") end @@ -64,9 +64,9 @@ class GrabFile debug(3, "Grab the #{tag} file #{source}") fetcher.grab(destination) - #fetcher does not provides checksum + # fetcher does not provides checksum if md5 && fetcher.checksum.nil? && md5 != Digest::MD5.file(destination).hexdigest! - error(APIError::INVALID_FILE,"Checksum of the file '#{source}' does not match "\ + error(APIError::INVALID_FILE, "Checksum of the file '#{source}' does not match "\ "(an update is necessary)") end end @@ -78,11 +78,11 @@ class GrabFile cf end - def self.grab(gfm,context,path,prio,tag,opts={}) + def self.grab(gfm, context, path, prio, tag, opts = {}) file = nil begin return if !path or path.empty? - version,user = nil + version, user = nil if opts[:env] and opts[:env].recorded? version = opts[:env].cache_version user = opts[:env].user @@ -107,9 +107,9 @@ class GrabFile ) if file.is_a?(String) - path.gsub!(path,file) + path.gsub!(path, file) else - path.gsub!(path,file.file) + path.gsub!(path, file.file) end rescue KadeployError => ke ke.context = context @@ -119,32 +119,32 @@ class GrabFile file end - def self.grab_user_files(context,files,lock,kind) + def self.grab_user_files(context, files, lock, kind) # If something is going wrong, the will be cleaned by kaworkflow cexec = context[:execution] - gfm = self.new(context[:caches][:global],files[:global],lock, - context[:output],640,cexec.client) + gfm = self.new(context[:caches][:global], files[:global], lock, + context[:output], 640, cexec.client) env = cexec.environment envprio = nil envprio = (env.recorded? ? :db : :anon) if env # SSH key file - grab(gfm,context,cexec.key,:anon,'key') + grab(gfm, context, cexec.key, :anon, 'key') - #Grab tarball, Preinstall and Postinstall archive if only inside deploy kind + # Grab tarball, Preinstall and Postinstall archive if only inside deploy kind if kind == :deploy # Env tarball if env and (tmp = env.tarball) - grab(gfm,context,tmp['file'],envprio,'tarball', - :md5=>tmp['md5'], :env => env + grab(gfm, context, tmp['file'], envprio, 'tarball', + :md5 => tmp['md5'], :env => env ) end # Preinstall archive if env and (tmp = env.preinstall) - grab(gfm,context,tmp['file'],envprio,'preinstall', + grab(gfm, context, tmp['file'], envprio, 'preinstall', :md5 => tmp['md5'], :env => env, :maxsize => context[:common].max_preinstall_size ) @@ -153,7 +153,7 @@ class GrabFile # Postinstall archive if env and env.postinstall env.postinstall.each do |f| - grab(gfm,context,f['file'],envprio,'postinstall', + grab(gfm, context, f['file'], envprio, 'postinstall', :md5 => f['md5'], :env => env, :maxsize => context[:common].max_postinstall_size ) @@ -163,14 +163,14 @@ class GrabFile # Custom files if cexec.custom_operations - cexec.custom_operations[:operations].each_pair do |_macro,micros| + cexec.custom_operations[:operations].each_pair do |_macro, micros| micros.each_value do |entries| entries.each do |entry| if entry[:action] == :send entry[:filename] = File.basename(entry[:file].dup) - grab(gfm,context,entry[:file],:anon,'custom_file') + grab(gfm, context, entry[:file], :anon, 'custom_file') elsif entry[:action] == :run - grab(gfm,context,entry[:file],:anon,'custom_file') + grab(gfm, context, entry[:file], :anon, 'custom_file') end end end @@ -179,11 +179,11 @@ class GrabFile # Custom PXE files if cexec.pxe and cexec.pxe[:profile] and cexec.pxe[:files] and !cexec.pxe[:files].empty? - gfmk = self.new(context[:caches][:netboot],files[:netboot],lock, - context[:output],744, cexec.client) + gfmk = self.new(context[:caches][:netboot], files[:netboot], lock, + context[:output], 744, cexec.client) cexec.pxe[:files].each do |pxefile| - grab(gfmk,context,pxefile,:anon_keep,'pxe', + grab(gfmk, context, pxefile, :anon_keep, 'pxe', :file => File.join(context[:caches][:netboot].directory, ( NetBoot.custom_prefix( diff --git a/lib/kadeploy3/server/ident.rb b/lib/kadeploy3/server/ident.rb index 8f5edf794519c36a938fe592432dc4b5895e67fd..c24f52291c37b31d722b1f41ed9ceee5848345eb 100644 --- a/lib/kadeploy3/server/ident.rb +++ b/lib/kadeploy3/server/ident.rb @@ -6,13 +6,13 @@ class IdentError < RuntimeError end class Ident - def self.userid(sock,port) + def self.userid(sock, port) source = { :ip => sock[3], :port => sock[1] } ident = nil begin Timeout::timeout(10) do - sock = TCPSocket.new(source[:ip],113) + sock = TCPSocket.new(source[:ip], 113) sock.puts("#{source[:port]}, #{port}") ident = sock.gets.strip sock.close @@ -37,7 +37,7 @@ class Ident if res.upcase == 'USERID' user = usr else - raise IdentError, "Ident authentication failed: #{dom||res}" + raise IdentError, "Ident authentication failed: #{dom || res}" end else raise IdentError, 'Ident authentication failed, invalid answer from service' diff --git a/lib/kadeploy3/server/kaconsole.rb b/lib/kadeploy3/server/kaconsole.rb index e7794e706fdba35760bb8c8e061c3743c2ac472a..a4640abec15d5b196834ca1c7aee3719beff9592 100644 --- a/lib/kadeploy3/server/kaconsole.rb +++ b/lib/kadeploy3/server/kaconsole.rb @@ -30,7 +30,7 @@ module Kaconsole end def console_init_resources(cexec) - bind(:console,cexec.info,'error','/error') + bind(:console, cexec.info, 'error', '/error') end def console_free_exec_context(context) @@ -44,7 +44,7 @@ module Kaconsole context end - def console_prepare(params,operation,context) + def console_prepare(params, operation, context) context = console_init_exec_context(context) operation ||= :get @@ -53,12 +53,12 @@ module Kaconsole context.config = duplicate_config() parse_params(params) do |p| - context.node = p.parse('node',String,:type=>:node,:mandatory=>true) + context.node = p.parse('node', String, :type => :node, :mandatory => true) context.nodelist = [context.node.hostname.dup] end kaerror(APIError::INVALID_RIGHTS) \ - unless context.rights.granted?(context.user,context.node,'') + unless context.rights.granted?(context.user, context.node, '') when :get # do nithing when :delete @@ -76,20 +76,20 @@ module Kaconsole context end - def console_rights?(cexec,operation,names,wid=nil,*) + def console_rights?(cexec, operation, names, wid = nil, *) case operation when :create # do nothing when :get if wid and names - workflow_get(:console,wid) do |info| + workflow_get(:console, wid) do |info| return (cexec.almighty_users.include?(cexec.user) \ or cexec.user == info[:user]) end end when :delete return false unless wid - workflow_get(:console,wid) do |info| + workflow_get(:console, wid) do |info| return (cexec.almighty_users.include?(cexec.user) \ or cexec.user == info[:user]) end @@ -102,12 +102,12 @@ module Kaconsole def console_create(cexec) info = cexec.info - workflow_create(:console,info[:wid],info,:console) + workflow_create(:console, info[:wid], info, :console) console_init_resources(cexec) node = info[:node] cmd = node.cmd.console || cexec.config.clusters[node.cluster].cmd_console - cmd = Nodes::NodeCmd.generate(cmd.dup,node) + cmd = Nodes::NodeCmd.generate(cmd.dup, node) info[:sock] = TCPServer.new(0) @@ -121,7 +121,7 @@ module Kaconsole sock.syswrite("[Kaconsole] console already attached\n") sock.close else - info[:client] = console_client_run(sock,info[:attached],cmd) + info[:client] = console_client_run(sock, info[:attached], cmd) end end ensure @@ -133,7 +133,7 @@ module Kaconsole { :wid => info[:wid], :resources => info[:resources] } end - def console_get(cexec,wid=nil) + def console_get(cexec, wid = nil) get_status = Proc.new do |info| ret = { :id => info[:wid], @@ -149,18 +149,18 @@ module Kaconsole end else ret[:error] = true - #info[:done] = true + # info[:done] = true console_kill(info) console_free(info) end - ret[:time] = ((info[:end_time]||Time.now) - info[:start_time]).round(2) + ret[:time] = ((info[:end_time] || Time.now) - info[:start_time]).round(2) ret end if wid - workflow_get(:console,wid) do |info| + workflow_get(:console, wid) do |info| get_status.call(info) end else @@ -172,13 +172,13 @@ module Kaconsole end end - def console_delete(cexec,wid) - workflow_delete(:console,wid) do |info| - console_delete!(cexec,info) + def console_delete(cexec, wid) + workflow_delete(:console, wid) do |info| + console_delete!(cexec, info) end end - def console_delete!(_cexec,info) + def console_delete!(_cexec, info) console_kill(info) console_free(info) @@ -206,8 +206,8 @@ module Kaconsole end end - def console_get_error(_cexec,wid) - workflow_get(:console,wid) do |info| + def console_get_error(_cexec, wid) + workflow_get(:console, wid) do |info| break if info[:thread].alive? begin info[:thread].join @@ -219,7 +219,7 @@ module Kaconsole end end - def console_client_run(sock,lock,cmd) + def console_client_run(sock, lock, cmd) Thread.new do lock.synchronize do begin @@ -230,7 +230,7 @@ module Kaconsole sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) - PTY.spawn(cmd) do |r,w,pid| + PTY.spawn(cmd) do |r, w, pid| Thread.current[:pid] = pid done = false @@ -239,7 +239,7 @@ module Kaconsole buf = String.new until done do begin - r.sysread(4096,buf) + r.sysread(4096, buf) rescue Errno::EIO sock.close_write break @@ -253,7 +253,7 @@ module Kaconsole c = String.new until done do begin - sock.sysread(1,c) + sock.sysread(1, c) w.syswrite(c) rescue EOFError, Errno::ECONNRESET sock.close_read diff --git a/lib/kadeploy3/server/kadeploy.rb b/lib/kadeploy3/server/kadeploy.rb index d8faf6c6f35910f7c76d1a2c7fe43eeac1ced719..70c91e2bf9f54e4980f19740a6c5a619eb208546 100644 --- a/lib/kadeploy3/server/kadeploy.rb +++ b/lib/kadeploy3/server/kadeploy.rb @@ -4,7 +4,7 @@ module Kadeploy module Kadeploy def deploy_init_exec_context(ret) - ret = work_init_exec_context(:deploy,ret) + ret = work_init_exec_context(:deploy, ret) ret.reformat_tmp = nil ret.disable_kexec = false ret.disable_bootloader_install = false @@ -15,19 +15,19 @@ module Kadeploy ret end - def deploy_prepare(params,operation,context) - context = work_prepare(:deploy,params,operation,context) + def deploy_prepare(params, operation, context) + context = work_prepare(:deploy, params, operation, context) operation ||= :create # Check user - parse_params_default(params,context) + parse_params_default(params, context) case operation when :create parse_params(params) do |p| # Check Anonymous Environment if context.environment and !context.environment.id - env = p.parse('environment',Hash,:mandatory=>true) + env = p.parse('environment', Hash, :mandatory => true) env.delete('kind') unless context.environment.load_from_desc( @@ -36,7 +36,7 @@ module Kadeploy context.user, context.client ) then - kaerror(APIError::INVALID_ENVIRONMENT,'the environment cannot be loaded from the description you specified') + kaerror(APIError::INVALID_ENVIRONMENT, 'the environment cannot be loaded from the description you specified') end end @@ -44,50 +44,50 @@ module Kadeploy if context.environment.multipart part = context.environment.options['block_device'] + \ context.environment.options['deploy_part'] - kaerror(APIError::INVALID_RIGHTS,"deployment on partition #{part}") \ - unless context.rights.granted?(context.user,nodes,part) + kaerror(APIError::INVALID_RIGHTS, "deployment on partition #{part}") \ + unless context.rights.granted?(context.user, nodes, part) end # Check rights on the deploy partition on nodes by cluster # TODO: use context.block_device and context.deploy_part context.nodes.group_by_cluster.each_pair do |cluster, nodes| part = ( - p.parse('block_device',String, - :default=>context.config.clusters[cluster].block_device) \ - + '/' + p.parse('deploy_partition',String,:emptiable=>true, - :default=>context.config.clusters[cluster].deploy_part) + p.parse('block_device', String, + :default => context.config.clusters[cluster].block_device) \ + + '/' + p.parse('deploy_partition', String, :emptiable => true, + :default => context.config.clusters[cluster].deploy_part) ) - kaerror(APIError::INVALID_RIGHTS,"deployment on partition #{part}") \ - unless context.rights.granted?(context.user,nodes,part) + kaerror(APIError::INVALID_RIGHTS, "deployment on partition #{part}") \ + unless context.rights.granted?(context.user, nodes, part) end # Check the boot partition - context.boot_part = p.parse('boot_partition',Integer) + context.boot_part = p.parse('boot_partition', Integer) # Check disable options - context.disable_bootloader_install = p.parse('disable_bootloader_install',nil,:toggle=>true) - context.disable_disk_partitioning = p.parse('disable_disk_partitioning',nil,:toggle=>true) - context.disable_kexec = p.parse('disable_kexec',nil,:toggle=>true) - context.dont_trust_env = p.parse('dont_trust_env',nil,:toggle=>true) - context.always_trust_env = p.parse('always_trust_env',nil,:toggle=>true) + context.disable_bootloader_install = p.parse('disable_bootloader_install', nil, :toggle => true) + context.disable_disk_partitioning = p.parse('disable_disk_partitioning', nil, :toggle => true) + context.disable_kexec = p.parse('disable_kexec', nil, :toggle => true) + context.dont_trust_env = p.parse('dont_trust_env', nil, :toggle => true) + context.always_trust_env = p.parse('always_trust_env', nil, :toggle => true) # Check rights on multipart environement if context.environment.multipart context.environment.options['partitions'].each do |par| - unless context.rights.granted?(context.user,context.nodes,par['device']) - kaerror(APIError::INVALID_RIGHTS,"deployment on partition #{par['device']}") + unless context.rights.granted?(context.user, context.nodes, par['device']) + kaerror(APIError::INVALID_RIGHTS, "deployment on partition #{par['device']}") end end end # Check reformat tmp partition - context.reformat_tmp = p.parse('reformat_tmp_partition',String) + context.reformat_tmp = p.parse('reformat_tmp_partition', String) # Check custom automata - context.steps = p.parse('automata',Hash,:type=>:custom_automata) + context.steps = p.parse('automata', Hash, :type => :custom_automata) # Check kexec timeout - p.parse('timeout_reboot_kexec',String) do |timeout| + p.parse('timeout_reboot_kexec', String) do |timeout| begin eval("n=1; #{timeout}") rescue diff --git a/lib/kadeploy3/server/kaenvs.rb b/lib/kadeploy3/server/kaenvs.rb index 89d9830f104de39a9a7403c9a3964ae2d5bc9b1f..8fb12cbbfd488298f3888bafc8b8224fe2170865 100644 --- a/lib/kadeploy3/server/kaenvs.rb +++ b/lib/kadeploy3/server/kaenvs.rb @@ -18,7 +18,7 @@ module Kaenvs context end - def envs_prepare(params,operation,context) + def envs_prepare(params, operation, context) context = envs_init_exec_context(context) case operation @@ -26,10 +26,10 @@ module Kaenvs context.config = duplicate_config() parse_params(params) do |p| # Check client - context.client = p.parse('client',String,:type=>:client) + context.client = p.parse('client', String, :type => :client) # Check Environment - env = p.parse('environment',Hash,:mandatory=>true) + env = p.parse('environment', Hash, :mandatory => true) if context.config.common.env_name_regex && !env['name'].match?(/\A#{context.config.common.env_name_regex}\Z/) kaerror(APIError::INVALID_ENVIRONMENT, "Invalid environment name \"#{env['name']}\", should match regex \"#{context.config.common.env_name_regex}\"") end @@ -56,11 +56,11 @@ module Kaenvs end when :get parse_params(params) do |p| - context.last = p.parse('last',nil,:toggle=>true) - context.env_user = p.parse('username',String) - context.env_version = p.parse('version',String) - context.env_arch = p.parse('arch',String,:values=>@config.common.archs_list) - context.env_name = p.parse('name',String) + context.last = p.parse('last', nil, :toggle => true) + context.env_user = p.parse('username', String) + context.env_version = p.parse('version', String) + context.env_arch = p.parse('arch', String, :values => @config.common.archs_list) + context.env_name = p.parse('name', String) end when :modify context.config = duplicate_config() @@ -68,38 +68,38 @@ module Kaenvs env = context.environment parse_params(params) do |p| # Check client - context.client = p.parse('client',String,:type=>:client) + context.client = p.parse('client', String, :type => :client) # Destructive toggle - env[:destructive] = p.parse('toggle_destructive',nil,:toggle=>true) + env[:destructive] = p.parse('toggle_destructive', nil, :toggle => true) # Architecture modification - env[:new_arch] = p.parse('new_arch',String, :values => @config.common.archs_list) + env[:new_arch] = p.parse('new_arch', String, :values => @config.common.archs_list) # Visibility modification - env[:visibility] = p.parse('visibility',String, - :values => ['public','private','shared']) + env[:visibility] = p.parse('visibility', String, + :values => ['public', 'private', 'shared']) # Checksums updates - env[:update_image_checksum] = p.parse('update_image_checksum',nil,:toggle=>true) - env[:update_preinstall_checksum] = p.parse('update_preinstall_checksum',nil,:toggle=>true) - env[:update_postinstalls_checksum] = p.parse('update_postinstalls_checksum',nil,:toggle=>true) + env[:update_image_checksum] = p.parse('update_image_checksum', nil, :toggle => true) + env[:update_preinstall_checksum] = p.parse('update_preinstall_checksum', nil, :toggle => true) + env[:update_postinstalls_checksum] = p.parse('update_postinstalls_checksum', nil, :toggle => true) - p.parse('update_files',Hash) do |files| + p.parse('update_files', Hash) do |files| env[:update_files] = {} - files.each do |oldf,newf| - p.check(oldf,String,:mandatory=>true) - kaerror(APIError::INVALID_FILE,"Invalid file name #{newf}") \ - unless FetchFile[newf,context.client] + files.each do |oldf, newf| + p.check(oldf, String, :mandatory => true) + kaerror(APIError::INVALID_FILE, "Invalid file name #{newf}") \ + unless FetchFile[newf, context.client] env[:update_files][oldf] = newf end end - context.last = p.parse('last',nil,:toggle=>true) + context.last = p.parse('last', nil, :toggle => true) end when :delete parse_params(params) do |p| - context.last = p.parse('last',nil,:toggle=>true) + context.last = p.parse('last', nil, :toggle => true) end else raise @@ -108,28 +108,28 @@ module Kaenvs context end - def envs_rights?(cexec,operation,_names,user=nil,_name=nil,_version=nil) + def envs_rights?(cexec, operation, _names, user = nil, _name = nil, _version = nil) # check if env is private and cexec != user on GET # check if cexec == user on DELETE case operation when :create if cexec.environment.visibility == 'public' and !cexec.almighty_users.include?(cexec.username) - return [false,'Only administrators can use the "public" tag'] + return [false, 'Only administrators can use the "public" tag'] end when :get # do nothing when :modify unless cexec.almighty_users.include?(cexec.user) - return [false,'Only administrators are allowed to modify other user\'s environment'] if cexec.user != user - return [false,'Only administrators can move the files in the environments'] if cexec.environment[:update_files] + return [false, 'Only administrators are allowed to modify other user\'s environment'] if cexec.user != user + return [false, 'Only administrators can move the files in the environments'] if cexec.environment[:update_files] end unless cexec.almighty_users.include?(user) - return [false,'Only administrators can use the "public" tag'] if cexec.environment[:visibility] == 'public' + return [false, 'Only administrators can use the "public" tag'] if cexec.environment[:visibility] == 'public' end when :delete if cexec.user != user and !cexec.almighty_users.include?(cexec.user) - return [false,'Only administrators are allowed to delete other user\'s environment'] + return [false, 'Only administrators are allowed to delete other user\'s environment'] end else raise @@ -149,10 +149,10 @@ module Kaenvs if !envs.empty? if envs[0].name == cexec.environment.name || envs[0].name == cexec.environment.alias kaerror(APIError::EXISTING_ELEMENT, - "An environment with name: #{envs[0].name}, architecture: #{envs[0].arch} and version: #{envs[0].version} is already recorded for user #{envs[0].user||''}") + "An environment with name: #{envs[0].name}, architecture: #{envs[0].arch} and version: #{envs[0].version} is already recorded for user #{envs[0].user || ''}") else kaerror(APIError::EXISTING_ELEMENT, - "An environment with alias: #{envs[0].alias}, architecture: #{envs[0].arch} and version: #{envs[0].version} is already recorded for user #{envs[0].user||''}") + "An environment with alias: #{envs[0].alias}, architecture: #{envs[0].arch} and version: #{envs[0].version} is already recorded for user #{envs[0].user || ''}") end else kaerror(APIError::NOTHING_MODIFIED) @@ -173,15 +173,15 @@ module Kaenvs if envs envs.collect do |env| - env.to_hash.merge!({'user'=>env.user}) + env.to_hash.merge!({'user' => env.user}) end else [] end end - def envs_modify(cexec,user=nil,name=nil,arch=nil,version=nil) - fileupdate = Proc.new do |env,kind,upfile| + def envs_modify(cexec, user = nil, name = nil, arch = nil, version = nil) + fileupdate = Proc.new do |env, kind, upfile| file = env.send(kind.to_sym) next unless file file = file.dup @@ -198,13 +198,13 @@ module Kaenvs file.each do |f| if !upfile or (upfile and f['file'] =~ /^#{upfile[:old]}/) if upfile - tmp = f['file'].gsub(upfile[:old],'') + tmp = f['file'].gsub(upfile[:old], '') f['file'] = upfile[:new] - f['file'] = File.join(f['file'],tmp) unless tmp.empty? - FetchFile[f['file'],cexec.client].size + f['file'] = File.join(f['file'], tmp) unless tmp.empty? + FetchFile[f['file'], cexec.client].size else - md5 = FetchFile[f['file'],cexec.client].checksum - kaerror(APIError::INVALID_FILE,"#{kind} md5") if !md5 or md5.empty? + md5 = FetchFile[f['file'], cexec.client].checksum + kaerror(APIError::INVALID_FILE, "#{kind} md5") if !md5 or md5.empty? kaerror(APIError::NOTHING_MODIFIED) if f['md5'] and f['md5'] == md5 f['md5'] = md5 end @@ -214,7 +214,7 @@ module Kaenvs file = file[0] unless arr if changes - Environment.send("flatten_#{kind}".to_sym,file,true) + Environment.send("flatten_#{kind}".to_sym, file, true) else nil end @@ -224,17 +224,17 @@ module Kaenvs ret = [] updates = {} - envs = Environment.get_from_db(cexec.database,user,nil,nil,nil,true,true,true) + envs = Environment.get_from_db(cexec.database, user, nil, nil, nil, true, true, true) envs.each do |env| - cexec.environment[:update_files].each do |oldf,newf| + cexec.environment[:update_files].each do |oldf, newf| updates.clear - updates['tarball'] = fileupdate.call(env,'tarball',{:old=>oldf,:new=>newf}) - updates['preinstall'] = fileupdate.call(env,'preinstall',{:old=>oldf,:new=>newf}) - updates['postinstall'] = fileupdate.call(env,'postinstall',{:old=>oldf,:new=>newf}) + updates['tarball'] = fileupdate.call(env, 'tarball', {:old => oldf, :new => newf}) + updates['preinstall'] = fileupdate.call(env, 'preinstall', {:old => oldf, :new => newf}) + updates['postinstall'] = fileupdate.call(env, 'postinstall', {:old => oldf, :new => newf}) - updates.each{ |k,v| updates.delete(k) if v.nil? } + updates.each{ |k, v| updates.delete(k) if v.nil? } unless updates.empty? if (r = Environment.update_to_db( @@ -288,18 +288,18 @@ module Kaenvs end if cexec.environment[:update_image_checksum] - updates['tarball'] = fileupdate.call(env,'tarball') + updates['tarball'] = fileupdate.call(env, 'tarball') end if cexec.environment[:update_preinstall_checksum] - updates['preinstall'] = fileupdate.call(env,'preinstall') + updates['preinstall'] = fileupdate.call(env, 'preinstall') end if cexec.environment[:update_postinstalls_checksum] - updates['postinstall'] = fileupdate.call(env,'postinstall') + updates['postinstall'] = fileupdate.call(env, 'postinstall') end - updates.each{ |k,v| updates.delete(k) if v.nil? } + updates.each{ |k, v| updates.delete(k) if v.nil? } if updates['arch'] && (existing_env = Environment.get_from_db( cexec.database, @@ -336,7 +336,7 @@ module Kaenvs end - def envs_delete(cexec,user,name,arch=nil,version=nil) + def envs_delete(cexec, user, name, arch = nil, version = nil) if (envs = Environment.del_from_db( cexec.database, name, diff --git a/lib/kadeploy3/server/kanodes.rb b/lib/kadeploy3/server/kanodes.rb index 1f6fbfdd3bee1120f553d32ed0aba826a2f31469..642370afcf3efb3db2adc805224ba38539e0d94b 100644 --- a/lib/kadeploy3/server/kanodes.rb +++ b/lib/kadeploy3/server/kanodes.rb @@ -8,26 +8,26 @@ module Kanodes ret end - def nodes_prepare(params,_operation,context) + def nodes_prepare(params, _operation, context) context = nodes_init_exec_context(context) parse_params(params) do |p| # Check nodelist - context.nodes = p.parse('nodes',Array,:type=>:nodeset, - :errno=>APIError::INVALID_NODELIST) + context.nodes = p.parse('nodes', Array, :type => :nodeset, + :errno => APIError::INVALID_NODELIST) if context.nodes tmp = context.nodes.make_array_of_hostname context.nodes.free context.nodes = tmp end - context.list = p.parse('list',nil,:toggle=>true) - context.arch = p.parse('arch',nil,:toggle=>true) + context.list = p.parse('list', nil, :toggle => true) + context.arch = p.parse('arch', nil, :toggle => true) end context end - def nodes_get(cexec,node=nil) + def nodes_get(cexec, node = nil) nodes = [] nodes << node if node nodes += cexec.nodes if cexec.nodes @@ -44,7 +44,7 @@ module Kanodes [n, @config.clusters[@config.common.nodes.get_node_by_host(n).cluster].default_arch] end.to_h else - ret = Nodes::get_states(cexec.database,nodes || server_nodes) + ret = Nodes::get_states(cexec.database, nodes || server_nodes) error_not_found!(node) if nodes and (!ret or ret.empty?) # Check that every nodes has a state, init to nil if not diff --git a/lib/kadeploy3/server/kapower.rb b/lib/kadeploy3/server/kapower.rb index f56d183f93df216f6b31fb0e10b3a5d06a71d3ec..c3f61a8cc632aa180d379a2a407c1c3b673111cc 100644 --- a/lib/kadeploy3/server/kapower.rb +++ b/lib/kadeploy3/server/kapower.rb @@ -2,30 +2,30 @@ module Kadeploy module Kapower def power_init_exec_context(ret) - ret = work_init_exec_context(:power,ret) + ret = work_init_exec_context(:power, ret) ret.operation = nil ret.level = nil ret end - def power_prepare(params,operation,context) - context = work_prepare(:power,params,operation,context) + def power_prepare(params, operation, context) + context = work_prepare(:power, params, operation, context) operation ||= :create case operation when :modify parse_params(params) do |p| - context.operation = p.parse('status',String,:values=>['on','off']).to_sym - context.level = p.parse('level',String, - :values=>['soft','hard','very_hard'],:default=>'soft') + context.operation = p.parse('status', String, :values => ['on', 'off']).to_sym + context.level = p.parse('level', String, + :values => ['soft', 'hard', 'very_hard'], :default => 'soft') end - context.info = run_wmethod(:power,:init_info,context) + context.info = run_wmethod(:power, :init_info, context) when :get context.config = duplicate_config() parse_params(params) do |p| # Check nodelist - context.nodes = p.parse('nodes',Array,:type=>:nodeset, - :errno=>APIError::INVALID_NODELIST) + context.nodes = p.parse('nodes', Array, :type => :nodeset, + :errno => APIError::INVALID_NODELIST) context.nodelist = context.nodes.make_array_of_hostname if context.nodes end context.operation = :status @@ -34,28 +34,28 @@ module Kapower context end - def power_get(cexec,wid=nil) + def power_get(cexec, wid = nil) if !wid and cexec.nodes # TODO: do it a better way #->power_prepare(cexec,:modify) - cexec.info = run_wmethod(:power,:init_info,cexec) + cexec.info = run_wmethod(:power, :init_info, cexec) kaerror(APIError::INVALID_RIGHTS) \ - unless cexec.rights.granted?(cexec.user,cexec.nodes,'') + unless cexec.rights.granted?(cexec.user, cexec.nodes, '') - work_create(:power,cexec) do |info| - info[:output].push(0,'---') + work_create(:power, cexec) do |info| + info[:output].push(0, '---') info[:nodes_ok].each do |node| - info[:output].push(0,"#{node}: #{info[:state].get(node)[:out]}") + info[:output].push(0, "#{node}: #{info[:state].get(node)[:out]}") end - info[:output].push(0,'---') + info[:output].push(0, '---') end else - work_get(:power,cexec,wid) + work_get(:power, cexec, wid) end end def power_modify(*args) - work_create(:power,*args) + work_create(:power, *args) end end diff --git a/lib/kadeploy3/server/kareboot.rb b/lib/kadeploy3/server/kareboot.rb index 9fe18cc94efaca28484da5753b51633f356a728e..0e6c87785d739038ef0c63826dc0ac162b7f0a25 100644 --- a/lib/kadeploy3/server/kareboot.rb +++ b/lib/kadeploy3/server/kareboot.rb @@ -2,27 +2,27 @@ module Kadeploy module Kareboot def reboot_init_exec_context(ret) - ret = work_init_exec_context(:reboot,ret) + ret = work_init_exec_context(:reboot, ret) ret.operation = nil ret.level = nil ret end - def reboot_prepare(params,operation,context) - context = work_prepare(:reboot,params,operation,context) + def reboot_prepare(params, operation, context) + context = work_prepare(:reboot, params, operation, context) operation ||= :create case operation when :create parse_params(params) do |p| - context.operation = p.parse('kind',String, - :values=>['set_pxe','simple','deploy_env','recorded_env'] + context.operation = p.parse('kind', String, + :values => ['set_pxe', 'simple', 'deploy_env', 'recorded_env'] ).to_sym - context.level = p.parse('level',String, - :values=>['soft','hard','very_hard'],:default=>'soft') + context.level = p.parse('level', String, + :values => ['soft', 'hard', 'very_hard'], :default => 'soft') if context.operation == :recorded_env \ - and p.parse('check_destructive',nil,:toggle=>true) \ + and p.parse('check_destructive', nil, :toggle => true) \ and context.nodes.check_demolishing_env(context.database) then kaerror(APIError::DESTRUCTIVE_ENVIRONMENT) @@ -32,14 +32,14 @@ module Kareboot case context.operation when :set_pxe if !context.pxe or !context.pxe[:profile] or context.pxe[:profile].empty? - kaerror(APIError::MISSING_OPTION,"You must specify a PXE boot profile when rebooting using set_pxe") + kaerror(APIError::MISSING_OPTION, "You must specify a PXE boot profile when rebooting using set_pxe") end when :recorded_env if !context.environment or context.environment.id < 0 - kaerror(APIError::MISSING_OPTION,"You must specify an environment when rebooting using recorded_env") + kaerror(APIError::MISSING_OPTION, "You must specify an environment when rebooting using recorded_env") end if !context.deploy_part or context.deploy_part.empty? - kaerror(APIError::MISSING_OPTION,"You must specify a partition when rebooting using recorded_env") + kaerror(APIError::MISSING_OPTION, "You must specify a partition when rebooting using recorded_env") end end when :get diff --git a/lib/kadeploy3/server/karights.rb b/lib/kadeploy3/server/karights.rb index fe75a4b0fd46f6b5d1adef34e022da5e0bdf0649..c4f5a39c8f193ff5463bce9faee5a5a048ada514 100644 --- a/lib/kadeploy3/server/karights.rb +++ b/lib/kadeploy3/server/karights.rb @@ -8,22 +8,22 @@ module Karights ret end - def rights_prepare(params,operation,context) + def rights_prepare(params, operation, context) context = rights_init_exec_context(context) parse_params(params) do |p| # Check nodelist - context.nodes = p.parse('nodes',Array,:type=>:nodeset, - :errno=>APIError::INVALID_NODELIST) + context.nodes = p.parse('nodes', Array, :type => :nodeset, + :errno => APIError::INVALID_NODELIST) context.nodes = context.nodes.make_array_of_hostname if context.nodes # Check partition - context.partitions = p.parse('partitions',Array) + context.partitions = p.parse('partitions', Array) case operation when :create - context.username = p.parse('username',String, :default => context.user) - context.overwrite = p.parse('overwrite',nil,:toggle=>true) + context.username = p.parse('username', String, :default => context.user) + context.overwrite = p.parse('overwrite', nil, :toggle => true) when :get # do nothing @@ -37,17 +37,17 @@ module Karights context end - def rights_rights?(cexec,_operation,_names,*) + def rights_rights?(cexec, _operation, _names, *) # check almighty unless cexec.almighty_users.include?(cexec.user) - return [ false, 'Only administrators are allowed to manage rights' ] + return [false, 'Only administrators are allowed to manage rights'] end return true end def rights_create(cexec) - existing = cexec.rights.get(cexec.username,cexec.nodes) + existing = cexec.rights.get(cexec.username, cexec.nodes) existing = existing[cexec.username] if existing if existing.is_a?(Hash) # Some rights have to be set for every nodes but there is already some sets in the db @@ -63,13 +63,13 @@ module Karights end if cexec.nodes - existing = cexec.rights.get(nil,cexec.nodes) + existing = cexec.rights.get(nil, cexec.nodes) # Rights already exists for another user that isnt almighty if existing and (existing.keys.size > 1 or existing.keys[0] != cexec.username) existing.keys.each do |usr| unless cexec.almighty_users.include?(usr) if cexec.overwrite - cexec.rights.delete(usr,cexec.nodes) + cexec.rights.delete(usr, cexec.nodes) else if usr != cexec.username kaerror(APIError::CONFLICTING_ELEMENTS, @@ -83,22 +83,22 @@ module Karights end end - if (ret = cexec.rights.add(cexec.username,cexec.nodes,cexec.partitions)) + if (ret = cexec.rights.add(cexec.username, cexec.nodes, cexec.partitions)) ret else kaerror(APIError::NOTHING_MODIFIED) end end - def rights_get(cexec,user=nil,node=nil) + def rights_get(cexec, user = nil, node = nil) nodes = [] nodes << node if node nodes += cexec.nodes if cexec.nodes - res = cexec.rights.get(user,nodes) + res = cexec.rights.get(user, nodes) error_not_found! unless res ret = {} - res.each do |usr,nods| + res.each do |usr, nods| ret[usr] = {} unless ret[usr] if nods.is_a?(Array) ret[usr]['*'] = nods @@ -111,11 +111,11 @@ module Karights ret end - def rights_modify(_cexec,_user,_nodes=nil) + def rights_modify(_cexec, _user, _nodes = nil) error_invalid! end - def rights_delete(cexec,user,node=nil) + def rights_delete(cexec, user, node = nil) nodes = [] nodes << node if node nodes += cexec.nodes if cexec.nodes @@ -123,34 +123,34 @@ module Karights existing = nil # nothing to delete - kaerror(APIError::NOTHING_MODIFIED) unless (existing = cexec.rights.get(user,nodes)) + kaerror(APIError::NOTHING_MODIFIED) unless (existing = cexec.rights.get(user, nodes)) existing = existing[user] partitions = cexec.partitions partitions = nil if partitions and partitions.empty? if nodes and existing.is_a?(Array) # Rights are defined on all the nodes (*) - kaerror(APIError::CONFLICTING_ELEMENTS,"Trying to remove rights for a specific node while rights are defined with a wildcard") + kaerror(APIError::CONFLICTING_ELEMENTS, "Trying to remove rights for a specific node while rights are defined with a wildcard") end if partitions if existing.is_a?(Array) if existing.include?('*') - kaerror(APIError::CONFLICTING_ELEMENTS,"Trying to remove rights on a specific partition of node #{n} while rights are defined with a wildcard") + kaerror(APIError::CONFLICTING_ELEMENTS, "Trying to remove rights on a specific partition of node #{n} while rights are defined with a wildcard") end else - existing.each do |n,parts| + existing.each do |n, parts| if parts.include?('*') - kaerror(APIError::CONFLICTING_ELEMENTS,"Trying to remove rights on a specific partition of node #{n} while rights are defined with a wildcard") + kaerror(APIError::CONFLICTING_ELEMENTS, "Trying to remove rights on a specific partition of node #{n} while rights are defined with a wildcard") end end end end - if (ret = cexec.rights.delete(user,nodes,partitions)) + if (ret = cexec.rights.delete(user, nodes, partitions)) # If the user do not have anymore rights on some nodes, # kill current operations on these nodes - remaining = cexec.rights.get(user,nodes) + remaining = cexec.rights.get(user, nodes) remaining = remaining[user] if remaining nodes = nil @@ -168,7 +168,7 @@ module Karights end end - workflows_kill(nodes,user) + workflows_kill(nodes, user) ret else diff --git a/lib/kadeploy3/server/kastats.rb b/lib/kadeploy3/server/kastats.rb index 63c2bddd5ae8962d40db971839f1802f2a435239..f60a90e30c6bb79a97a1ce05e071c5f7ee3f2f45 100644 --- a/lib/kadeploy3/server/kastats.rb +++ b/lib/kadeploy3/server/kastats.rb @@ -10,46 +10,46 @@ module Kastats ret end - def stats_prepare(params,_operation,context) + def stats_prepare(params, _operation, context) context = stats_init_exec_context(context) parse_params(params) do |p| # Check nodelist - nodes = p.parse('nodes',Array,:type=>:nodeset, - :errno=>APIError::INVALID_NODELIST) + nodes = p.parse('nodes', Array, :type => :nodeset, + :errno => APIError::INVALID_NODELIST) if nodes tmp = nodes.make_array_of_hostname nodes.free context.filters[:nodes] = tmp end - context.kind = p.parse('kind',String,:values=>['all','failure_rates'],:default=>'all') - context.fields = p.parse('fields',Array,:values=>['wid','user','hostname','step1','step2','step3','timeout_step1','timeout_step2','timeout_step3','retry_step1','retry_step2','retry_step3','start','step1_duration','step2_duration','step3_duration','env','md5','success','error'], :default=>['wid','user','hostname','step1','step2','step3','timeout_step1','timeout_step2','timeout_step3','retry_step1','retry_step2','retry_step3','start','step1_duration','step2_duration','step3_duration','env','md5','success','error']) + context.kind = p.parse('kind', String, :values => ['all', 'failure_rates'], :default => 'all') + context.fields = p.parse('fields', Array, :values => ['wid', 'user', 'hostname', 'step1', 'step2', 'step3', 'timeout_step1', 'timeout_step2', 'timeout_step3', 'retry_step1', 'retry_step2', 'retry_step3', 'start', 'step1_duration', 'step2_duration', 'step3_duration', 'env', 'md5', 'success', 'error'], :default => ['wid', 'user', 'hostname', 'step1', 'step2', 'step3', 'timeout_step1', 'timeout_step2', 'timeout_step3', 'retry_step1', 'retry_step2', 'retry_step3', 'start', 'step1_duration', 'step2_duration', 'step3_duration', 'env', 'md5', 'success', 'error']) - context.options[:sort] = p.parse('sort',Array,:values=>['wid','user','hostname','step1','step2','step3','timeout_step1','timeout_step2','timeout_step3','retry_step1','retry_step2','retry_step3','start','step1_duration','step2_duration','step3_duration','env','md5','success','error'],:default=>['start']) - context.options[:limit] = p.parse('limit',String,:regexp=>/^\d+|\d+,\d+$/) - context.options[:failure_rate] = p.parse('min_failure_rate',String,:regexp=>/^0?\.\d+|1(?:\.0)?$/) # float between 0 and 1 + context.options[:sort] = p.parse('sort', Array, :values => ['wid', 'user', 'hostname', 'step1', 'step2', 'step3', 'timeout_step1', 'timeout_step2', 'timeout_step3', 'retry_step1', 'retry_step2', 'retry_step3', 'start', 'step1_duration', 'step2_duration', 'step3_duration', 'env', 'md5', 'success', 'error'], :default => ['start']) + context.options[:limit] = p.parse('limit', String, :regexp => /^\d+|\d+,\d+$/) + context.options[:failure_rate] = p.parse('min_failure_rate', String, :regexp => /^0?\.\d+|1(?:\.0)?$/) # float between 0 and 1 - context.filters[:date_min] = p.parse('date_min',String,:type=>:date) - context.filters[:date_max] = p.parse('date_max',String,:type=>:date) - context.filters[:wid] = p.parse('wid',String) - context.filters[:min_retries] = p.parse('min_retries',String,:regexp=>/^\d+$/) - context.filters[:step_retries] = p.parse('step_retries',Array,:values=>['1','2','3']) + context.filters[:date_min] = p.parse('date_min', String, :type => :date) + context.filters[:date_max] = p.parse('date_max', String, :type => :date) + context.filters[:wid] = p.parse('wid', String) + context.filters[:min_retries] = p.parse('min_retries', String, :regexp => /^\d+$/) + context.filters[:step_retries] = p.parse('step_retries', Array, :values => ['1', '2', '3']) end context end - def stats_get(cexec,operation=nil) + def stats_get(cexec, operation = nil) if operation - if ['deploy','reboot','power'].include?(operation.strip) + if ['deploy', 'reboot', 'power'].include?(operation.strip) operation = operation.to_sym else error_not_found! end end - Stats.send(:"list_#{cexec.kind}",cexec.database,operation,cexec.filters,cexec.options,cexec.fields) + Stats.send(:"list_#{cexec.kind}", cexec.database, operation, cexec.filters, cexec.options, cexec.fields) end end diff --git a/lib/kadeploy3/server/kaworkflow.rb b/lib/kadeploy3/server/kaworkflow.rb index 9166cb63f10caab76181f9cae50fa7f24364667c..b5098efb89490369f55fb6a339b6398f0f9d9b3b 100644 --- a/lib/kadeploy3/server/kaworkflow.rb +++ b/lib/kadeploy3/server/kaworkflow.rb @@ -1,9 +1,9 @@ module Kadeploy module Kaworkflow - WORKFLOW_STATUS_CHECK_PITCH=1 + WORKFLOW_STATUS_CHECK_PITCH = 1 - def work_init_exec_context(kind,ret) + def work_init_exec_context(kind, ret) ret.config = nil ret.info = nil ret.nodes = nil @@ -18,7 +18,7 @@ module Kaworkflow ret.outputfile = nil ret.logger = nil ret.loggerfile = nil - if [:deploy,:reboot].include?(kind) + if [:deploy, :reboot].include?(kind) ret.pxe = nil ret.client = nil ret.environment = nil @@ -34,7 +34,7 @@ module Kaworkflow ret end - def work_free_exec_context(kind,context) + def work_free_exec_context(kind, context) context = free_exec_context(context) context.config = nil @@ -51,7 +51,7 @@ module Kaworkflow context.outputfile = nil context.logger = nil context.loggerfile = nil - if [:deploy,:reboot].include?(kind) + if [:deploy, :reboot].include?(kind) context.pxe = nil context.client = nil context.environment = nil @@ -68,7 +68,7 @@ module Kaworkflow context end - def work_init_info(kind,cexec) + def work_init_info(kind, cexec) hook = nil nodes = Nodes::NodeSet.new(0) cexec.nodes.duplicate(nodes) @@ -104,27 +104,27 @@ module Kaworkflow :bindings => [], :freed => false, ### - :cached_files => {:global=>[],:netboot=>[]}, + :cached_files => {:global => [], :netboot => []}, :environment => cexec.environment, } end - def work_init_resources(kind,cexec) + def work_init_resources(kind, cexec) info = cexec.info - bind(kind,info,'log','/logs') - bind(kind,info,'logs','/logs',info[:clusterlist]) - bind(kind,info,'state','/state') - bind(kind,info,'status','/status') - bind(kind,info,'error','/error') + bind(kind, info, 'log', '/logs') + bind(kind, info, 'logs', '/logs', info[:clusterlist]) + bind(kind, info, 'state', '/state') + bind(kind, info, 'status', '/status') + bind(kind, info, 'error', '/error') if info[:debugger] - bind(kind,info,'debug','/debugs') - bind(kind,info,'debugs','/debugs',info[:nodelist]) + bind(kind, info, 'debug', '/debugs') + bind(kind, info, 'debugs', '/debugs', info[:nodelist]) end end - def work_prepare(kind,params,operation,context) - context = run_wmethod(kind,:init_exec_context,context) + def work_prepare(kind, params, operation, context) + context = run_wmethod(kind, :init_exec_context, context) operation ||= :create case operation @@ -132,36 +132,36 @@ module Kaworkflow context.config = duplicate_config() parse_params(params) do |p| # Check nodelist - context.nodes = p.parse('nodes',Array,:mandatory=>true, - :type=>:nodeset, :errno=>APIError::INVALID_NODELIST) + context.nodes = p.parse('nodes', Array, :mandatory => true, + :type => :nodeset, :errno => APIError::INVALID_NODELIST) context.nodelist = context.nodes.make_array_of_hostname # Check existing rights on nodes by cluster kaerror(APIError::INVALID_RIGHTS) \ - unless context.rights.granted?(context.user,context.nodes,'') + unless context.rights.granted?(context.user, context.nodes, '') # Check rights for custom operation on the cluster kaerror(APIError::INVALID_RIGHTS, "Custom operations only allowed if you have the rights on all the partiions of the nodes") \ - unless context.rights.granted?(context.user,context.nodes,'*') || params["custom_operations"].nil? + unless context.rights.granted?(context.user, context.nodes, '*') || params["custom_operations"].nil? # Check custom breakpoint - context.breakpoint = p.parse('breakpoint',String,:type=>:breakpoint,:kind=>kind) + context.breakpoint = p.parse('breakpoint', String, :type => :breakpoint, :kind => kind) # Check custom microsteps - context.custom_operations = p.parse('custom_operations',Hash, - :type=>:custom_ops,:kind=>kind,:errno=>APIError::INVALID_CUSTOMOP) + context.custom_operations = p.parse('custom_operations', Hash, + :type => :custom_ops, :kind => kind, :errno => APIError::INVALID_CUSTOMOP) # Check force - context.force = p.parse('force',nil,:toggle=>true) + context.force = p.parse('force', nil, :toggle => true) # Check verbose level - context.verbose_level = p.parse('verbose_level',Integer,:range=>(1..5)) + context.verbose_level = p.parse('verbose_level', Integer, :range => (1..5)) # Check debug - context.debug = p.parse('debug',nil,:toggle=>true) + context.debug = p.parse('debug', nil, :toggle => true) # Check hook - context.hook = p.parse('hook',nil,:toggle=>true) + context.hook = p.parse('hook', nil, :toggle => true) # Loading OutputControl if context.config.common.dbg_to_file and !context.config.common.dbg_to_file.empty? @@ -173,67 +173,67 @@ module Kaworkflow context.loggerfile = Debug::FileOutput.new(context.config.static[:logfile]) end - if [:deploy,:reboot].include?(kind) + if [:deploy, :reboot].include?(kind) # Check client - context.client = p.parse('client',String,:type=>:client) + context.client = p.parse('client', String, :type => :client) # authorized_keys file - context.key = p.parse('ssh_authorized_keys',String) + context.key = p.parse('ssh_authorized_keys', String) # Check VLAN - p.parse('vlan',String) do |vlan| + p.parse('vlan', String) do |vlan| context.vlan_id = vlan dns = Resolv::DNS.new context.vlan_addr = {} context.nodelist.each do |hostname| - host,domain = hostname.split('.',2) + host, domain = hostname.split('.', 2) vlan_hostname = "#{host}#{context.config.common.vlan_hostname_suffix}.#{domain}" vlan_hostname.gsub!('VLAN_ID', context.vlan_id) begin context.vlan_addr[hostname] = dns.getaddress(vlan_hostname).to_s rescue Resolv::ResolvError - kaerror(APIError::INVALID_VLAN,"Cannot resolv #{vlan_hostname}") + kaerror(APIError::INVALID_VLAN, "Cannot resolv #{vlan_hostname}") end - kaerror(APIError::INVALID_VLAN,"Resolv error #{vlan_hostname}") if !context.vlan_addr[hostname] or context.vlan_addr[hostname].empty? + kaerror(APIError::INVALID_VLAN, "Resolv error #{vlan_hostname}") if !context.vlan_addr[hostname] or context.vlan_addr[hostname].empty? end dns.close dns = nil end # Check PXE options - p.parse('pxe',Hash) do |pxe| + p.parse('pxe', Hash) do |pxe| context.pxe = {} - context.pxe[:profile] = p.check(pxe['profile'],String) + context.pxe[:profile] = p.check(pxe['profile'], String) - p.check(pxe['singularities'],Hash) do |singularities| - p.check(singularities.keys,Array,:type=>:nodeset, - :errno=>APIError::INVALID_NODELIST) + p.check(pxe['singularities'], Hash) do |singularities| + p.check(singularities.keys, Array, :type => :nodeset, + :errno => APIError::INVALID_NODELIST) context.pxe[:singularities] = singularities end - context.pxe[:files] = p.check(pxe['files'],Array) + context.pxe[:files] = p.check(pxe['files'], Array) end # Check partition - context.block_device = p.parse('block_device',String) + context.block_device = p.parse('block_device', String) if context.block_device - context.deploy_part = p.parse('deploy_partition',String,:emptiable=>true) + context.deploy_part = p.parse('deploy_partition', String, :emptiable => true) else context.block_device = '' - context.deploy_part = p.parse('deploy_partition',String,:default=>'') + context.deploy_part = p.parse('deploy_partition', String, :default => '') end # Check Database Environment - env = p.parse('environment',Hash) + env = p.parse('environment', Hash) if env context.environment = Environment.new - p.check(env['name'],String,:mandatory=>true) + p.check(env['name'], String, :mandatory => true) - type = p.check(env['kind'],String,:values=>['anonymous','database'], - :default=>'database') + type = p.check(env['kind'], String, :values => ['anonymous', 'database'], + :default => 'database') if type == 'database' - p.check(env['user'],String,:errno=>APIError::INVALID_ENVIRONMENT) + p.check(env['user'], String, :errno => APIError::INVALID_ENVIRONMENT) unless context.environment.load_from_db_context( context.database, env['name'], @@ -243,15 +243,15 @@ module Kaworkflow context.user, context.almighty_users ) then - kaerror(APIError::INVALID_ENVIRONMENT,"the environment #{env['name']}:#{env['user']}:#{env['version']}:#{env['arch']} does not exist") + kaerror(APIError::INVALID_ENVIRONMENT, "the environment #{env['name']}:#{env['user']}:#{env['version']}:#{env['arch']} does not exist") end end end unsupported_arch_nodes = context.nodes.set.reject { |n| context.config.clusters[n.cluster].supported_arch.include?(env['arch'])} - kaerror(APIError::INVALID_NODELIST,"Nodes from cluster #{unsupported_arch_nodes.map(&:cluster).uniq.join(',')} do not support the architecture of environment #{env['name']}:#{env['user']}:#{env['arch']}:#{env['version']}") unless unsupported_arch_nodes.empty? + kaerror(APIError::INVALID_NODELIST, "Nodes from cluster #{unsupported_arch_nodes.map(&:cluster).uniq.join(',')} do not support the architecture of environment #{env['name']}:#{env['user']}:#{env['arch']}:#{env['version']}") unless unsupported_arch_nodes.empty? # Check reboot timeout - p.parse('timeout_reboot_classical',String) do |timeout| + p.parse('timeout_reboot_classical', String) do |timeout| begin eval("n=1; #{timeout}") rescue StandardError => e @@ -269,25 +269,25 @@ module Kaworkflow raise end - context.info = run_wmethod(kind,:init_info,context) if operation == :create + context.info = run_wmethod(kind, :init_info, context) if operation == :create context end - def work_rights?(kind,cexec,operation,names,wid=nil,*) + def work_rights?(kind, cexec, operation, names, wid = nil, *) case operation - when :create,:modify + when :create, :modify nil when :get if wid and names - workflow_get(kind,wid) do |info| + workflow_get(kind, wid) do |info| return (cexec.almighty_users.include?(cexec.user) \ or cexec.user == info[:user]) end end when :delete return false unless wid - workflow_get(kind,wid) do |info| + workflow_get(kind, wid) do |info| return (cexec.almighty_users.include?(cexec.user) \ or cexec.user == info[:user]) end @@ -298,10 +298,10 @@ module Kaworkflow return true end - def work_create(kind,cexec) + def work_create(kind, cexec) info = cexec.info - workflow_create(kind,info[:wid],info) - run_wmethod(kind,:init_resources,cexec) + workflow_create(kind, info[:wid], info) + run_wmethod(kind, :init_resources, cexec) cexecdup = cexec.dup cexecdup.nodes = nil @@ -331,10 +331,10 @@ module Kaworkflow # Cache the files begin - GrabFile.grab_user_files(context,info[:cached_files],workflow_lock(kind,info[:wid]),kind) + GrabFile.grab_user_files(context, info[:cached_files], workflow_lock(kind, info[:wid]), kind) rescue KadeployError => ke info[:lock].synchronize do - info[:nodes].set_state('aborted',nil,context[:database],context[:user]) + info[:nodes].set_state('aborted', nil, context[:database], context[:user]) end raise ke end @@ -350,7 +350,7 @@ module Kaworkflow end # Run a Workflow by cluster - clusters.each_pair do |cluster,nodeset| + clusters.each_pair do |cluster, nodeset| context[:cluster] = info[:config].clusters[cluster] if clusters.size > 1 if context[:cluster].prefix.empty? @@ -359,7 +359,7 @@ module Kaworkflow else context[:cluster_prefix] = context[:cluster].prefix.dup end - context[:nodesets_id] = context[:nodesets_id].dup #Avoid to link the counter of different clusters, because they have different prefixs. + context[:nodesets_id] = context[:nodesets_id].dup # Avoid to link the counter of different clusters, because they have different prefixs. else context[:cluster_prefix] = '' end @@ -381,7 +381,7 @@ module Kaworkflow (info[:config].common.log_to_db ? context[:database] : nil) ) - workflow = Workflow.const_get("#{kind.to_s.capitalize}").new(nodeset,context.dup) + workflow = Workflow.const_get("#{kind.to_s.capitalize}").new(nodeset, context.dup) workflows[cluster] = workflow end @@ -390,12 +390,12 @@ module Kaworkflow # Print debug if clusters.size > 1 and output - output.push(0,"---") - output.push(0,"Clusters involved in the operation:") + output.push(0, "---") + output.push(0, "Clusters involved in the operation:") workflows.each_value do |workflow| - output.push(0," #{Debug.prefix(workflow.context[:cluster_prefix])}: #{workflow.context[:cluster].name}") + output.push(0, " #{Debug.prefix(workflow.context[:cluster_prefix])}: #{workflow.context[:cluster].name}") end - output.push(0,"---") + output.push(0, "---") end # Run every workflows @@ -455,18 +455,18 @@ module Kaworkflow # Clean everything info[:lock].synchronize do free_exec_context(context[:execution]) - run_wmethod(kind,:free,info) + run_wmethod(kind, :free, info) end rescue StandardError => e info[:lock].synchronize do info[:error] = true - run_wmethod(kind,:kill,info) - run_wmethod(kind,:free,info) + run_wmethod(kind, :kill, info) + run_wmethod(kind, :free, info) end raise e ensure - run_wmethod(kind,:end_hook,info) + run_wmethod(kind, :end_hook, info) end end @@ -478,7 +478,7 @@ module Kaworkflow error_invalid! end - def work_get(kind,cexec,wid=nil) + def work_get(kind, cexec, wid = nil) get_status = Proc.new do |info| done = nil error = false @@ -556,8 +556,8 @@ module Kaworkflow end end - ret[:time] = ((info[:end_time]||Time.now) - info[:start_time]).round(2) - #ret[:states] = info[:state].states + ret[:time] = ((info[:end_time] || Time.now) - info[:start_time]).round(2) + # ret[:states] = info[:state].states else ret[:nodes] = info[:nodelist] end @@ -566,7 +566,7 @@ module Kaworkflow end if wid - workflow_get(kind,wid) do |info| + workflow_get(kind, wid) do |info| get_status.call(info) end else @@ -578,15 +578,15 @@ module Kaworkflow end end - def work_delete(kind,cexec,wid) - workflow_delete(kind,wid) do |info| - run_wmethod(kind,:delete!,cexec,info) + def work_delete(kind, cexec, wid) + workflow_delete(kind, wid) do |info| + run_wmethod(kind, :delete!, cexec, info) end end - def work_delete!(kind,_cexec,info) - run_wmethod(kind,:kill,info) - run_wmethod(kind,:free,info) + def work_delete!(kind, _cexec, info) + run_wmethod(kind, :kill, info) + run_wmethod(kind, :free, info) info[:output].free if info[:output] info.delete(:output) info[:debugger].free if info[:debugger] @@ -601,7 +601,7 @@ module Kaworkflow end - def work_kill(_kind,info) + def work_kill(_kind, info) unless info[:freed] info[:thread].kill if info[:thread] and info[:thread].alive? and info[:thread] != Thread.current info[:threads].each_value{|thread| thread.kill} if info[:threads] @@ -610,7 +610,7 @@ module Kaworkflow begin workflow.kill rescue KadeployError - #do nothing + # do nothing end end end @@ -631,7 +631,7 @@ module Kaworkflow end end - def work_free(_kind,info) + def work_free(_kind, info) unless info[:freed] info[:freed] = true info[:nodes].free if info[:nodes] @@ -670,8 +670,8 @@ module Kaworkflow end end - def work_get_logs(kind,_cexec,wid,cluster=nil) - workflow_get(kind,wid) do |info| + def work_get_logs(kind, _cexec, wid, cluster = nil) + workflow_get(kind, wid) do |info| # check if already done break if info[:error] error_not_found! if info[:workflows] and cluster and !info[:workflows][cluster] @@ -691,8 +691,8 @@ module Kaworkflow end end - def work_get_debugs(kind,_cexec,wid,node=nil) - workflow_get(kind,wid) do |info| + def work_get_debugs(kind, _cexec, wid, node = nil) + workflow_get(kind, wid) do |info| break if info[:error] error_not_found! if (node and !info[:nodelist].include?(node)) or !info[:debugger] @@ -700,19 +700,19 @@ module Kaworkflow end end - def work_get_state(kind,_cexec,wid) - workflow_get(kind,wid) do |info| + def work_get_state(kind, _cexec, wid) + workflow_get(kind, wid) do |info| break if info[:error] info[:state].states end end - def work_get_status(kind,_cexec,wid) - workflow_get(kind,wid) do |info| + def work_get_status(kind, _cexec, wid) + workflow_get(kind, wid) do |info| break if info[:error] ret = {} if info[:thread] and info[:thread].alive? - info[:workflows].each_pair do |cluster,workflow| + info[:workflows].each_pair do |cluster, workflow| ret[cluster] = workflow.status end end @@ -720,28 +720,28 @@ module Kaworkflow end end - def work_get_error(kind,_cexec,wid) - workflow_get(kind,wid) do |info| + def work_get_error(kind, _cexec, wid) + workflow_get(kind, wid) do |info| break if !info[:error] begin info[:thread].join info[:threads].each_value{|thr| thr.join unless thr.alive?} if info[:threads] nil rescue StandardError => e - run_wmethod(kind,:free,info) + run_wmethod(kind, :free, info) raise e end end end - def work_end_hook(_kind,info) + def work_end_hook(_kind, info) if info[:hook] - cmd = info[:hook].gsub('WORKFLOW_ID',info[:wid]) + cmd = info[:hook].gsub('WORKFLOW_ID', info[:wid]) run = Execute[cmd] begin Timeout::timeout(20) do - run.run!(:stdin=>false,:stdout=>false,:stderr=>false) - run.wait(:checkstatus=>false) + run.run!(:stdin => false, :stdout => false, :stderr => false) + run.wait(:checkstatus => false) end if run.status.exitstatus != 0 STDERR.puts("[#{Time.now}] The hook command has returned non-null status: #{run.status.exitstatus} (#{cmd})") diff --git a/lib/kadeploy3/server/macrostep.rb b/lib/kadeploy3/server/macrostep.rb index 66e7752a1d79e10e7536953aef54121178e8ee6a..961a9d852c732f13e8f0d886d9643d33ea6b9c35 100644 --- a/lib/kadeploy3/server/macrostep.rb +++ b/lib/kadeploy3/server/macrostep.rb @@ -8,7 +8,7 @@ module Macrostep def initialize(name, idx, subidx, nodes, nsid, manager_queue, output, logger, context = {}, config = {}, params = []) @tasks = [] @output = output - super(name,idx,subidx,nodes,nsid,manager_queue,context,config,params) + super(name, idx, subidx, nodes, nsid, manager_queue, context, config, params) @logger = logger @start_time = nil end @@ -51,94 +51,94 @@ module Macrostep retries = 0 retries = operation.delete(:retries) if operation[:retries] if op == :custom_pre - pre << [ opname, operation ] + pre << [opname, operation] elsif op == :custom_post - post << [ opname, operation ] + post << [opname, operation] else - subst << [ opname, operation ] + subst << [opname, operation] end - conf_task(opname,conf_task_default()) - conf_task(opname,{ :timeout => timeout, :retries => retries }) + conf_task(opname, conf_task_default()) + conf_task(opname, { :timeout => timeout, :retries => retries }) end end - custom = Proc.new do |task,op,i,j| + custom = Proc.new do |task, op, i, j| if @config[task][op] if j pres = [] posts = [] subst = [] - addcustoms.call(op,@config[task][op],subst,pres,posts) + addcustoms.call(op, @config[task][op], subst, pres, posts) - new_tasks[i+offset].insert(j+suboffset,*pres) unless pres.empty? + new_tasks[i + offset].insert(j + suboffset, *pres) unless pres.empty? suboffset += pres.size unless subst.empty? - new_tasks[i+offset].delete_at(j+suboffset) - new_tasks[i+offset].insert(j+suboffset,*subst) + new_tasks[i + offset].delete_at(j + suboffset) + new_tasks[i + offset].insert(j + suboffset, *subst) suboffset += (subst.size - 1) end - new_tasks[i+offset].insert(j+suboffset+1,*posts) unless posts.empty? + new_tasks[i + offset].insert(j + suboffset + 1, *posts) unless posts.empty? suboffset += posts.size else pres = [] posts = [] subst = [] - addcustoms.call(op,@config[task][op],subst,pres,posts) + addcustoms.call(op, @config[task][op], subst, pres, posts) - new_tasks.insert(i+offset,*pres) unless pres.empty? + new_tasks.insert(i + offset, *pres) unless pres.empty? offset += pres.size unless subst.empty? - new_tasks.delete_at(i+offset) - new_tasks.insert(i+offset,*subst) + new_tasks.delete_at(i + offset) + new_tasks.insert(i + offset, *subst) offset += (subst.size - 1) end - new_tasks.insert(i+offset+1,*posts) unless posts.empty? + new_tasks.insert(i + offset + 1, *posts) unless posts.empty? offset += posts.size end end end tasks.each_index do |i| - if multi_task?(i,tasks) + if multi_task?(i, tasks) suboffset = 0 tasks[i].each do |j| - taskval = get_task(i,j) - custom.call(taskval[0],:custom_pre,i,j) - custom.call(taskval[0],:custom_sub,i,j) - custom.call(taskval[0],:custom_post,i,j) + taskval = get_task(i, j) + custom.call(taskval[0], :custom_pre, i, j) + custom.call(taskval[0], :custom_sub, i, j) + custom.call(taskval[0], :custom_post, i, j) end else - taskval = get_task(i,0) - custom.call(taskval[0],:custom_pre,i,nil) - custom.call(taskval[0],:custom_sub,i,nil) - custom.call(taskval[0],:custom_post,i,nil) + taskval = get_task(i, 0) + custom.call(taskval[0], :custom_pre, i, nil) + custom.call(taskval[0], :custom_sub, i, nil) + custom.call(taskval[0], :custom_post, i, nil) end end @tasks = new_tasks end - def delete_task(taskname, reason=nil) + def delete_task(taskname, reason = nil) to_delete = [] - delete = lambda do |arr,index| + delete = lambda do |arr, index| if arr[index][0] == taskname - to_delete << [arr,index] + to_delete << [arr, index] message = " * Bypassing the step #{macroname}-#{taskname}" message += " (#{reason})" unless reason.nil? || reason.empty? - debug(5, message,nsid) + debug(5, message, nsid) end end tasks.each_index do |i| - if multi_task?(i,tasks) + if multi_task?(i, tasks) tasks[i].each do |j| - delete.call(tasks[i],j) + delete.call(tasks[i], j) end else - delete.call(tasks,i) + delete.call(tasks, i) end end to_delete.each{|tmp| tmp[0].delete_at(tmp[1])} @@ -146,7 +146,7 @@ module Macrostep # clean empty tasks tasks.each_index do |i| - to_delete << [tasks,i] if tasks[i].empty? + to_delete << [tasks, i] if tasks[i].empty? end to_delete.each{|tmp| tmp[0].delete_at(tmp[1])} to_delete.clear @@ -155,8 +155,8 @@ module Macrostep end - def create_task(idx,subidx,nodes,nsid,context) - taskval = get_task(idx,subidx) + def create_task(idx, subidx, nodes, nsid, context) + taskval = get_task(idx, subidx) microclass().new( taskval[0], @@ -171,22 +171,22 @@ module Macrostep ) end - def break!(task,nodeset) - debug(2,"*** Breakpoint on #{task.name} reached for #{nodeset.to_s_fold}",task.nsid) - debug(1,"Step #{macroname} breakpointed",task.nsid) - log("step#{idx+1}_duration",(Time.now.to_i-@start_time),nodeset) + def break!(task, nodeset) + debug(2, "*** Breakpoint on #{task.name} reached for #{nodeset.to_s_fold}", task.nsid) + debug(1, "Step #{macroname} breakpointed", task.nsid) + log("step#{idx + 1}_duration", (Time.now.to_i - @start_time), nodeset) end - def success!(task,nodeset) + def success!(task, nodeset) debug(1, "End of step #{macroname} after #{Time.now.to_i - @start_time}s", task.nsid ) - log("step#{idx+1}_duration",(Time.now.to_i-@start_time),nodeset) + log("step#{idx + 1}_duration", (Time.now.to_i - @start_time), nodeset) end - def display_fail_message(task,nodeset) - debug(2,"!!! The nodes #{nodeset.to_s_fold} failed on step #{task.name}",task.nsid) + def display_fail_message(task, nodeset) + debug(2, "!!! The nodes #{nodeset.to_s_fold} failed on step #{task.name}", task.nsid) debug(1, "Step #{macroname} failed for #{nodeset.to_s_fold} "\ "after #{Time.now.to_i - @start_time}s", @@ -194,12 +194,12 @@ module Macrostep ) end - def fail!(_task,nodeset) - log("step#{idx+1}_duration",(Time.now.to_i-@start_time),nodeset) + def fail!(_task, nodeset) + log("step#{idx + 1}_duration", (Time.now.to_i - @start_time), nodeset) end def timeout!(task) - debug(1,"Timeout in the #{task.name} step, let's kill the instance", + debug(1, "Timeout in the #{task.name} step, let's kill the instance", task.nsid) task.nodes.set_error_msg("Timeout in the #{task.name} step") nodes.set.each do |node| @@ -208,22 +208,22 @@ module Macrostep end end - def split!(nsid0,nsid1,ns1,nsid2,ns2) - initnsid = Debug.prefix(context[:cluster_prefix],nsid0) + def split!(nsid0, nsid1, ns1, nsid2, ns2) + initnsid = Debug.prefix(context[:cluster_prefix], nsid0) initnsid = '[0] ' if initnsid.empty? - debug(1,'---',nsid0) - debug(1,"Nodeset #{initnsid}split into :",nsid0) - debug(1," #{Debug.prefix(context[:cluster_prefix],nsid1)}#{ns1.to_s_fold}",nsid0) - debug(1," #{Debug.prefix(context[:cluster_prefix],nsid2)}#{ns2.to_s_fold}",nsid0) - debug(1,'---',nsid0) + debug(1, '---', nsid0) + debug(1, "Nodeset #{initnsid}split into :", nsid0) + debug(1, " #{Debug.prefix(context[:cluster_prefix], nsid1)}#{ns1.to_s_fold}", nsid0) + debug(1, " #{Debug.prefix(context[:cluster_prefix], nsid2)}#{ns2.to_s_fold}", nsid0) + debug(1, '---', nsid0) end def start!() @start_time = Time.now.to_i - debug(1,"Performing a #{macroname} step",nsid) - debug(2,"Description of #{macroname}: #{self.class::DESC}",nsid) if defined?(self.class::DESC) - log("step#{idx+1}",step_name,nodes) - log("timeout_step#{idx+1}", context[:local][:timeout] || 0, nodes) + debug(1, "Performing a #{macroname} step", nsid) + debug(2, "Description of #{macroname}: #{self.class::DESC}", nsid) if defined?(self.class::DESC) + log("step#{idx + 1}", step_name, nodes) + log("timeout_step#{idx + 1}", context[:local][:timeout] || 0, nodes) end def done!() @@ -245,7 +245,7 @@ module Macrostep class Deploy < Macrostep def self.step_name() - name.split('::').last.gsub(/^Deploy/,'') + name.split('::').last.gsub(/^Deploy/, '') end def load_tasks @@ -263,7 +263,7 @@ module Macrostep delete_task(:decompress_environment) if !context[:cluster].decompress_environment and cexec.environment.image[:kind] != 'fsa' - if ['dd','fsa'].include?(cexec.environment.image[:kind]) + if ['dd', 'fsa'].include?(cexec.environment.image[:kind]) delete_task(:format_deploy_part, "environment image is #{cexec.environment.image[:kind]}") # mount deploy part after send_environemnt delete_task(:mount_deploy_partn, "mount deploy part after send_environemnt") if self.class.superclass == DeploySetDeploymentEnv @@ -332,7 +332,7 @@ module Macrostep class Power < Macrostep def self.step_name() - name.split('::').last.gsub(/^Power/,'') + name.split('::').last.gsub(/^Power/, '') end def load_tasks @@ -342,7 +342,7 @@ module Macrostep class Reboot < Macrostep def self.step_name() - name.split('::').last.gsub(/^Reboot/,'') + name.split('::').last.gsub(/^Reboot/, '') end def load_tasks diff --git a/lib/kadeploy3/server/microsteps.rb b/lib/kadeploy3/server/microsteps.rb index 9b4a4b9bd03fb7b3e1d9a9fc4de8ea38fde46450..dcdb5a60c7a231b4bfe8912a1e845c395fa7e672 100644 --- a/lib/kadeploy3/server/microsteps.rb +++ b/lib/kadeploy3/server/microsteps.rb @@ -22,13 +22,13 @@ class Microstep < Automata::QueueTask @lock = Mutex.new end - def debug(level,msg,info=true,opts={}) + def debug(level, msg, info = true, opts = {}) if info msg = " * #{msg}" elsif !info.nil? msg = " #{msg}" end - __debug__(level,msg,nsid(),opts) + __debug__(level, msg, nsid(), opts) end def run() @@ -51,19 +51,19 @@ class Microstep < Automata::QueueTask if ret @timestart = Time.now.to_i if @name.to_s =~ /^custom_sub_.*$/ - debug(3,"#{@name.to_s.sub(/^custom_sub_/,'')}",false) - ret = ret && send(:custom,*@params) + debug(3, "#{@name.to_s.sub(/^custom_sub_/, '')}", false) + ret = ret && send(:custom, *@params) elsif @name.to_s =~ /^custom_pre_.*$/ - debug(3,"#{@name.to_s.sub(/^custom_pre_/,'')}",false) - ret = ret && send(:custom,*@params) + debug(3, "#{@name.to_s.sub(/^custom_pre_/, '')}", false) + ret = ret && send(:custom, *@params) elsif @name.to_s =~ /^custom_post_.*$/ - debug(3,"#{@name.to_s.sub(/^custom_post_/,'')}",false) - ret = ret && send(:custom,*@params) + debug(3, "#{@name.to_s.sub(/^custom_post_/, '')}", false) + ret = ret && send(:custom, *@params) else - debug(3,"#{@name}",false) - ret = ret && send("ms_#{@name}".to_sym,*@params) + debug(3, "#{@name}", false) + ret = ret && send("ms_#{@name}".to_sym, *@params) end - debug(4, " ~ Time in #{@name}: #{Time.now.to_i - @timestart}s",false) + debug(4, " ~ Time in #{@name}: #{Time.now.to_i - @timestart}s", false) end rescue KadeployError => ke ke.context = context() unless ke.context @@ -100,7 +100,7 @@ class Microstep < Automata::QueueTask (@done.nil? ? true : @done) end - def kill(dofree=true) + def kill(dofree = true) @waitreboot_threads_lock.synchronize do if @waitreboot_threads @waitreboot_threads.list.each do |thr| @@ -149,7 +149,7 @@ class Microstep < Automata::QueueTask private # Get the identifier that allow to contact a node (hostname|ip) - def get_nodeid(node,vlan=false) + def get_nodeid(node, vlan = false) if vlan and !context[:execution].vlan_id.nil? ret = context[:execution].vlan_addr[node.hostname] else @@ -162,7 +162,7 @@ class Microstep < Automata::QueueTask ret end - def get_nodeobj(nodes,str) + def get_nodeobj(nodes, str) ret = nil if context[:cluster].use_ip_to_deploy then ret = nodes.get_node_by_ip(str) @@ -172,18 +172,18 @@ class Microstep < Automata::QueueTask ret end - def init_nodes(opts={}) + def init_nodes(opts = {}) @nodes.set.each do |node| - set_node(node,opts) + set_node(node, opts) end end - def set_node(node,opts={}) + def set_node(node, opts = {}) node.last_cmd_stdout = opts[:stdout] unless opts[:stdout].nil? node.last_cmd_stderr = opts[:stderr] unless opts[:stderr].nil? node.last_cmd_exit_status = opts[:status] unless opts[:status].nil? node.state = opts[:state] unless opts[:state].nil? - context[:states].set(node.hostname,'','',opts[:node_state]) unless opts[:node_state].nil? + context[:states].set(node.hostname, '', '', opts[:node_state]) unless opts[:node_state].nil? end def failed_microstep(msg) @@ -241,7 +241,7 @@ class Microstep < Automata::QueueTask end end - def command(cmd,opts={},&_block) + def command(cmd, opts = {}, &_block) raise '@current_operation should not be set' if @current_operation @lock.synchronize{ @current_operation = Execute[cmd] } @current_operation.run(opts) @@ -273,7 +273,7 @@ class Microstep < Automata::QueueTask # Output # * return true if the command has been successfully ran on one node at least, false otherwise # TODO: scattering kind - def parallel_exec(cmd, opts={}, expects={}, window=nil) + def parallel_exec(cmd, opts = {}, expects = {}, window = nil) node_set = Nodes::NodeSet.new if @nodes_ok.empty? @nodes.linked_copy(node_set) @@ -290,14 +290,14 @@ class Microstep < Automata::QueueTask @debugger ) ) do |op| - res = op.taktuk_exec(cmd,opts,expects) + res = op.taktuk_exec(cmd, opts, expects) end classify_nodes(res) end if window then - window.launch_on_node_set(node_set,&do_exec) + window.launch_on_node_set(node_set, &do_exec) else do_exec.call(node_set) end @@ -315,7 +315,7 @@ class Microstep < Automata::QueueTask # Output # * return true if the file has been successfully sent on one node at least, false otherwise # TODO: scattering kind - def parallel_sendfile(src_file, dest_dir, opts={}) + def parallel_sendfile(src_file, dest_dir, opts = {}) nodeset = Nodes::NodeSet.new if @nodes_ok.empty? @nodes.linked_copy(nodeset) @@ -331,7 +331,7 @@ class Microstep < Automata::QueueTask @debugger ) ) do |op| - res = op.taktuk_sendfile(src_file,dest_dir,opts) + res = op.taktuk_sendfile(src_file, dest_dir, opts) end classify_nodes(res) @@ -340,7 +340,7 @@ class Microstep < Automata::QueueTask def parallel_run(nodeset_id) raise unless block_given? - parallel_op(ParallelRunner.new(@debugger,nodeset_id)) do |op| + parallel_op(ParallelRunner.new(@debugger, nodeset_id)) do |op| yield(op) end end @@ -364,9 +364,9 @@ class Microstep < Automata::QueueTask parallel_run(node_set.id) do |pr| node_set.set.each do |node| if node.cmd.power_status - pr.add(Nodes::NodeCmd.generate(node.cmd.power_status,node),node) + pr.add(Nodes::NodeCmd.generate(node.cmd.power_status, node), node) elsif context[:cluster].cmd_power_status - pr.add(Nodes::NodeCmd.generate(context[:cluster].cmd_power_status,node),node) + pr.add(Nodes::NodeCmd.generate(context[:cluster].cmd_power_status, node), node) else set_node(node, :stderr => 'power_status command is not provided') @nodes_ko.push(node) @@ -378,7 +378,7 @@ class Microstep < Automata::QueueTask end classify_nodes(res) @nodes_ok.set.each do |node| - context[:states].set(node.hostname,nil,nil,nil,nil,node.last_cmd_stdout) + context[:states].set(node.hostname, nil, nil, nil, nil, node.last_cmd_stdout) end return (not @nodes_ok.empty?) end @@ -424,13 +424,13 @@ class Microstep < Automata::QueueTask def _escalation_cmd_wrapper(kind, level, node_set, initial_node_set) debug(3, "Performing a #{level} #{kind} on #{node_set.to_s_fold}") - #First, we remove the nodes without command + # First, we remove the nodes without command no_command_provided_nodes = Nodes::NodeSet.new to_remove = Array.new node_set.set.each { |node| if !node.cmd.instance_variable_get("@#{kind}_#{level}") and !context[:cluster].instance_variable_get("@cmd_#{kind}_#{level}") set_node(node, :stderr => "#{level}_#{kind} command is not provided") - debug(3, " ! No #{level} #{kind} command is defined for #{node.hostname}",false) + debug(3, " ! No #{level} #{kind} command is defined for #{node.hostname}", false) no_command_provided_nodes.push(node) to_remove.push(node) end @@ -441,7 +441,7 @@ class Microstep < Automata::QueueTask final_node_array = Array.new - #Then, we check if there are grouped commands + # Then, we check if there are grouped commands missing_dependency = false if context[:cluster].group_of_nodes.has_key?("#{level}_#{kind}") then node_set.set.each { |node| @@ -469,7 +469,7 @@ class Microstep < Automata::QueueTask node_found_in_group = false dependency_group = nil context[:cluster].group_of_nodes["#{level}_#{kind}"].each { |group| - #The node belongs to a group + # The node belongs to a group node_found_in_group = false dependency_group = group if group.include?(node.hostname) then @@ -505,7 +505,7 @@ class Microstep < Automata::QueueTask final_node_array = node_set.make_array_of_hostname end - #We remove the grouped nodes previously ok + # We remove the grouped nodes previously ok final_node_array.each { |entry| if entry.is_a?(Array) then entry.each { |hostname| @@ -516,7 +516,7 @@ class Microstep < Automata::QueueTask backup_of_final_node_array = final_node_array.clone - #Finally, fire !!!!!!!! + # Finally, fire !!!!!!!! bad_nodes = Nodes::NodeSet.new if not final_node_array.empty? context[:windows][:reboot].launch_on_node_array(final_node_array) do |na| @@ -533,7 +533,7 @@ class Microstep < Automata::QueueTask end cmd = node.cmd.instance_variable_get("@#{kind}_#{level}") cmd = context[:cluster].instance_variable_get("@cmd_#{kind}_#{level}") unless cmd - cmd = Nodes::NodeCmd.generate(cmd,node) + cmd = Nodes::NodeCmd.generate(cmd, node) cmd = replace_groups_in_command(cmd, entry) if entry.is_a?(Array) pr.add(cmd, node) end @@ -546,7 +546,7 @@ class Microstep < Automata::QueueTask end end - #We eventually copy the status of grouped nodes + # We eventually copy the status of grouped nodes backup_of_final_node_array.each do |entry| if entry.is_a?(Array) then ref_node = initial_node_set.get_node_by_host(entry[0]) @@ -728,16 +728,16 @@ class Microstep < Automata::QueueTask if File.symlink?(File.join(dest_dir, file)) then link = File.readlink(File.join(dest_dir, file)) if is_absolute_link?(link) then - file = link.sub(/\A\//,"") + file = link.sub(/\A\//, "") elsif is_relative_link?(link) then base_dir = remove_sub_paths(File.dirname(file), get_nb_dotdotslash(link)) - file = File.join(base_dir, remove_dotdotslash(link)).sub(/\A\//,"") + file = File.join(base_dir, remove_dotdotslash(link)).sub(/\A\//, "") else dirname = File.dirname(file) if (dirname == ".") then file = link else - file = File.join(dirname.sub(/\A\.\//,""),link) + file = File.join(dirname.sub(/\A\.\//, ""), link) end end else @@ -746,8 +746,8 @@ class Microstep < Automata::QueueTask end dest = File.basename(initial_file) if (file != dest) then - if not command("mv #{File.join(dest_dir,file)} #{File.join(dest_dir,dest)}") then - failed_microstep("Cannot move the file #{File.join(dest_dir,file)} to #{File.join(dest_dir,dest)}") + if not command("mv #{File.join(dest_dir, file)} #{File.join(dest_dir, dest)}") then + failed_microstep("Cannot move the file #{File.join(dest_dir, file)} to #{File.join(dest_dir, dest)}") return false end end @@ -896,7 +896,7 @@ class Microstep < Automata::QueueTask # Output # * return the path of the swap partition def get_swap_part_path - "/dev/disk/by-partlabel/"+ get_swap_label + "/dev/disk/by-partlabel/" + get_swap_label end # Get the label of the tmp partition @@ -915,7 +915,7 @@ class Microstep < Automata::QueueTask # Output # * return the path of the tmp partition def get_tmp_part_path - "/dev/disk/by-partlabel/"+ get_tmp_label + "/dev/disk/by-partlabel/" + get_tmp_label end # Get the kernel parameters @@ -931,7 +931,7 @@ class Microstep < Automata::QueueTask return params end - def get_decompress_cmd(kind,directory,partition=nil,input_file=nil,output_file=nil) + def get_decompress_cmd(kind, directory, partition = nil, input_file = nil, output_file = nil) if output_file "cat #{(input_file ? input_file : '-')} > #{output_file}" else @@ -1017,29 +1017,29 @@ class Microstep < Automata::QueueTask @nodes_ok.linked_copy(node_set) end - cmd.gsub!("ENVFILE",file) + cmd.gsub!("ENVFILE", file) nodefile = Tempfile.new("nodefile") node_set.make_sorted_array_of_nodes.each do |node| nodefile.puts(get_nodeid(node)) end nodefile.close - cmd.gsub!("NODEFILE",nodefile.path) - cmd.gsub!("DECOMPRESS",decompress) - cmd.gsub!("TAKTUK_CONNECTOR",context[:common].taktuk_connector) + cmd.gsub!("NODEFILE", nodefile.path) + cmd.gsub!("DECOMPRESS", decompress) + cmd.gsub!("TAKTUK_CONNECTOR", context[:common].taktuk_connector) @nodes_ok.clean() - status,out,err = nil + status, out, err = nil command(cmd, :stdout_size => 1000, :stderr_size => 1000 - ) do |st,stdout,stderr| + ) do |st, stdout, stderr| status = st.exitstatus out = stdout err = stderr end nodefile.unlink - @debugger.push(cmd,@nodes,out,err,status) if @debugger + @debugger.push(cmd, @nodes, out, err, status) if @debugger if (status != 0) then failed_microstep("Error while processing to the file broadcast with #{File.basename(cmd.split(' ')[0])} (exited with status #{status})") return false @@ -1086,7 +1086,7 @@ class Microstep < Automata::QueueTask res = nil parallel_run(ns.id) do |pr| ns.set.each do |node| - #kastafior_hostname = node.ip + # kastafior_hostname = node.ip cmd = "#{context[:common].taktuk_connector} #{node.ip} \"echo #{node.ip} > /tmp/kastafior_hostname\"" pr.add(cmd, node) end @@ -1125,17 +1125,17 @@ class Microstep < Automata::QueueTask end @nodes_ok.clean() - status,out,err = nil + status, out, err = nil command(cmd, :stdout_size => 1000, :stderr_size => 1000 - ) do |st,stdout,stderr| + ) do |st, stdout, stderr| status = st.exitstatus out = stdout err = stderr end - @debugger.push(cmd,@nodes,out,err,status) if @debugger + @debugger.push(cmd, @nodes, out, err, status) if @debugger if (status != 0) then failed_microstep("Error while processing to the file broadcast with Kastafior (exited with status #{status})") return false @@ -1161,23 +1161,23 @@ class Microstep < Automata::QueueTask kofile = Tempfile.new("kascade-kofile") kofile.close - cmd = "#{context[:common].kascade} "+ - "-i #{file} -n #{nodefile.path} "+ - "-O '#{decompress}' "+ - "-S '#{context[:common].taktuk_connector}' "+ - "--ok #{okfile.path} "+ - "--ko #{kofile.path} "+ - "#{(context[:cluster].use_ip_to_deploy)?'-I ':''} "+ - "-D taktuk "+ - "-P '-d #{context[:common].taktuk_tree_arity}#{context[:common].taktuk_auto_propagate ? ' -s':''}' "+ + cmd = "#{context[:common].kascade} " + + "-i #{file} -n #{nodefile.path} " + + "-O '#{decompress}' " + + "-S '#{context[:common].taktuk_connector}' " + + "--ok #{okfile.path} " + + "--ko #{kofile.path} " + + "#{(context[:cluster].use_ip_to_deploy) ? '-I ' : ''} " + + "-D taktuk " + + "-P '-d #{context[:common].taktuk_tree_arity}#{context[:common].taktuk_auto_propagate ? ' -s' : ''}' " + "#{context[:common].kascade_options}" @nodes_ok.clean() - status,out,err = nil + status, out, err = nil command(cmd, :stdout_size => 1000, :stderr_size => 1000 - ) do |st,stdout,stderr| + ) do |st, stdout, stderr| status = st.exitstatus out = stdout err = stderr @@ -1187,7 +1187,7 @@ class Microstep < Automata::QueueTask okfile.unlink kofile.unlink - @debugger.push(cmd,@nodes,out,err,status) if @debugger + @debugger.push(cmd, @nodes, out, err, status) if @debugger node_set.linked_copy(@nodes_ok) @@ -1202,7 +1202,7 @@ class Microstep < Automata::QueueTask rescue oknodes = [] tmp = node_set.make_sorted_array_of_nodes.collect{|n| get_nodeid(n)} - konodes = Hash[tmp.zip [err]*tmp.size] + konodes = Hash[tmp.zip [err] * tmp.size] end node_set.set.each do |node| @@ -1219,7 +1219,7 @@ class Microstep < Automata::QueueTask node.last_cmd_stderr = "KASCADE-ERROR: #{konodes[id].inspect}" node.last_cmd_exit_status = status else - @debugger.push(cmd,node_set) if @debugger + @debugger.push(cmd, node_set) if @debugger failed_microstep("Error while processing Kascade output files") return false end @@ -1230,7 +1230,7 @@ class Microstep < Automata::QueueTask konodes = nil end - @debugger.push(cmd,node_set) if @debugger + @debugger.push(cmd, node_set) if @debugger return true end @@ -1304,7 +1304,7 @@ class Microstep < Automata::QueueTask return true end - def run_script(custom_env="") + def run_script(custom_env = "") "tmp=`mktemp` " \ "&& chmod 755 ${tmp} " \ "&& cat - > $tmp "\ @@ -1315,13 +1315,13 @@ class Microstep < Automata::QueueTask def custom(op) case op[:action] when :exec - debug(4,'Executing custom command') - return parallel_exec("#{set_env()} && #{op[:command]}",{ :scattering => op[:scattering] }) + debug(4, 'Executing custom command') + return parallel_exec("#{set_env()} && #{op[:command]}", { :scattering => op[:scattering] }) when :send - debug(4,'Sending custom file') - dest = File.join(op[:destination].dup,op[:filename].dup) - deploy_context().each_pair do |key,val| - dest.gsub!("$#{key}",val.to_s) + debug(4, 'Sending custom file') + dest = File.join(op[:destination].dup, op[:filename].dup) + deploy_context().each_pair do |key, val| + dest.gsub!("$#{key}", val.to_s) end return parallel_sendfile( op[:file], @@ -1329,13 +1329,13 @@ class Microstep < Automata::QueueTask { :scattering => op[:scattering] } ) when :run - debug(4,'Executing custom script') + debug(4, 'Executing custom script') return parallel_exec( run_script(), { :input_file => op[:file], :scattering => op[:scattering] } ) else - debug(0,"Invalid custom action '#{op[:action]}'") + debug(0, "Invalid custom action '#{op[:action]}'") return false end end @@ -1353,7 +1353,7 @@ class Microstep < Automata::QueueTask public - def self.load_deploy_context(vals={:env=>{},:parts=>{}}) + def self.load_deploy_context(vals = {:env => {}, :parts => {}}) ret = { 'KADEPLOY_CLUSTER' => vals[:cluster], @@ -1442,20 +1442,20 @@ class Microstep < Automata::QueueTask # * return the string containing the environment variables for pre/post installs def set_env ret = '' - deploy_context().each_pair do |key,val| + deploy_context().each_pair do |key, val| ret += "#{key}=\"#{val}\" " end ret end def get_tmp_file(file) - File.join(context[:common].rambin_path,"_KATMP_#{File.basename(file)}") + File.join(context[:common].rambin_path, "_KATMP_#{File.basename(file)}") end - def set_parttype(map,val,empty) - map.gsub!(/PARTTYPE#{get_deploy_part_num()}(\D)/,"#{val}\\1") if val - map.gsub!(/PARTTYPE\d+/,empty) - map.gsub!('PARTTYPE',val || empty) + def set_parttype(map, val, empty) + map.gsub!(/PARTTYPE#{get_deploy_part_num()}(\D)/, "#{val}\\1") if val + map.gsub!(/PARTTYPE\d+/, empty) + map.gsub!('PARTTYPE', val || empty) map end @@ -1474,7 +1474,7 @@ class Microstep < Automata::QueueTask end map = File.read(context[:cluster].partition_file) - map = set_parttype(map,context[:execution].environment.fdisk_type,'0') + map = set_parttype(map, context[:execution].environment.fdisk_type, '0') temp.write(map) temp.close @@ -1497,7 +1497,7 @@ class Microstep < Automata::QueueTask # * return true if the parted has been successfully performed, false otherwise def do_parted() map = File.read(context[:cluster].partition_file) - map.gsub!("\n",' ') + map.gsub!("\n", ' ') map = set_parttype(map, context[:execution].environment.filesystem, '') return parallel_exec( "parted -a optimal #{get_block_device_str()} --script #{map}", @@ -1506,7 +1506,7 @@ class Microstep < Automata::QueueTask end def ms_dummy() - sleep((200+rand(800)) / 1000.0) + sleep((200 + rand(800)) / 1000.0) true end @@ -1613,7 +1613,7 @@ class Microstep < Automata::QueueTask end end } - #We have to generate PXE profiles for both production and VLAN networks if --vlan switch is used + # We have to generate PXE profiles for both production and VLAN networks if --vlan switch is used p.call(get_nodes.call(true)) if context[:execution].vlan_id p.call(get_nodes.call(false)) end @@ -1640,7 +1640,7 @@ class Microstep < Automata::QueueTask if first_attempt then escalation_cmd_wrapper("reboot", "soft") else - #After the first attempt, we must not perform another soft reboot in order to avoid loop reboot on the same environment + # After the first attempt, we must not perform another soft reboot in order to avoid loop reboot on the same environment escalation_cmd_wrapper("reboot", "hard") end when "hard" @@ -1655,7 +1655,7 @@ class Microstep < Automata::QueueTask retries = context[:local][:parent].context[:local][:retries] # FIXME Maybe we can guess kexec kind based on the current task instead ? - raise "Unsupported kind of kexec operation: #{kexec_kind}" unless [:to_deploy_kernel,:to_deployed_env].include?(kexec_kind) + raise "Unsupported kind of kexec operation: #{kexec_kind}" unless [:to_deploy_kernel, :to_deployed_env].include?(kexec_kind) if retries == 0 parallel_exec( run_script("KADEPLOY_KEXEC_KIND=#{kexec_kind}"), @@ -1686,8 +1686,8 @@ class Microstep < Automata::QueueTask tmpfile = Tempfile.new('kernel_check') tmpfile.write( - "kernel=#{shell_follow_symlink(envkernel,envdir)}\n"\ - "initrd=#{shell_follow_symlink(envinitrd,envdir)}\n"\ + "kernel=#{shell_follow_symlink(envkernel, envdir)}\n"\ + "initrd=#{shell_follow_symlink(envinitrd, envdir)}\n"\ "test -e \"$kernel\" || (echo \"Environment kernel file #{envkernel} not found in tarball (${kernel})\" 1>&2; false)\n"\ "test -e \"$initrd\" || (echo \"Environment initrd file #{envinitrd} not found in tarball (${initrd})\" 1>&2; false)\n" ) @@ -1713,7 +1713,7 @@ class Microstep < Automata::QueueTask # such as inside of chroot prefix. # * filename: the file # * prefixpath: if specified, follow the link as if chrooted in 'prefixpath' directory - def shell_follow_symlink(filename,prefixpath=nil) + def shell_follow_symlink(filename, prefixpath = nil) "$("\ "prefix=#{(prefixpath and !prefixpath.empty? ? prefixpath : '')} "\ "&& file=#{filename} "\ @@ -1748,13 +1748,13 @@ class Microstep < Automata::QueueTask ret = parallel_exec("mkdir -p #{context[:cluster].kexec_repository}") ret = ret && parallel_sendfile( - File.join(pxedir,context[:cluster].deploy_kernel), + File.join(pxedir, context[:cluster].deploy_kernel), context[:cluster].kexec_repository, { :scattering => scattering_kind } ) ret = ret && parallel_sendfile( - File.join(pxedir,context[:cluster].deploy_initrd), + File.join(pxedir, context[:cluster].deploy_initrd), context[:cluster].kexec_repository, { :scattering => scattering_kind } ) @@ -1768,7 +1768,7 @@ class Microstep < Automata::QueueTask # Output # * return true if the reboot has been successfully performed, false otherwise def ms_reboot_from_deploy_env() - return parallel_exec(shell_detach('/sbin/reboot -f'), {},{}, context[:windows][:reboot]) + return parallel_exec(shell_detach('/sbin/reboot -f'), {}, {}, context[:windows][:reboot]) end # Perform a power operation on the current set of nodes_ok @@ -1819,7 +1819,7 @@ class Microstep < Automata::QueueTask # * return true if the format has been successfully performed, false otherwise def ms_format_deploy_part() if context[:cluster].formating_script && !context[:cluster].formating_script.empty? - debug(5,"Using the formating script for \"format_deploy_part\" step") + debug(5, "Using the formating script for \"format_deploy_part\" step") parallel_exec( run_script("KADEPLOY_FORMAT_PART=DEPLOY"), { @@ -1853,7 +1853,7 @@ class Microstep < Automata::QueueTask # * return true if the format has been successfully performed, false otherwise def ms_format_tmp_part() if context[:cluster].formating_script && !context[:cluster].formating_script.empty? - debug(5,"Using the formating script for \"format_tmp_part\" step") + debug(5, "Using the formating script for \"format_tmp_part\" step") parallel_exec( run_script("KADEPLOY_FORMAT_PART=TMP"), { @@ -1880,7 +1880,7 @@ class Microstep < Automata::QueueTask # * return true if the format has been successfully performed, false otherwise def ms_format_swap_part() if context[:cluster].formating_script && !context[:cluster].formating_script.empty? - debug(5,"Using the formating script for \"format_swap_part\" step") + debug(5, "Using the formating script for \"format_swap_part\" step") parallel_exec( run_script("KADEPLOY_FORMAT_PART=SWAP"), { @@ -1919,9 +1919,9 @@ class Microstep < Automata::QueueTask # Output # * return true if the keys have been successfully copied, false otherwise def ms_send_key(scattering_kind) - dir = File.join(context[:common].environment_extraction_dir,'root','.ssh') + dir = File.join(context[:common].environment_extraction_dir, 'root', '.ssh') return parallel_exec( - "mkdir -p #{dir}; cat - >> #{File.join(dir,'authorized_keys')}"\ + "mkdir -p #{dir}; cat - >> #{File.join(dir, 'authorized_keys')}"\ "", {:input_file => context[:execution].key, :scattering => scattering_kind } ) @@ -1938,7 +1938,7 @@ class Microstep < Automata::QueueTask # * ports_down: down ports used to perform a reach test on the nodes # Output # * return true if some nodes are here, false otherwise - def ms_wait_reboot(kind='classical', env='deploy', vlan=false, timeout=nil, ports_up=nil, ports_down=nil) + def ms_wait_reboot(kind = 'classical', env = 'deploy', vlan = false, timeout = nil, ports_up = nil, ports_down = nil) unless timeout if kind == 'kexec' timeout = context[:execution].timeout_reboot_kexec \ @@ -1951,7 +1951,7 @@ class Microstep < Automata::QueueTask timeout = eval(timeout).to_i unless ports_up - ports_up = [ context[:common].ssh_port ] + ports_up = [context[:common].ssh_port] ports_up << context[:common].test_deploy_env_port if env == 'deploy' end @@ -1981,15 +1981,15 @@ class Microstep < Automata::QueueTask context[:windows][:check].launch_on_node_set(nodes_to_test) do |ns| ns.set.each do |node| thr = Thread.new do - nodeid = get_nodeid(node,vlan) + nodeid = get_nodeid(node, vlan) if PortScanner.ping(nodeid, 1, context[:common].ssh_port) then - unless PortScanner.ports_test(nodeid,ports_up,true) + unless PortScanner.ports_test(nodeid, ports_up, true) node.state = 'KO' next end - unless PortScanner.ports_test(nodeid,ports_down,false) + unless PortScanner.ports_test(nodeid, ports_down, false) node.state = 'KO' next end @@ -2003,7 +2003,7 @@ class Microstep < Automata::QueueTask ) @nodes_ok.push(node) - debug(5,"#{node.hostname} is here after #{Time.now.tv_sec - start}s") + debug(5, "#{node.hostname} is here after #{Time.now.tv_sec - start}s") end end @waitreboot_threads_lock.synchronize do @@ -2011,7 +2011,7 @@ class Microstep < Automata::QueueTask end end - #let's wait everybody + # let's wait everybody @waitreboot_threads_lock.synchronize do @waitreboot_threads.list.each do |thr| thr.join @@ -2099,18 +2099,18 @@ class Microstep < Automata::QueueTask start = Time.now.to_i case scattering_kind when :bittorrent - res = send_tarball_and_uncompress_with_bittorrent(file,decompress) + res = send_tarball_and_uncompress_with_bittorrent(file, decompress) when :chain - res = send_tarball_and_uncompress_with_taktuk(:chain,file,decompress) + res = send_tarball_and_uncompress_with_taktuk(:chain, file, decompress) when :tree - res = send_tarball_and_uncompress_with_taktuk(:tree,file,decompress) + res = send_tarball_and_uncompress_with_taktuk(:tree, file, decompress) when :kastafior - res = send_tarball_and_uncompress_with_kastafior(file,decompress) + res = send_tarball_and_uncompress_with_kastafior(file, decompress) when :kascade - res = send_tarball_and_uncompress_with_kascade(file,decompress) + res = send_tarball_and_uncompress_with_kascade(file, decompress) when :custom res = send_tarball_and_uncompress_with_custom( - context[:cluster].cmd_sendenv.dup,file,decompress) + context[:cluster].cmd_sendenv.dup, file, decompress) end debug(3, "Broadcast time: #{Time.now.to_i - start}s") if res return res @@ -2148,7 +2148,7 @@ class Microstep < Automata::QueueTask # Output # * return true if the admin preinstall has been successfully uncompressed, false otherwise def ms_manage_admin_pre_install(scattering_kind) - #First we check if the preinstall has been defined in the environment + # First we check if the preinstall has been defined in the environment if (context[:execution].environment.preinstall != nil) then preinstall = context[:execution].environment.preinstall @@ -2259,7 +2259,7 @@ class Microstep < Automata::QueueTask # Arguments # Output # * return true if the operation has been correctly performed, false otherwise - def ms_set_vlan(vlan_id=nil) + def ms_set_vlan(vlan_id = nil) list = String.new @nodes.make_array_of_hostname.each { |hostname| list += " -m #{hostname}" } @@ -2283,8 +2283,8 @@ class CustomMicrostep < Microstep nodes.linked_copy(@basenodes) end - def method_missing(methname,*args) - super(methname,*args) if methname.to_s =~ /^ms_/ + def method_missing(methname, *args) + super(methname, *args) if methname.to_s =~ /^ms_/ @name = methname @params = args diff --git a/lib/kadeploy3/server/netboot.rb b/lib/kadeploy3/server/netboot.rb index 1d358d2278dbf0f6895de943c7b105caa76202d2..f04a7e49c27db68ec7675a050bf474f2a4ec9331 100644 --- a/lib/kadeploy3/server/netboot.rb +++ b/lib/kadeploy3/server/netboot.rb @@ -7,7 +7,7 @@ module NetBoot "pxe-#{user}" end - def self.Factory(kind, binary, export_kind, export_server, repository_dir, custom_dir, profiles_dir, profiles_kind, chain=nil) + def self.Factory(kind, binary, export_kind, export_server, repository_dir, custom_dir, profiles_dir, profiles_kind, chain = nil) begin c = NetBoot.class_eval(kind) rescue NameError @@ -16,7 +16,7 @@ module NetBoot c.new( binary, - c::Export.new(export_kind,export_server), + c::Export.new(export_kind, export_server), repository_dir, custom_dir, profiles_dir, @@ -51,7 +51,7 @@ module NetBoot attr_reader :repository_dir attr_reader :custom_dir - def initialize(binary, export, repository_dir, custom_dir, profiles_dir, profiles_kind, chain=nil) + def initialize(binary, export, repository_dir, custom_dir, profiles_dir, profiles_kind, chain = nil) @binary = binary @export = export @repository_dir = repository_dir @@ -61,30 +61,30 @@ module NetBoot elsif Pathname.new(profiles_dir).absolute? @profiles_dir = profiles_dir else - @profiles_dir = File.join(@repository_dir,profiles_dir) + @profiles_dir = File.join(@repository_dir, profiles_dir) end @profiles_kind = "profilename_#{profiles_kind}".to_sym @chain = chain end - def boot(kind,nodes,headers,*args) + def boot(kind, nodes, headers, *args) if @chain and (@chain.class != self.class or @chain.binary != @binary) - @chain.boot(:chain,nodes,headers,@binary) + @chain.boot(:chain, nodes, headers, @binary) end - profile, meth = send("boot_#{kind}".to_sym,*args) + profile, meth = send("boot_#{kind}".to_sym, *args) unless kind == :custom header = headers[kind].to_s header += "\n" if header != '' and header[-1] != "\n" - profile = labelize(header,kind.to_s,profile,args) + profile = labelize(header, kind.to_s, profile, args) end - write_profile(nodes,profile,meth) + write_profile(nodes, profile, meth) end protected - def labelize(_header,_kind,_profile,*) + def labelize(_header, _kind, _profile, *) raise 'Should be reimplemented' end @@ -92,7 +92,7 @@ module NetBoot raise 'Should be reimplemented' end - def boot_local(_env, _diskname, _device_id, _partition_id, _default_params='') + def boot_local(_env, _diskname, _device_id, _partition_id, _default_params = '') raise 'Should be reimplemented' end @@ -100,12 +100,12 @@ module NetBoot raise 'Should be reimplemented' end - def boot_custom(profile, user, _id, singularities=nil) + def boot_custom(profile, user, _id, singularities = nil) [ profile, - lambda do |prof,node| - #prof.gsub!("PXE_EXPORT",export_path(@custom_dir)) - prof.gsub!("NODE_SINGULARITY",singularities[node[:hostname]].to_s) \ + lambda do |prof, node| + # prof.gsub!("PXE_EXPORT",export_path(@custom_dir)) + prof.gsub!("NODE_SINGULARITY", singularities[node[:hostname]].to_s) \ if singularities prof.gsub!("FILES_PREFIX", File.join( @@ -140,17 +140,17 @@ module NetBoot end def profile_dir(node) - File.join(@profiles_dir,send(@profiles_kind, node)) + File.join(@profiles_dir, send(@profiles_kind, node)) end - def write_profile(nodes, profile, meth=nil) + def write_profile(nodes, profile, meth = nil) prof = profile nodes.each do |node| file = profile_dir(node) File.delete(file) if File.exist?(file) begin - f = File.new(file, File::CREAT|File::RDWR, 0644) - prof = meth.call(profile.dup,node) if meth + f = File.new(file, File::CREAT | File::RDWR, 0644) + prof = meth.call(profile.dup, node) if meth f.write(prof) f.close rescue @@ -171,15 +171,15 @@ module NetBoot def path(path) if path - File.join('/',path) + File.join('/', path) else '' end end end - def labelize(header,kind,profile,*) - header+ + def labelize(header, kind, profile, *) + header + "DEFAULT #{kind}\n"\ "LABEL #{kind}\n"\ + profile.collect{|line| "\t#{line}"}.join("\n") @@ -192,7 +192,7 @@ module NetBoot ]] end - def boot_local(_env, _diskname, _device_id, partition_id, _default_params='') + def boot_local(_env, _diskname, _device_id, partition_id, _default_params = '') [[ "COM32 #{export_path('chain.c32')}", "APPEND label=#{partition_id}", @@ -210,7 +210,7 @@ module NetBoot profile << "KERNEL #{export_path(kernel)}" profile << "APPEND #{initrd}#{params}" - [ profile ] + [profile] end end @@ -227,17 +227,17 @@ module NetBoot def path(path) case @kind - when :tftp,:auto + when :tftp, :auto if path - File.join('/',path) + File.join('/', path) else '' end - when :http,:ftp + when :http, :ftp if path - File.join("#{@kind}://",@server,path) + File.join("#{@kind}://", @server, path) else - File.join("#{@kind}://",@server) + File.join("#{@kind}://", @server) end end end @@ -259,21 +259,21 @@ module NetBoot case @kind when :tftp if path - File.join('/',path) + File.join('/', path) else '' end - when :http,:ftp + when :http, :ftp if path - File.join("#{@kind}://",@server,path) + File.join("#{@kind}://", @server, path) else - File.join("#{@kind}://",@server) + File.join("#{@kind}://", @server) end end end end - def labelize(header,_kind,profile,*) + def labelize(header, _kind, profile, *) "#!ipxe\n#{header}#{profile.join("\n")}" end @@ -283,7 +283,7 @@ module NetBoot ]] end - def boot_local(_env, _diskname, device_id, partition_id, _default_params='') + def boot_local(_env, _diskname, device_id, partition_id, _default_params = '') [[ "chain #{export_path('chain.c32')} hd#{device_id} #{partition_id}", ]] @@ -295,7 +295,7 @@ module NetBoot profile << "initrd #{export_path(initrd)}" if initrd profile << "chain #{export_path(kernel)} #{params}" - [ profile ] + [profile] end end @@ -313,13 +313,13 @@ module NetBoot when :tftp # Compatibility for old GRUB disks versions if path - File.join('(pxe)',path) + File.join('(pxe)', path) else '(pxe)' end when :http if path - File.join("(#{@kind},#{@server})",path) + File.join("(#{@kind},#{@server})", path) else "(#{@kind},#{@server})" end @@ -327,7 +327,7 @@ module NetBoot end end - def labelize(header,kind,profile,*) + def labelize(header, kind, profile, *) header += "\ntimeout=0\n" unless header.include?("timeout") header + "default=0\n"\ @@ -343,12 +343,12 @@ module NetBoot ]] end - def boot_local(env, diskname, device_id, partition_id, default_params='') + def boot_local(env, diskname, device_id, partition_id, default_params = '') # The search command should be used to find the device, several options: # --fs-uuid + one microstep to gather the uuid on each machine # --label + write a label on the disk when partitioning # --file + create a unique file (deploy ID# ?) on the deployed filesystem - profile = [ "set root=(hd#{device_id},#{partition_id})" ] + profile = ["set root=(hd#{device_id},#{partition_id})"] partname = "#{diskname}#{partition_id}" kernel_params = (env.kernel_params.empty? ? default_params : env.kernel_params) @@ -374,16 +374,16 @@ module NetBoot profile << "chainloader +1" end - [ profile ] + [profile] end - def boot_network(kernel, initrd, params, kind='linux') + def boot_network(kernel, initrd, params, kind = 'linux') profile = [] profile << "#{kind} #{export_path(kernel)} #{params}" profile << "initrd #{export_path(initrd)}" if initrd - [ profile ] + [profile] end end end diff --git a/lib/kadeploy3/server/parallel_ops.rb b/lib/kadeploy3/server/parallel_ops.rb index a9c19e9ee31c51e0dfd91e5fa7a343957af6be09..bca67b7f8c26028f8be093995baad0a024743ad0 100644 --- a/lib/kadeploy3/server/parallel_ops.rb +++ b/lib/kadeploy3/server/parallel_ops.rb @@ -27,7 +27,7 @@ module Kadeploy def kill @taktuk.kill! unless @taktuk.nil? - #free() It is a race condition and it will be freed by do_taktuk + # free() It is a race condition and it will be freed by do_taktuk end def free @@ -46,7 +46,7 @@ module Kadeploy # * expects: Hash of expectations, will be used to sort nodes in OK and KO sets: :stdout, :stderr, :status, ... # Output # * returns an array that contains two arrays ([0] is the nodes OK and [1] is the nodes KO) - def taktuk_exec(command,opts={},expects={}) + def taktuk_exec(command, opts = {}, expects = {}) nodes_init(:stdout => '', :stderr => '', :status => '0') res = nil @@ -74,7 +74,7 @@ module Kadeploy node.last_cmd_stderr = stderr end end - ret = [[],@nodes.set.dup] + ret = [[], @nodes.set.dup] end res = nil @output.push("#{takbin} #{takargs.join(' ')}", @nodes) if @output @@ -90,7 +90,7 @@ module Kadeploy # * expects: Hash of expectations, will be used to sort nodes in OK and KO sets: :stdout, :stderr, :status, ... # Output # * returns an array that contains two arrays ([0] is the nodes OK and [1] is the nodes KO) - def taktuk_sendfile(src,dst,_opts={},expects={}) + def taktuk_sendfile(src, dst, _opts = {}, expects = {}) nodes_init(:stdout => '', :stderr => '', :status => '0') res = nil @@ -116,7 +116,7 @@ module Kadeploy node.last_cmd_stderr = stderr end end - ret = [[],@nodes.set.dup] + ret = [[], @nodes.set.dup] end res = nil @output.push("#{takbin} #{takargs.join(' ')}", @nodes) if @output @@ -126,9 +126,9 @@ module Kadeploy private - def nodes_init(opts={}) + def nodes_init(opts = {}) @nodes.set.each do |node| - node_set(node,opts) + node_set(node, opts) end end @@ -153,12 +153,12 @@ module Kadeploy ret end - def node_set(node,opts={}) + def node_set(node, opts = {}) node.last_cmd_stdout = opts[:stdout] unless opts[:stdout].nil? node.last_cmd_stderr = opts[:stderr] unless opts[:stderr].nil? node.last_cmd_exit_status = opts[:status] unless opts[:status].nil? node.state = opts[:state] unless opts[:state].nil? - @context[:states].set(node.hostname,'','',opts[:node_state]) unless opts[:node_state].nil? + @context[:states].set(node.hostname, '', '', opts[:node_state]) unless opts[:node_state].nil? end # Set information about a Taktuk command execution @@ -169,15 +169,15 @@ module Kadeploy value[fieldkey].each_index do |i| node = node_get(value[fieldkey][i]) if value[fieldval].is_a?(Array) - yield(node,[value[fieldval][i]]) + yield(node, [value[fieldval][i]]) else - yield(node,[value[fieldval]]) + yield(node, [value[fieldval]]) end end end end else - result.each_pair do |host,pids| + result.each_pair do |host, pids| node = node_get(host) ret = nil pids.each_value do |value| @@ -194,27 +194,27 @@ module Kadeploy raise end end - yield(node,ret) + yield(node, ret) end end end # Set information about a Taktuk command execution def nodes_updates(results) - nodes_update(results[:output]) do |node,val| + nodes_update(results[:output]) do |node, val| node.last_cmd_stdout = val if node end - nodes_update(results[:error]) do |node,val| + nodes_update(results[:error]) do |node, val| node.last_cmd_stderr = "#{val.join("\n")}\n" if node end - nodes_update(results[:status]) do |node,val| + nodes_update(results[:status]) do |node, val| node.last_cmd_exit_status = val[0] if node end regexp = /^Warning:.*$/ - nodes_update(results[:connector]) do |node,val| + nodes_update(results[:connector]) do |node, val| next unless node val.each do |v| if !(v =~ regexp) @@ -225,10 +225,10 @@ module Kadeploy end end - nodes_update(results[:state],:peer) do |node,val| + nodes_update(results[:state], :peer) do |node, val| next unless node val.each do |v| - if TakTuk::StateStream.check?(:error,v) + if TakTuk::StateStream.check?(:error, v) node.last_cmd_exit_status = v node.last_cmd_stderr = '' unless node.last_cmd_stderr node.last_cmd_stderr += "TAKTUK-ERROR-state: #{TakTuk::StateStream::errmsg(v.to_i)}\n" @@ -237,7 +237,7 @@ module Kadeploy end end - def nodes_sort(expects={}) + def nodes_sort(expects = {}) good = [] bad = [] @@ -260,10 +260,10 @@ module Kadeploy end good << node end - [good,bad] + [good, bad] end - def taktuk_init(opts={}) + def taktuk_init(opts = {}) taktuk_opts = {} connector = @context[:common].taktuk_connector @@ -285,10 +285,10 @@ module Kadeploy end end - TakTuk.taktuk(nodes_array(),taktuk_opts) + TakTuk.taktuk(nodes_array(), taktuk_opts) end - def do_taktuk(opts={}) + def do_taktuk(opts = {}) @taktuk = taktuk_init(opts) yield(@taktuk) @taktuk.free! if @taktuk diff --git a/lib/kadeploy3/server/parallel_runner.rb b/lib/kadeploy3/server/parallel_runner.rb index 51f1b9354276701eb27d52a547f99a4c944663fa..11bdbcc55fac41591a080f376c167c575a34a12b 100644 --- a/lib/kadeploy3/server/parallel_runner.rb +++ b/lib/kadeploy3/server/parallel_runner.rb @@ -11,7 +11,7 @@ module Kadeploy # * output: instance of OutputControl # Output # * nothing - def initialize(output, nodesetid=-1) + def initialize(output, nodesetid = -1) @execs = {} @output = output @nodesetid = nodesetid @@ -54,7 +54,7 @@ module Kadeploy # Output # * nothing def run - @execs.each_pair do |node,exec| + @execs.each_pair do |node, exec| @listlock.synchronize do raise SignalException.new(0) if @killed @@ -67,7 +67,7 @@ module Kadeploy end end - status,stdout,stderr = exec.wait(:checkstatus => false) + status, stdout, stderr = exec.wait(:checkstatus => false) node.last_cmd_stdout = stdout.chomp node.last_cmd_stderr = stderr.chomp node.last_cmd_exit_status = status.exitstatus.to_s @@ -121,11 +121,11 @@ module Kadeploy # * nothing # Output # * array of two arrays ([0] contains the nodes OK and [1] contains the nodes KO) - def get_results(expects={}) + def get_results(expects = {}) good = [] bad = [] - @execs.each_pair do |node,exec| + @execs.each_pair do |node, exec| status = (expects[:status] ? expects[:status] : ['0']) if !status.include?(node.last_cmd_exit_status) diff --git a/lib/kadeploy3/server/paramsparser.rb b/lib/kadeploy3/server/paramsparser.rb index c2b9c85482c0e0d773452a04f3db4ad4a3233676..fc6424b466accf0ee7428edf5ee3e38de73f6796 100644 --- a/lib/kadeploy3/server/paramsparser.rb +++ b/lib/kadeploy3/server/paramsparser.rb @@ -4,7 +4,7 @@ require 'time' module Kadeploy class ParamsParser - def initialize(params,config) + def initialize(params, config) raise unless params.is_a?(Hash) @params = params @secure_client = config.common.secure_client @@ -24,21 +24,21 @@ class ParamsParser @curparam = nil end - def error(errno,msg='',klass=nil) + def error(errno, msg = '', klass = nil) msg = "Parameter '#{@curparam}': #{msg}" if @curparam if klass raise klass.new(msg) else - raise KadeployError.new(errno,nil,msg) + raise KadeployError.new(errno, nil, msg) end end - def check(value, klass, opts={}, &block) + def check(value, klass, opts = {}, &block) opts[:value] = value - parse(nil,klass,opts,&block) + parse(nil, klass, opts, &block) end - def parse(name, klass, opts={}) + def parse(name, klass, opts = {}) @curparam = name param = opts[:value] || @params[name] errno = opts[:errno] || APIError::INVALID_OPTION @@ -58,13 +58,13 @@ class ParamsParser msg = "mandatory" case opts[:mandatory] when :invalid - error(nil,msg,HTTPd::InvalidError) + error(nil, msg, HTTPd::InvalidError) when :forbidden - error(nil,msg,HTTPd::ForbiddenError) + error(nil, msg, HTTPd::ForbiddenError) when :unauthorized - error(nil,msg,HTTPd::UnauthorizedError) + error(nil, msg, HTTPd::UnauthorizedError) else - error(errno,"mandatory") + error(errno, "mandatory") end else return nil @@ -74,31 +74,31 @@ class ParamsParser param = [param] if klass.is_a?(Class) and klass == Array and param.is_a?(String) and !opts[:strict] if klass.is_a?(Array) - error(errno,"should be #{klass.join(' or ')}") \ + error(errno, "should be #{klass.join(' or ')}") \ unless klass.include?(param.class) else - error(errno,"should be a #{klass.name}") \ + error(errno, "should be a #{klass.name}") \ if !klass.nil? and !param.is_a?(klass) end - error(errno,"cannot be empty") \ + error(errno, "cannot be empty") \ if param.respond_to?(:empty?) and param.empty? and !opts[:emptiable] if opts[:values] if param.is_a?(Array) # Check if Array1 includes Array2 - error(errno,"must have a value in (#{opts[:values].join(',')})") unless (param-opts[:values]).empty? + error(errno, "must have a value in (#{opts[:values].join(',')})") unless (param - opts[:values]).empty? else - error(errno,"must have a value in (#{opts[:values].join(',')})") unless opts[:values].include?(param) + error(errno, "must have a value in (#{opts[:values].join(',')})") unless opts[:values].include?(param) end end if opts[:regexp] and !param =~ opts[:regexp] - error(errno,"must be like #{opts[:regexp]}") + error(errno, "must be like #{opts[:regexp]}") end if opts[:range] and !opts[:range].include?(param) - error(errno,"must be in the range #{opts[:range]}") + error(errno, "must be in the range #{opts[:range]}") end case opts[:type] @@ -106,22 +106,22 @@ class ParamsParser begin param = URI.parse(param) rescue StandardError => e - error(errno,"invalid URI (#{e.message})") + error(errno, "invalid URI (#{e.message})") end - error(APIError::INVALID_CLIENT,'Invalid client protocol') \ - unless ['http','https'].include?(param.scheme.downcase) + error(APIError::INVALID_CLIENT, 'Invalid client protocol') \ + unless ['http', 'https'].include?(param.scheme.downcase) error(APIError::INVALID_CLIENT, 'Secure connection is mandatory for the client fileserver') \ if @secure_client and param.scheme.downcase == 'http' when :node - error(APIError::INVALID_NODELIST,"Must be a single node") if Nodes::REGEXP_NODELIST =~ param + error(APIError::INVALID_NODELIST, "Must be a single node") if Nodes::REGEXP_NODELIST =~ param # Get the node param = param.strip - error(APIError::INVALID_NODELIST,"Empty node name") if param.empty? + error(APIError::INVALID_NODELIST, "Empty node name") if param.empty? unless (param = @nodes.get_node(param)) - error(APIError::INVALID_NODELIST,"The node #{param} does not exist") + error(APIError::INVALID_NODELIST, "The node #{param} does not exist") end when :nodeset # Get hostlist @@ -138,16 +138,16 @@ class ParamsParser param = Nodes::NodeSet.new(0) hosts.each do |host| host = host.strip - error(APIError::INVALID_NODELIST,"Empty node name") if host.empty? + error(APIError::INVALID_NODELIST, "Empty node name") if host.empty? node = @nodes.get_node(host) if node if node.is_a?(Array) - error(APIError::INVALID_NODELIST,"Ambibuous node name '#{host}' that can refer to #{node.collect{|n| n.hostname}.join(' or ')}") + error(APIError::INVALID_NODELIST, "Ambibuous node name '#{host}' that can refer to #{node.collect{|n| n.hostname}.join(' or ')}") else param.push(node) end else - error(APIError::INVALID_NODELIST,"The node '#{host}' does not exist") + error(APIError::INVALID_NODELIST, "The node '#{host}' does not exist") end end Nodes::sort_list(param.set) @@ -159,21 +159,21 @@ class ParamsParser ret = [] raise unless opts[:kind] if param =~ /^(\w+)(?::(\w+))?$/ - if Configuration::check_macrostep_instance(Regexp.last_match(1),opts[:kind]) or Configuration::check_macrostep_interface(Regexp.last_match(1),opts[:kind]) + if Configuration::check_macrostep_instance(Regexp.last_match(1), opts[:kind]) or Configuration::check_macrostep_interface(Regexp.last_match(1), opts[:kind]) ret[0] = Regexp.last_match(1) else - error(errno,"Invalid macrostep name '#{Regexp.last_match(1)}'") + error(errno, "Invalid macrostep name '#{Regexp.last_match(1)}'") end if Regexp.last_match(2) and !Regexp.last_match(2).empty? if Configuration::check_microstep(Regexp.last_match(2)) ret[1] = Regexp.last_match(2) else - error(errno,"Invalid microstep name '#{Regexp.last_match(2)}'") + error(errno, "Invalid microstep name '#{Regexp.last_match(2)}'") end end param = ret else - error(errno,'The breakpoint should be specified as macrostep_name:microstep_name or macrostep_name') + error(errno, 'The breakpoint should be specified as macrostep_name:microstep_name or macrostep_name') end when :custom_ops ret = { :operations => {}, :overrides => {}} @@ -181,27 +181,27 @@ class ParamsParser customops = ret[:operations] customover = ret[:overrides] - param.each_pair do |macro,micros| - error(errno,'Macrostep name must be a String') unless macro.is_a?(String) - error(errno,'Macrostep description must be a Hash') unless micros.is_a?(Hash) - error(errno,"Invalid macrostep '#{macro}'") \ - if !Configuration::check_macrostep_interface(macro,opts[:kind]) and \ - !Configuration::check_macrostep_instance(macro,opts[:kind]) + param.each_pair do |macro, micros| + error(errno, 'Macrostep name must be a String') unless macro.is_a?(String) + error(errno, 'Macrostep description must be a Hash') unless micros.is_a?(Hash) + error(errno, "Invalid macrostep '#{macro}'") \ + if !Configuration::check_macrostep_interface(macro, opts[:kind]) and \ + !Configuration::check_macrostep_instance(macro, opts[:kind]) customops[macro.to_sym] = {} unless customops[macro.to_sym] - micros.each_pair do |micro,operations| - error(errno,'Microstep name must be a String') unless micro.is_a?(String) - error(errno,"The microstep '#{micro}' is empty") unless operations - error(errno,'Microstep description must be a Hash') unless operations.is_a?(Hash) - error(errno,"Invalid microstep '#{micro}'") \ + micros.each_pair do |micro, operations| + error(errno, 'Microstep name must be a String') unless micro.is_a?(String) + error(errno, "The microstep '#{micro}' is empty") unless operations + error(errno, 'Microstep description must be a Hash') unless operations.is_a?(Hash) + error(errno, "Invalid microstep '#{micro}'") \ unless Configuration::check_microstep(micro) cp = Configuration::Parser.new(operations) begin - tmp = Configuration::parse_custom_operations(cp,micro, - :set_target=>true) + tmp = Configuration::parse_custom_operations(cp, micro, + :set_target => true) rescue ArgumentError => ae - error(errno,"#{macro}/#{micro}, #{ae.message}") + error(errno, "#{macro}/#{micro}, #{ae.message}") end if tmp[:over] @@ -220,7 +220,7 @@ class ParamsParser begin param = Configuration::parse_custom_macrosteps(cp) rescue ArgumentError => ae - error(errno,ae.message) + error(errno, ae.message) end when :date begin diff --git a/lib/kadeploy3/server/port_scanner.rb b/lib/kadeploy3/server/port_scanner.rb index 39c1cabd314c1f136148ac223642ae7703ab764b..2232f3fa51eff11e278c7ba774a2ea43ed175baf 100644 --- a/lib/kadeploy3/server/port_scanner.rb +++ b/lib/kadeploy3/server/port_scanner.rb @@ -14,7 +14,7 @@ module PortScanner res = false tid = Thread.new { begin - s = TCPSocket.new(hostname,port) + s = TCPSocket.new(hostname, port) s.close res = true rescue @@ -34,7 +34,7 @@ module PortScanner end # Test if a node accept or refuse connections on every ports of a list (TCP) - def self.ports_test(nodeid, ports, accept=true) + def self.ports_test(nodeid, ports, accept = true) max_retry = 2 current_retry = 0 ret = true diff --git a/lib/kadeploy3/server/rights.rb b/lib/kadeploy3/server/rights.rb index c64d996aa27b4f4407b26d26f7855feaf9390b9c..eed42c2ac8ab8d79513f413ada79f8077d231ec3 100644 --- a/lib/kadeploy3/server/rights.rb +++ b/lib/kadeploy3/server/rights.rb @@ -15,26 +15,26 @@ module Rights end class Rights - def add(_user, _nodes=nil, _parts=nil) + def add(_user, _nodes = nil, _parts = nil) true end - def get(_user, _nodes=nil) + def get(_user, _nodes = nil) true end - def delete(_user,_nodes=nil) + def delete(_user, _nodes = nil) true end - def granted?(_user,_nodes,_parts=nil) + def granted?(_user, _nodes, _parts = nil) true end protected - def prepare(user=nil,nodes=nil,parts=nil) - parts = [ parts ] if parts and !parts.is_a?(Array) - nodes = [ nodes.hostname ] if nodes.is_a?(Nodes::Node) + def prepare(user = nil, nodes = nil, parts = nil) + parts = [parts] if parts and !parts.is_a?(Array) + nodes = [nodes.hostname] if nodes.is_a?(Nodes::Node) nodes = nodes.make_array_of_hostname if nodes.is_a?(Nodes::NodeSet) nodes.uniq! if nodes.is_a?(Array) user = nil if user and user.empty? @@ -53,16 +53,16 @@ module Rights end nodes = nil if nodes and nodes.empty? - [user,nodes,parts] + [user, nodes, parts] end end class RightsDummy < Rights - def get(user,nodes=nil) - _,nodes = prepare(user,nodes) + def get(user, nodes = nil) + _, nodes = prepare(user, nodes) if nodes and !nodes.empty? nodes.uniq! if nodes.is_a?(Array) - nodes.inject({}){|h,n| h[n] = '*'; h} + nodes.inject({}){|h, n| h[n] = '*'; h} else {} end @@ -74,21 +74,21 @@ module Rights @db = db end - def add(user,nodes=nil,parts=nil) - user,nodes,parts = prepare(user,nodes,parts) + def add(user, nodes = nil, parts = nil) + user, nodes, parts = prepare(user, nodes, parts) raise if !user or user.empty? - existing = get(user,nodes) + existing = get(user, nodes) existing = existing[user] if existing parts = ['*'] unless parts - treatment = Proc.new do |h,n,p| #h: to_add, p: rights that already in the base + treatment = Proc.new do |h, n, p| # h: to_add, p: rights that already in the base if p.sort != parts.sort and !p.include?('*') # some modifications are needed and the already set rights do not include the ones we want to set if parts.include?('*') # we delete all previously set rights if n == '*' delete(user) else - delete(user,[n]) + delete(user, [n]) end h[n] = ['*'] # and add all rights to this node else @@ -106,15 +106,15 @@ module Rights if nodes if existing.is_a?(Array) # User have rights on every nodes nodes.each do - treatment.call(to_add,node,existing) + treatment.call(to_add, node, existing) end elsif existing.is_a?(Hash) - existing.each do |n,p| - treatment.call(to_add,n,p) + existing.each do |n, p| + treatment.call(to_add, n, p) end # The nodes that did not have any rights - (nodes-existing.keys).each do |node| + (nodes - existing.keys).each do |node| to_add[node] = parts end else @@ -124,7 +124,7 @@ module Rights end else if existing.is_a?(Array) # User have rights on every nodes - treatment.call(to_add,'*',existing) + treatment.call(to_add, '*', existing) elsif existing.is_a?(Hash) if parts.include?('*') delete(user) @@ -142,7 +142,7 @@ module Rights else args = [] size = 0 - to_add.each do |n,ps| + to_add.each do |n, ps| ps.each do |p| args << user args << n @@ -150,15 +150,15 @@ module Rights size += 1 end end - values = ([ "(?, ?, ?)" ] * size).join(", ") + values = (["(?, ?, ?)"] * size).join(", ") query = "INSERT INTO rights (user, node, part) VALUES #{values}" - db_run(query,*args) + db_run(query, *args) { user => to_add } end end - def get(user=nil,nodes=nil) - user,nodes = prepare(user,nodes) + def get(user = nil, nodes = nil) + user, nodes = prepare(user, nodes) query = "SELECT * FROM rights" args = [] where = [] @@ -172,12 +172,12 @@ module Rights args += tmp[1] end query << " WHERE #{where.join(' AND ')}" unless where.empty? -#hash if right on some nodes, array if rights on all nodes +# hash if right on some nodes, array if rights on all nodes - res = db_run(query,*args) + res = db_run(query, *args) if res ret = {} - res.each do |usr,nods| + res.each do |usr, nods| # nods.collect! if nods.include?('*') ret[usr] = nods['*'] @@ -191,15 +191,15 @@ module Rights end end - def delete(user,nodes=nil,parts=nil) - user,nodes,parts = prepare(user,nodes,parts) + def delete(user, nodes = nil, parts = nil) + user, nodes, parts = prepare(user, nodes, parts) raise if !user or user.empty? query = "DELETE FROM rights" where = ['(user = ?)'] args = [user] if nodes if parts - tmp = db_partlist(parts,nodes) + tmp = db_partlist(parts, nodes) where << tmp[0] args += tmp[1] else @@ -215,7 +215,7 @@ module Rights end end query << " WHERE #{where.join(' AND ')}" - if db_run(query,*args) + if db_run(query, *args) ret = {} ret[user] = {} if nodes @@ -240,21 +240,21 @@ module Rights end # if parts.empty? => check if some rights on nodes - def granted?(user,nodes,parts=nil) + def granted?(user, nodes, parts = nil) raise unless nodes - user,nodes,parts = prepare(user,nodes,parts) - rights = get(user,nodes) + user, nodes, parts = prepare(user, nodes, parts) + rights = get(user, nodes) rights = rights[user] if rights parts = ['*'] unless parts if rights.is_a?(Array) # check if rights includes parts - parts[0].empty? or rights[0] == '*' or (parts.sort-rights.sort).empty? + parts[0].empty? or rights[0] == '*' or (parts.sort - rights.sort).empty? elsif rights.is_a?(Hash) if nodes.sort == rights.keys.sort unless parts[0].empty? - rights.each do |_,p| - return false if p[0] != '*' and !(parts.sort-p.sort).empty? + rights.each do |_, p| + return false if p[0] != '*' and !(parts.sort - p.sort).empty? end end true @@ -267,10 +267,10 @@ module Rights end private - def db_run(query,*args) - res = @db.run_query(query,*args) + def db_run(query, *args) + res = @db.run_query(query, *args) if res.affected_rows > 0 - ret = res.to_hash.inject({}) do |h,v| + ret = res.to_hash.inject({}) do |h, v| h[v['user']] = {} unless h[v['user']] h[v['user']][v['node']] = [] unless h[v['user']][v['node']] h[v['user']][v['node']] << v['part'] @@ -282,13 +282,13 @@ module Rights end end - def db_nodelist(nodes,field='node') + def db_nodelist(nodes, field = 'node') tmp = nodes.dup tmp << '*' - Database::where_nodelist(tmp,field) + Database::where_nodelist(tmp, field) end - def db_partlist(parts,nodes=nil,partfield='part',nodefield='node') + def db_partlist(parts, nodes = nil, partfield = 'part', nodefield = 'node') if nodes queries = [] args = [] @@ -301,9 +301,9 @@ module Rights query << ')' queries << query end - ["(#{queries.join(' OR ')})",args] + ["(#{queries.join(' OR ')})", args] else - ["(#{(["(#{partfield} = ? )"] * parts.size).join(' OR ')})",parts] + ["(#{(["(#{partfield} = ? )"] * parts.size).join(' OR ')})", parts] end end end diff --git a/lib/kadeploy3/server/server.rb b/lib/kadeploy3/server/server.rb index 48b4137ca84aa607b7e79a9252a4702ef877cfd4..bfb5037e41f537c45f8ababc2559151f40d89b4d 100644 --- a/lib/kadeploy3/server/server.rb +++ b/lib/kadeploy3/server/server.rb @@ -61,12 +61,12 @@ class KadeployServer workflows_kill(get_nodes()) end - def load_config(caches=nil) + def load_config(caches = nil) ret = nil begin - ret = Configuration::Config.new(nil,caches) + ret = Configuration::Config.new(nil, caches) rescue KadeployError, ArgumentError => e - kaerror(APIError::BAD_CONFIGURATION,e.message) + kaerror(APIError::BAD_CONFIGURATION, e.message) end ret end @@ -79,7 +79,7 @@ class KadeployServer @config = newconfig oldconfig.free else - kaerror(APIError::BAD_CONFIGURATION,'Some static parameters were modified, please restart the server') + kaerror(APIError::BAD_CONFIGURATION, 'Some static parameters were modified, please restart the server') end end end @@ -107,75 +107,75 @@ class KadeployServer conf.common.deploy_db_passwd.dup, conf.common.deploy_db_name.dup ) then - kaerror(APIError::DATABASE_ERROR,'Cannot connect to the database') + kaerror(APIError::DATABASE_ERROR, 'Cannot connect to the database') end db end end def rights_handler(db) - Rights::Factory.create(cfg.common.rights_kind.dup,db) + Rights::Factory.create(cfg.common.rights_kind.dup, db) end def check_database() begin database_handler().free rescue - kaerror(APIError::DATABASE_ERROR,'Cannot connect to the database') + kaerror(APIError::DATABASE_ERROR, 'Cannot connect to the database') end end - def kaerror(errno,msg='') - raise KadeployError.new(errno,nil,msg) + def kaerror(errno, msg = '') + raise KadeployError.new(errno, nil, msg) end - def error_not_found!(msg=nil) + def error_not_found!(msg = nil) raise HTTPd::NotFoundError.new(msg) end - def error_unauthorized!(msg=nil) + def error_unauthorized!(msg = nil) headers = nil if cfg.static[:auth][:http_basic] headers = {'WWW-Authenticate' => "Basic realm=\"#{cfg.static[:auth][:http_basic].realm}\""} end - raise HTTPd::UnauthorizedError.new(msg,headers) + raise HTTPd::UnauthorizedError.new(msg, headers) end - def error_forbidden!(msg=nil) + def error_forbidden!(msg = nil) raise HTTPd::ForbiddenError.new(msg) end - def error_invalid!(msg=nil) + def error_invalid!(msg = nil) raise HTTPd::InvalidError.new(msg) end - def error_unavailable!(msg=nil) + def error_unavailable!(msg = nil) raise HTTPd::UnavailableError.new(msg) end - def uuid(prefix='') + def uuid(prefix = '') "#{prefix}#{SecureRandom.uuid}" end - def bind(kind,info,resource,path=nil,multi=nil) + def bind(kind, info, resource, path = nil, multi = nil) if @httpd - instpath = File.join(info[:wid],path||'') + instpath = File.join(info[:wid], path || '') unless multi - path = API.path(kind,instpath) - info[:resources][resource] = API.ppath(kind,'/',instpath) + path = API.path(kind, instpath) + info[:resources][resource] = API.ppath(kind, '/', instpath) if block_given? - yield(@httpd,path) + yield(@httpd, path) info[:bindings] << path end else info[:resources][resource] = {} multi.each do |res| - minstpath = File.join(instpath,res) - path = API.path(kind,minstpath) + minstpath = File.join(instpath, res) + path = API.path(kind, minstpath) info[:resources][resource][res] = HTTP::Client.path_params( - API.ppath(kind,'/',minstpath),{:user=>info[:user]}) + API.ppath(kind, '/', minstpath), {:user => info[:user]}) if block_given? - yield(@httpd,path,res) + yield(@httpd, path, res) info[:bindings] << path end end @@ -219,29 +219,29 @@ class KadeployServer end def wipe_exec_context(context) - #context.marshal_dump.keys.each do |name| + # context.marshal_dump.keys.each do |name| # obj = context.send(name.to_sym) # obj.free if obj.respond_to?(:free) # obj.clear if obj.respond_to?(:clear) # context.delete_field(name) - #end + # end end - def parse_params_default(params,context) + def parse_params_default(params, context) parse_params(params) do |p| - context.dry_run = p.parse('dry_run',nil,:toggle=>true) + context.dry_run = p.parse('dry_run', nil, :toggle => true) end end def parse_params(params) parser = nil - cfg(){ |conf| parser = ParamsParser.new(params,conf) } + cfg(){ |conf| parser = ParamsParser.new(params, conf) } yield(parser) parser.free parser = nil end - def parse_auth_header(req,key,error=true) + def parse_auth_header(req, key, error = true) val = req["#{cfg.static[:auth_headers_prefix]}#{key}"] val = nil if val.is_a?(String) and val.empty? if error and !val @@ -252,33 +252,33 @@ class KadeployServer end def authenticate!(request) - user = parse_auth_header(request,'User',false) + user = parse_auth_header(request, 'User', false) # Authentication with ACL if cfg.static[:auth][:acl] and user - ok,msg = cfg.static[:auth][:acl].auth!(HTTPd.get_sockaddr(request)) + ok, msg = cfg.static[:auth][:acl].auth!(HTTPd.get_sockaddr(request)) return user if ok end # Authentication by HTTP Basic Authentication (RFC 2617) if request['Authorization'] and cfg.static[:auth][:http_basic] - ok,msg = cfg.static[:auth][:http_basic].auth!( - HTTPd.get_sockaddr(request), :req=>request) + ok, msg = cfg.static[:auth][:http_basic].auth!( + HTTPd.get_sockaddr(request), :req => request) error_unauthorized!("Authentication failed: #{msg}") unless ok user = request.user elsif user and !user.empty? - user = parse_auth_header(request,'User') - cert = parse_auth_header(request,'Certificate',false) + user = parse_auth_header(request, 'User') + cert = parse_auth_header(request, 'Certificate', false) # Authentication with certificate if cfg.static[:auth][:cert] and cert - ok,msg = cfg.static[:auth][:cert].auth!( - HTTPd.get_sockaddr(request), :user=>user, :cert=>Base64.strict_decode64(cert)) + ok, msg = cfg.static[:auth][:cert].auth!( + HTTPd.get_sockaddr(request), :user => user, :cert => Base64.strict_decode64(cert)) error_unauthorized!("Authentication failed: #{msg}") unless ok # Authentication with Ident elsif cfg.static[:auth][:ident] - ok,msg = cfg.static[:auth][:ident].auth!( - HTTPd.get_sockaddr(request), :user=>user, :port=>@httpd.port) + ok, msg = cfg.static[:auth][:ident].auth!( + HTTPd.get_sockaddr(request), :user => user, :port => @httpd.port) error_unauthorized!("Authentication failed: #{msg}") unless ok else error_unauthorized!("Authentication failed: valid methods are "\ @@ -287,13 +287,13 @@ class KadeployServer else # Authentication with Ident if cfg.static[:auth][:ident] - user,_ = cfg.static[:auth][:ident].auth!( - HTTPd.get_sockaddr(request), :port=>@httpd.port) + user, _ = cfg.static[:auth][:ident].auth!( + HTTPd.get_sockaddr(request), :port => @httpd.port) return user if user and user.is_a?(String) and !user.empty? # Authentication with certificate elsif cfg.static[:auth][:cert] and cert - user,_ = cfg.static[:auth][:cert].auth!( - HTTPd.get_sockaddr(request), :cert=>Base64.strict_decode64(cert)) + user, _ = cfg.static[:auth][:cert].auth!( + HTTPd.get_sockaddr(request), :cert => Base64.strict_decode64(cert)) return user if user and user.is_a?(String) and !user.empty? end error = "Authentication failed: no user specified "\ @@ -308,22 +308,22 @@ class KadeployServer def config_httpd_bindings(httpd) # GET @httpd = httpd - @httpd.bind([:GET],'/version',:content,cfg.common.version) - @httpd.bind([:GET],'/auth_headers_prefix',:content,cfg.static[:auth_headers_prefix]) - @httpd.bind([:GET],'/info',:method,:object=>self,:method=>:get_users_info) - @httpd.bind([:GET],'/clusters',:method,:object=>self,:method=>:get_clusters) - #@httpd.bind([:GET],'/nodes',:method,:object=>self,:method=>:get_nodes) - - [:deploy,:reboot,:power].each do |kind| - @httpd.bind([:POST,:PUT,:GET], - API.path(kind),:filter,:object=>self,:method=>:launch, - :args=>[1],:static=>[[kind,:work]] + @httpd.bind([:GET], '/version', :content, cfg.common.version) + @httpd.bind([:GET], '/auth_headers_prefix', :content, cfg.static[:auth_headers_prefix]) + @httpd.bind([:GET], '/info', :method, :object => self, :method => :get_users_info) + @httpd.bind([:GET], '/clusters', :method, :object => self, :method => :get_clusters) + # @httpd.bind([:GET],'/nodes',:method,:object=>self,:method=>:get_nodes) + + [:deploy, :reboot, :power].each do |kind| + @httpd.bind([:POST, :PUT, :GET], + API.path(kind), :filter, :object => self, :method => :launch, + :args => [1], :static => [[kind, :work]] ) end - @httpd.bind([:POST,:GET],API.path(:console),:filter, - :object=>self,:method=>:launch, - :args=>[1],:static=>[:console],:name=>[(2..-1)] + @httpd.bind([:POST, :GET], API.path(:console), :filter, + :object => self, :method => :launch, + :args => [1], :static => [:console], :name => [(2..-1)] ) args = { @@ -339,22 +339,22 @@ class KadeployServer :stats => [(2..-1)], } - [:envs,:rights].each do |kind| - @httpd.bind([:POST,:GET,:PUT,:DELETE], - API.path(kind),:filter,:object=>self, - :method =>:launch,:args=>args[kind],:static=>[kind],:name=>names[kind] + [:envs, :rights].each do |kind| + @httpd.bind([:POST, :GET, :PUT, :DELETE], + API.path(kind), :filter, :object => self, + :method => :launch, :args => args[kind], :static => [kind], :name => names[kind] ) end - [:nodes,:stats].each do |kind| - @httpd.bind([:GET],API.path(kind),:filter, - :object=>self,:method=>:launch, - :args=>args[kind],:static=>[kind],:name=>names[kind] + [:nodes, :stats].each do |kind| + @httpd.bind([:GET], API.path(kind), :filter, + :object => self, :method => :launch, + :args => args[kind], :static => [kind], :name => names[kind] ) end end - def prepare(_request,_kind,_query,*) + def prepare(_request, _kind, _query, *) options end @@ -363,7 +363,7 @@ class KadeployServer # if the method :deploy_my_method exists, returns [ :deploy_my_method, [1,2,3] ] # else if the method :work_my_method exists, returns [ :work_my_method, [:deploy,1,2,3] ] # else throws a NoMethodError exception - def get_method(kind,meth,args=[]) + def get_method(kind, meth, args = []) if kind.is_a?(Array) name = nil before = [] @@ -374,33 +374,33 @@ class KadeployServer end before << k end - raise NoMethodError.new("undefined method [#{kind.join(',')}]_#{meth} for #{self}","_#{meth}") unless name + raise NoMethodError.new("undefined method [#{kind.join(',')}]_#{meth} for #{self}", "_#{meth}") unless name before += args - [:"#{name}_#{meth}",before] + [:"#{name}_#{meth}", before] else if respond_to?(:"#{kind}_#{meth}") - [:"#{kind}_#{meth}",args] + [:"#{kind}_#{meth}", args] else - raise NoMethodError.new("undefined method #{kind}_#{meth} for #{self}","_#{meth}") + raise NoMethodError.new("undefined method #{kind}_#{meth} for #{self}", "_#{meth}") end end end # Run the specified method, kind defaults to 'work' if no method is found - def run_wmethod(kind,meth,*args) + def run_wmethod(kind, meth, *args) raise unless kind.is_a?(Symbol) - run_method([kind,:work],meth,*args) + run_method([kind, :work], meth, *args) end # Run the specified method depending on kind (kind_meth) - def run_method(kind,meth,*args) + def run_method(kind, meth, *args) name = nil begin - name,args = get_method(kind,meth,args) - send(name,*args) + name, args = get_method(kind, meth, args) + send(name, *args) rescue ArgumentError => e # if the problem is that the method is called with the wrong nb of args - if name and e.backtrace[0].split(/\s+/)[-1] =~ /#{get_method(kind,meth)[0]}/ \ + if name and e.backtrace[0].split(/\s+/)[-1] =~ /#{get_method(kind, meth)[0]}/ \ and e.message =~ /wrong number of arguments/ error_not_found! else @@ -408,7 +408,7 @@ class KadeployServer end rescue NoMethodError => e # if the problem is that the method does not exists - if (name and e.name and e.name.to_sym == get_method(kind,meth)[0]) or (e.name and e.name.to_sym == :"_#{meth}") + if (name and e.name and e.name.to_sym == get_method(kind, meth)[0]) or (e.name and e.name.to_sym == :"_#{meth}") error_not_found! else raise e @@ -416,7 +416,7 @@ class KadeployServer end end - def launch(params,kind,*args) + def launch(params, kind, *args) query = nil case params[:kind] when :POST @@ -439,23 +439,23 @@ class KadeployServer user = authenticate!(params[:request]) options = init_exec_context(user) - parse_params_default(params[:params],options) + parse_params_default(params[:params], options) begin # Prepare the treatment (parse arguments, ...) - options = run_method(kind,:prepare,params[:params],query,options) + options = run_method(kind, :prepare, params[:params], query, options) # Check rights # (only check rights if the method 'kind'_rights? is defined) check_rights = nil begin - get_method(kind,:'rights?') + get_method(kind, :'rights?') check_rights = true rescue check_rights = false end if check_rights - ok,msg = run_method(kind,:'rights?',options,query,params[:names],*args) + ok, msg = run_method(kind, :'rights?', options, query, params[:names], *args) msg = "You do not the rights to perform this operation" if msg.nil? or msg.empty? error_forbidden!(msg) unless ok end @@ -464,13 +464,13 @@ class KadeployServer meth = query.to_s meth << "_#{params[:names].join('_')}" if params[:names] - run_method(kind,meth,options,*args) unless options.dry_run + run_method(kind, meth, options, *args) unless options.dry_run ensure # Clean everything if options begin - get_method(kind,:free_exec_context) - run_method(kind,:free_exec_context,options) + get_method(kind, :free_exec_context) + run_method(kind, :free_exec_context, options) rescue free_exec_context(options) wipe_exec_context(options) @@ -479,7 +479,7 @@ class KadeployServer end end - def workflow_create(kind,wid,info,workkind=nil) + def workflow_create(kind, wid, info, workkind = nil) raise unless @workflows_locks[kind] raise unless @workflows_info[kind] raise unless @httpd @@ -499,18 +499,18 @@ class KadeployServer if workkind static = workkind else - static = [kind,:work] + static = [kind, :work] end - bind(kind,info,'resource') do |httpd,path| - httpd.bind([:GET,:DELETE],path,:filter,:object=>self,:method =>:launch, - :args=>[1,3,5,7],:static=>[static],:name=>[2,4,6] + bind(kind, info, 'resource') do |httpd, path| + httpd.bind([:GET, :DELETE], path, :filter, :object => self, :method => :launch, + :args => [1, 3, 5, 7], :static => [static], :name => [2, 4, 6] ) end end end - def workflow_lock(kind,wid) + def workflow_lock(kind, wid) @workflows_locks[kind].synchronize do kaerror(APIError::INVALID_WORKFLOW_ID) unless @workflows_info[kind][wid] @workflows_info[kind][wid][:lock] @@ -529,7 +529,7 @@ class KadeployServer end end - def workflow_get(kind,wid) + def workflow_get(kind, wid) raise unless @workflows_locks[kind] raise unless @workflows_info[kind] @@ -548,7 +548,7 @@ class KadeployServer ret end - def workflow_delete(kind,wid) + def workflow_delete(kind, wid) raise unless @workflows_locks[kind] raise unless @workflows_info[kind] raise unless @httpd @@ -574,13 +574,13 @@ class KadeployServer end # Kill workflows involving nodes - def workflows_kill(nodes,user=nil) + def workflows_kill(nodes, user = nil) nodes.each do |node| - [:deploy,:reboot,:power,:console].each do |kind| + [:deploy, :reboot, :power, :console].each do |kind| if @workflows_locks[kind] and @workflows_info[kind] to_kill = [] @workflows_locks[kind].synchronize do - @workflows_info[kind].each_pair do |wid,info| + @workflows_info[kind].each_pair do |wid, info| if info[:nodelist].include?(node) and (!user or info[:user] == user) to_kill << info info[:lock].lock @@ -592,9 +592,9 @@ class KadeployServer to_kill.each do |info| begin if kind == :console - console_delete!(nil,info) + console_delete!(nil, info) else - run_wmethod(kind,:delete!,nil,info) + run_wmethod(kind, :delete!, nil, info) end ensure info[:lock].unlock @@ -610,10 +610,10 @@ class KadeployServer def workflows_clean() clean_threshold = cfg().common.autoclean_threshold - [:deploy,:reboot,:power].each do |kind| + [:deploy, :reboot, :power].each do |kind| to_clean = [] @workflows_locks[kind].synchronize do - @workflows_info[kind].each_pair do |wid,info| + @workflows_info[kind].each_pair do |wid, info| info[:lock].lock if info[:done] or info[:error] # Done or Error workflow if (Time.now - info[:start_time]) > clean_threshold @@ -630,7 +630,7 @@ class KadeployServer end to_clean.each do |info| begin - run_wmethod(kind,:delete!,nil,info) + run_wmethod(kind, :delete!, nil, info) ensure info[:lock].unlock end @@ -656,7 +656,7 @@ class KadeployServer ret[:pxe] = cfg.common.pxe[:dhcp].class.name.split('::').last ret[:automata] = {} ret[:supported_fs] = {} - cfg.clusters.each_pair do |cluster,conf| + cfg.clusters.each_pair do |cluster, conf| ret[:automata][cluster] = {} conf.workflow_steps.each do |steps| ret[:automata][cluster][steps.name] = [] diff --git a/lib/kadeploy3/server/stats.rb b/lib/kadeploy3/server/stats.rb index d89b193dd9afbb2ed1e1dccba0b785b3fcb60015..10110481b9be5a7ac2bd0198fc9a3cb0ead3486a 100644 --- a/lib/kadeploy3/server/stats.rb +++ b/lib/kadeploy3/server/stats.rb @@ -1,29 +1,29 @@ module Kadeploy module Stats - MAX_RESULTS_PER_REQUEST=50000 + MAX_RESULTS_PER_REQUEST = 50000 - def self.list_failure_rates(db,operation,filters={},options={},_fields=nil) - where,args = db_filters(operation,filters) - op,args = db_options(options,args) + def self.list_failure_rates(db, operation, filters = {}, options = {}, _fields = nil) + where, args = db_filters(operation, filters) + op, args = db_options(options, args) query = "SELECT hostname,COUNT(*) FROM log" query << " WHERE #{where}" unless where.empty? query << " GROUP BY hostname" query << op unless op.empty? - total = db.run_query(query,*args).to_array + total = db.run_query(query, *args).to_array query = "SELECT hostname,COUNT(*) FROM log" query << " WHERE success = 'true'" query << " AND #{where}" unless where.empty? query << " GROUP BY hostname" query << op unless op.empty? - success = db.run_query(query,*args).to_array + success = db.run_query(query, *args).to_array ret = {} total.each do |tot| suc = success.select{|s| s[0] == tot[0]} if suc.empty? - suc = [tot[0],0] + suc = [tot[0], 0] else suc = suc[0] end @@ -36,18 +36,18 @@ module Stats ret end - def self.list_all(db,operation,filters={},options={},fields=nil) + def self.list_all(db, operation, filters = {}, options = {}, fields = nil) total = nil if options[:limit] total = options[:limit].to_i options.delete(:limit) else - where,args = db_filters(operation,filters) - opt,args = db_options(options,args) + where, args = db_filters(operation, filters) + opt, args = db_options(options, args) query = "SELECT COUNT(*) FROM log" query << " WHERE #{where}" unless where.empty? query << opt unless opt.empty? - res = db.run_query(query,*args) + res = db.run_query(query, *args) total = res.to_array[0][0] end @@ -56,17 +56,17 @@ module Stats begin ret = CompressedCSV.new() if total > 0 - where,args = db_filters(operation,filters) - opt,args = db_options(options,args) + where, args = db_filters(operation, filters) + opt, args = db_options(options, args) tot = total - (total.to_f/MAX_RESULTS_PER_REQUEST).ceil.times do |i| - to_treat = (tot>=MAX_RESULTS_PER_REQUEST ? MAX_RESULTS_PER_REQUEST : tot) + (total.to_f / MAX_RESULTS_PER_REQUEST).ceil.times do |i| + to_treat = (tot >= MAX_RESULTS_PER_REQUEST ? MAX_RESULTS_PER_REQUEST : tot) query = "SELECT CONCAT_WS(',',#{fields.join(',')}) FROM log" query << " WHERE #{where}" unless where.empty? query << opt unless opt.empty? - query << " LIMIT #{i*MAX_RESULTS_PER_REQUEST},#{to_treat}" + query << " LIMIT #{i * MAX_RESULTS_PER_REQUEST},#{to_treat}" - res = db.run_query(query,*args) + res = db.run_query(query, *args) res.to_array.flatten!.each{|r| ret << r; ret << "\n"} res.free @@ -84,43 +84,43 @@ module Stats ret end - def self.db_field(table,name,expr) - "#{table && (table+'.'+name) || name} #{expr}" + def self.db_field(table, name, expr) + "#{table && (table + '.' + name) || name} #{expr}" end - def self.db_filters(operation,filters,table=nil) + def self.db_filters(operation, filters, table = nil) ret = '' args = [] - return ret,args unless filters + return ret, args unless filters if operation ret << ' AND ' unless ret.empty? - ret << db_field(table,'wid',"like '#{API.wid_prefix(operation)}%'") + ret << db_field(table, 'wid', "like '#{API.wid_prefix(operation)}%'") end if filters[:nodes] ret << ' AND ' unless ret.empty? args += filters[:nodes] - ret << db_field(table,'hostname',"IN (#{(['?']*filters[:nodes].size).join(',')})") + ret << db_field(table, 'hostname', "IN (#{(['?'] * filters[:nodes].size).join(',')})") end if filters[:date_min] ret << ' AND ' unless ret.empty? args << filters[:date_min].to_i - ret << db_field(table,'start','>= ?') + ret << db_field(table, 'start', '>= ?') end if filters[:date_max] ret << ' AND ' unless ret.empty? args << filters[:date_max].to_i - ret << db_field(table,'start','<= ?') + ret << db_field(table, 'start', '<= ?') end if filters[:wid] ret << ' AND ' unless ret.empty? args << filters[:wid] - ret << db_field(table,'wid','= ?') + ret << db_field(table, 'wid', '= ?') end if filters[:min_retries] @@ -134,16 +134,16 @@ module Stats end end - return [ret,args] + return [ret, args] end - def self.db_options(options,args=[]) + def self.db_options(options, args = []) ret = '' - #if options[:failure_rate] + # if options[:failure_rate] # ret << ' HAVING success >= ?' # args << options[:failure_rate].to_f - #end + # end if options[:sort] # Has to be the last one ret << " ORDER BY #{options[:sort].join(',')}" @@ -154,7 +154,7 @@ module Stats args << options[:limit] end - return [ret,args] + return [ret, args] end private_class_method :db_field, :db_filters, :db_options diff --git a/lib/kadeploy3/server/stepdeploy.rb b/lib/kadeploy3/server/stepdeploy.rb index 11fa583176f1e548a136297806f620ce9eea3c38..f2e984bbf6e5112ef50fb2d2f3f2a476c29586b8 100644 --- a/lib/kadeploy3/server/stepdeploy.rb +++ b/lib/kadeploy3/server/stepdeploy.rb @@ -12,16 +12,16 @@ module Macrostep class DeploySetDeploymentEnvUntrusted < DeploySetDeploymentEnv def steps() [ - [ :switch_pxe, "prod_to_deploy_env", "" ], - [ :set_default_vlan ], - [ :reboot, "soft" ], - [ :wait_reboot ], - [ :send_key_in_deploy_env, :tree ], - [ :create_partition_table ], - [ :format_deploy_part ], - [ :mount_deploy_part ], - [ :format_tmp_part ], - [ :format_swap_part ], + [:switch_pxe, "prod_to_deploy_env", ""], + [:set_default_vlan], + [:reboot, "soft"], + [:wait_reboot], + [:send_key_in_deploy_env, :tree], + [:create_partition_table], + [:format_deploy_part], + [:mount_deploy_part], + [:format_tmp_part], + [:format_swap_part], ] end end @@ -29,17 +29,17 @@ module Macrostep class DeploySetDeploymentEnvKexec < DeploySetDeploymentEnv def steps() [ - [ :switch_pxe, "prod_to_deploy_env", "" ], - [ :send_deployment_kernel, :tree ], - [ :set_default_vlan ], - [ :kexec, :to_deploy_kernel], - [ :wait_reboot ], - [ :send_key_in_deploy_env, :tree ], - [ :create_partition_table ], - [ :format_deploy_part ], - [ :mount_deploy_part ], - [ :format_tmp_part ], - [ :format_swap_part ], + [:switch_pxe, "prod_to_deploy_env", ""], + [:send_deployment_kernel, :tree], + [:set_default_vlan], + [:kexec, :to_deploy_kernel], + [:wait_reboot], + [:send_key_in_deploy_env, :tree], + [:create_partition_table], + [:format_deploy_part], + [:mount_deploy_part], + [:format_tmp_part], + [:format_swap_part], ] end end @@ -52,12 +52,12 @@ module Macrostep class DeploySetDeploymentEnvUntrustedCustomPreInstall < DeploySetDeploymentEnv def steps() [ - [ :switch_pxe, "prod_to_deploy_env" ], - [ :set_default_vlan ], - [ :reboot, "soft" ], - [ :wait_reboot ], - [ :send_key_in_deploy_env, :tree ], - [ :manage_admin_pre_install, :tree ], + [:switch_pxe, "prod_to_deploy_env"], + [:set_default_vlan], + [:reboot, "soft"], + [:wait_reboot], + [:send_key_in_deploy_env, :tree], + [:manage_admin_pre_install, :tree], ] end end @@ -65,9 +65,9 @@ module Macrostep class DeploySetDeploymentEnvProd < DeploySetDeploymentEnv def steps() [ - [ :format_deploy_part ], - [ :mount_deploy_part ], - [ :format_tmp_part ], + [:format_deploy_part], + [:mount_deploy_part], + [:format_tmp_part], ] end end @@ -75,16 +75,16 @@ module Macrostep class DeploySetDeploymentEnvNfsroot < DeploySetDeploymentEnv def steps() [ - [ :switch_pxe, "prod_to_nfsroot_env" ], - [ :set_default_vlan ], - [ :reboot, "soft" ], - [ :wait_reboot ], - [ :send_key_in_deploy_env, :tree ], - [ :create_partition_table ], - [ :format_deploy_part ], - [ :mount_deploy_part ], - [ :format_tmp_part ], - [ :format_swap_part ], + [:switch_pxe, "prod_to_nfsroot_env"], + [:set_default_vlan], + [:reboot, "soft"], + [:wait_reboot], + [:send_key_in_deploy_env, :tree], + [:create_partition_table], + [:format_deploy_part], + [:mount_deploy_part], + [:format_tmp_part], + [:format_swap_part], ] end end @@ -92,8 +92,8 @@ module Macrostep class DeploySetDeploymentEnvDummy < DeploySetDeploymentEnv def steps() [ - [ :dummy ], - [ :dummy ], + [:dummy], + [:dummy], ] end end @@ -109,14 +109,14 @@ module Macrostep class DeployBroadcastEnvChain < DeployBroadcastEnv def steps() [ - [ :send_environment, :chain ], - [ :decompress_environment, :tree ], - [ :manage_admin_post_install, :tree ], - [ :manage_user_post_install, :tree ], - [ :check_kernel_files ], - [ :send_key, :tree ], - [ :sync ], - [ :install_bootloader ], + [:send_environment, :chain], + [:decompress_environment, :tree], + [:manage_admin_post_install, :tree], + [:manage_user_post_install, :tree], + [:check_kernel_files], + [:send_key, :tree], + [:sync], + [:install_bootloader], ] end end @@ -124,15 +124,15 @@ module Macrostep class DeployBroadcastEnvKascade < DeployBroadcastEnv def steps() [ - [ :send_environment, :kascade ], - [ :decompress_environment, :tree ], - [ :mount_deploy_part ], - [ :manage_admin_post_install, :tree ], - [ :manage_user_post_install, :tree ], - [ :check_kernel_files ], - [ :send_key, :tree ], - [ :sync ], - [ :install_bootloader ], + [:send_environment, :kascade], + [:decompress_environment, :tree], + [:mount_deploy_part], + [:manage_admin_post_install, :tree], + [:manage_user_post_install, :tree], + [:check_kernel_files], + [:send_key, :tree], + [:sync], + [:install_bootloader], ] end end @@ -140,15 +140,15 @@ module Macrostep class DeployBroadcastEnvKastafior < DeployBroadcastEnv def steps() [ - [ :send_environment, :kastafior ], - [ :decompress_environment, :tree ], - [ :mount_deploy_part ], - [ :manage_admin_post_install, :tree ], - [ :manage_user_post_install, :tree ], - [ :check_kernel_files ], - [ :send_key, :tree ], - [ :sync ], - [ :install_bootloader ], + [:send_environment, :kastafior], + [:decompress_environment, :tree], + [:mount_deploy_part], + [:manage_admin_post_install, :tree], + [:manage_user_post_install, :tree], + [:check_kernel_files], + [:send_key, :tree], + [:sync], + [:install_bootloader], ] end end @@ -156,14 +156,14 @@ module Macrostep class DeployBroadcastEnvTree < DeployBroadcastEnv def steps() [ - [ :send_environment, :tree ], - [ :decompress_environment, :tree ], - [ :manage_admin_post_install, :tree ], - [ :manage_user_post_install, :tree ], - [ :check_kernel_files ], - [ :send_key, :tree ], - [ :sync ], - [ :install_bootloader ], + [:send_environment, :tree], + [:decompress_environment, :tree], + [:manage_admin_post_install, :tree], + [:manage_user_post_install, :tree], + [:check_kernel_files], + [:send_key, :tree], + [:sync], + [:install_bootloader], ] end end @@ -171,15 +171,15 @@ module Macrostep class DeployBroadcastEnvBittorrent < DeployBroadcastEnv def steps() [ - [ :mount_tmp_part ], #we need /tmp to store the tarball - [ :send_environment, :bittorrent ], - [ :decompress_environment, :tree ], - [ :manage_admin_post_install, :tree ], - [ :manage_user_post_install, :tree ], - [ :check_kernel_files ], - [ :send_key, :tree ], - [ :sync ], - [ :install_bootloader ], + [:mount_tmp_part], # we need /tmp to store the tarball + [:send_environment, :bittorrent], + [:decompress_environment, :tree], + [:manage_admin_post_install, :tree], + [:manage_user_post_install, :tree], + [:check_kernel_files], + [:send_key, :tree], + [:sync], + [:install_bootloader], ] end end @@ -187,14 +187,14 @@ module Macrostep class DeployBroadcastEnvCustom < DeployBroadcastEnv def steps() [ - [ :send_environment, :custom ], - [ :decompress_environment, :tree ], - [ :manage_admin_post_install, :tree ], - [ :manage_user_post_install, :tree ], - [ :check_kernel_files ], - [ :send_key, :tree ], - [ :sync ], - [ :install_bootloader ], + [:send_environment, :custom], + [:decompress_environment, :tree], + [:manage_admin_post_install, :tree], + [:manage_user_post_install, :tree], + [:check_kernel_files], + [:send_key, :tree], + [:sync], + [:install_bootloader], ] end end @@ -202,8 +202,8 @@ module Macrostep class DeployBroadcastEnvDummy < DeployBroadcastEnv def steps() [ - [ :dummy ], - [ :dummy ], + [:dummy], + [:dummy], ] end end @@ -219,12 +219,12 @@ module Macrostep class DeployBootNewEnvKexec < DeployBootNewEnv def steps() [ - [ :switch_pxe, "deploy_to_deployed_env" ], - [ :umount_deploy_part ], - [ :mount_deploy_part ], - [ :kexec, :to_deployed_env], - [ :set_vlan ], - [ :wait_reboot, "kexec", "user", true ], + [:switch_pxe, "deploy_to_deployed_env"], + [:umount_deploy_part], + [:mount_deploy_part], + [:kexec, :to_deployed_env], + [:set_vlan], + [:wait_reboot, "kexec", "user", true], ] end end @@ -241,11 +241,11 @@ module Macrostep DESC = "Reboot to the deployed environment without kexec. Used when a cluster does not support kexec." def steps() [ - [ :switch_pxe, "deploy_to_deployed_env" ], - [ :umount_deploy_part ], - [ :reboot_from_deploy_env ], - [ :set_vlan ], - [ :wait_reboot, "classical", "user", true ], + [:switch_pxe, "deploy_to_deployed_env"], + [:umount_deploy_part], + [:reboot_from_deploy_env], + [:set_vlan], + [:wait_reboot, "classical", "user", true], ] end end @@ -253,10 +253,10 @@ module Macrostep class DeployBootNewEnvHardReboot < DeployBootNewEnv def steps() [ - [ :switch_pxe, "deploy_to_deployed_env" ], - [ :reboot, "hard" ], - [ :set_vlan ], - [ :wait_reboot, "classical", "user", true ], + [:switch_pxe, "deploy_to_deployed_env"], + [:reboot, "hard"], + [:set_vlan], + [:wait_reboot, "classical", "user", true], ] end end @@ -264,8 +264,8 @@ module Macrostep class DeployBootNewEnvDummy < DeployBootNewEnv def steps() [ - [ :dummy ], - [ :dummy ], + [:dummy], + [:dummy], ] end end diff --git a/lib/kadeploy3/server/steppower.rb b/lib/kadeploy3/server/steppower.rb index 3e7f101795aa793963bd802ff1e1fd18efce9b17..52585c758d8be3dfd9b94957f47eefd1e1116f18 100644 --- a/lib/kadeploy3/server/steppower.rb +++ b/lib/kadeploy3/server/steppower.rb @@ -4,7 +4,7 @@ module Macrostep class PowerOn < Power def steps() [ - [ :power, :on, context[:execution].level ], + [:power, :on, context[:execution].level], ] end end @@ -12,7 +12,7 @@ module Macrostep class PowerOff < Power def steps() [ - [ :power, :off, context[:execution].level ], + [:power, :off, context[:execution].level], ] end end @@ -20,7 +20,7 @@ module Macrostep class PowerStatus < Power def steps() [ - [ :power, :status, nil ], + [:power, :status, nil], ] end end diff --git a/lib/kadeploy3/server/stepreboot.rb b/lib/kadeploy3/server/stepreboot.rb index db8fa7c061962e2480dc37624ba1388f70fa67d9..7d7c522e3f2f62c443a119d971b897fa159c0494 100644 --- a/lib/kadeploy3/server/stepreboot.rb +++ b/lib/kadeploy3/server/stepreboot.rb @@ -4,9 +4,9 @@ module Macrostep class RebootSimple < Reboot def steps() [ - [ :reboot, context[:execution].level ], - [ :set_vlan ], - [ :wait_reboot, 'classical', 'user', true ], + [:reboot, context[:execution].level], + [:set_vlan], + [:wait_reboot, 'classical', 'user', true], ] end end @@ -14,10 +14,10 @@ module Macrostep class RebootSetPXE < Reboot def steps() [ - [ :switch_pxe, 'set_pxe', context[:execution].pxe[:profile] ], - [ :reboot, context[:execution].level ], - [ :set_vlan ], - [ :wait_reboot, 'classical', 'user', true ], + [:switch_pxe, 'set_pxe', context[:execution].pxe[:profile]], + [:reboot, context[:execution].level], + [:set_vlan], + [:wait_reboot, 'classical', 'user', true], ] end end @@ -25,11 +25,11 @@ module Macrostep class RebootDeployEnv < Reboot def steps() [ - [ :switch_pxe, 'prod_to_deploy_env' ], - [ :reboot, context[:execution].level ], - [ :set_vlan ], - [ :wait_reboot, 'classical', 'deploy', true ], - [ :send_key_in_deploy_env, :tree ], + [:switch_pxe, 'prod_to_deploy_env'], + [:reboot, context[:execution].level], + [:set_vlan], + [:wait_reboot, 'classical', 'deploy', true], + [:send_key_in_deploy_env, :tree], ] end end @@ -37,10 +37,10 @@ module Macrostep class RebootRecordedEnv < Reboot def steps() [ - [ :switch_pxe, 'deploy_to_deployed_env' ], - [ :reboot, context[:execution].level ], - [ :set_vlan ], - [ :wait_reboot, 'classical', 'user', true ], + [:switch_pxe, 'deploy_to_deployed_env'], + [:reboot, context[:execution].level], + [:set_vlan], + [:wait_reboot, 'classical', 'user', true], ] end end diff --git a/lib/kadeploy3/server/taktuk.rb b/lib/kadeploy3/server/taktuk.rb index 74519ecfba64e69b3826bf55c39c228a76db23c4..de20ec12aebeb68f742c4ac0de649c4c946829ba 100644 --- a/lib/kadeploy3/server/taktuk.rb +++ b/lib/kadeploy3/server/taktuk.rb @@ -13,17 +13,17 @@ module TakTuk def visit(results) ret = {} - results.each_pair do |host,pids| - pids.each_pair do |pid,values| + results.each_pair do |host, pids| + pids.each_pair do |pid, values| affected = false - ret.each_pair do |k,v| + ret.each_pair do |k, v| if values.eql?(v) - k << [ host, pid ] + k << [host, pid] affected = true break end end - ret[[[host,pid]]] = values unless affected + ret[[[host, pid]]] = values unless affected end end ret @@ -32,7 +32,7 @@ module TakTuk class DefaultAggregator < Aggregator def initialize - super([:host,:pid]) + super([:host, :pid]) end end @@ -40,7 +40,7 @@ module TakTuk class Result < Hash attr_reader :content - def initialize(content={}) + def initialize(content = {}) @content = content end @@ -54,10 +54,10 @@ module TakTuk self.clear end - def add(host,pid,val,concatval=false) + def add(host, pid, val, concatval = false) raise unless val.is_a?(Hash) - self.store(host,{}) unless self[host] - self[host].store(pid,{}) unless self[host][pid] + self.store(host, {}) unless self[host] + self[host].store(pid, {}) unless self[host][pid] val.each_key do |k| if concatval self[host][pid][k] = '' unless self[host][pid][k] @@ -86,7 +86,7 @@ module TakTuk "(?:[A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])" HOSTNAME_REGEXP = "#{IP_REGEXP}|#{DOMAIN_REGEXP}" - def initialize(type,template=nil,concat=false) + def initialize(type, template = nil, concat = false) @type = type @template = template @concat = concat @@ -116,7 +116,7 @@ module TakTuk end def to_cmd - #"#{@type.to_s}="\ + # "#{@type.to_s}="\ "\"$type#{SEPARATOR}$pid#{SEPARATOR}$host#{SEPARATOR}\""\ "#{@template.to_cmd}.\"\\n\"" end @@ -124,25 +124,25 @@ module TakTuk class ConnectorStream < Stream def initialize(template) - super(:connector,template) + super(:connector, template) end end class OutputStream < Stream def initialize(template) - super(:output,template,true) + super(:output, template, true) end end class ErrorStream < Stream def initialize(template) - super(:error,template) + super(:error, template) end end class StatusStream < Stream def initialize(template) - super(:status,template) + super(:status, template) end end @@ -179,11 +179,11 @@ module TakTuk } def initialize(template) - super(:state,template) + super(:state, template) end # type can be :error, :progress or :done - def self.check?(type,state) + def self.check?(type, state) return nil unless STATES[type] state = state.strip @@ -204,24 +204,24 @@ module TakTuk class MessageStream < Stream def initialize(template) - super(:message,template) + super(:message, template) end end class InfoStream < Stream def initialize(template) - super(:info,template) + super(:info, template) end end class TaktukStream < Stream def initialize(template) - super(:taktuk,template) + super(:taktuk, template) end end class Template - SEPARATOR=':' + SEPARATOR = ':' attr_reader :fields def initialize(fields) @@ -240,7 +240,7 @@ module TakTuk end def to_cmd - @fields.inject('') do |ret,field| + @fields.inject('') do |ret, field| ret + ".length(\"$#{field}\").\"#{SEPARATOR}$#{field}\"" end end @@ -249,13 +249,13 @@ module TakTuk ret = {} curpos = 0 @fields.each do |field| - len,tmp = string[curpos..-1].split(SEPARATOR,2) + len, tmp = string[curpos..-1].split(SEPARATOR, 2) leni = len.to_i raise ArgumentError.new('Command line output do not match the template') if tmp.nil? if leni <= 0 ret[field] = '' else - ret[field] = tmp.slice!(0..(leni-1)) + ret[field] = tmp.slice!(0..(leni - 1)) end curpos += len.length + leni + 1 end @@ -271,17 +271,17 @@ module TakTuk 'send-files', 'taktuk-command', 'path-value', 'command-separator', 'escape-character', 'option-separator', 'output-redirect', 'worksteal-behavior', 'time-granularity', 'no-numbering', 'timeout', - 'cache-limit', 'window','window-adaptation','not-root','debug' + 'cache-limit', 'window', 'window-adaptation', 'not-root', 'debug' ] def check(optname) - ret = optname.to_s.gsub(/_/,'-').strip + ret = optname.to_s.gsub(/_/, '-').strip raise ArgumentError.new("Invalid TakTuk option '--#{ret}'") unless VALID.include?(ret) ret end def to_cmd - self.keys.inject([]) do |ret,opt| + self.keys.inject([]) do |ret, opt| ret << "--#{check(opt)}" if self[opt] if self[opt].is_a?(String) @@ -297,7 +297,7 @@ module TakTuk class Hostlist def initialize(hostlist) - @hostlist=hostlist + @hostlist = hostlist end def free @@ -332,7 +332,7 @@ module TakTuk end class Commands < Array - TOKENS=[ + TOKENS = [ 'broadcast', 'downcast', 'exec', 'get', 'put', 'input', 'data', 'file', 'pipe', 'close', 'line', 'target', 'kill', 'message', 'network', 'state', 'cancel', 'renumber', 'update', 'option', @@ -350,7 +350,7 @@ module TakTuk elsif val.nil? or val.empty? false else - tmp = val.split(' ',2) + tmp = val.split(' ', 2) return false unless valid?(tmp[0]) if !tmp[1].nil? and !tmp[1].empty? check(tmp[1]) @@ -368,9 +368,9 @@ module TakTuk end def to_cmd - self.inject([]) do |ret,val| + self.inject([]) do |ret, val| if val =~ /^\[(.*)\]$/ - ret + ['[',Regexp.last_match(1).strip,']'] + ret + ['[', Regexp.last_match(1).strip, ']'] else ret + val.split(' ') end @@ -379,19 +379,19 @@ module TakTuk end class TakTuk - attr_accessor :streams,:binary - attr_reader :stdout,:stderr,:status, :args, :exec + attr_accessor :streams, :binary + attr_reader :stdout, :stderr, :status, :args, :exec - def initialize(hostlist,options = {:connector => 'ssh'}) + def initialize(hostlist, options = {:connector => 'ssh'}) @binary = 'taktuk' @options = Options[options] @streams = { :output => OutputStream.new(Template[:line]), :error => ErrorStream.new(Template[:line]), - :status => StatusStream.new(Template[:command,:line]), - :connector => ConnectorStream.new(Template[:command,:line]), - :state => StateStream.new(Template[:command,:line,:peer]), + :status => StatusStream.new(Template[:command, :line]), + :connector => ConnectorStream.new(Template[:command, :line]), + :state => StateStream.new(Template[:command, :line, :peer]), :info => nil, :message => nil, :taktuk => nil, @@ -409,7 +409,7 @@ module TakTuk @curthread = nil end - def opts!(opts={}) + def opts!(opts = {}) @options = Options[opts] end @@ -417,7 +417,7 @@ module TakTuk @curthread = Thread.current @args = [] @args += @options.to_cmd - @streams.each_pair do |name,stream| + @streams.each_pair do |name, stream| temp = (stream.is_a?(Stream) ? "=#{stream.to_cmd}" : '') @args << '-o' @args << "#{name}#{temp}" @@ -427,12 +427,12 @@ module TakTuk hosts = @hostlist.to_a outputs_size = opts[:outputs_size] || 0 - @exec = Execute[@binary,*@args].run!( + @exec = Execute[@binary, *@args].run!( :stdout_size => outputs_size * hosts.size, :stderr_size => outputs_size * hosts.size, :stdin => false ) - @status, @stdout, @stderr, emptypipes = @exec.wait({:checkstatus=>false}) + @status, @stdout, @stderr, emptypipes = @exec.wait({:checkstatus => false}) unless @status.success? @curthread = nil @@ -446,7 +446,7 @@ module TakTuk end results = {} - @streams.each_pair do |name,stream| + @streams.each_pair do |name, stream| if stream.is_a?(Stream) results[name] = stream.parse(@stdout) else @@ -496,13 +496,13 @@ module TakTuk self end - def [](command,prefix='[',suffix=']') + def [](command, prefix = '[', suffix = ']') @commands << "#{prefix} #{command} #{suffix}" self end - def method_missing(meth,*args) - @commands << (meth.to_s.gsub(/_/,' ').strip.downcase) + def method_missing(meth, *args) + @commands << (meth.to_s.gsub(/_/, ' ').strip.downcase) args.each do |arg| @commands.push(arg.strip.downcase) end diff --git a/lib/kadeploy3/server/workflow.rb b/lib/kadeploy3/server/workflow.rb index ad13e55cead30f9fd380862935c5f781d1a803a0..5f80537848255d6bbf6ce362f9fe24554dcc712a 100644 --- a/lib/kadeploy3/server/workflow.rb +++ b/lib/kadeploy3/server/workflow.rb @@ -8,11 +8,11 @@ module Workflow include Printer attr_reader :nodes_brk, :nodes_ok, :nodes_ko, :tasks, :output, :logger, :errno - def initialize(nodeset,context={}) + def initialize(nodeset, context = {}) @tasks = [] @errno = nil @output = context[:output] - super(nodeset,context) + super(nodeset, context) @nodes_brk = Nodes::NodeSet.new @nodes_ok = Nodes::NodeSet.new @nodes_ko = Nodes::NodeSet.new @@ -26,11 +26,11 @@ module Workflow @errno = nil @output.free if @output @output = nil - #@nodes_brk.free(false) if @nodes_brk + # @nodes_brk.free(false) if @nodes_brk @nodes_brk = nil - #@nodes_ok.free(false) if @nodes_ok + # @nodes_ok.free(false) if @nodes_ok @nodes_ok = nil - #@nodes_ko.free(false) if @nodes_ko + # @nodes_ko.free(false) if @nodes_ko @nodes_ko = nil @logger.free if @logger @logger = nil @@ -49,10 +49,10 @@ module Workflow super() or !@errno.nil? end - def error(errno,msg='',abrt=true) + def error(errno, msg = '', abrt = true) @errno = errno - @nodes.set_state('aborted',nil,context[:database],context[:user]) if abrt - raise KadeployError.new(@errno,nil,msg) + @nodes.set_state('aborted', nil, context[:database], context[:user]) if abrt + raise KadeployError.new(@errno, nil, msg) end def check_file(path) @@ -66,10 +66,10 @@ module Workflow if kind.nil? unless File.readable?(path) - error(APIError::INVALID_FILE,"The file '#{path}' is not readable on the server") + error(APIError::INVALID_FILE, "The file '#{path}' is not readable on the server") end else - error(APIError::CACHE_ERROR,"The file '#{path}' should have been cached") + error(APIError::CACHE_ERROR, "The file '#{path}' should have been cached") end end end @@ -132,20 +132,20 @@ module Workflow end # Config the macrostep instsym = instance[0].to_sym - conf_task(instsym, {:retries => instance[1],:timeout => instance[2]}) + conf_task(instsym, {:retries => instance[1], :timeout => instance[2]}) conf_task(instsym, {:raisable => instance[3]}) if instance.size >= 4 conf_task(instsym, {:breakpoint => breakpoint}) conf_task(instsym, {:config => conf}) end end - error(APIError::INVALID_OPTION,"The step '#{brk[0]}:#{brk[1]}' is not used during the operation") if brk and !breaked + error(APIError::INVALID_OPTION, "The step '#{brk[0]}:#{brk[1]}' is not used during the operation") if brk and !breaked check_config() end - def create_task(idx,subidx,nodes,nsid,context) - taskval = get_task(idx,subidx) + def create_task(idx, subidx, nodes, nsid, context) + taskval = get_task(idx, subidx) begin klass = ::Kadeploy::Macrostep.const_get("#{self.class.name.split('::').last}#{taskval[0]}") @@ -174,12 +174,12 @@ module Workflow yield if block_given? self.start rescue KadeployError => ke - error(ke.errno,ke.message) + error(ke.errno, ke.message) end end end - def kill(dofree=true) + def kill(dofree = true) super(false) @nodes_ok.clean() @nodes.linked_copy(@nodes_ko) @@ -199,7 +199,7 @@ module Workflow # Check nodes deploying unless context[:execution].force - _,to_discard = @nodes.check_nodes_used( + _, to_discard = @nodes.check_nodes_used( context[:database], context[:common].purge_deployment_timer ) @@ -235,23 +235,23 @@ module Workflow load_custom_operations() end - def break!(task,nodeset) - @nodes_brk.set_state(self.class.operation('ed'),nil, - context[:database],context[:user]) + def break!(task, nodeset) + @nodes_brk.set_state(self.class.operation('ed'), nil, + context[:database], context[:user]) @nodes_brk.set.each do |node| - context[:states].set(node.hostname,nil,nil,'brk') - context[:states].unset(node.hostname,:macro,:micro,:error) + context[:states].set(node.hostname, nil, nil, 'brk') + context[:states].unset(node.hostname, :macro, :micro, :error) end log('success', true, nodeset) - debug(1,"Breakpoint reached for #{nodeset.to_s_fold}",task.nsid) + debug(1, "Breakpoint reached for #{nodeset.to_s_fold}", task.nsid) end - def success!(task,nodeset) - @nodes_ok.set_state(self.class.operation('ed'),nil, - context[:database],context[:user]) + def success!(task, nodeset) + @nodes_ok.set_state(self.class.operation('ed'), nil, + context[:database], context[:user]) @nodes_ok.set.each do |node| - context[:states].set(node.hostname,nil,nil,'ok') - context[:states].unset(node.hostname,:macro,:micro,:error) + context[:states].set(node.hostname, nil, nil, 'ok') + context[:states].unset(node.hostname, :macro, :micro, :error) end log('success', true, nodeset) debug(1, @@ -261,17 +261,17 @@ module Workflow ) end - def fail!(_task,nodeset) - @nodes_ko.set_state(self.class.operation('_failed'),nil, - context[:database],context[:user]) + def fail!(_task, nodeset) + @nodes_ko.set_state(self.class.operation('_failed'), nil, + context[:database], context[:user]) @nodes_ko.set.each do |node| - context[:states].set(node.hostname,nil,nil,'ko') + context[:states].set(node.hostname, nil, nil, 'ko') end log('success', false, nodeset) - @logger.error(nodeset,context[:states]) + @logger.error(nodeset, context[:states]) end - def display_fail_message(task,nodeset) + def display_fail_message(task, nodeset) debug(1, "#{self.class.opname().capitalize} failed for #{nodeset.to_s_fold} "\ "after #{Time.now.to_i - @start_time}s", @@ -292,14 +292,14 @@ module Workflow @nodes_brk.linked_copy(nodes_ok) end - def retry!(task,nodeset) - log("retry_step#{task.idx+1}",nil,nodeset,:increment=>true) + def retry!(task, nodeset) + log("retry_step#{task.idx + 1}", nil, nodeset, :increment => true) end def timeout!(task) - log("step#{task.idx+1}_duration",task.context[:local][:timeout]||0, + log("step#{task.idx + 1}_duration", task.context[:local][:timeout] || 0, (task.nodes.empty? ? task.nodes_done : task.nodes)) - debug(1,"Timeout in the #{task.name} step, let's kill the instance", + debug(1, "Timeout in the #{task.name} step, let's kill the instance", task.nsid) task.nodes.set_error_msg("Timeout in the #{task.name} step") end @@ -308,8 +308,8 @@ module Workflow log('success', false) @logger.dump @nodes.set_state('aborted', nil, context[:database], context[:user]) - debug(2," * Kill a #{self.class.opname()} instance") - debug(0,"#{self.class.opname().capitalize} aborted") + debug(2, " * Kill a #{self.class.opname()} instance") + debug(0, "#{self.class.opname().capitalize} aborted") end private @@ -317,9 +317,9 @@ module Workflow def load_custom_operations # Custom files if context[:execution].custom_operations - context[:execution].custom_operations[:operations].each_pair do |macrobase,micros| + context[:execution].custom_operations[:operations].each_pair do |macrobase, micros| @config.keys.select{|v| v =~ /^#{macrobase}/}.each do |macro| - micros.each_pair do |micro,entries| + micros.each_pair do |micro, entries| @config[macro] = {} unless @config[macro] @config[macro][:config] = {} unless @config[macro][:config] @config[macro][:config][micro] = conf_task_default() unless @config[macro][:config][micro] @@ -384,7 +384,7 @@ module Workflow :scattering => entry[:scattering] } else - error(APIError::INVALID_FILE,'Custom operations file') + error(APIError::INVALID_FILE, 'Custom operations file') end end end @@ -396,7 +396,7 @@ module Workflow def check_config() end - def self.operation(_suffix='') + def self.operation(_suffix = '') raise end @@ -408,11 +408,11 @@ module Workflow end class Deploy < Workflow - def self.opname(_suffix='') + def self.opname(_suffix = '') "deployment" end - def self.operation(suffix='') + def self.operation(suffix = '') "deploy#{suffix}" end @@ -426,13 +426,13 @@ module Workflow def last_deploy_is_trusted?() return true if context[:execution].always_trust_env || context[:execution].environment.options['trust_env'] - nodes_state_before_start = Nodes::get_states(context[:database],@nodes.set.map(&:hostname)) + nodes_state_before_start = Nodes::get_states(context[:database], @nodes.set.map(&:hostname)) @nodes.set.all? do |n| node_state = nodes_state_before_start[n.hostname] || {} if !context[:cluster].kexec_server_precmd.empty? exit_code = Execute[context[:cluster].kexec_server_precmd].run!.wait(checkstatus: false).first.exitstatus unless exit_code.zero? - debug(3,"kexec server precmd return #{exit_code}. We do not trust the last deployment.") + debug(3, "kexec server precmd return #{exit_code}. We do not trust the last deployment.") return false end end @@ -440,7 +440,7 @@ module Workflow env_name = node_state['environment']['name'] env_user = node_state['environment']['user'] env_version = node_state['environment']['version'] - ['deployed','recorded_env'].include?(node_state['state']) && + ['deployed', 'recorded_env'].include?(node_state['state']) && context[:cluster].trusted_deployment_user == node_state['user'] && context[:cluster].trusted_deployment_partition == node_state['deploy_part'] && context[:cluster].trusted_envs.any? do |env| @@ -450,7 +450,7 @@ module Workflow end def load_tasks() - @tasks = [ [], [], [] ] + @tasks = [[], [], []] macrosteps = load_macrosteps() @@ -464,7 +464,7 @@ module Workflow ] instances.clear instances << tmp - debug(0,"A specific presinstall will be used with this environment") + debug(0, "A specific presinstall will be used with this environment") end # SetDeploymentEnv step macrosteps[0].to_a.each do |instance| @@ -479,24 +479,24 @@ module Workflow elsif !last_deploy_is_trusted? "the last deployment is not trusted" end - debug(0,"Using classical reboot instead of kexec (#{macrosteps[0].name}) because #{debug_message_reason}") + debug(0, "Using classical reboot instead of kexec (#{macrosteps[0].name}) because #{debug_message_reason}") end - @tasks[0] << [ instance[0].to_sym ] + @tasks[0] << [instance[0].to_sym] end # BroadcastEnv step macrosteps[1].to_a.each do |instance| - @tasks[1] << [ instance[0].to_sym ] + @tasks[1] << [instance[0].to_sym] end # BootNewEnv step - setclassical = lambda do |inst,msg| + setclassical = lambda do |inst, msg| if inst[0] == 'BootNewEnvKexec' inst[0] = 'BootNewEnvClassical' # Should not be hardcoded inst[1] = 0 inst[2] = eval("(#{context[:cluster].timeout_reboot_classical})+200").to_i - debug(0,msg) + debug(0, msg) end end macrosteps[2].to_a.each do |instance| @@ -513,14 +513,14 @@ module Workflow instance, "Using classical reboot instead of kexec since the filesystem is not supported by the deployment environment (#{macrosteps[2].name})" ) - elsif context[:execution].disable_kexec || context[:execution].environment.options['kexec']==false + elsif context[:execution].disable_kexec || context[:execution].environment.options['kexec'] == false setclassical.call( instance, "Using classical reboot instead of kexec (#{macrosteps[2].name})" ) end - @tasks[2] << [ instance[0].to_sym ] + @tasks[2] << [instance[0].to_sym] end @tasks.each do |macro| @@ -530,12 +530,12 @@ module Workflow # Some extra debugs cexec = context[:execution] unless context[:cluster].deploy_supported_fs.include?(cexec.environment.filesystem) - debug(0,"Disable some micro-steps since the filesystem is not supported by the deployment environment") + debug(0, "Disable some micro-steps since the filesystem is not supported by the deployment environment") end if cexec.block_device and !cexec.block_device.empty? \ and (!cexec.deploy_part or cexec.deploy_part.empty?) - debug(0,"Deploying on block device, disable format micro-steps") + debug(0, "Deploying on block device, disable format micro-steps") end end @@ -547,16 +547,16 @@ module Workflow # Without a dd image unless cexec.environment.image[:kind] == 'dd' - error(APIError::INVALID_OPTION,"You can only deploy directly on block device when using a dd image") + error(APIError::INVALID_OPTION, "You can only deploy directly on block device when using a dd image") end # Without specifying the partition to chainload on if cexec.boot_part.nil? - error(APIError::MISSING_OPTION,"You must specify the partition to boot on when deploying directly on block device") + error(APIError::MISSING_OPTION, "You must specify the partition to boot on when deploying directly on block device") end end if cexec.reformat_tmp and !context[:cluster].deploy_supported_fs.include?(cexec.reformat_tmp) - error(APIError::CONFLICTING_OPTIONS,"The filesystem '#{cexec.reformat_tmp}' is not supported by the deployment environment") + error(APIError::CONFLICTING_OPTIONS, "The filesystem '#{cexec.reformat_tmp}' is not supported by the deployment environment") end =begin @@ -574,11 +574,11 @@ module Workflow end class Power < Workflow - def self.opname(_suffix='') + def self.opname(_suffix = '') "power operation" end - def self.operation(suffix='') + def self.operation(suffix = '') "power#{suffix}" end @@ -586,32 +586,32 @@ module Workflow step = nil case context[:execution].operation when :on - step = [['On',0,0]] + step = [['On', 0, 0]] when :off - step = [['Off',0,0]] + step = [['Off', 0, 0]] when :status - step = [['Status',0,0]] + step = [['Status', 0, 0]] else raise end - [Configuration::MacroStep.new('Power',step)] + [Configuration::MacroStep.new('Power', step)] end def load_tasks() - @tasks = [[ ]] + @tasks = [[]] macrosteps = load_macrosteps() macrosteps[0].to_a.each do |instance| - @tasks[0] << [ instance[0].to_sym ] + @tasks[0] << [instance[0].to_sym] end end end class Reboot < Workflow - def self.opname(_suffix='') + def self.opname(_suffix = '') "reboot" end - def self.operation(suffix='') + def self.operation(suffix = '') "reboot#{suffix}" end @@ -619,24 +619,24 @@ module Workflow step = nil case context[:execution].operation when :simple - step = [['Simple',0,0]] + step = [['Simple', 0, 0]] when :set_pxe - step = [['SetPXE',0,0]] + step = [['SetPXE', 0, 0]] when :deploy_env - step = [['DeployEnv',0,0]] + step = [['DeployEnv', 0, 0]] when :recorded_env - step = [['RecordedEnv',0,0]] + step = [['RecordedEnv', 0, 0]] else raise end - [Configuration::MacroStep.new('Reboot',step)] + [Configuration::MacroStep.new('Reboot', step)] end def load_tasks() - @tasks = [[ ]] + @tasks = [[]] macrosteps = load_macrosteps() macrosteps[0].to_a.each do |instance| - @tasks[0] << [ instance[0].to_sym ] + @tasks[0] << [instance[0].to_sym] end end @@ -645,28 +645,28 @@ module Workflow case cexec.operation when :set_pxe if !cexec.pxe or !cexec.pxe[:profile] or cexec.pxe[:profile].empty? - error(APIError::MISSING_OPTION,"You must specify a PXE boot profile when rebooting using set_pxe") + error(APIError::MISSING_OPTION, "You must specify a PXE boot profile when rebooting using set_pxe") end when :recorded_env if !cexec.environment or cexec.environment.id < 0 - error(APIError::MISSING_OPTION,"You must specify an environment when rebooting using recorded_env") + error(APIError::MISSING_OPTION, "You must specify an environment when rebooting using recorded_env") end if !cexec.deploy_part or cexec.deploy_part.empty? - error(APIError::MISSING_OPTION,"You must specify a partition when rebooting using recorded_env") + error(APIError::MISSING_OPTION, "You must specify a partition when rebooting using recorded_env") end end end - def success!(task,nodeset) - super(task,nodeset) + def success!(task, nodeset) + super(task, nodeset) case context[:execution].operation when :deploy_env - @nodes_ok.set_state('deploy_env',nil, - context[:database],context[:user]) + @nodes_ok.set_state('deploy_env', nil, + context[:database], context[:user]) when :recorded_env - @nodes_ok.set_state('recorded_env',context[:execution].environment, - context[:database],context[:user]) + @nodes_ok.set_state('recorded_env', context[:execution].environment, + context[:database], context[:user]) end end end