You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ya...@apache.org on 2013/07/22 07:37:53 UTC
[44/50] [abbrv] git commit: updated refs/heads/pvlan to ce299da
PVLAN: CLOUDSTACK-2401: VM Migration support
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/eb7c3214
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/eb7c3214
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/eb7c3214
Branch: refs/heads/pvlan
Commit: eb7c3214260371b0551040831ad7404f5880fc8d
Parents: 7260e8d
Author: Sheng Yang <sh...@citrix.com>
Authored: Fri May 3 11:02:44 2013 -0700
Committer: Sheng Yang <sh...@citrix.com>
Committed: Mon May 20 16:43:24 2013 -0700
----------------------------------------------------------------------
.../network/element/VirtualRouterElement.java | 70 +++++++++++++++++++-
.../router/VirtualNetworkApplianceManager.java | 2 +-
.../VirtualNetworkApplianceManagerImpl.java | 32 ++++++---
server/src/com/cloud/vm/UserVmManager.java | 1 +
server/src/com/cloud/vm/UserVmManagerImpl.java | 13 ++--
.../com/cloud/vm/MockUserVmManagerImpl.java | 6 ++
.../MockVpcVirtualNetworkApplianceManager.java | 6 ++
7 files changed, 110 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb7c3214/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java
index 8021e6f..1916678 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -47,7 +47,9 @@ import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
+import com.cloud.network.NetworkMigrationResponder;
import com.cloud.network.NetworkModel;
+import com.cloud.network.Networks;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkServiceProvider;
@@ -85,9 +87,13 @@ import com.cloud.utils.db.SearchCriteriaService;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
+import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
+import com.cloud.vm.UserVmManager;
+import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
@@ -108,10 +114,12 @@ import java.util.Set;
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
DhcpServiceProvider.class, UserDataServiceProvider.class,
StaticNatServiceProvider.class, LoadBalancingServiceProvider.class,
- PortForwardingServiceProvider.class, IpDeployer.class, RemoteAccessVPNServiceProvider.class} )
+ PortForwardingServiceProvider.class, IpDeployer.class,
+ RemoteAccessVPNServiceProvider.class, NetworkMigrationResponder.class} )
public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider,
UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider,
- LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer {
+ LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer,
+ NetworkMigrationResponder {
private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class);
protected static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@@ -130,6 +138,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
ConfigurationManager _configMgr;
@Inject
RulesManager _rulesMgr;
+ @Inject
+ UserVmManager _userVmMgr;
@Inject
UserVmDao _userVmDao;
@@ -1024,7 +1034,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
// TODO Auto-generated method stub
return null;
}
-
private boolean canHandleLbRules(List<LoadBalancingRule> rules) {
Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) {
@@ -1039,5 +1048,60 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
}
}
return true;
+ }
+
+ @Override
+ public boolean prepareMigration(NicProfile nic, Network network,
+ VirtualMachineProfile<? extends VirtualMachine> vm,
+ DeployDestination dest, ReservationContext context) {
+ if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
+ return true;
+ }
+ if (vm.getType() == Type.DomainRouter) {
+ assert vm instanceof DomainRouterVO;
+ DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine();
+ _routerMgr.setupDhcpForPvlan(false, router, router.getHostId(), nic);
+ } else if (vm.getType() == Type.User){
+ assert vm instanceof UserVmVO;
+ UserVmVO userVm = (UserVmVO)vm.getVirtualMachine();
+ _userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic);
+ }
+ return true;
+ }
+
+ @Override
+ public void rollbackMigration(NicProfile nic, Network network,
+ VirtualMachineProfile<? extends VirtualMachine> vm,
+ ReservationContext src, ReservationContext dst) {
+ if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
+ return;
+ }
+ if (vm.getType() == Type.DomainRouter) {
+ assert vm instanceof DomainRouterVO;
+ DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine();
+ _routerMgr.setupDhcpForPvlan(true, router, router.getHostId(), nic);
+ } else if (vm.getType() == Type.User){
+ assert vm instanceof UserVmVO;
+ UserVmVO userVm = (UserVmVO)vm.getVirtualMachine();
+ _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
+ }
+ }
+
+ @Override
+ public void commitMigration(NicProfile nic, Network network,
+ VirtualMachineProfile<? extends VirtualMachine> vm,
+ ReservationContext src, ReservationContext dst) {
+ if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
+ return;
+ }
+ if (vm.getType() == Type.DomainRouter) {
+ assert vm instanceof DomainRouterVO;
+ DomainRouterVO router = (DomainRouterVO)vm.getVirtualMachine();
+ _routerMgr.setupDhcpForPvlan(true, router, router.getHostId(), nic);
+ } else if (vm.getType() == Type.User){
+ assert vm instanceof UserVmVO;
+ UserVmVO userVm = (UserVmVO)vm.getVirtualMachine();
+ _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb7c3214/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java
index 9852c47..72fddf4 100644
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java
@@ -33,7 +33,6 @@ import com.cloud.user.User;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Manager;
import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachineProfile;
@@ -113,4 +112,5 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
boolean removeDhcpSupportForSubnet(Network network, List<DomainRouterVO> routers) throws ResourceUnavailableException;
+ boolean setupDhcpForPvlan(boolean add, DomainRouterVO router, Long hostId, NicProfile nic);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb7c3214/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 50ae4c1..64e412a 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -2223,8 +2223,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
return dhcpRange;
}
- private boolean setupDhcpForPvlan(boolean add, DomainRouterVO router, Nic nic) {
- if (!nic.getBroadcastUri().getScheme().equals("pvlan")) {
+ @Override
+ public boolean setupDhcpForPvlan(boolean add, DomainRouterVO router, Long hostId, NicProfile nic) {
+ if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
return false;
}
String op = "add";
@@ -2233,15 +2234,22 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
Network network = _networkDao.findById(nic.getNetworkId());
String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
- PvlanSetupCommand cmd = PvlanSetupCommand.createDhcpSetup(op, nic.getBroadcastUri(), networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
- Commands cmds = new Commands(cmd);
+ PvlanSetupCommand cmd = PvlanSetupCommand.createDhcpSetup(op, nic.getBroadCastUri(), networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
// In fact we send command to the host of router, we're not programming router but the host
- try {
- sendCommandsToRouter(router, cmds);
- } catch (AgentUnavailableException e) {
+ Answer answer = null;
+ try {
+ answer = _agentMgr.send(hostId, cmd);
+ } catch (OperationTimedoutException e) {
+ s_logger.warn("Timed Out", e);
+ return false;
+ } catch (AgentUnavailableException e) {
s_logger.warn("Agent Unavailable ", e);
- return false;
- }
+ return false;
+ }
+
+ if (answer == null || !answer.getResult()) {
+ return false;
+ }
return true;
}
@@ -2563,7 +2571,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
if (network.getTrafficType() == TrafficType.Guest) {
guestNetworks.add(network);
if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
- result = setupDhcpForPvlan(true, router, nic);
+ NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
+ result = setupDhcpForPvlan(true, router, router.getHostId(), nicProfile);
}
}
}
@@ -2601,7 +2610,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (Nic nic : routerNics) {
Network network = _networkModel.getNetwork(nic.getNetworkId());
if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri().getScheme().equals("pvlan")) {
- setupDhcpForPvlan(false, domR, nic);
+ NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
+ setupDhcpForPvlan(false, domR, domR.getHostId(), nicProfile);
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb7c3214/server/src/com/cloud/vm/UserVmManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java
index 0f8e368..4dcfb73 100755
--- a/server/src/com/cloud/vm/UserVmManager.java
+++ b/server/src/com/cloud/vm/UserVmManager.java
@@ -94,4 +94,5 @@ public interface UserVmManager extends VirtualMachineGuru<UserVmVO>, UserVmServi
boolean upgradeVirtualMachine(Long id, Long serviceOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
+ boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb7c3214/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 86150a2..71b4e3f 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2821,8 +2821,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
return true;
}
- private boolean setupVmForPvlan(boolean add, Long hostId, NicVO nic) {
- if (!nic.getBroadcastUri().getScheme().equals("pvlan")) {
+ @Override
+ public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) {
+ if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
return false;
}
String op = "add";
@@ -2833,7 +2834,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
Network network = _networkDao.findById(nic.getNetworkId());
Host host = _hostDao.findById(hostId);
String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
- PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadcastUri(), networkTag, nic.getMacAddress());
+ PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress());
Answer answer = null;
try {
answer = _agentMgr.send(hostId, cmd);
@@ -2916,7 +2917,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
// In vmware, we will be effecting pvlan settings in portgroups in StartCommand.
if (profile.getHypervisorType() != HypervisorType.VMware) {
if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
- if (!setupVmForPvlan(true, hostId, nic)) {
+ NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
+ if (!setupVmForPvlan(true, hostId, nicProfile)) {
return false;
}
}
@@ -3058,7 +3060,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
NetworkVO network = _networkDao.findById(nic.getNetworkId());
if (network.getTrafficType() == TrafficType.Guest) {
if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
- setupVmForPvlan(false, vm.getHostId(), nic);
+ NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
+ setupVmForPvlan(false, vm.getHostId(), nicProfile);
}
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb7c3214/server/test/com/cloud/vm/MockUserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/MockUserVmManagerImpl.java b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
index 50a90f2..448a5dd 100644
--- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java
+++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
@@ -455,4 +455,10 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb7c3214/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
index 8d50211..f325c4a 100644
--- a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
+++ b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
@@ -420,4 +420,10 @@ VpcVirtualNetworkApplianceService {
return null;
}
+ @Override
+ public boolean setupDhcpForPvlan(boolean add, DomainRouterVO router, Long hostId,
+ NicProfile nic) {
+ // TODO Auto-generated method stub
+ return false;
+ }
}