Skip to content

Instantly share code, notes, and snippets.

@KINGSABRI
Last active December 23, 2021 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KINGSABRI/2397271 to your computer and use it in GitHub Desktop.
Save KINGSABRI/2397271 to your computer and use it in GitHub Desktop.
Switch-hash v2
#!/usr/bin/ruby
gems = %w{rubygems colorize socket net/ssh net/scp logger} ; gems.each { |gem| require gem }
class Type
attr_accessor :name , :cmd
def initialize(name, cmd)
@name = name
@cmd = cmd
end
end
class Switch
attr_accessor :cust_name , :switch_type
def initialize(cust_name, switch_type)
@cust_name = cust_name
@switch_type = switch_type
end
end
class Start
def initialize()
# http://h20000.www2.hp.com/bc/docs/support/SupportManual/c01096664/c01096664.pdf
# ftp://ftp.hp.com/pub/networking/software/59692339_2.pdf
hpcmds = {"Start" => "enable", #0 User Level-EXEC
"sudo" => "configure terminal", #1 Privileged Level-EXEC to Global Level-CONFIG (May no need for it)
"ifup" => "/oper/port <port number> ena", #2 Enable port
"ifdown" => "/oper/port <port number> dis", #3 Disable port
"ifstat" => "/oper/port <port number> cur", #4 Display Port Status
"ARPcls" => "/maint/arp clear" #5 Clear ARP Cache
}
@hp = Type.new("hp", hpcmds)
hucmds = {"sudo" => "system-view", #0 Previlige Escalation
"ifconfig" => "Int GigabitEthernet1/0/42", #1 Interface Level
"ifdown" => "Shut", #2 Shutdow
"ifup" => "Un Shut", #3 Undo Shutdow
"ifstat" => "Dis b int GigabitEthernet1/0/42", #4 Interface Status
"ARPcls" => "How to clear the ARP cache", #5 Clear ARP Cache
"Quit" => "quit" #6 quit
}
@hu = Type.new("Huawei", hucmds)
end
def get_customer
cust1 = Switch.new("Cust1", @hp)
cust2 = Switch.new("Cust2", @hu)
cust3 = Switch.new("Cust3", @hu)
customer = {"Cust1" => cust1 , "Cust2" => cust2 , "Cust3" => cust3}
end
end
cust = Start.new.get_customer
puts "#{cust["Seder"].cust_name}: #{cust["Seder"].switch_type.name} \n#{cust["Seder"].switch_type.cmd["sudo"]}"
# puts "Customer name: #{cust["Seder"].cust_name}" # Customer name
# puts "Swuitch type: #{cust["Seder"].switch_type.name}" # Switch Type
# puts "Command is: #{cust["Seder"].switch_type.cmd["sudo"]}" # Switch commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment