Skip to content

Commit 6bb95c0

Browse files
committed
Merge release branch 4.18 to main
* 4.18: Storage and volumes statistics tasks for StorPool primary storage (#7404) proper storage construction (#6797) guarantee MAC uniqueness (#7634) server: allow migration of all VMs with local storage on KVM (#7656) Add L2 networks to Zones with SG (#7719)
2 parents b5eebc4 + f32a63b commit 6bb95c0

File tree

27 files changed

+323
-108
lines changed

27 files changed

+323
-108
lines changed

api/src/main/java/com/cloud/network/NetworkModel.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public interface NetworkModel {
9090
INSTANCE_ID_FILE, VM_ID_FILE, PUBLIC_KEYS_FILE, CLOUD_IDENTIFIER_FILE, HYPERVISOR_HOST_NAME_FILE));
9191

9292
static final ConfigKey<Integer> MACIdentifier = new ConfigKey<>("Advanced",Integer.class, "mac.identifier", "0",
93-
"This value will be used while generating the mac addresses for isolated and shared networks. The hexadecimal equivalent value will be present at the 2nd octet of the mac address. Default value is null which means this feature is disabled.Its scope is global.", true, ConfigKey.Scope.Global);
93+
"This value will be used while generating the mac addresses for isolated and shared networks. The hexadecimal equivalent value will be present at the 2nd octet of the mac address. Default value is zero (0) which means that the DB id of the zone will be used.", true, ConfigKey.Scope.Zone);
9494

