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, single_host = nil) ⇒ Netid

Returns a new instance of Netid.



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

def initialize(netid,system_user=nil,systems=nil,single_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"
                         ]
  @single_host = single_host || "ovid02.u.washington.edu"
end

Instance Attribute Details

#netidObject

Returns the value of attribute netid.



10
11
12
# File 'lib/netid-tools.rb', line 10

def netid
  @netid
end

#single_hostObject

Returns the value of attribute single_host.



10
11
12
# File 'lib/netid-tools.rb', line 10

def single_host
  @single_host
end

#system_userObject

Returns the value of attribute system_user.



10
11
12
# File 'lib/netid-tools.rb', line 10

def system_user
  @system_user
end

#systemsObject

Returns the value of attribute systems.



10
11
12
# File 'lib/netid-tools.rb', line 10

def systems
  @systems
end

#user_clustersObject

Returns the value of attribute user_clusters.



10
11
12
# File 'lib/netid-tools.rb', line 10

def user_clusters
  @user_clusters
end

Class Method Details

.validate_netid?(netid) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#check_for_localhomeObject



60
61
62
63
64
65
66
67
# File 'lib/netid-tools.rb', line 60

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

#check_for_mysql_presence(host) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/netid-tools.rb', line 35

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]
  else
    false
  end
end

#check_quotaObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/netid-tools.rb', line 81

def check_quota
  result = run_remote_command("quota #{netid}",single_host)
  result = result.chomp.split("\n")
  result.delete_at(0) if result.first == ''
  uid = /uid\s(\d+)/.match(result.first)[1].to_i
  result.delete_at(0)

  headings = process_quota_headers(result)

  results = []
  results << headings
  result.each do |line|
    line = line.split
    line.insert(4, 'n/a') if line.size == 6

    expand_cluster_path(line)

    results << line
  end
  results
end

#check_webtypeObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/netid-tools.rb', line 69

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

#get_processes(host) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/netid-tools.rb', line 46

def get_processes(host)
  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



23
24
25
# File 'lib/netid-tools.rb', line 23

def validate_netid
  NetidValidator.do(netid)
end

#validate_netid?Boolean

Returns:

  • (Boolean)


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

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