8282import com .cloud .network .dao .NetworkVO ;
8383import com .cloud .network .dao .PhysicalNetworkVO ;
8484import com .cloud .network .manager .NuageVspManager ;
85+ import com .cloud .network .router .VirtualRouter ;
8586import com .cloud .offering .NetworkOffering ;
8687import com .cloud .offerings .dao .NetworkOfferingDao ;
8788import com .cloud .offerings .dao .NetworkOfferingServiceMapDao ;
9495import com .cloud .utils .db .DB ;
9596import com .cloud .utils .exception .CloudRuntimeException ;
9697import com .cloud .utils .net .Ip ;
98+ import com .cloud .vm .DomainRouterVO ;
9799import com .cloud .vm .Nic ;
98100import com .cloud .vm .NicProfile ;
99101import com .cloud .vm .NicVO ;
100102import com .cloud .vm .ReservationContext ;
101103import com .cloud .vm .VMInstanceVO ;
102104import com .cloud .vm .VirtualMachine ;
103105import com .cloud .vm .VirtualMachineProfile ;
106+ import com .cloud .vm .dao .DomainRouterDao ;
104107import com .cloud .vm .dao .VMInstanceDao ;
105108
106109public class NuageVspGuestNetworkGuru extends GuestNetworkGuru implements NetworkGuruAdditionalFunctions {
@@ -134,6 +137,8 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru implements Networ
134137 DataCenterDetailsDao _dcDetailsDao ;
135138 @ Inject
136139 VlanDetailsDao _vlanDetailsDao ;
140+ @ Inject
141+ private DomainRouterDao _routerDao ;
137142
138143 public NuageVspGuestNetworkGuru () {
139144 super ();
@@ -528,29 +533,34 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D
528533 nic .setBroadcastUri (network .getBroadcastUri ());
529534 nic .setIsolationUri (network .getBroadcastUri ());
530535
531- //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
532- //that we create in VSP
533- NicVO nicFromDb = _nicDao .findById (nic .getId ());
534- IPAddressVO staticNatIp = _ipAddressDao .findByVmIdAndNetworkId (network .getId (), vm .getId ());
535536 VspVm vspVm = _nuageVspEntityBuilder .buildVspVm (vm .getVirtualMachine (), network );
536- VspNic vspNic = _nuageVspEntityBuilder .buildVspNic (nicFromDb .getUuid (), nic );
537- VspStaticNat vspStaticNat = null ;
538- if (staticNatIp != null ) {
539- VlanVO staticNatVlan = _vlanDao .findById (staticNatIp .getVlanId ());
540- vspStaticNat = _nuageVspEntityBuilder .buildVspStaticNat (null , staticNatIp , staticNatVlan , vspNic );
541- }
542537
543- boolean defaultHasDns = getDefaultHasDns (networkHasDnsCache , nicFromDb );
544- VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder .buildVmDhcpOption (nicFromDb , defaultHasDns , networkHasDns );
545- ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand (vspNetwork , vspVm , vspNic , vspStaticNat , dhcpOption );
546- Answer answer = _agentMgr .easySend (nuageVspHost .getId (), cmd );
538+ if (vm .isRollingRestart ()) {
539+ ((NetworkVO )network ).setRollingRestart (true );
540+ } else {
541+ //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
542+ //that we create in VSP
543+ NicVO nicFromDb = _nicDao .findById (nic .getId ());
544+ IPAddressVO staticNatIp = _ipAddressDao .findByVmIdAndNetworkId (network .getId (), vm .getId ());
545+ VspNic vspNic = _nuageVspEntityBuilder .buildVspNic (nicFromDb .getUuid (), nic );
546+ VspStaticNat vspStaticNat = null ;
547+ if (staticNatIp != null ) {
548+ VlanVO staticNatVlan = _vlanDao .findById (staticNatIp .getVlanId ());
549+ vspStaticNat = _nuageVspEntityBuilder .buildVspStaticNat (null , staticNatIp , staticNatVlan , vspNic );
550+ }
547551
548- if (answer == null || !answer .getResult ()) {
549- s_logger .error ("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic .getId () + " attached to VM " + vm .getId () + " in network " + network .getId ());
550- if ((null != answer ) && (null != answer .getDetails ())) {
551- s_logger .error (answer .getDetails ());
552+ boolean defaultHasDns = getDefaultHasDns (networkHasDnsCache , nicFromDb );
553+ VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder .buildVmDhcpOption (nicFromDb , defaultHasDns , networkHasDns );
554+ ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand (vspNetwork , vspVm , vspNic , vspStaticNat , dhcpOption );
555+ Answer answer = _agentMgr .easySend (nuageVspHost .getId (), cmd );
556+
557+ if (answer == null || !answer .getResult ()) {
558+ s_logger .error ("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic .getId () + " attached to VM " + vm .getId () + " in network " + network .getId ());
559+ if ((null != answer ) && (null != answer .getDetails ())) {
560+ s_logger .error (answer .getDetails ());
561+ }
562+ throw new InsufficientVirtualNetworkCapacityException ("Failed to reserve VM in Nuage VSP." , Network .class , network .getId ());
552563 }
553- throw new InsufficientVirtualNetworkCapacityException ("Failed to reserve VM in Nuage VSP." , Network .class , network .getId ());
554564 }
555565
556566 if (vspVm .getDomainRouter () == Boolean .TRUE ) {
@@ -695,15 +705,18 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm
695705 }
696706
697707 try {
708+ final VirtualMachine virtualMachine = vm .getVirtualMachine ();
698709 if (s_logger .isDebugEnabled ()) {
699710 s_logger .debug ("Handling deallocate() call back, which is called when a VM is destroyed or interface is removed, " + "to delete VM Interface with IP "
700- + nic .getIPv4Address () + " from a VM " + vm .getInstanceName () + " with state " + vm .getVirtualMachine ().getState ());
711+ + nic .getIPv4Address () + " from a VM " + vm .getInstanceName () + " with state " + virtualMachine
712+ .getState ());
701713 }
702714
703715 NicVO nicFromDb = _nicDao .findById (nic .getId ());
704716
705- VspNetwork vspNetwork = _nuageVspEntityBuilder .buildVspNetwork (vm .getVirtualMachine ().getDomainId (), network );
706- VspVm vspVm = _nuageVspEntityBuilder .buildVspVm (vm .getVirtualMachine (), network );
717+ VspNetwork vspNetwork = _nuageVspEntityBuilder .buildVspNetwork (virtualMachine
718+ .getDomainId (), network );
719+ VspVm vspVm = _nuageVspEntityBuilder .buildVspVm (virtualMachine , network );
707720 VspNic vspNic = _nuageVspEntityBuilder .buildVspNic (nicFromDb .getUuid (), nic );
708721 HostVO nuageVspHost = _nuageVspManager .getNuageVspHost (network .getPhysicalNetworkId ());
709722
@@ -723,6 +736,32 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm
723736 } else {
724737 super .deallocate (network , nic , vm );
725738 }
739+
740+ if (virtualMachine .getType () == VirtualMachine .Type .DomainRouter ) {
741+ final List <DomainRouterVO > routers = _routerDao .listByNetworkAndRole (network .getId (), VirtualRouter .Role .VIRTUAL_ROUTER );
742+ final DomainRouterVO otherRouter = routers .stream ()
743+ .filter (r -> r .getId () != vm .getId ())
744+ .findFirst ()
745+ .orElse (null );
746+
747+ if (otherRouter != null ) {
748+ nicFromDb = _nicDao .findByNtwkIdAndInstanceId (network .getId (), otherRouter .getId ());
749+ vspVm = _nuageVspEntityBuilder .buildVspVm (otherRouter , network );
750+ vspNic = _nuageVspEntityBuilder .buildVspNic (nicFromDb );
751+
752+ VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder .buildVmDhcpOption (nicFromDb , false , false );
753+ ReserveVmInterfaceVspCommand reserveCmd = new ReserveVmInterfaceVspCommand (vspNetwork , vspVm , vspNic , null , dhcpOption );
754+
755+ answer = _agentMgr .easySend (nuageVspHost .getId (), reserveCmd );
756+ if (answer == null || !answer .getResult ()) {
757+ s_logger .error ("DeallocateVmNuageVspCommand for VM " + vm .getUuid () + " failed on Nuage VSD " + nuageVspHost .getDetail ("hostname" ));
758+ if ((null != answer ) && (null != answer .getDetails ())) {
759+ s_logger .error (answer .getDetails ());
760+ }
761+ }
762+ }
763+
764+ }
726765 } finally {
727766 if (network != null && lockedNetwork ) {
728767 _networkDao .releaseFromLockTable (network .getId ());
0 commit comments