Skip to content

Instantly share code, notes, and snippets.

@KINGSABRI
Created April 17, 2012 09:55
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/2404990 to your computer and use it in GitHub Desktop.
Save KINGSABRI/2404990 to your computer and use it in GitHub Desktop.
Switch-hash v3 with Connect
#!/usr/bin/ruby
gems = %w{rubygems colorize logger} ; gems.each { |gem| require gem }
load 'Connect.rb'
logger = Logger.new('logs/ninjaFW.log', 10, 1024000) # Filename: ninjaFW.log , Number of rotation: 10 , Rotation Size= 125MB
#--> Supported Switches
HP = "hp"
HU = "Huawei"
class Type
attr_accessor :name , :cmd
def initialize(name, cmd)
@name = name
@cmd = cmd
end
end
class CustomerSwitch
attr_accessor :cust_name , :switch_type , :ip
def initialize(cust_name, switch_type , ip)
@cust_name = cust_name
@switch_type = switch_type
@ip = ip
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" => "interface 17 enable", #2 Enable port
"ifdown" => "interface 17 disable", #3 Disable port
"ifstat" => "show interfaces brief 17", #4 Display Port Status
"clsMAC" => "/maint/arp clear", #5 Clear MAC table
"exit" => "exit", #6 Return to the previous context
"mgmt" => "end", #6 Return to the previous context
"Quit" => "logout" #7 quit
}
@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
"clsMAC" => "How to clear the ARP cache", #5 Clear MAC table
"Quit" => "quit" #6 quit
}
@hu = Type.new(HU, hucmds)
end
def get_customer
nayifat = CustomerSwitch.new("Nayifat", @hp , "10.51.1.32")
seder = CustomerSwitch.new("Seder" , @hu , "10.50.1.12")
mudifer = CustomerSwitch.new("Mudifer", @hu , "10.50.1.12")
customer = {"Nayifat" => nayifat , "Seder" => seder , "Mudifer" => mudifer}
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
# puts "Command is: #{cust["Seder"].ip}" # Switch IP
connect = Connect.new(cust["Seder"]) # Customer name is an argument from the user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment