require 'net/ssh' require 'ipaddr' class NEWhub def add_eoip_for_mikr(bridge_name, ap_ip_address, tunnel_id, tunnel_name, hub1, hub2, user_hub, password_hub) Net::SSH.start(hub1, user_hub, :password => password_hub) do |ssh| result = ssh.exec!("/interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{tunnel_id} name=#{tunnel_name}") result2 = ssh.exec!("/interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name} unknown-multicast-flood=no unknown-unicast-flood=no") end #Net::SSH.stop Net::SSH.start(hub2, user_hub, :password => password_hub) do |ssh| result = ssh.exec!("/interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{tunnel_id} name=#{tunnel_name}") result2 = ssh.exec!("/interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name} unknown-multicast-flood=no unknown-unicast-flood=no") end #Net::SSH.stop end def del_eoip_for_mikr(bridge_name, ap_ip_address, tunnel_id, tunnel_name, hub1, hub2, user_hub, password_hub) Net::SSH.start(hub1, user_hub, :password => password_hub) do |ssh| #result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}") #p result result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}") regimsi = /\s+name=\"(.+)\"\s+/ m1 = regimsi.match(result)[1] sleep 0.2 result2 = ssh.exec!("/interface bridge port remove [/interface bridge port find interface=#{m1}]") sleep 0.2 result3 = ssh.exec!("/interface eoip remove [/interface eoip find where tunnel-id=#{tunnel_id}]") #result2 = ssh.exec!("interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name}") end #Net::SSH.stop Net::SSH.start(hub2, user_hub, :password => password_hub) do |ssh| result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}") regimsi = /\s+name=\"(.+)\"\s+/ m1 = regimsi.match(result)[1] sleep 0.2 result2 = ssh.exec!("/interface bridge port remove [/interface bridge port find interface=#{m1}]") sleep 0.2 result3 = ssh.exec!("/interface eoip remove [/interface eoip find where tunnel-id=#{tunnel_id}]") #result = ssh.exec!("interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{tunnel_id} name=#{tunnel_name}") #result2 = ssh.exec!("interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name}") end #Net::SSH.stop end def ap_get_info(ap_ip_address, ap_login, ap_password) res = "" Net::SSH.start(ap_ip_address, ap_login, :password => ap_password) do |ssh| result = ssh.exec!("system identity print") dff = result.to_s res = dff.gsub!("name: ","").gsub!("\r\n\r\n","").gsub!(" ","") end res end def ap_tun_rewrite(ap_ip_address,tun_id, ap_login, ap_password) res = "" Net::SSH.start(ap_ip_address, ap_login, :password => ap_password) do |ssh| result = ssh.exec!("/interface eoip set tunnel_to_hab1 tunnel-id=#{tun_id} remote-address=172.24.202.145") end res end def mikr_tunnelid_gen() t_id_min = 10001 t_id_max = 65535 end end