9595
static final ConfigKey<Boolean> AdminIsAllowedToDeployAnywhere = new ConfigKey<>("Advanced",Boolean.class, "admin.is.allowed.to.deploy.anywhere", "false",
9696
"This will determine if the root admin is allowed to deploy in networks in subdomains.", true, ConfigKey.Scope.Global);
@@ -114,6 +114,13 @@ public interface NetworkModel {
114114

115115
List<? extends Nic> getNics(long vmId);
116116

117+
/**
118+
* Gets the next available MAC and checks it for global uniqueness in the nics table. It will keep looking until it finds a MAC address that is unique.
119+
*
120+
* @param networkConfigurationId the id of the network to use the nic in. used for finding the zone
121+
* @return a string containing a MAC address
122+
* @throws InsufficientAddressCapacityException if no MAC can be returned
123+
*/
117124
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
118125

119126
PublicIpAddress getPublicIpAddress(long ipAddressId);

api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ public Long getPhysicalNetworkId() {
323323
}
324324
}
325325
if (physicalNetworkId != null) {
326-
if (offering.getGuestType() == GuestType.Shared) {
326+
if ((offering.getGuestType() == GuestType.Shared) || (offering.getGuestType() == GuestType.L2)) {
327327
return physicalNetworkId;
328328
} else {
329-
throw new InvalidParameterValueException("Physical network ID can be specified for networks of guest IP type " + GuestType.Shared + " only.");
329+
throw new InvalidParameterValueException("Physical network ID can be specified for networks of guest IP type " + GuestType.Shared + " or " + GuestType.L2 + " only.");
330330
}
331331
} else {
332332
if (zoneId == null) {

api/src/test/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmdTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,23 @@ public void testGetPhysicalNetworkIdForNonSharedNet() {
251251
try {
252252
cmd.getPhysicalNetworkId();
253253
} catch (Exception e) {
254-
Assert.assertTrue(e.getMessage().startsWith("Physical network ID can be specified for networks of guest IP type Shared only"));
254+
Assert.assertTrue(e.getMessage().startsWith("Physical network ID can be specified for networks of guest IP type Shared or L2 only."));
255+
}
256+
}
257+
258+
@Test
259+
public void testGetPhysicalNetworkIdForL2Net() {
260+
Long physicalNetworkId = 1L;
261+
Long networkOfferingId = 1L;
262+
ReflectionTestUtils.setField(cmd, "networkOfferingId", networkOfferingId);
263+
NetworkOffering networkOffering = Mockito.mock(NetworkOffering.class);
264+
ReflectionTestUtils.setField(cmd, "physicalNetworkId", physicalNetworkId);
265+
Mockito.when(_entityMgr.findById(NetworkOffering.class, networkOfferingId)).thenReturn(networkOffering);
266+
Mockito.when(networkOffering.getGuestType()).thenReturn(Network.GuestType.L2);
267+
try {
268+
Assert.assertEquals(cmd.getPhysicalNetworkId(), physicalNetworkId);
269+
} catch (Exception e) {
270+
Assert.fail("Failed to get physical network id");
255271
}
256272
}
257273

engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineDataCenterDao.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ public interface EngineDataCenterDao extends GenericDao<EngineDataCenterVO, Long
2828
StateDao<DataCenterResourceEntity.State, DataCenterResourceEntity.State.Event, DataCenterResourceEntity> {
2929
EngineDataCenterVO findByName(String name);
3030

31-
/**
32-
* @param id data center id
33-
* @return a pair of mac address strings. The first one is private and second is public.
34-
*/
35-
String[] getNextAvailableMacAddressPair(long id);
36-
37-
String[] getNextAvailableMacAddressPair(long id, long mask);
38-
3931
List<EngineDataCenterVO> findZonesByDomainId(Long domainId);
4032

4133
List<EngineDataCenterVO> listPublicZones(String keyword);

engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineDataCenterDaoImpl.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import javax.inject.Inject;
2525
import javax.naming.ConfigurationException;
26-
import javax.persistence.TableGenerator;
2726

2827
import org.apache.log4j.Logger;
2928
import org.springframework.stereotype.Component;
@@ -39,10 +38,8 @@
3938
import com.cloud.utils.db.GenericDaoBase;
4039
import com.cloud.utils.db.SearchBuilder;
4140
import com.cloud.utils.db.SearchCriteria;
42-
import com.cloud.utils.db.SequenceFetcher;
4341
import com.cloud.utils.db.TransactionLegacy;
4442
import com.cloud.utils.db.UpdateBuilder;
45-
import com.cloud.utils.net.NetUtils;
4643

4744
/**
4845
* @config
@@ -66,7 +63,6 @@ public class EngineDataCenterDaoImpl extends GenericDaoBase<EngineDataCenterVO,
6663

6764
protected long _prefix;
6865
protected Random _rand = new Random(System.currentTimeMillis());
69-
protected TableGenerator _tgMacAddress;
7066

7167
@Inject
7268
protected DcDetailsDao _detailsDao;
@@ -139,25 +135,6 @@ public List<EngineDataCenterVO> findByKeyword(String keyword) {
139135
return listBy(ssc);
140136
}
141137

142-
@Override
143-
public String[] getNextAvailableMacAddressPair(long id) {
144-
return getNextAvailableMacAddressPair(id, 0);
145-
}
146-
147-
@Override
148-
public String[] getNextAvailableMacAddressPair(long id, long mask) {
149-
SequenceFetcher fetch = SequenceFetcher.getInstance();
150-
151-
long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id);
152-
seq = seq | _prefix | ((id & 0x7f) << 32);
153-
seq |= mask;
154-
seq |= ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
155-
String[] pair = new String[2];
156-
pair[0] = NetUtils.long2Mac(seq);
157-
pair[1] = NetUtils.long2Mac(seq | 0x1l << 39);
158-
return pair;
159-
}
160-
161138
@Override
162139
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
163140
if (!super.configure(name, params)) {
@@ -204,9 +181,6 @@ protected EngineDataCenterDaoImpl() {
204181
UUIDSearch = createSearchBuilder();
205182
UUIDSearch.and("uuid", UUIDSearch.entity().getUuid(), SearchCriteria.Op.EQ);
206183
UUIDSearch.done();
207-
208-
_tgMacAddress = _tgs.get("macAddress");
209-
assert _tgMacAddress != null : "Couldn't get mac address table generator";
210184
}
211185

212186
@Override

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,8 +2665,8 @@ private Network createGuestNetwork(final long networkOfferingId, final String na
26652665
}
26662666
// Only Account specific Isolated network with sourceNat service disabled are allowed in security group
26672667
// enabled zone
2668-
if (ntwkOff.getGuestType() != GuestType.Shared) {
2669-
throw new InvalidParameterValueException("Only shared guest network can be created in security group enabled zone");
2668+
if ((ntwkOff.getGuestType() != GuestType.Shared) && (ntwkOff.getGuestType() != GuestType.L2)) {
2669+
throw new InvalidParameterValueException("Only shared or L2 guest network can be created in security group enabled zone");
26702670
}
26712671
if (_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) {
26722672
throw new InvalidParameterValueException("Service SourceNat is not allowed in security group enabled zone");

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDao.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ public Integer getVlan() {
5252

5353
DataCenterVO findByName(String name);
5454

55-
/**
56-
* @param id data center id
57-
* @return a pair of mac address strings. The first one is private and second is public.
58-
*/
59-
String[] getNextAvailableMacAddressPair(long id);
60-
61-
String[] getNextAvailableMacAddressPair(long id, long mask);
62-
6355
PrivateAllocationData allocatePrivateIpAddress(long id, long podId, long instanceId, String reservationId, boolean forSystemVms);
6456

6557
DataCenterIpAddressVO allocatePrivateIpAddress(long id, String reservationId);

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
27-
import javax.persistence.TableGenerator;
2827

2928
import org.apache.commons.collections.CollectionUtils;
3029
import org.apache.log4j.Logger;
@@ -45,9 +44,7 @@
4544
import com.cloud.utils.db.GenericDaoBase;
4645
import com.cloud.utils.db.SearchBuilder;
4746
import com.cloud.utils.db.SearchCriteria;
48-
import com.cloud.utils.db.SequenceFetcher;
4947
import com.cloud.utils.db.TransactionLegacy;
50-
import com.cloud.utils.net.NetUtils;
5148

5249
/**
5350
* @config
@@ -83,7 +80,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
8380

8481
protected long _prefix;
8582
protected Random _rand = new Random(System.currentTimeMillis());
86-
protected TableGenerator _tgMacAddress;
83+
8784

8885
@Override
8986
public DataCenterVO findByName(String name) {
@@ -230,25 +227,6 @@ public String allocatePodVlan(long podId, long accountId) {
230227
return vo.getVlan();
231228
}
232229

233-
@Override
234-
public String[] getNextAvailableMacAddressPair(long id) {
235-
return getNextAvailableMacAddressPair(id, 0);
236-
}
237-
238-
@Override
239-
public String[] getNextAvailableMacAddressPair(long id, long mask) {
240-
SequenceFetcher fetch = SequenceFetcher.getInstance();
241-
242-
long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id);
243-
seq = seq | _prefix | ((id & 0x7f) << 32);
244-
seq |= mask;
245-
seq |= ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
246-
String[] pair = new String[2];
247-
pair[0] = NetUtils.long2Mac(seq);
248-
pair[1] = NetUtils.long2Mac(seq | 0x1l << 39);
249-
return pair;
250-
}
251-
252230
@Override
253231
public PrivateAllocationData allocatePrivateIpAddress(long dcId, long podId, long instanceId, String reservationId, boolean forSystemVms) {
254232
_ipAllocDao.releaseIpAddress(instanceId);
@@ -348,9 +326,6 @@ public DataCenterDaoImpl() {
348326
TokenSearch = createSearchBuilder();
349327
TokenSearch.and("zoneToken", TokenSearch.entity().getZoneToken(), SearchCriteria.Op.EQ);
350328
TokenSearch.done();
351-
352-
_tgMacAddress = _tgs.get("macAddress");
353-
assert _tgMacAddress != null : "Couldn't get mac address table generator";
354329
}
355330

356331
@Override

engine/schema/src/main/java/com/cloud/network/dao/NetworkDaoImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,6 @@ public String getNextAvailableMacAddress(final long networkConfigId, Integer zon
436436
if(zoneMacIdentifier != null && zoneMacIdentifier.intValue() != 0 ){
437437
seq = seq | _prefix << 40 | (long)zoneMacIdentifier << 32 | networkConfigId << 16 & 0x00000000ffff0000l;
438438
}
439-
else {
440-
seq = seq | _prefix << 40 | _rand.nextInt(Short.MAX_VALUE) << 16 & 0x00000000ffff0000l;
441-
}
442439
return NetUtils.long2Mac(seq);
443440
}
444441

engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public interface NicDao extends GenericDao<NicVO, Long> {
8787

8888
List<NicVO> listByVmIdAndKeyword(long instanceId, String keyword);
8989

90-
NicVO findByInstanceIdAndMacAddress(long instanceId, String macAddress);
90+
NicVO findByMacAddress(String macAddress);
9191

9292
NicVO findByNetworkIdAndMacAddressIncludingRemoved(long networkId, String mac);
9393

0 commit comments

Comments
 (0)