Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public class AddHostCmd extends BaseCmd {
@Parameter(name = ApiConstants.CLUSTER_NAME, type = CommandType.STRING, description = "the cluster name for the host")
private String clusterName;

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

@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "the password for the host; required to be passed for hypervisors other than VMWare")
private String password;

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

@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "the username for the host")
private String username;

@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the Zone ID for the host")
private Long zoneId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
import com.google.common.base.Strings;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
Expand Down Expand Up @@ -687,6 +688,10 @@ private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long c
if ((clusterName != null || clusterId != null) && podId == null) {
throw new InvalidParameterValueException("Can't specify cluster without specifying the pod");
}
if (!HypervisorType.VMware.toString().equalsIgnoreCase(hypervisorType) &&
(Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(password))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could import org.apache.commons.lang3.StringUtils here and use StringUtils.isAnyEmpty(username, password).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @GutoVeronezi.

Nowadays we already have some discussions about adopting org.apache.commons.lang3.StringUtils vs com.cloud.utils.StringUtils "facade" (@DaanHoogland 🙂); with the google.common.base.Strings adds a third variable to this "equation".

throw new InvalidParameterValueException("Username and Password need to be provided.");
}

if (clusterId != null) {
if (_clusterDao.findById(clusterId) == null) {
Expand Down