Class: Netid
- Inherits:
-
Object
- Object
- Netid
- Defined in:
- lib/netid-tools.rb
Class Method Summary collapse
-
.check_for_localhome(user, system_user) ⇒ Object
Returns location of localhome if present.
-
.check_for_mysql_presence(host, user, system_user) ⇒ Object
Checks to see if MySQL is running on a specified host.
- .check_webtype(user, system_user) ⇒ Object
- .quota_check(user, system_user) ⇒ Object
-
.validate_netid?(netid) ⇒ Boolean
Validate that string is in the form of a valid NetID.
Class Method Details
.check_for_localhome(user, system_user) ⇒ Object
Returns location of localhome if present
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/netid-tools.rb', line 30 def self.check_for_localhome(user,system_user) host = 'ovid02.u.washington.edu' Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh| output = ssh.exec!("cpw -poh #{user}") if output =~ /Unknown/ false else output.chomp end end end |
.check_for_mysql_presence(host, user, system_user) ⇒ Object
Checks to see if MySQL is running on a specified host. Returns array with host, port if present, returns false if not present.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/netid-tools.rb', line 17 def self.check_for_mysql_presence(host,user,system_user) Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh| output = ssh.exec!("ps -U #{user} -u #{user} u") if output =~ /mysql/ /port=(?<port>\d+)/ =~ output [host,port] else false end end end |
.check_webtype(user, system_user) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/netid-tools.rb', line 42 def self.check_webtype(user,system_user) host = 'ovid02.u.washington.edu' Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh| ssh.exec!("webtype -user #{user}").chomp end end |
.quota_check(user, system_user) ⇒ Object
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 |
# File 'lib/netid-tools.rb', line 50 def self.quota_check(user,system_user) host = 'ovid02.u.washington.edu' Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh| result = ssh.exec!("quota #{user}").chomp # Split along newlines result = result.split("\n") # This deletes the first blank line. There be an easier way to do this result.delete_at(0) if result.first == '' # Go through each line of the result result.each_with_index do |line,index| # The first two are headers: print and ignore if index == 0 || index == 1 puts line next end # Break the line up into elements line_components = line.squeeze(" ").split(" ") # Check to see if usage is over quota if line_components[1].to_f > line_components[2].to_f puts "#{line.bold.red}" # If there's a grace period, it shows up in [4], so we account for that # and flag if its present 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
Validate that string is in the form of a valid NetID. eg: 1-8 chars, doesn’t start with a number, and no special characters
7 8 9 10 11 12 13 |
# File 'lib/netid-tools.rb', line 7 def self.validate_netid?(netid) if netid.to_s.length > 8 || netid !~ /^[a-zA-Z][\w-]{0,7}$/ false else true end end |