DaanHoogland commented on code in PR #11591:
URL: https://github.com/apache/cloudstack/pull/11591#discussion_r2348414005
##########
server/src/main/java/com/cloud/server/ManagementServerImpl.java:
##########
@@ -2451,19 +2451,29 @@ public Pair<List<? extends IpAddress>, Integer>
searchForIPAddresses(final ListP
final Long vpcId = cmd.getVpcId();
final String state = cmd.getState();
+ List<IpAddress.State> states = new ArrayList<>();
+ if (StringUtils.isNotBlank(state)) {
+ for (String s : StringUtils.split(state, ",")) {
+ try {
+ states.add(IpAddress.State.valueOf(s));
+ } catch (IllegalArgumentException e) {
+ throw new InvalidParameterValueException("Invalid state: "
+ s);
+ }
+ }
+ }
Boolean isAllocated = cmd.isAllocatedOnly();
if (isAllocated == null) {
- if (state != null &&
(state.equalsIgnoreCase(IpAddress.State.Free.name()) ||
state.equalsIgnoreCase(IpAddress.State.Reserved.name()))) {
+ if (states.contains(IpAddress.State.Free) ||
states.contains(IpAddress.State.Reserved)) {
isAllocated = Boolean.FALSE;
} else {
isAllocated = Boolean.TRUE; // default
}
} else {
- if (state != null &&
(state.equalsIgnoreCase(IpAddress.State.Free.name()) ||
state.equalsIgnoreCase(IpAddress.State.Reserved.name()))) {
+ if (states.contains(IpAddress.State.Free) ||
states.contains(IpAddress.State.Reserved)) {
if (isAllocated) {
throw new InvalidParameterValueException("Conflict:
allocatedonly is true but state is Free");
}
- } else if (state != null &&
state.equalsIgnoreCase(IpAddress.State.Allocated.name())) {
+ } else if (states.contains(IpAddress.State.Allocated)) {
isAllocated = Boolean.TRUE;
}
}
Review Comment:
can we move this logic to its own method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]