1
2
3
4 package net.sf.provisioner.adapters;
5
6 import java.io.IOException;
7
8 import net.sf.provisioner.config.NetworkElement;
9 import net.sf.provisioner.connectors.TelnetConnector;
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class TelnetAdapter extends Adapter{
24
25 private NetworkElement ne;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public TelnetAdapter(NetworkElement ne) { this.ne = ne; }
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public String ExecuteCommand(String command) throws Exception {
60
61 String trash;
62 String result = null;
63
64
65 TelnetConnector connection = new TelnetConnector(this.ne);
66 connection.Connect();
67
68
69 try {
70
71 trash = connection.inputConsumer.consumeInput(3000);
72 logger.info("stdin trash: " + trash);
73
74 } catch (IOException e) {
75 throw e;
76 }
77
78
79 command = command + "\r\n";
80 logger.info("Sending command: \"" + command + "\"");
81
82 connection.writer.println(command);
83
84
85 try {
86
87 result = connection.inputConsumer.consumeInput(10000);
88 logger.info("Consumption: " + result);
89
90 } catch (IOException e) {
91 throw e;
92 }
93
94 connection.Disconnect();
95
96 return result;
97 }
98 }