|
41 | 41 | import org.apache.commons.codec.binary.Base64; |
42 | 42 | import org.apache.log4j.Logger; |
43 | 43 |
|
| 44 | +import com.cloud.agent.api.routing.NetworkElementCommand; |
44 | 45 | import com.cloud.configuration.Config; |
45 | 46 | import com.cloud.configuration.ConfigurationVO; |
46 | 47 | import com.cloud.configuration.dao.ConfigurationDao; |
|
84 | 85 | import com.cloud.utils.component.ComponentLocator; |
85 | 86 | import com.cloud.utils.db.DB; |
86 | 87 | import com.cloud.utils.db.Transaction; |
| 88 | +import com.cloud.utils.exception.CloudRuntimeException; |
87 | 89 | import com.cloud.utils.net.NetUtils; |
88 | 90 | import com.cloud.utils.script.Script; |
89 | 91 |
|
@@ -248,54 +250,8 @@ public void persistDefaultValues() throws InvalidParameterValueException, Intern |
248 | 250 | _configDao.update("init", "true"); |
249 | 251 | } |
250 | 252 |
|
251 | | - /* |
252 | | - private String getManagementNetworkCIDR() { |
253 | | - String[] gatewayAndNetmask = getGatewayAndNetmask(); |
254 | | - |
255 | | - if (gatewayAndNetmask == null) { |
256 | | - return null; |
257 | | - } else { |
258 | | - String gateway = gatewayAndNetmask[0]; |
259 | | - String netmask = gatewayAndNetmask[1]; |
260 | | - |
261 | | - String subnet = NetUtils.getSubNet(gateway, netmask); |
262 | | - long cidrSize = NetUtils.getCidrSize(netmask); |
263 | | - |
264 | | - return subnet + "/" + cidrSize; |
265 | | - } |
266 | | - } |
267 | | - */ |
268 | 253 |
|
269 | | - private String[] getGatewayAndNetmask() { |
270 | | - String defaultRoute = Script.runSimpleBashScript("/sbin/ip route | grep default"); |
271 | | - |
272 | | - if (defaultRoute == null) { |
273 | | - return null; |
274 | | - } |
275 | | - |
276 | | - String[] defaultRouteList = defaultRoute.split("\\s+"); |
277 | | - |
278 | | - if (defaultRouteList.length < 5) { |
279 | | - return null; |
280 | | - } |
281 | | - |
282 | | - String gateway = defaultRouteList[2]; |
283 | | - String ethDevice = defaultRouteList[4]; |
284 | | - String netmask = null; |
285 | | - |
286 | | - if (ethDevice != null) { |
287 | | - netmask = Script.runSimpleBashScript("/sbin/ifconfig " + ethDevice + " | grep Mask | awk '{print $4}' | cut -d':' -f2"); |
288 | | - } |
289 | | - |
290 | | - if (gateway == null || netmask == null) { |
291 | | - return null; |
292 | | - } else if (!NetUtils.isValidIp(gateway) || !NetUtils.isValidNetmask(netmask)) { |
293 | | - return null; |
294 | | - } else { |
295 | | - return new String[] {gateway, netmask}; |
296 | | - } |
297 | | - } |
298 | | - |
| 254 | + |
299 | 255 | private String getEthDevice() { |
300 | 256 | String defaultRoute = Script.runSimpleBashScript("/sbin/route | grep default"); |
301 | 257 |
|
@@ -334,19 +290,7 @@ private String getEnvironmentProperty(String name) { |
334 | 290 | } |
335 | 291 | } |
336 | 292 |
|
337 | | - private String getDNS() { |
338 | | - String dnsLine = Script.runSimpleBashScript("grep nameserver /etc/resolv.conf"); |
339 | | - if (dnsLine == null) { |
340 | | - return null; |
341 | | - } else { |
342 | | - String[] dnsLineArray = dnsLine.split(" "); |
343 | | - if (dnsLineArray.length != 2) { |
344 | | - return null; |
345 | | - } else { |
346 | | - return dnsLineArray[1]; |
347 | | - } |
348 | | - } |
349 | | - } |
| 293 | + |
350 | 294 |
|
351 | 295 | @DB |
352 | 296 | protected String getHost() { |
@@ -511,6 +455,29 @@ protected void updateKeyPairs() { |
511 | 455 | s_logger.error("SQL of the public key failed",ex); |
512 | 456 | throw new RuntimeException("SQL of the public key failed"); |
513 | 457 | } |
| 458 | + injectSshKeyIntoSystemVmIsoPatch(pubkeyfile.getAbsolutePath()); |
| 459 | + if (s_logger.isDebugEnabled()) { |
| 460 | + s_logger.debug("Public key inserted into systemvm iso"); |
| 461 | + } |
| 462 | + } else { |
| 463 | + s_logger.info("Keypairs already in database"); |
| 464 | + } |
| 465 | + } |
| 466 | + |
| 467 | + |
| 468 | + protected void injectSshKeyIntoSystemVmIsoPatch(String publicKeyPath) { |
| 469 | + String injectScript = "scripts/vm/systemvm/injectkeys.sh"; |
| 470 | + String scriptPath = Script.findScript("" , injectScript); |
| 471 | + if ( scriptPath == null ) { |
| 472 | + throw new CloudRuntimeException("Unable to find key inject script " + injectScript); |
| 473 | + } |
| 474 | + final Script command = new Script(scriptPath, s_logger); |
| 475 | + command.add(publicKeyPath); |
| 476 | + |
| 477 | + final String result = command.execute(); |
| 478 | + if (result != null) { |
| 479 | + s_logger.warn("Failed to inject generated public key into systemvm iso " + result); |
| 480 | + throw new CloudRuntimeException("Failed to inject generated public key into systemvm iso " + result); |
514 | 481 | } |
515 | 482 | } |
516 | 483 |
|
|
0 commit comments