Class: Netid

Inherits:
Object
  • Object
show all
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) ⇒ Netid

Returns a new instance of Netid.



7
8
9
10
# File 'lib/netid-tools.rb', line 7

def initialize(netid,system_user=nil)
  @netid = netid
  @system_user = system_user
end

Instance Attribute Details

#netidObject

Returns the value of attribute netid.



5
6
7
# File 'lib/netid-tools.rb', line 5

def netid
  @netid
end

#system_userObject

Returns the value of attribute system_user.



5
6
7
# File 'lib/netid-tools.rb', line 5

def system_user
  @system_user
end

Class Method Details

.validate_netid?(netid) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.validate_netid?(netid)
  if netid.to_s.length > 8 || netid !~ /^[a-zA-Z][\w-]{0,7}$/
    false
  else
    true
  end
end

Instance Method Details

#check_for_localhomeObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/netid-tools.rb', line 52

def check_for_localhome
   host = 'ovid02.u.washington.edu'
   Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
     output = ssh.exec!("cpw -poh #{netid}")
     if output =~ /Unknown/
       false
     else
      output.chomp
    end
  end
end

#check_for_mysql_presence(host) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/netid-tools.rb', line 24

def check_for_mysql_presence(host)
  Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
    output = ssh.exec!("ps -U #{netid} -u #{netid} u")
    if output =~ /mysql/
      /port=(?<port>\d+)/ =~ output
      [host,port]
    else
      false
    end
  end
end

#check_webtypeObject



64
65
66
67
68
69
# File 'lib/netid-tools.rb', line 64

def check_webtype
  host = 'ovid02.u.washington.edu'
  Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
    ssh.exec!("webtype -user #{netid}").chomp.split(" ")
  end
end

#get_processes(host) ⇒ Object



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

def get_processes(host)
  output = ""
  Net::SSH.start(host,system_user,{auth_methods: %w(publickey)}) do |ssh|
    if /no such user/i =~ ssh.exec!("id #{netid}")
      output = nil
    else
      output = ssh.exec!("ps -f --user=#{netid}").lines
    end
  end
  if output.nil? || output.count == 1
    false
  else
    output
  end
end

#quota_checkObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/netid-tools.rb', line 72

def quota_check
host = 'ovid02.u.washington.edu'
Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
  result = ssh.exec!("quota #{netid}").chomp
    result = result.split("\n")
    result.delete_at(0) if result.first == ''
    result.each_with_index do |line,index|
      if index == 0 || index == 1
        puts line
        next
      end
      line_components = line.squeeze(" ").split(" ")
      if line_components[1].to_f > line_components[2].to_f
        puts "#{line.bold.red}"
      elsif line_components[4] =~ /day/i || line_components[4].to_i > line_components[5].to_i
        puts line.bold.red+'\n'
      else
        puts line
      end
    end
  end
end

#validate_netid?(netid) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/netid-tools.rb', line 20

def validate_netid?(netid)
  Netid.validate_netid?(netid)
end