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 @@ -311,10 +311,10 @@ public Long getPhysicalNetworkId() {
}
}
if (physicalNetworkId != null) {
if (offering.getGuestType() == GuestType.Shared) {
if ((offering.getGuestType() == GuestType.Shared) || (offering.getGuestType() == GuestType.L2)) {
return physicalNetworkId;
} else {
throw new InvalidParameterValueException("Physical network ID can be specified for networks of guest IP type " + GuestType.Shared + " only.");
throw new InvalidParameterValueException("Physical network ID can be specified for networks of guest IP type " + GuestType.Shared + " or " + GuestType.L2 + " only.");
}
} else {
if (zoneId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,23 @@ public void testGetPhysicalNetworkIdForNonSharedNet() {
try {
cmd.getPhysicalNetworkId();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().startsWith("Physical network ID can be specified for networks of guest IP type Shared only"));
Assert.assertTrue(e.getMessage().startsWith("Physical network ID can be specified for networks of guest IP type Shared or L2 only."));
}
}

@Test
public void testGetPhysicalNetworkIdForL2Net() {
Long physicalNetworkId = 1L;
Long networkOfferingId = 1L;
ReflectionTestUtils.setField(cmd, "networkOfferingId", networkOfferingId);
NetworkOffering networkOffering = Mockito.mock(NetworkOffering.class);
ReflectionTestUtils.setField(cmd, "physicalNetworkId", physicalNetworkId);
Mockito.when(_entityMgr.findById(NetworkOffering.class, networkOfferingId)).thenReturn(networkOffering);
Mockito.when(networkOffering.getGuestType()).thenReturn(Network.GuestType.L2);
try {
Assert.assertEquals(cmd.getPhysicalNetworkId(), physicalNetworkId);
} catch (Exception e) {
Assert.fail("Failed to get physical network id");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2665,8 +2665,8 @@ private Network createGuestNetwork(final long networkOfferingId, final String na
}
// Only Account specific Isolated network with sourceNat service disabled are allowed in security group
// enabled zone
if (ntwkOff.getGuestType() != GuestType.Shared) {
throw new InvalidParameterValueException("Only shared guest network can be created in security group enabled zone");
if ((ntwkOff.getGuestType() != GuestType.Shared) && (ntwkOff.getGuestType() != GuestType.L2)) {
throw new InvalidParameterValueException("Only shared or L2 guest network can be created in security group enabled zone");
}
if (_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) {
throw new InvalidParameterValueException("Service SourceNat is not allowed in security group enabled zone");
Expand Down
6 changes: 4 additions & 2 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
import com.cloud.hypervisor.kvm.dpdk.DpdkHelper;
import com.cloud.network.IpAddressManager;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.IpAddresses;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
Expand Down Expand Up @@ -3584,13 +3585,14 @@ public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, Service

for (Long networkId : networkIdList) {
NetworkVO network = _networkDao.findById(networkId);
NetworkOffering ntwkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());

if (network == null) {
throw new InvalidParameterValueException("Unable to find network by id " + networkId);
}

if (!_networkModel.isSecurityGroupSupportedInNetwork(network)) {
throw new InvalidParameterValueException("Network is not security group enabled: " + network.getId());
if (!_networkModel.isSecurityGroupSupportedInNetwork(network) && (ntwkOffering.getGuestType() != GuestType.L2)) {
throw new InvalidParameterValueException("Network is not security group enabled or not L2 network: " + network.getId());
}

_accountMgr.checkAccess(owner, AccessType.UseEntry, false, network);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/network/CreateL2NetworkForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export default {
api('listZones', params).then(json => {
for (const i in json.listzonesresponse.zone) {
const zone = json.listzonesresponse.zone[i]
if (zone.networktype === 'Advanced' && zone.securitygroupsenabled !== true) {
if (zone.networktype === 'Advanced') {
this.zones.push(zone)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/network/CreateNetwork.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@refresh-data="refreshParent"
@refresh="handleRefresh"/>
</a-tab-pane>
<a-tab-pane :tab="$t('label.l2')" key="3" v-if="isAdvancedZoneWithoutSGAvailable">
<a-tab-pane :tab="$t('label.l2')" key="3">
<CreateL2NetworkForm
:loading="loading"
:resource="resource"
Expand Down