methods/in_common.rb
# List clients for an install service
List clients for an install service
List clients for an install service
def list_clients(options)
  case options['method'].downcase
  when /ai/
    list_ai_clients()
    return
  when /js|jumpstart/
    search_string = "sol_6|sol_7|sol_8|sol_9|sol_10"
  when /ks|kickstart/
    search_string = "centos|redhat|rhel|scientific|fedora"
  when /ps|preseed/
    search_string = "debian|ubuntu"
  when /ci/
    search_string = "live"
  when /vmware|vsphere|esx|vs/
    search_string = "vmware"
  when /ay|autoyast/
    search_string = "suse|sles"
  when /xb/
    search_string = "bsd|coreos"
  end
  service_list = Dir.entries(options['clientdir'])
  service_list = service_list.grep(/#{search_string}|#{options['service']}/)
  if service_list.length > 0
    if options['output'].to_s.match(/html/)
      if options['service'].to_s.match(/[a-z,A-Z]/)
        handle_output(options,"<h1>Available #{options['service']} clients:</h1>")
      else
        handle_output(options,"<h1>Available clients:</h1>")
      end
      handle_output(options,"<table border=\"1\">")
      handle_output(options,"<tr>")
      handle_output(options,"<th>Client</th>")
      handle_output(options,"<th>Service</th>")
      handle_output(options,"<th>IP</th>")
      handle_output(options,"<th>MAC</th>")
      handle_output(options,"</tr>")
    else
      handle_output(options,"")
      if options['service'].to_s.match(/[a-z,A-Z]/)
        handle_output(options,"Available #{options['service']} clients:")
      else
        handle_output(options,"Available clients:")
      end
      handle_output(options,"")
    end
    service_list.each do |service_name|
      if service_name.match(/#{search_string}|#{service_name}/) and service_name.match(/[a-z,A-Z]/)
        options['repodir'] = options['clientdir']+"/"+options['service']
        if File.directory?(options['repodir']) or File.symlink?(options['repodir'])
          client_list = Dir.entries(options['repodir'])
          client_list.each do |client_name|
            if client_name.match(/[a-z,A-Z,0-9]/)
              options['clientdir']  = options['repodir']+"/"+client_name
              options['ip']  = get_install_ip(options)
              options['mac'] = get_install_mac(options)
              if File.directory?(options['clientdir'])
                if options['output'].to_s.match(/html/)
                  handle_output(options,"<tr>")
                  handle_output(options,"<td>#{client_name}</td>")
                  handle_output(options,"<td>#{service_name}</td>")
                  handle_output(options,"<td>#{client_ip}</td>")
                  handle_output(options,"<td>#{client_mac}</td>")
                  handle_output(options,"</tr>")
                else
                  handle_output(options,"#{client_name}\t[ service = #{service_name}, ip = #{client_ip}, mac = #{client_mac} ] ")
                end
              end
            end
          end
        end
      end
    end
    if options['output'].to_s.match(/html/)
      handle_output(options,"</table>")
    end
  end
  handle_output(options,"")
  return
end
def list_clients ( options ) case options [ 'method' ] . downcase when / ai / list_ai_clients ( ) return when / js|jumpstart / search_string = "sol_6|sol_7|sol_8|sol_9|sol_10" when / ks|kickstart / search_string = "centos|redhat|rhel|scientific|fedora" when / ps|preseed / search_string = "debian|ubuntu" when / ci / search_string = "live" when / vmware|vsphere|esx|vs / search_string = "vmware" when / ay|autoyast / search_string = "suse|sles" when / xb / search_string = "bsd|coreos" end service_list = Dir . entries ( options [ 'clientdir' ] ) service_list = service_list . grep ( / #{ search_string } | #{ options [ 'service' ] } / ) if service_list . length > 0 if options [ 'output' ] . to_s . match ( / html / ) if options [ 'service' ] . to_s . match ( / [a-z,A-Z] / ) handle_output ( options , "<h1>Available #{options['service']} clients:</h1>" ) else handle_output ( options , "<h1>Available clients:</h1>" ) end handle_output ( options , "<table border=\"1\">" ) handle_output ( options , "<tr>" ) handle_output ( options , "<th>Client</th>" ) handle_output ( options , "<th>Service</th>" ) handle_output ( options , "<th>IP</th>" ) handle_output ( options , "<th>MAC</th>" ) handle_output ( options , "</tr>" ) else handle_output ( options , "" ) if options [ 'service' ] . to_s . match ( / [a-z,A-Z] / ) handle_output ( options , "Available #{options['service']} clients:" ) else handle_output ( options , "Available clients:" ) end handle_output ( options , "" ) end service_list . each do | service_name | if service_name . match ( / #{ search_string } | #{ service_name } / ) and service_name . match ( / [a-z,A-Z] / ) options [ 'repodir' ] = options [ 'clientdir' ] + "/" + options [ 'service' ] if File . directory? ( options [ 'repodir' ] ) or File . symlink? ( options [ 'repodir' ] ) client_list = Dir . entries ( options [ 'repodir' ] ) client_list . each do | client_name | if client_name . match ( / [a-z,A-Z,0-9] / ) options [ 'clientdir' ] = options [ 'repodir' ] + "/" + client_name options [ 'ip' ] = get_install_ip ( options ) options [ 'mac' ] = get_install_mac ( options ) if File . directory? ( options [ 'clientdir' ] ) if options [ 'output' ] . to_s . match ( / html / ) handle_output ( options , "<tr>" ) handle_output ( options , "<td>#{client_name}</td>" ) handle_output ( options , "<td>#{service_name}</td>" ) handle_output ( options , "<td>#{client_ip}</td>" ) handle_output ( options , "<td>#{client_mac}</td>" ) handle_output ( options , "</tr>" ) else handle_output ( options , "#{client_name}\t[ service = #{service_name}, ip = #{client_ip}, mac = #{client_mac} ] " ) end end end end end end end if options [ 'output' ] . to_s . match ( / html / ) handle_output ( options , "</table>" ) end end handle_output ( options , "" ) return end
List clients for an install service
List clients for an install service
options
<not_specific>