View Javadoc
1   package org.metricshub.ipmi.client;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * IPMI Java Client
6    * ჻჻჻჻჻჻
7    * Copyright 2023 MetricsHub
8    * ჻჻჻჻჻჻
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23   */
24  
25  import org.metricshub.ipmi.core.common.Constants;
26  
27  /**
28   * IPMI configuration including the required credentials that need to be used to establish the
29   * communication with the IPMI interface.
30   *
31   */
32  public class IpmiClientConfiguration {
33  
34  	private String hostname;
35  	private String username;
36  	private char[] password;
37  	private byte[] bmcKey;
38  	private boolean skipAuth;
39  	private int port = Constants.IPMI_PORT;
40  	private long timeout;
41  	private long pingPeriod = -1;
42  
43  	/**
44  	 * Instantiates a new {@link IpmiClientConfiguration} in order to query the IPMI host.
45  	 * 
46  	 * @param hostname IP Address or host name of the remote IPMI host.
47  	 * @param username Name used to establish the connection with the host via the IPMI protocol.
48  	 * @param password Password used to establish the connection with the host via the IPMI protocol.
49  	 * @param bmcKey   The key that should be provided if the two-key authentication is enabled, null otherwise.
50  	 * @param skipAuth Whether the client should skip authentication
51  	 * @param timeout  Timeout used for each IPMI request.
52  	 */
53  	public IpmiClientConfiguration(String hostname, String username, char[] password,
54  			byte[] bmcKey, boolean skipAuth, long timeout) {
55  		this.hostname = hostname;
56  		this.username = username;
57  		this.password = password;
58  		this.bmcKey = bmcKey;
59  		this.skipAuth = skipAuth;
60  		this.timeout = timeout;
61  	}
62  
63  	/**
64  	 * Instantiates a new {@link IpmiClientConfiguration} in order to query the IPMI host.
65  	 * 
66  	 * @param hostname IP Address or host name of the remote IPMI host.
67  	 * @param port UDP port number of the remote IPMI host.
68  	 * @param username Name used to establish the connection with the host via the IPMI protocol.
69  	 * @param password Password used to establish the connection with the host via the IPMI protocol.
70  	 * @param bmcKey   The key that should be provided if the two-key authentication is enabled, null otherwise.
71  	 * @param skipAuth Whether the client should skip authentication
72  	 * @param timeout  Timeout used for each IPMI request.
73  	 */
74  	public IpmiClientConfiguration(String hostname, int port, String username, char[] password,
75  			byte[] bmcKey, boolean skipAuth, long timeout) {
76  		this(hostname, username, password, bmcKey, skipAuth, timeout);
77  		this.port = port;
78  	}
79  
80  	/**
81  	 * Instantiates a new {@link IpmiClientConfiguration} in order to query the IPMI host.
82  	 * 
83  	 * @param hostname   IP Address or host name of the remote IPMI host.
84  	 * @param username   Name used to establish the connection with the host via the IPMI protocol.
85  	 * @param password   Password used to establish the connection with the host via the IPMI protocol.
86  	 * @param bmcKey     The key that should be provided if the two-key authentication is enabled, null otherwise.
87  	 * @param skipAuth   Whether the client should skip authentication
88  	 * @param timeout    Timeout used for each IPMI request.
89  	 * @param pingPeriod The period in milliseconds used to send the keep alive messages.<br>
90  	 *                   Set pingPeriod to 0 to turn off keep-alive messages sent to the remote host.
91  	 */
92  	public IpmiClientConfiguration(String hostname, String username, char[] password,
93  			byte[] bmcKey, boolean skipAuth, long timeout, long pingPeriod) {
94  		this(hostname, username, password, bmcKey, skipAuth, timeout);
95  		this.pingPeriod = pingPeriod;
96  	}
97  
98  	/**
99  	 * Returns the IP Address or host name of the remote IPMI host.
100 	 * 
101 	 * @return IP Address or host name of the remote IPMI host.
102 	 */
103 	public String getHostname() {
104 		return hostname;
105 	}
106 
107 	/**
108 	 * Sets the IP Address or host name of the remote IPMI host.
109 	 * 
110 	 * @param hostname IP Address or host name of the remote IPMI host.
111 	 */
112 	public void setHostname(String hostname) {
113 		this.hostname = hostname;
114 	}
115 
116 	/**
117 	 * Returns the UDP port number of the remote IPMI host.
118 	 * 
119 	 * @return UDP port number of the remote IPMI host.
120 	 */
121 	public int getPort() {
122 		return port;
123 	}
124 
125 	/**
126 	 * Sets the UDP port number of the remote IPMI host.
127 	 * 
128 	 * @param port UDP port number of the remote IPMI host.
129 	 */
130 	public void setPort(int port) {
131 		this.port = port;
132 	}
133 
134 	/**
135 	 * Returns the name used to establish the connection with the host via the IPMI
136 	 * protocol.
137 	 * 
138 	 * @return Name used to establish the connection with the host via the IPMI protocol.
139 	 */
140 	public String getUsername() {
141 		return username;
142 	}
143 
144 	/**
145 	 * Sets the name used to establish the connection with the host via the IPMI
146 	 * protocol.
147 	 * 
148 	 * @param username Name used to establish the connection with the host via the
149 	 *                 IPMI protocol.
150 	 */
151 	public void setUsername(String username) {
152 		this.username = username;
153 	}
154 
155 	/**
156 	 * Returns the password used to establish the connection with the host via the
157 	 * IPMI protocol.
158 	 * 
159 	 * @return Password used to establish the connection with the host via the IPMI protocol.
160 	 */
161 	public char[] getPassword() {
162 		return password;
163 	}
164 
165 	/**
166 	 * Sets the password used to establish the connection with the host via the IPMI
167 	 * protocol.
168 	 * 
169 	 * @param password Password used to establish the connection with the host via the IPMI protocol.
170 	 */
171 	public void setPassword(char[] password) {
172 		this.password = password;
173 	}
174 
175 	/**
176 	 * Returns the key that should be provided if the two-key authentication is
177 	 * enabled, null otherwise.
178 	 * 
179 	 * @return The key that should be provided if the two-key authentication is
180 	 *         enabled, null otherwise.
181 	 */
182 	public byte[] getBmcKey() {
183 		return bmcKey;
184 	}
185 
186 	/**
187 	 * Sets the key that should be provided if the two-key authentication is
188 	 * enabled, null otherwise.
189 	 * 
190 	 * @param bmcKey The key that should be provided if the two-key authentication
191 	 *               is enabled, null otherwise.
192 	 */
193 	public void setBmcKey(byte[] bmcKey) {
194 		this.bmcKey = bmcKey;
195 	}
196 
197 	/**
198 	 * Returns whether the client should skip authentication.
199 	 * 
200 	 * @return Whether the client should skip authentication.
201 	 */
202 	public boolean isSkipAuth() {
203 		return skipAuth;
204 	}
205 
206 	/**
207 	 * Sets whether the client should skip authentication.
208 	 * 
209 	 * @param skipAuth Whether the client should skip authentication.
210 	 */
211 	public void setSkipAuth(boolean skipAuth) {
212 		this.skipAuth = skipAuth;
213 	}
214 
215 	/**
216 	 * Returns the timeout used for each IPMI request.
217 	 * 
218 	 * @return The timeout used for each IPMI request.
219 	 */
220 	public long getTimeout() {
221 		return timeout;
222 	}
223 
224 	/**
225 	 * Sets the timeout used for each IPMI request.
226 	 * 
227 	 * @param timeout The timeout used for each IPMI request.
228 	 */
229 	public void setTimeout(long timeout) {
230 		this.timeout = timeout;
231 	}
232 
233 	/**
234 	 * Returns the period in milliseconds used to send the keep alive messages.
235 	 * 
236 	 * @return The period in milliseconds used to send the keep alive messages.
237 	 */
238 	public long getPingPeriod() {
239 		return pingPeriod;
240 	}
241 
242 	/**
243 	 * Sets the period in milliseconds used to send the keep alive messages.<br>
244 	 * Set pingPeriod to 0 to turn off keep-alive messages sent to the remote host.
245 	 * 
246 	 * @param pingPeriod The period in milliseconds used to send the keep alive messages.
247 	 */
248 	public void setPingPeriod(long pingPeriod) {
249 		this.pingPeriod = pingPeriod;
250 	}
251 
252 }