-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatform.rb
87 lines (80 loc) · 2.53 KB
/
Platform.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
80
81
82
83
84
85
86
87
require File.expand_path(File.join(File.dirname(__FILE__), 'Device.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), 'OSMINENBI.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), 'XMLNBI.rb'))
class Platform
DEVICES = {\
"CMS"=>{:LoginPrompt=>"", :PasswordPrompt=>""}, \
"E348"=>{:LoginPrompt=>"User name:", :PasswordPrompt=>"Password"}, \
"E348C"=>{:LoginPrompt=>"Username:", :PasswordPrompt=>"Password:"}, \
"E312C"=>{:LoginPrompt=>"User name:", :PasswordPrompt=>"Password:"}, \
"C7"=>{:LoginPrompt=>"", :PasswordPrompt=>""}, \
"E7"=>{:LoginPrompt=>"Username:", :PasswordPrompt=>"Password:"}, \
"E5111"=>{:LoginPrompt=>"User name:", :PasswordPrompt=>"Password:"}, \
"E5120"=>{:LoginPrompt=>"User name:", :PasswordPrompt=>"Password:"}, \
"E5121"=>{:LoginPrompt=>"User name:", :PasswordPrompt=>"Password:"}, \
"XMLNBI"=>{}, \
"C7"=>{}
}
def initialize devicetable
@device = {}
File.open(devicetable, "r") do |file|
file.each_with_index do |str, number|
unless str.strip =~ /^#/
unless str.strip.empty?
sp = str.rstrip.split("|")
if (6 != sp.size) || (not DEVICES.keys.include?(sp[0]))
raise "wrong configuration in devicetable: #{str}\n"
else
name = sp[0]
ip = sp[1]
port = sp[2].to_i
user = sp[3]
password = sp[4]
cmdprompt = sp[5]
end
begin
if "CMS" == name
@device[name] = OSMINENBI::OSMINEServer.new ip, port, cmdprompt
elsif "XMLNBI" == name
@device[name] = XMLNBI::XMLServer.new ip, user, password
elsif "C7" == name
@device[name] = Device::DeviceCLI.new ip, port, cmdprompt
@device[name].execute("ACT-USER::#{user}:asfdf::#{password};")
@device[name].execute("INH-MSG-ALL:::INHMSG::ALL;")
else
dev_para = DEVICES[name]
@device[name] = Device::DeviceCLI.new ip, port, cmdprompt
unless dev_para[:LoginPrompt].empty?
@device[name].login dev_para[:LoginPrompt], user, dev_para[:PasswordPrompt], password
end
end
rescue =>e
puts e.to_s
puts e.backtrace
self.exit()
Process.exit(false)
end
end
end
end
end
# puts @device
end
def execute device, cmd_str
if @device[device]
@device[device].execute cmd_str
else
"No device #{device} exist, pls check devicetable\n"
end
end
def retrieve device
if "CMS" == device
@device[device].retrieve
end
end
def exit
@device.keys.each do |d|
@device[d].exit if @device[d]
end
end
end