Skip to content

Commit e1e6ec1

Browse files
vmware: Bypass empty string check for username and password (#5337)
* Bypass empty string check for username and password Co-authored-by: dahn <daan.hoogland@gmail.com>
1 parent 83dd294 commit e1e6ec1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public class AddHostCmd extends BaseCmd {
5454
@Parameter(name = ApiConstants.CLUSTER_NAME, type = CommandType.STRING, description = "the cluster name for the host")
5555
private String clusterName;
5656

57-
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "the password for the host")
57+
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "the username for the host; required to be passed for hypervisors other than VMWare")
58+
private String username;
59+
60+
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "the password for the host; required to be passed for hypervisors other than VMWare")
5861
private String password;
5962

6063
@Parameter(name = ApiConstants.POD_ID, type = CommandType.UUID, entityType = PodResponse.class, required = true, description = "the Pod ID for the host")
@@ -63,9 +66,6 @@ public class AddHostCmd extends BaseCmd {
6366
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "the host URL")
6467
private String url;
6568

66-
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "the username for the host")
67-
private String username;
68-
6969
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the Zone ID for the host")
7070
private Long zoneId;
7171

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.cloud.vm.UserVmManager;
4545
import com.cloud.vm.VirtualMachineProfile;
4646
import com.cloud.vm.VirtualMachineProfileImpl;
47+
import com.google.common.base.Strings;
4748
import org.apache.cloudstack.api.ApiConstants;
4849
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
4950
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
@@ -688,6 +689,10 @@ private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long c
688689
if ((clusterName != null || clusterId != null) && podId == null) {
689690
throw new InvalidParameterValueException("Can't specify cluster without specifying the pod");
690691
}
692+
if (!HypervisorType.VMware.toString().equalsIgnoreCase(hypervisorType) &&
693+
(Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(password))) {
694+
throw new InvalidParameterValueException("Username and Password need to be provided.");
695+
}
691696

692697
if (clusterId != null) {
693698
if (_clusterDao.findById(clusterId) == null) {

0 commit comments

Comments
 (0)