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>
This commit is contained in:
Pearl Dsilva 2021-08-24 12:45:29 +05:30 committed by GitHub
parent 83dd294940
commit e1e6ec107c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -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")
@ -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;

View File

@ -44,6 +44,7 @@ import com.cloud.storage.dao.DiskOfferingDao;
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;
@ -688,6 +689,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
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))) {
throw new InvalidParameterValueException("Username and Password need to be provided.");
}
if (clusterId != null) {
if (_clusterDao.findById(clusterId) == null) {