Skip to content

Commit adbfacd

Browse files
committed
Address review comment
1 parent d6cd15f commit adbfacd

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxGuestNetworkGuru.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.service;
1818

1919
import static java.util.Objects.isNull;
20+
import static java.util.Objects.nonNull;
2021

2122
import com.cloud.dc.DataCenter;
2223
import com.cloud.dc.dao.DataCenterDao;
@@ -275,11 +276,14 @@ public void commitMigration(NicProfile nic, Network network, VirtualMachineProfi
275276
}
276277

277278
private void createNsxSegment(NetworkVO networkVO, DataCenter zone) {
278-
VpcVO vpc = _vpcDao.findById(networkVO.getVpcId());
279-
if (isNull(vpc)) {
280-
throw new CloudRuntimeException(String.format("Failed to find VPC network with id: %s", networkVO.getVpcId()));
279+
String vpcName = null;
280+
if (nonNull(networkVO.getVpcId())) {
281+
VpcVO vpc = _vpcDao.findById(networkVO.getVpcId());
282+
if (isNull(vpc)) {
283+
throw new CloudRuntimeException(String.format("Failed to find VPC network with id: %s", networkVO.getVpcId()));
284+
}
285+
vpcName = vpc.getName();
281286
}
282-
String vpcName = vpc.getName();
283287
Account account = accountDao.findById(networkVO.getAccountId());
284288
if (isNull(account)) {
285289
throw new CloudRuntimeException(String.format("Unable to find account with id: %s", networkVO.getAccountId()));
@@ -290,7 +294,7 @@ private void createNsxSegment(NetworkVO networkVO, DataCenter zone) {
290294
LOGGER.error(msg);
291295
throw new CloudRuntimeException(msg);
292296
}
293-
CreateNsxSegmentCommand command = NsxHelper.createNsxSegmentCommand(domain, account, zone, vpc, networkVO);
297+
CreateNsxSegmentCommand command = NsxHelper.createNsxSegmentCommand(domain, account, zone, vpcName, networkVO);
294298
NsxAnswer answer = nsxControllerUtils.sendNsxCommand(command, zone.getId());
295299
if (!answer.getResult()) {
296300
throw new CloudRuntimeException("can not create NSX network");

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/utils/NsxHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public static CreateNsxDhcpRelayConfigCommand createNsxDhcpRelayConfigCommand(Do
3434
vpc.getName(), network.getName(), addresses);
3535
}
3636

37-
public static CreateNsxSegmentCommand createNsxSegmentCommand(DomainVO domain, Account account, DataCenter zone, VpcVO vpc, NetworkVO networkVO) {
37+
public static CreateNsxSegmentCommand createNsxSegmentCommand(DomainVO domain, Account account, DataCenter zone, String vpcName, NetworkVO networkVO) {
3838
return new CreateNsxSegmentCommand(domain.getName(), account.getAccountName(), zone.getName(),
39-
vpc.getName(), networkVO.getName(), networkVO.getGateway(), networkVO.getNetworkCidr());
39+
vpcName, networkVO.getName(), networkVO.getGateway(), networkVO.getNetworkCidr());
4040
}
4141
}

0 commit comments

Comments
 (0)