@@ -2168,6 +2168,80 @@ public void prepareNicForMigration(VirtualMachineProfile<? extends VMInstanceVO>
21682168 }
21692169 }
21702170
2171+ /*
2172+ Prepare All Nics for migration including the nics dynamically created and not stored in DB
2173+ This is a temporary workaround work KVM migration
2174+ Once clean fix is added by stored dynamically nics is DB, this workaround won't be needed
2175+ */
2176+ @ Override
2177+ public void prepareAllNicsForMigration (VirtualMachineProfile <? extends VMInstanceVO > vm , DeployDestination dest ) {
2178+ List <NicVO > nics = _nicDao .listByVmId (vm .getId ());
2179+ ReservationContext context = new ReservationContextImpl (UUID .randomUUID ().toString (), null , null );
2180+ Long guestNetworkId = null ;
2181+ for (NicVO nic : nics ) {
2182+ NetworkVO network = _networksDao .findById (nic .getNetworkId ());
2183+ if (network .getTrafficType ().equals (TrafficType .Guest ) && network .getGuestType ().equals (GuestType .Isolated )){
2184+ guestNetworkId = network .getId ();
2185+ }
2186+ Integer networkRate = _networkModel .getNetworkRate (network .getId (), vm .getId ());
2187+
2188+ NetworkGuru guru = AdapterBase .getAdapterByName (_networkGurus , network .getGuruName ());
2189+ NicProfile profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), networkRate ,
2190+ _networkModel .isSecurityGroupSupportedInNetwork (network ), _networkModel .getNetworkTag (vm .getHypervisorType (), network ));
2191+ if (guru instanceof NetworkMigrationResponder ){
2192+ if (!((NetworkMigrationResponder ) guru ).prepareMigration (profile , network , vm , dest , context )){
2193+ s_logger .error ("NetworkGuru " +guru +" prepareForMigration failed." ); // XXX: Transaction error
2194+ }
2195+ }
2196+ for (NetworkElement element : _networkElements ) {
2197+ if (element instanceof NetworkMigrationResponder ){
2198+ if (!((NetworkMigrationResponder ) element ).prepareMigration (profile , network , vm , dest , context )){
2199+ s_logger .error ("NetworkElement " +element +" prepareForMigration failed." ); // XXX: Transaction error
2200+ }
2201+ }
2202+ }
2203+ guru .updateNicProfile (profile , network );
2204+ vm .addNic (profile );
2205+ }
2206+
2207+ List <String > addedURIs = new ArrayList <String >();
2208+ if (guestNetworkId != null ){
2209+ List <IPAddressVO > publicIps = _ipAddressDao .listByAssociatedNetwork (guestNetworkId , null );
2210+ for (IPAddressVO userIp : publicIps ){
2211+ PublicIp publicIp = PublicIp .createFromAddrAndVlan (userIp , _vlanDao .findById (userIp .getVlanId ()));
2212+ URI broadcastUri = BroadcastDomainType .Vlan .toUri (publicIp .getVlanTag ());
2213+ long ntwkId = publicIp .getNetworkId ();
2214+ Nic nic = _nicDao .findByNetworkIdInstanceIdAndBroadcastUri (ntwkId , vm .getId (),
2215+ broadcastUri .toString ());
2216+ if (nic == null && !addedURIs .contains (broadcastUri .toString ())){
2217+ //Nic details are not available in DB
2218+ //Create nic profile for migration
2219+ s_logger .debug ("Creating nic profile for migration. BroadcastUri: " +broadcastUri .toString ()+" NetworkId: " +ntwkId +" Vm: " +vm .getId ());
2220+ NetworkVO network = _networksDao .findById (ntwkId );
2221+ Integer networkRate = _networkModel .getNetworkRate (network .getId (), vm .getId ());
2222+ NetworkGuru guru = AdapterBase .getAdapterByName (_networkGurus , network .getGuruName ());
2223+ NicProfile profile = new NicProfile ();
2224+ profile .setDeviceId (255 ); //dummyId
2225+ profile .setIp4Address (userIp .getAddress ().toString ());
2226+ profile .setNetmask (publicIp .getNetmask ());
2227+ profile .setGateway (publicIp .getGateway ());
2228+ profile .setMacAddress (publicIp .getMacAddress ());
2229+ profile .setBroadcastType (network .getBroadcastDomainType ());
2230+ profile .setTrafficType (network .getTrafficType ());
2231+ profile .setBroadcastUri (broadcastUri );
2232+ profile .setIsolationUri (IsolationType .Vlan .toUri (publicIp .getVlanTag ()));
2233+ profile .setSecurityGroupEnabled (_networkModel .isSecurityGroupSupportedInNetwork (network ));
2234+ profile .setName (_networkModel .getNetworkTag (vm .getHypervisorType (), network ));
2235+
2236+ guru .updateNicProfile (profile , network );
2237+ vm .addNic (profile );
2238+ addedURIs .add (broadcastUri .toString ());
2239+ }
2240+ }
2241+ }
2242+ }
2243+
2244+
21712245 private NicProfile findNicProfileById (VirtualMachineProfile <? extends VMInstanceVO > vm , long id ){
21722246 for (NicProfile nic : vm .getNics ()){
21732247 if (nic .getId () == id ){
@@ -4369,7 +4443,6 @@ public List<NicProfile> getNicProfiles(VirtualMachine vm) {
43694443 return profiles ;
43704444 }
43714445
4372-
43734446 @ Override
43744447 public int getNetworkLockTimeout () {
43754448 return _networkLockTimeout ;
0 commit comments