Class: Netid

Inherits:
Object
  • Object
show all
Includes:
SystemConnect
Defined in:
lib/netid-tools.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(netid, system_user = nil, systems = nil, primary_host = nil, secondary_host = nil) ⇒ Netid

Returns a new instance of Netid.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/netid-tools.rb', line 14

def initialize(netid,system_user=nil,systems=nil,primary_host=nil,secondary_host=nil)
  @netid = netid
  @system_user = system_user || `whoami`.chomp
  @systems = systems || ["ovid01.u.washington.edu",
                         "ovid02.u.washington.edu",
                         "ovid03.u.washington.edu",
                         "vergil.u.washington.edu"
                         ]
  @primary_host = primary_host || "ovid02.u.washington.edu"
  @secondary_host = secondary_host || "vergil.u.washington.edu"
end

Instance Attribute Details

#netidObject

Returns the value of attribute netid.



12
13
14
# File 'lib/netid-tools.rb', line 12

def netid
  @netid
end

#primary_hostObject

Returns the value of attribute primary_host.



12
13
14
# File 'lib/netid-tools.rb', line 12

def primary_host
  @primary_host
end

#secondary_hostObject

Returns the value of attribute secondary_host.



12
13
14
# File 'lib/netid-tools.rb', line 12

def secondary_host
  @secondary_host
end

#system_userObject

Returns the value of attribute system_user.



12
13
14
# File 'lib/netid-tools.rb', line 12

def system_user
  @system_user
end

#systemsObject

Returns the value of attribute systems.



12
13
14
# File 'lib/netid-tools.rb', line 12

def systems
  @systems
end

Class Method Details

.validate_netid?(netid) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/netid-tools.rb', line 30

def self.validate_netid?(netid)
  NetidValidator.do(netid).response
end

Instance Method Details

#check_for_localhomeObject



87
88
89
90
91
92
93
94
# File 'lib/netid-tools.rb', line 87

def check_for_localhome
  result = run_remote_command("cpw -poh #{netid}",primary_host)
  if result =~ /Unknown/
    false
  else
    result.chomp
  end
end

#check_for_mysql_presence(host) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/netid-tools.rb', line 38

def check_for_mysql_presence(host)
  command = "ps -F -U #{netid} -u #{netid}"
  result = run_remote_command(command,host)
  if result =~ /mysql/
    /port=(?<port>\d+)/ =~ result
    [host,port.to_i]
  else
    false
  end
end

#check_quotaObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/netid-tools.rb', line 108

def check_quota

  command_result = run_remote_command("quota #{netid}",primary_host)

  if command_result =~ /unknown user/
    result = GenericResponse.new
    result.error = "Unknown User #{netid} on #{primary_host}"
    result.response = false
  else
    result = QuotaResponse.new

    command_result = command_result.chomp.split("\n")
    command_result.delete_at(0) if command_result.first == ""
    command_result.delete_at(0) # remove uid line

    result.headers = process_quota_headers(command_result)
    result.response = command_result.map do |line|
      line = line.split
      line.insert(4, 'n/a') if line.size == 6
      expand_cluster_path(line)
      line
    end
  end
  result
end

#check_webtypeObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/netid-tools.rb', line 96

def check_webtype
  result = []
  command = "webtype -user #{netid}"
  result = run_remote_command(command,primary_host).chomp.split
  if result[0] == "user"
    result = run_remote_command(command,secondary_host).chomp.split
  else
    result
  end
end

#get_processes(host) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/netid-tools.rb', line 49

def get_processes(host)
  if /no such user/i =~ run_remote_command("id #{netid}",host)
    result = false
  else

    command = "ps -o pid,user,cputime,nice,wchan,pcpu,pmem,rss,start_time,cmd --user #{netid}"
    raw_processes = run_remote_command(command,host).lines.map{|l| l.chomp}
    refined_processes = UnixProcesses.new(host)

    refined_processes.headers = raw_processes[0].split
    raw_processes.delete_at(0)

    refined_processes.processes = raw_processes.map do |line|
      line = line.split

      if line.size > 9
        process = line.slice!(9,line.size-9)
        line[9] = process.join(" ")
      end
      line
    end
    refined_processes
  end


  # if /no such user/i =~ run_remote_command("id #{netid}",host)
  #   result = nil
  # else
  #   result = run_remote_command("ps -F --user=#{netid}",host).lines.map{|l| l.chomp}
  #   result = remove_extra_processes(result)
  # end
  # if result.nil? || result.count == 1
  #   false
  # else
  #   result
  # end
end

#validate_netidObject



26
27
28
# File 'lib/netid-tools.rb', line 26

def validate_netid
  NetidValidator.do(netid)
end

#validate_netid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/netid-tools.rb', line 34

def validate_netid?
  NetidValidator.do(netid).response
end