1717package org .apache .cloudstack .service ;
1818
1919import static java .util .Objects .isNull ;
20+ import static java .util .Objects .nonNull ;
2021
2122import com .cloud .dc .DataCenter ;
2223import 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" );
0 commit comments