Skip to content

Commit

Permalink
<fix>[compute]: allocate ip to applianceVm even dhcp is disabled <des…
Browse files Browse the repository at this point in the history
…cription>

Resolves: ZSTAC-69861

Change-Id: I6469667a6377626c6268676d7778696c66776b68
  • Loading branch information
ruansteve committed Sep 14, 2024
1 parent 8d25fc0 commit f46723c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public void run(final FlowTrigger trigger, final Map data) {
@Override
protected void scripts() {
VmNicVO nicVO = vnicFactory.createVmNic(nic, spec);
if (!nw.enableIpAddressAllocation() && nicNetworkInfoMap != null && nicNetworkInfoMap.containsKey(nw.getUuid())) {
if (!nw.enableIpAddressAllocation() && nicNetworkInfoMap != null
&& nicNetworkInfoMap.containsKey(nw.getUuid())
&& spec.getVmInventory().getType().equals(VmInstanceConstant.USER_VM_TYPE)) {
NicIpAddressInfo nicNicIpAddressInfo = nicNetworkInfoMap.get(nic.getL3NetworkUuid());
if (!nicNicIpAddressInfo.ipv6Address.isEmpty()) {
UsedIpVO vo = new UsedIpVO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,28 @@ public void run(final FlowTrigger trigger, final Map data) {
}
List<VmNicSpec> firstL3s = VmNicSpec.getFirstL3NetworkInventoryOfSpec(spec.getL3Networks())
.stream()
.filter(v -> v.getL3Invs().get(0).enableIpAddressAllocation())
.filter(v -> {
if (v.getL3Invs().get(0).enableIpAddressAllocation()) {
return true;
}

/* if dhcp is disabled, will not allocate ip address for user vm
* allocated ip to appliance vm based on following conditions */
if (spec.getVmInventory().getType().equals(VmInstanceConstant.USER_VM_TYPE)) {
return false;
} else {
L3NetworkInventory nw = v.getL3Invs().get(0);
VmNicInventory nicUuid = nicsL3.get(nw.getUuid());
VmNicVO nic = dbf.findByUuid(nicUuid.getUuid(), VmNicVO.class);

/* if there is no ip range, or created ip in VmAllocateNicFlow from systemTags */
if (!nic.getUsedIps().isEmpty() || nw.getIpRanges().isEmpty()) {
return false;
} else {
return true;
}
}
})
.peek(v -> {
if (!Q.New(NormalIpRangeVO.class)
.eq(NormalIpRangeVO_.l3NetworkUuid, v.getL3Invs().get(0).getUuid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,12 +1006,12 @@ public void run(MessageReply reply) {
VirtualRouterAsyncHttpCallReply re = reply.castReply();
VirtualRouterCommands.ConfigureNicRsp rsp = re.toResponse(VirtualRouterCommands.ConfigureNicRsp.class);
if (rsp.isSuccess()) {
logger.debug(String.format("successfully add nic[ip:%s, mac:%s] to virtual router vm[uuid:%s, ip:%s]",
info.getIp(), info.getMac(), vr.getUuid(), vr.getManagementNic().getIp()));
logger.debug(String.format("successfully add nic[ip:%s, ip6:%s, mac:%s] to virtual router vm[uuid:%s, ip:%s]",
info.getIp(), info.getIp6(), info.getMac(), vr.getUuid(), vr.getManagementNic().getIp()));
trigger.next();
} else {
ErrorCode err = operr("unable to add nic[ip:%s, mac:%s] to virtual router vm[uuid:%s ip:%s], because %s",
info.getIp(), info.getMac(), vr.getUuid(), vr.getManagementNic().getIp(), rsp.getError());
ErrorCode err = operr("unable to add nic[ip:%s, ip6:%s, mac:%s] to virtual router vm[uuid:%s ip:%s], because %s",
info.getIp(), info.getIp6(), info.getMac(), vr.getUuid(), vr.getManagementNic().getIp(), rsp.getError());
trigger.fail(err);
}
}
Expand Down

0 comments on commit f46723c

Please sign in to comment.