@@ -678,6 +678,7 @@ public IPAddressVO doInTransaction(TransactionStatus status) throws Insufficient
678678 boolean fetchFromDedicatedRange = false ;
679679 List <Long > dedicatedVlanDbIds = new ArrayList <Long >();
680680 List <Long > nonDedicatedVlanDbIds = new ArrayList <Long >();
681+ DataCenter zone = _entityMgr .findById (DataCenter .class , dcId );
681682
682683 SearchCriteria <IPAddressVO > sc = null ;
683684 if (podId != null ) {
@@ -691,10 +692,14 @@ public IPAddressVO doInTransaction(TransactionStatus status) throws Insufficient
691692
692693 // If owner has dedicated Public IP ranges, fetch IP from the dedicated range
693694 // Otherwise fetch IP from the system pool
694- List <AccountVlanMapVO > maps = _accountVlanMapDao .listAccountVlanMapsByAccount (owner .getId ());
695- for (AccountVlanMapVO map : maps ) {
696- if (vlanDbIds == null || vlanDbIds .contains (map .getVlanDbId ()))
697- dedicatedVlanDbIds .add (map .getVlanDbId ());
695+ Network network = _networksDao .findById (guestNetworkId );
696+ //Checking if network is null in the case of system VM's. At the time of allocation of IP address to systemVm, no network is present.
697+ if (network == null || !(network .getGuestType () == GuestType .Shared && zone .getNetworkType () == NetworkType .Advanced )) {
698+ List <AccountVlanMapVO > maps = _accountVlanMapDao .listAccountVlanMapsByAccount (owner .getId ());
699+ for (AccountVlanMapVO map : maps ) {
700+ if (vlanDbIds == null || vlanDbIds .contains (map .getVlanDbId ()))
701+ dedicatedVlanDbIds .add (map .getVlanDbId ());
702+ }
698703 }
699704 List <DomainVlanMapVO > domainMaps = _domainVlanMapDao .listDomainVlanMapsByDomain (owner .getDomainId ());
700705 for (DomainVlanMapVO map : domainMaps ) {
@@ -727,8 +732,6 @@ public IPAddressVO doInTransaction(TransactionStatus status) throws Insufficient
727732
728733 sc .setParameters ("dc" , dcId );
729734
730- DataCenter zone = _entityMgr .findById (DataCenter .class , dcId );
731-
732735 // for direct network take ip addresses only from the vlans belonging to the network
733736 if (vlanUse == VlanType .DirectAttached ) {
734737 sc .setJoinParameters ("vlan" , "networkId" , guestNetworkId );
0 commit comments