Skip to content

Commit f3289fb

Browse files
server: fix regular user can create isolated network without sourcenat (apache#5844)
* server: fix regular user can create isolated network without sourcenat
1 parent fb35f46 commit f3289fb

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,12 +1360,9 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
13601360

13611361
performBasicPrivateVlanChecks(vlanId, secondaryVlanId, privateVlanType);
13621362

1363-
// Regular user can create Guest Isolated Source Nat enabled network only
1364-
if (_accountMgr.isNormalUser(caller.getId()) && (ntwkOff.getTrafficType() != TrafficType.Guest
1365-
|| ntwkOff.getGuestType() != Network.GuestType.Isolated && areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) {
1366-
throw new InvalidParameterValueException(
1367-
String.format("Regular users can only create a network from network offerings having traffic type [%s] and network type [%s] with a service [%s] enabled.", TrafficType.Guest,
1368-
Network.GuestType.Isolated, Service.SourceNat.getName()));
1363+
// Regular user can create Guest Isolated Source Nat enabled network or L2 network only
1364+
if (_accountMgr.isNormalUser(caller.getId())) {
1365+
validateNetworkOfferingForRegularUser(ntwkOff);
13691366
}
13701367

13711368
// Don't allow to specify vlan if the caller is not ROOT admin
@@ -1457,6 +1454,23 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
14571454
return network;
14581455
}
14591456

1457+
private void validateNetworkOfferingForRegularUser(NetworkOfferingVO ntwkOff) {
1458+
if (ntwkOff.getTrafficType() != TrafficType.Guest) {
1459+
throw new InvalidParameterValueException("Regular users can only create a Guest network");
1460+
}
1461+
if (ntwkOff.getGuestType() == GuestType.Isolated && areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) {
1462+
s_logger.debug(String.format("Creating a network from network offerings having traffic type [%s] and network type [%s] with a service [%s] enabled.",
1463+
TrafficType.Guest, GuestType.Isolated, Service.SourceNat.getName()));
1464+
} else if (ntwkOff.getGuestType() == GuestType.L2) {
1465+
s_logger.debug(String.format("Creating a network from network offerings having traffic type [%s] and network type [%s].",
1466+
TrafficType.Guest, GuestType.L2));
1467+
} else {
1468+
throw new InvalidParameterValueException(
1469+
String.format("Regular users can only create an %s network with a service [%s] enabled, or a %s network.",
1470+
GuestType.Isolated, Service.SourceNat.getName(), GuestType.L2));
1471+
}
1472+
}
1473+
14601474
/**
14611475
* Retrieve information (if set) for private VLAN when creating the network
14621476
*/

0 commit comments

Comments
 (0)