mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-1131
[EC2 Query API] RunInstances allows negative values for paramters 'MinCount' and 'MaxCount' Add parameter validation to ensure MinCount is greater than 0 and MaxCount is great than or equal to MinCount
This commit is contained in:
parent
b0b2fd4833
commit
3337106693
@ -1142,14 +1142,26 @@ public class EC2RestServlet extends HttpServlet {
|
||||
else { response.sendError(530, "Missing ImageId parameter" ); return; }
|
||||
|
||||
String[] minCount = request.getParameterValues( "MinCount" );
|
||||
if ( null != minCount && 0 < minCount.length )
|
||||
EC2request.setMinCount( Integer.parseInt( minCount[0] ));
|
||||
else { response.sendError(530, "Missing MinCount parameter" ); return; }
|
||||
if ( minCount == null || minCount.length < 1) {
|
||||
response.sendError(530, "Missing MinCount parameter" );
|
||||
return;
|
||||
} else if ( Integer.parseInt(minCount[0]) < 1) {
|
||||
throw new EC2ServiceException(ClientError.InvalidParameterValue,
|
||||
"Value of parameter MinCount should be greater than 0");
|
||||
} else {
|
||||
EC2request.setMinCount( Integer.parseInt( minCount[0]) );
|
||||
}
|
||||
|
||||
String[] maxCount = request.getParameterValues( "MaxCount" );
|
||||
if ( null != maxCount && 0 < maxCount.length )
|
||||
EC2request.setMaxCount( Integer.parseInt( maxCount[0] ));
|
||||
else { response.sendError(530, "Missing MaxCount parameter" ); return; }
|
||||
if ( maxCount == null || maxCount.length < 1) {
|
||||
response.sendError(530, "Missing MaxCount parameter" );
|
||||
return;
|
||||
} else if ( Integer.parseInt(maxCount[0]) < 1) {
|
||||
throw new EC2ServiceException(ClientError.InvalidParameterValue,
|
||||
"Value of parameter MaxCount should be greater than 0");
|
||||
} else {
|
||||
EC2request.setMaxCount( Integer.parseInt( maxCount[0]) );
|
||||
}
|
||||
|
||||
String[] instanceType = request.getParameterValues( "InstanceType" );
|
||||
if ( null != instanceType && 0 < instanceType.length )
|
||||
|
||||
@ -731,8 +731,17 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
|
||||
EC2RunInstances request = new EC2RunInstances();
|
||||
|
||||
request.setTemplateId(rit.getImageId());
|
||||
request.setMinCount(rit.getMinCount());
|
||||
request.setMaxCount(rit.getMaxCount());
|
||||
|
||||
if (rit.getMinCount() < 1) {
|
||||
throw new EC2ServiceException(ClientError.InvalidParameterValue,
|
||||
"Value of parameter MinCount should be greater than 0");
|
||||
} else request.setMinCount( rit.getMinCount() );
|
||||
|
||||
if (rit.getMaxCount() < 1) {
|
||||
throw new EC2ServiceException(ClientError.InvalidParameterValue,
|
||||
"Value of parameter MaxCount should be greater than 0");
|
||||
} else request.setMaxCount(rit.getMaxCount());
|
||||
|
||||
if (null != type) request.setInstanceType(type);
|
||||
if (null != prt) request.setZoneName(prt.getAvailabilityZone());
|
||||
if (null != userData) request.setUserData(userData.getData());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user