From ec7a6e6863297d6938fd2d170707a5551350b462 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 1 Mar 2011 14:55:22 -0800 Subject: [PATCH] Bug 8208 - bare metal provisioning Add LinMin username, password, apid fields in AddPxeServerCmd --- api/src/com/cloud/api/ApiConstants.java | 3 +++ server/src/com/cloud/api/AddPxeServerCmd.java | 21 +++++++++++++++ .../baremetal/LinMinPxeServerManagerImpl.java | 21 +++++++++++++++ .../baremetal/LinMinPxeServerResource.java | 27 ++++++++++++++----- 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 02605c7a4bd..64ba091020b 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -195,6 +195,9 @@ public class ApiConstants { public static final String HOST_MEM_CAPACITY = "hostmemcapacity"; public static final String HOST_MAC = "hostmac"; public static final String PXE_SERVER_TYPE = "pxeservertype"; + public static final String LINMIN_USERNAME = "linminusername"; + public static final String LINMIN_PASSWORD = "linminpassword"; + public static final String LINMIN_APID = "linminapid"; } diff --git a/server/src/com/cloud/api/AddPxeServerCmd.java b/server/src/com/cloud/api/AddPxeServerCmd.java index f0ec9aefee6..941fa249585 100644 --- a/server/src/com/cloud/api/AddPxeServerCmd.java +++ b/server/src/com/cloud/api/AddPxeServerCmd.java @@ -47,6 +47,15 @@ public class AddPxeServerCmd extends BaseCmd { @Parameter(name=ApiConstants.PXE_SERVER_TYPE, type=CommandType.STRING, required = true, description="Type of PXE server. Current values are LinMin, DMCD") private String type; + + @Parameter(name=ApiConstants.LINMIN_USERNAME, type=CommandType.STRING, required = false, description="Optional, username uses to access LinMin API") + private String linminUsername; + + @Parameter(name=ApiConstants.LINMIN_PASSWORD, type=CommandType.STRING, required = false, description="Optional, password uses to access LinMin API") + private String linminPassword; + + @Parameter(name=ApiConstants.LINMIN_APID, type=CommandType.STRING, required = false, description="Optional, APID uses to access LinMin API") + private String linminApid; /////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -75,6 +84,18 @@ public class AddPxeServerCmd extends BaseCmd { public Long getPod() { return podId; } + + public String getLinMinUsername() { + return linminUsername; + } + + public String getLinMinPassword() { + return linminPassword; + } + + public String getLinMinApid() { + return linminApid; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/server/src/com/cloud/baremetal/LinMinPxeServerManagerImpl.java b/server/src/com/cloud/baremetal/LinMinPxeServerManagerImpl.java index c6199e211c1..b56a89e14ca 100644 --- a/server/src/com/cloud/baremetal/LinMinPxeServerManagerImpl.java +++ b/server/src/com/cloud/baremetal/LinMinPxeServerManagerImpl.java @@ -38,6 +38,9 @@ public class LinMinPxeServerManagerImpl extends PxeServerManagerImpl implements public Host addPxeServer(AddPxeServerCmd cmd) throws InvalidParameterValueException, CloudRuntimeException { long zoneId = cmd.getZoneId(); Long podId = cmd.getPod(); + String apiUsername; + String apiPassword; + String apid; DataCenterVO zone = _dcDao.findById(zoneId); if (zone == null) { @@ -57,6 +60,21 @@ public class LinMinPxeServerManagerImpl extends PxeServerManagerImpl implements throw new InvalidParameterValueException(e.getMessage()); } + apiUsername = cmd.getLinMinUsername(); + apiPassword = cmd.getLinMinPassword(); + apid = cmd.getLinMinApid(); + if (apiUsername == null) { + throw new InvalidParameterValueException("No LinMin username specified, without it I can user LinMin API"); + } + + if (apiPassword == null) { + throw new InvalidParameterValueException("No LinMin password specified, without it I can user LinMin API"); + } + + if (apid == null) { + throw new InvalidParameterValueException("No LinMin apid specified, without it I can user LinMin API"); + } + String ipAddress = uri.getHost(); String username = cmd.getUsername(); String password = cmd.getPassword(); @@ -69,6 +87,9 @@ public class LinMinPxeServerManagerImpl extends PxeServerManagerImpl implements params.put("password", password); params.put("guid", guid); params.put("pod", Long.toString(cmd.getPod())); + params.put("apiUsername", apiUsername); + params.put("apiPassword", apiPassword); + params.put("apid", apid); ServerResource resource = null; try { diff --git a/server/src/com/cloud/baremetal/LinMinPxeServerResource.java b/server/src/com/cloud/baremetal/LinMinPxeServerResource.java index f4222afa798..f4e4a994b00 100644 --- a/server/src/com/cloud/baremetal/LinMinPxeServerResource.java +++ b/server/src/com/cloud/baremetal/LinMinPxeServerResource.java @@ -49,6 +49,9 @@ public class LinMinPxeServerResource implements ServerResource { String _ip; String _zoneId; String _podId; + String _apiUsername; + String _apiPassword; + String _apid; class XmlReturn { NodeList nList; @@ -88,6 +91,9 @@ public class LinMinPxeServerResource implements ServerResource { _password = (String)params.get("password"); _zoneId = (String)params.get("zone"); _podId = (String)params.get("pod"); + _apiUsername = (String)params.get("apiUsername"); + _apiPassword = (String)params.get("apiPassword"); + _apid = (String)params.get("apid"); if (_guid == null) { throw new ConfigurationException("No Guid specified"); @@ -113,6 +119,18 @@ public class LinMinPxeServerResource implements ServerResource { throw new ConfigurationException("No password specified"); } + if (_apiUsername == null) { + throw new ConfigurationException("No API username specified"); + } + + if (_apiPassword == null) { + throw new ConfigurationException("No API password specified"); + } + + if (_apid == null) { + throw new ConfigurationException("No A specified"); + } + com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); s_logger.debug(String.format("Trying to connect to LinMin PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); @@ -212,19 +230,16 @@ public class LinMinPxeServerResource implements ServerResource { protected PrepareLinMinPxeServerAnswer execute(PrepareLinMinPxeServerCommand cmd) { - String apiUserName = "root"; - String apiPassword = "password"; - String apid = "2ad644fb479871a0f5543dd6d29fe9ed"; StringBuffer askApid = new StringBuffer(); askApid.append("http://"); askApid.append(_ip); askApid.append("/tftpboot/www/lbmp-API.php?actiontype=provision&apid="); - askApid.append(apid); + askApid.append(_apid); askApid.append("&auth_user="); - askApid.append(apiUserName); + askApid.append(_apiUsername); askApid.append("&auth_user_pw="); - askApid.append(apiPassword); + askApid.append(_apiPassword); askApid.append("&rtn_format=XML&action=authorize"); InputSource s = httpCall(askApid.toString()); if (s == null) {