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