Skip to content

Commit 73f3f29

Browse files
committed
Allow user attach multiple eips to one nic
Delete all checks for multi-eip binding to one nic and change query getAttachableVmNicForEip to make it returns the nics has other EIP attached. For zxwing/premium#1678
1 parent 5b385be commit 73f3f29

File tree

2 files changed

+1
-36
lines changed

2 files changed

+1
-36
lines changed

plugin/eip/src/main/java/org/zstack/network/service/eip/EipApiInterceptor.java

-34
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ private void validate(APIGetEipAttachableVmNicsMsg msg) {
8888
}
8989

9090
private void validate(final APIAttachEipMsg msg) {
91-
isVmNicUsed(msg.getVmNicUuid());
92-
9391
SimpleQuery<EipVO> q = dbf.createQuery(EipVO.class);
9492
q.select(EipVO_.state, EipVO_.vmNicUuid, EipVO_.vipIp);
9593
q.add(EipVO_.uuid, Op.EQ, msg.getEipUuid());
@@ -110,14 +108,6 @@ private void validate(final APIAttachEipMsg msg) {
110108
));
111109
}
112110

113-
q = dbf.createQuery(EipVO.class);
114-
q.add(EipVO_.vmNicUuid, Op.EQ, msg.getVmNicUuid());
115-
if (q.isExists()) {
116-
throw new ApiMessageInterceptionException(errf.stringToOperationError(
117-
String.format("the VM nic[uuid:%s] already has another EIP attached", msg.getVmNicUuid())
118-
));
119-
}
120-
121111
String vipIp = t.get(2, String.class);
122112
isVipInVmNicSubnet(vipIp, msg.getVmNicUuid());
123113

@@ -167,18 +157,6 @@ private void validate(APIDeleteEipMsg msg) {
167157
}
168158
}
169159

170-
private void isVmNicUsed(String vmNicUuid) {
171-
SimpleQuery<EipVO> eq = dbf.createQuery(EipVO.class);
172-
eq.select(EipVO_.uuid);
173-
eq.add(EipVO_.vmNicUuid, Op.EQ, vmNicUuid);
174-
String eipUuid = eq.findValue();
175-
if (eipUuid != null) {
176-
throw new ApiMessageInterceptionException(errf.instantiateErrorCode(SysErrors.OPERATION_ERROR,
177-
String.format("vm nic[uuid:%s] has attached to another eip[uuid:%s]", vmNicUuid, eipUuid)
178-
));
179-
}
180-
}
181-
182160
private void isVipInVmNicSubnet(String eipIp, String vmNicUuid) {
183161
SimpleQuery<VmNicVO> q = dbf.createQuery(VmNicVO.class);
184162
q.select(VmNicVO_.gateway, VmNicVO_.netmask);
@@ -212,10 +190,6 @@ private void checkIfVmAlreadyHasVipNetwork(String vmUuid, VipVO vip) {
212190
}
213191

214192
private void validate(APICreateEipMsg msg) {
215-
if (msg.getVmNicUuid() != null) {
216-
isVmNicUsed(msg.getVmNicUuid());
217-
}
218-
219193
VipVO vip = dbf.findByUuid(msg.getVipUuid(), VipVO.class);
220194
if (vip.getUseFor() != null) {
221195
throw new ApiMessageInterceptionException(errf.instantiateErrorCode(SysErrors.OPERATION_ERROR,
@@ -230,14 +204,6 @@ private void validate(APICreateEipMsg msg) {
230204
}
231205

232206
if (msg.getVmNicUuid() != null) {
233-
SimpleQuery<EipVO> q = dbf.createQuery(EipVO.class);
234-
q.add(EipVO_.vmNicUuid, Op.EQ, msg.getVmNicUuid());
235-
if (q.isExists()) {
236-
throw new ApiMessageInterceptionException(errf.stringToOperationError(
237-
String.format("the VM nic[uuid:%s] already has another EIP attached", msg.getVmNicUuid())
238-
));
239-
}
240-
241207
isVipInVmNicSubnet(vip.getIp(), msg.getVmNicUuid());
242208

243209
SimpleQuery<VmNicVO> nicq = dbf.createQuery(VmNicVO.class);

plugin/eip/src/main/java/org/zstack/network/service/eip/EipManagerImpl.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ private List<VmNicInventory> getAttachableVmNicForEip(String eipUuid, String vip
175175
" from VmNicVO nic, VmInstanceVO vm" +
176176
" where nic.l3NetworkUuid in (:l3Uuids)" +
177177
" and nic.vmInstanceUuid = vm.uuid" +
178-
" and vm.type = :vmType and vm.state in (:vmStates)" +
179-
" and nic.uuid not in (select eip.vmNicUuid from EipVO eip where eip.vmNicUuid is not null)";
178+
" and vm.type = :vmType and vm.state in (:vmStates)";
180179
TypedQuery<VmNicVO> nq = dbf.getEntityManager().createQuery(sql, VmNicVO.class);
181180
nq.setParameter("l3Uuids", l3Uuids);
182181
nq.setParameter("vmType", VmInstanceConstant.USER_VM_TYPE);

0 commit comments

Comments
 (0)