You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2013/07/30 14:59:09 UTC
git commit: updated refs/heads/4.2 to 1550f5e
Updated Branches:
refs/heads/4.2 7cb1c6fa7 -> 1550f5e26
CLOUDSTACK-3439: Include dynamically created nics in Prepare for migration command in KVM
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1550f5e2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1550f5e2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1550f5e2
Branch: refs/heads/4.2
Commit: 1550f5e26c71bc69242173019b2369fd6bb53604
Parents: 7cb1c6f
Author: Kishan Kavala <ki...@cloud.com>
Authored: Tue Jul 30 17:52:10 2013 +0530
Committer: Kishan Kavala <ki...@cloud.com>
Committed: Tue Jul 30 18:23:56 2013 +0530
----------------------------------------------------------------------
api/src/com/cloud/vm/NicProfile.java | 4 ++
.../src/com/cloud/network/dao/IPAddressDao.java | 2 +
.../com/cloud/network/dao/IPAddressDaoImpl.java | 7 ++
.../cloud/hypervisor/HypervisorGuruBase.java | 24 ++++---
.../src/com/cloud/network/NetworkManager.java | 1 +
.../com/cloud/network/NetworkManagerImpl.java | 75 +++++++++++++++++++-
.../VirtualNetworkApplianceManagerImpl.java | 4 ++
.../com/cloud/vm/VirtualMachineManagerImpl.java | 9 ++-
.../cloud/network/MockNetworkManagerImpl.java | 5 ++
.../com/cloud/vpc/MockNetworkManagerImpl.java | 9 +--
10 files changed, 126 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/api/src/com/cloud/vm/NicProfile.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java
index 5970ccd..47cb197 100644
--- a/api/src/com/cloud/vm/NicProfile.java
+++ b/api/src/com/cloud/vm/NicProfile.java
@@ -66,6 +66,10 @@ public class NicProfile implements InternalIdentity {
return name;
}
+ public void setName(String name) {
+ this.name = name;
+ }
+
public String getDns2() {
return dns2;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
index 314ae18..0803645 100755
--- a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
@@ -80,4 +80,6 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
boolean deletePublicIPRange(long vlanDbId) ;
void lockRange(long vlandbId);
+
+ List<IPAddressVO> listByAssociatedVmId(long vmId);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
index 9f5f403..9130ad2 100755
--- a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
@@ -410,6 +410,13 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
}
@Override
+ public List<IPAddressVO> listByAssociatedVmId(long vmId) {
+ SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("associatedWithVmId", vmId);
+ return listBy(sc);
+ }
+
+ @Override
public void lockRange(long vlandbId) {
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
sc.setParameters("vlan", vlandbId);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
index 478baf3..e042eb8 100644
--- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
+++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
@@ -18,6 +18,7 @@ package com.cloud.hypervisor;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import javax.inject.Inject;
@@ -73,15 +74,22 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
// Workaround to make sure the TO has the UUID we need for Niciri integration
NicVO nicVO = _nicDao.findById(profile.getId());
- to.setUuid(nicVO.getUuid());
- //check whether the this nic has secondary ip addresses set
- //set nic secondary ip address in NicTO which are used for security group
- // configuration. Use full when vm stop/start
- List <String> secIps = null;
- if (nicVO.getSecondaryIp()) {
- secIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nicVO.getId());
+ if(nicVO != null){
+ to.setUuid(nicVO.getUuid());
+ //check whether the this nic has secondary ip addresses set
+ //set nic secondary ip address in NicTO which are used for security group
+ // configuration. Use full when vm stop/start
+ List <String> secIps = null;
+ if (nicVO.getSecondaryIp()) {
+ secIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nicVO.getId());
+ }
+ to.setNicSecIps(secIps);
+ } else {
+ //Workaround for dynamically created nics
+ //FixMe: uuid and secondary IPs can be made part of nic profile
+ to.setUuid(UUID.randomUUID().toString());
}
- to.setNicSecIps(secIps);
+
return to;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/server/src/com/cloud/network/NetworkManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java
index 8dc7743..dab7a13 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -387,4 +387,5 @@ public interface NetworkManager {
PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException;
+ void prepareAllNicsForMigration(VirtualMachineProfile<? extends VMInstanceVO> vm, DeployDestination dest);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 61cff4a..7ebcb44 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -2168,6 +2168,80 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
}
+ /*
+ Prepare All Nics for migration including the nics dynamically created and not stored in DB
+ This is a temporary workaround work KVM migration
+ Once clean fix is added by stored dynamically nics is DB, this workaround won't be needed
+ */
+ @Override
+ public void prepareAllNicsForMigration(VirtualMachineProfile<? extends VMInstanceVO> vm, DeployDestination dest) {
+ List<NicVO> nics = _nicDao.listByVmId(vm.getId());
+ ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null);
+ Long guestNetworkId = null;
+ for (NicVO nic : nics) {
+ NetworkVO network = _networksDao.findById(nic.getNetworkId());
+ if(network.getTrafficType().equals(TrafficType.Guest) && network.getGuestType().equals(GuestType.Isolated)){
+ guestNetworkId = network.getId();
+ }
+ Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
+
+ NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
+ NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate,
+ _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
+ if(guru instanceof NetworkMigrationResponder){
+ if(!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)){
+ s_logger.error("NetworkGuru "+guru+" prepareForMigration failed."); // XXX: Transaction error
+ }
+ }
+ for (NetworkElement element : _networkElements) {
+ if(element instanceof NetworkMigrationResponder){
+ if(!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)){
+ s_logger.error("NetworkElement "+element+" prepareForMigration failed."); // XXX: Transaction error
+ }
+ }
+ }
+ guru.updateNicProfile(profile, network);
+ vm.addNic(profile);
+ }
+
+ List<String> addedURIs = new ArrayList<String>();
+ if(guestNetworkId != null){
+ List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(guestNetworkId, null);
+ for (IPAddressVO userIp : publicIps){
+ PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
+ URI broadcastUri = BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag());
+ long ntwkId = publicIp.getNetworkId();
+ Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ntwkId, vm.getId(),
+ broadcastUri.toString());
+ if(nic == null && !addedURIs.contains(broadcastUri.toString())){
+ //Nic details are not available in DB
+ //Create nic profile for migration
+ s_logger.debug("Creating nic profile for migration. BroadcastUri: "+broadcastUri.toString()+" NetworkId: "+ntwkId+" Vm: "+vm.getId());
+ NetworkVO network = _networksDao.findById(ntwkId);
+ Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
+ NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
+ NicProfile profile = new NicProfile();
+ profile.setDeviceId(255); //dummyId
+ profile.setIp4Address(userIp.getAddress().toString());
+ profile.setNetmask(publicIp.getNetmask());
+ profile.setGateway(publicIp.getGateway());
+ profile.setMacAddress(publicIp.getMacAddress());
+ profile.setBroadcastType(network.getBroadcastDomainType());
+ profile.setTrafficType(network.getTrafficType());
+ profile.setBroadcastUri(broadcastUri);
+ profile.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
+ profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
+ profile.setName(_networkModel.getNetworkTag(vm.getHypervisorType(), network));
+
+ guru.updateNicProfile(profile, network);
+ vm.addNic(profile);
+ addedURIs.add(broadcastUri.toString());
+ }
+ }
+ }
+ }
+
+
private NicProfile findNicProfileById(VirtualMachineProfile<? extends VMInstanceVO> vm, long id){
for(NicProfile nic: vm.getNics()){
if(nic.getId() == id){
@@ -4369,7 +4443,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
return profiles;
}
-
@Override
public int getNetworkLockTimeout() {
return _networkLockTimeout;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 477b086..3ee8a1c 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -146,6 +146,8 @@ import com.cloud.network.dao.Site2SiteVpnGatewayDao;
import com.cloud.network.dao.UserIpv6AddressDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.dao.VpnUserDao;
+import com.cloud.network.guru.NetworkGuru;
+import com.cloud.network.guru.PublicNetworkGuru;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
@@ -194,6 +196,7 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.StringUtils;
+import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
@@ -237,6 +240,7 @@ import org.springframework.stereotype.Component;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 45aa50c..31bae47 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -1521,12 +1521,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
VirtualMachineProfile<VMInstanceVO> vmSrc = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
+
for(NicProfile nic: _networkMgr.getNicProfiles(vm)){
vmSrc.addNic(nic);
}
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
- _networkMgr.prepareNicForMigration(profile, dest);
+
+ if(vm.getType().equals(VirtualMachine.Type.DomainRouter) && vm.getHypervisorType().equals(HypervisorType.KVM)){
+ //Include nics hot plugged and not stored in DB
+ _networkMgr.prepareAllNicsForMigration(profile, dest);
+ } else {
+ _networkMgr.prepareNicForMigration(profile, dest);
+ }
volumeMgr.prepareForMigration(profile, dest);
VirtualMachineTO to = toVmTO(profile);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index 4577d0a..a3d6f53 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -938,6 +938,11 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
}
@Override
+ public void prepareAllNicsForMigration(VirtualMachineProfile<? extends VMInstanceVO> vm, DeployDestination dest) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
public void prepareNicForMigration(
VirtualMachineProfile<? extends VMInstanceVO> vm,
DeployDestination dest) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1550f5e2/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index fd61bc6..a282840 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -1413,11 +1413,12 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
return null; //To change body of implemented methods use File | Settings | File Templates.
}
+ @Override
+ public void prepareAllNicsForMigration(VirtualMachineProfile<? extends VMInstanceVO> vm, DeployDestination dest) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
-
-
-
- @Override
+ @Override
public void prepareNicForMigration(
VirtualMachineProfile<? extends VMInstanceVO> vm,
DeployDestination dest) {