Yaniv Bronhaim has uploaded a new change for review. Change subject: core: host-deploy: Applying usage for public key authentication method ......................................................................
core: host-deploy: Applying usage for public key authentication method Due to the picked option via the UI, the authentication to the host will be set and enforced. Change-Id: I51f2566f91935a74504785a6e62d66b765dfa671 Signed-off-by: Yaniv Bronhaim <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdsOperationActionParameters.java 4 files changed, 75 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/16688/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java index 6748100..dd3b4e6 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java @@ -29,6 +29,7 @@ import org.ovirt.engine.core.common.action.VdcReturnValueBase; import org.ovirt.engine.core.common.action.VdsActionParameters; import org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions; +import org.ovirt.engine.core.common.action.VdsOperationActionParameters.AuthenticationMethod; import org.ovirt.engine.core.common.businessentities.StoragePool; import org.ovirt.engine.core.common.businessentities.StorageType; import org.ovirt.engine.core.common.businessentities.VDS; @@ -149,6 +150,7 @@ // clients). they are installed as part of the approve process if (Config.<Boolean> GetValue(ConfigValues.InstallVds) && !getParameters().getAddPending()) { final InstallVdsParameters installVdsParameters = new InstallVdsParameters(getVdsId(), getParameters().getPassword()); + installVdsParameters.setAuthMethod(getParameters().getAuthMethod()); installVdsParameters.setOverrideFirewall(getParameters().getOverrideFirewall()); installVdsParameters.setRebootAfterInstallation(getParameters().isRebootAfterInstallation()); Map<String, String> values = new HashMap<String, String>(); @@ -326,6 +328,7 @@ && !EngineEncryptionUtils.haveKey()) { returnValue = failCanDoAction(VdcBllMessages.VDS_TRY_CREATE_SECURE_CERTIFICATE_NOT_FOUND); } else if (!getParameters().getAddPending() + && (getParameters().getAuthMethod() == AuthenticationMethod.Password) && StringUtils.isEmpty(getParameters().getPassword())) { // We block vds installations if it's not a RHEV-H and password is empty // Note that this may override local host SSH policy. See BZ#688718. @@ -362,16 +365,26 @@ return ClusterUtils.getInstance(); } - public EngineSSHClient getSSHClient() { + public EngineSSHClient getSSHClient() throws Exception { Long timeout = TimeUnit.SECONDS.toMillis(Config.<Integer> GetValue(ConfigValues.ConnectToServerTimeoutInSeconds)); EngineSSHClient sshclient = new EngineSSHClient(); + sshclient.setVds(getParameters().getvds()); sshclient.setHardTimeout(timeout); sshclient.setSoftTimeout(timeout); - sshclient.setHost(getVds().getStaticData().getHostName(), getVds().getStaticData().getSshPort()); - sshclient.setUser(getVds().getStaticData().getSshUsername()); sshclient.setPassword(getParameters().getPassword()); + switch (getParameters().getAuthMethod()) { + case PublicKey: + sshclient.useDefaultKeyPair(); + break; + case Password: + sshclient.setPassword(getParameters().getPassword()); + break; + default: + throw new Exception("Invalid authentication method value was sent to AddVdsCommand"); + } + return sshclient; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java index d904301..c7fa92a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java @@ -154,7 +154,6 @@ switch (getVds().getVdsType()) { case VDS: - installer.setPassword(parameters.getPassword()); installer.setFirewall(parameters.getOverrideFirewall()); break; case oVirtNode: @@ -165,7 +164,6 @@ getVds().getVdsType().name() ); } - installer.useDefaultKeyPair(); break; default: throw new IllegalArgumentException( @@ -175,6 +173,18 @@ ) ); } + + switch (getParameters().getAuthMethod()) { + case Password: + installer.setPassword(parameters.getPassword()); + break; + case PublicKey: + installer.useDefaultKeyPair(); + break; + default: + throw new Exception("Invalid authentication method value was sent to InstallVdsCommand"); + } + setVdsStatus(VDSStatus.Installing); installer.execute(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java index 72422ec..8999eb5 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java @@ -13,6 +13,7 @@ import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.action.VdsOperationActionParameters.AuthenticationMethod; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSStatus; import org.ovirt.engine.core.common.businessentities.VDSType; @@ -87,6 +88,7 @@ && _oldVds.getStatus() != VDSStatus.InstallFailed) { addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_INSTALL_STATUS_ILLEGAL); } else if (getParameters().getInstallVds() + && getParameters().getAuthMethod() == AuthenticationMethod.Password && StringUtils.isEmpty(getParameters().getPassword()) && getParameters().getVdsStaticData().getVdsType() == VDSType.VDS) { addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_INSTALL_EMPTY_PASSWORD); @@ -134,6 +136,7 @@ tempVar.setoVirtIsoFile(getParameters().getoVirtIsoFile()); tempVar.setOverrideFirewall(getParameters().getOverrideFirewall()); tempVar.setRebootAfterInstallation(getParameters().isRebootAfterInstallation()); + tempVar.setAuthMethod(getParameters().getAuthMethod()); ArrayList<VdcReturnValueBase> resultList = Backend.getInstance().runInternalMultipleActions( VdcActionType.InstallVds, new ArrayList<VdcActionParametersBase>(Arrays diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdsOperationActionParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdsOperationActionParameters.java index 8cdda7b..7f20c70 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdsOperationActionParameters.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdsOperationActionParameters.java @@ -1,5 +1,8 @@ package org.ovirt.engine.core.common.action; +import java.util.HashMap; +import java.util.Map; + import javax.validation.Valid; import org.ovirt.engine.core.common.businessentities.VDS; @@ -20,6 +23,35 @@ */ private boolean rebootAfterInstallation = true; + private AuthenticationMethod authMethod; + + public enum AuthenticationMethod { + Password(0), + PublicKey(1); + + private int intValue; + private static Map<Integer, AuthenticationMethod> mappings; + + static { + mappings = new HashMap<Integer, AuthenticationMethod>(); + for (AuthenticationMethod error : values()) { + mappings.put(error.getValue(), error); + } + } + + private AuthenticationMethod(int value) { + intValue = value; + } + + public int getValue() { + return intValue; + } + + public static AuthenticationMethod forValue(int value) { + return mappings.get(value); + } + } + public VdsOperationActionParameters(VdsStatic vdsStaticVal, String passwordVal) { super(vdsStaticVal.getId()); if ("".equals(vdsStaticVal.getManagementIp())) { @@ -27,10 +59,16 @@ } vdsStatic = vdsStaticVal; password = passwordVal; + authMethod = AuthenticationMethod.Password; } public VdsOperationActionParameters(VdsStatic vdsStatic) { this(vdsStatic, null); + authMethod = AuthenticationMethod.Password; + } + + public VdsOperationActionParameters() { + authMethod = AuthenticationMethod.Password; } public VdsStatic getVdsStaticData() { @@ -45,7 +83,12 @@ password = value; } - public VdsOperationActionParameters() { + public void setAuthMethod(AuthenticationMethod value) { + authMethod = value; + } + + public AuthenticationMethod getAuthMethod() { + return authMethod; } // Deprecated to keep old api with root password -- To view, visit http://gerrit.ovirt.org/16688 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I51f2566f91935a74504785a6e62d66b765dfa671 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
