You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/07/11 03:08:25 UTC
[1/2] git commit: VPC: add vm to network - no need to prepare nic
when add vm in Stopped state to the network;
the nic will be prepared once the vm starts up
Updated Branches:
refs/heads/vpc f59b935da -> b407b3bea
VPC: add vm to network - no need to prepare nic when add vm in Stopped state to the network; the nic will be prepared once the vm starts up
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/b407b3be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/b407b3be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/b407b3be
Branch: refs/heads/vpc
Commit: b407b3beaaa432e3914d6cb6bcff85f2c642433a
Parents: 697aa45
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Tue Jul 10 17:41:52 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Tue Jul 10 18:07:45 2012 -0700
----------------------------------------------------------------------
server/src/com/cloud/network/NetworkManager.java | 3 +-
.../src/com/cloud/network/NetworkManagerImpl.java | 47 +++++++------
.../VpcVirtualNetworkApplianceManagerImpl.java | 44 ++++++------
.../com/cloud/vm/VirtualMachineManagerImpl.java | 57 ++++++++++-----
.../src/com/cloud/vm/dao/DomainRouterDaoImpl.java | 2 +-
5 files changed, 88 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b407b3be/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 f3a448b..6aa5bea 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -462,6 +462,7 @@ public interface NetworkManager extends NetworkService {
* @param requested
* @param context
* @param vmProfile
+ * @param prepare TODO
* @return
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
@@ -469,7 +470,7 @@ public interface NetworkManager extends NetworkService {
* @throws InsufficientCapacityException
* @throws ResourceUnavailableException
*/
- NicProfile allocateAndPrepareNic(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfileImpl<VMInstanceVO> vmProfile) throws InsufficientVirtualNetworkCapcityException,
+ NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfileImpl<VMInstanceVO> vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b407b3be/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 76b3465..a80ba56 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -7358,8 +7358,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
- public NicProfile allocateAndPrepareNic(Network network, NicProfile requested, ReservationContext context,
- VirtualMachineProfileImpl<VMInstanceVO> vmProfile)
+ public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context,
+ VirtualMachineProfileImpl<VMInstanceVO> vmProfile, boolean prepare)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException,
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
@@ -7369,20 +7369,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
- NicProfile nic = null;
- String broadcastUri = null;
- if (requested != null && requested.getBroadCastUri() != null) {
- broadcastUri = requested.getBroadCastUri().toString();
- NicVO nicVO = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
- if (nicVO != null) {
- nic = getNicProfile(vm, network.getId());
- }
- } else {
- NicVO nicVO = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
- if (nicVO != null) {
- nic = getNicProfile(vm, network.getId());
- }
- }
+ NicProfile nic = getNicProfileForVm(network, requested, vm);
//1) allocate nic (if needed)
if (nic == null) {
@@ -7396,16 +7383,32 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
}
- s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
-
-
-
- s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
+ s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
}
//2) prepare nic
- nic = prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
+ if (prepare) {
+ nic = prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
+ s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
+ }
return nic;
}
+
+ private NicProfile getNicProfileForVm(Network network, NicProfile requested, VirtualMachine vm) {
+ NicProfile nic = null;
+ if (requested != null && requested.getBroadCastUri() != null) {
+ String broadcastUri = requested.getBroadCastUri().toString();
+ NicVO nicVO = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
+ if (nicVO != null) {
+ nic = getNicProfile(vm, network.getId());
+ }
+ } else {
+ NicVO nicVO = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
+ if (nicVO != null) {
+ nic = getNicProfile(vm, network.getId());
+ }
+ }
+ return nic;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b407b3be/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 6b645e3..a15640b 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -419,9 +419,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName() + " in network " + network,
dest.getHost().getId(), e);
}
- } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
- s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() +
- ", so not sending PlugNic command to the backend");
} else {
s_logger.warn("Unable to apply PlugNic, vm " + router + " is not in the right state " + router.getState());
@@ -472,22 +469,30 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
protected boolean setupVpcGuestNetwork(Network network, VirtualRouter router, boolean add, NicProfile guestNic)
throws ConcurrentOperationException, ResourceUnavailableException{
- boolean result = true;
-
- SetupGuestNetworkCommand setupCmd = createSetupGuestNetworkCommand(router, add, guestNic);
+ boolean result = true;
+ if (router.getState() == State.Running) {
+ SetupGuestNetworkCommand setupCmd = createSetupGuestNetworkCommand(router, add, guestNic);
- Commands cmds = new Commands(OnError.Stop);
- cmds.addCommand("setupguestnetwork", setupCmd);
- sendCommandsToRouter(router, cmds);
-
- SetupGuestNetworkAnswer setupAnswer = cmds.getAnswer(SetupGuestNetworkAnswer.class);
- String setup = add ? "set" : "destroy";
- if (!(setupAnswer != null && setupAnswer.getResult())) {
- s_logger.warn("Unable to " + setup + " guest network on router " + router);
- result = false;
- }
-
- return result;
+ Commands cmds = new Commands(OnError.Stop);
+ cmds.addCommand("setupguestnetwork", setupCmd);
+ sendCommandsToRouter(router, cmds);
+
+ SetupGuestNetworkAnswer setupAnswer = cmds.getAnswer(SetupGuestNetworkAnswer.class);
+ String setup = add ? "set" : "destroy";
+ if (!(setupAnswer != null && setupAnswer.getResult())) {
+ s_logger.warn("Unable to " + setup + " guest network on router " + router);
+ result = false;
+ }
+ return result;
+ } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
+ s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() +
+ ", so not sending setup guest network command to the backend");
+ return true;
+ } else {
+ s_logger.warn("Unable to setup guest network on virtual router " + router + " is not in the right state " + router.getState());
+ throw new ResourceUnavailableException("Unable to setup guest network on the backend," +
+ " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn());
+ }
}
protected SetupGuestNetworkCommand createSetupGuestNetworkCommand(VirtualRouter router, boolean add, NicProfile guestNic) {
@@ -511,7 +516,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
String networkDomain = network.getNetworkDomain();
String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId()));
- VirtualMachine vm = _vmDao.findById(router.getId());
NicProfile nicProfile = _networkMgr.getNicProfile(router, nic.getNetworkId());
SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, false, null,
@@ -957,9 +961,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
protected boolean setupVpcPrivateNetwork(VirtualRouter router, boolean add, NicProfile privateNic)
throws ResourceUnavailableException {
-
if (router.getState() == State.Running) {
-
PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(), privateNic.getIp4Address());
Network network = _networkDao.findById(privateNic.getNetworkId());
String vlanTag = network.getBroadcastUri().getHost();
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b407b3be/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 2e75e72..c85a80f 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -2458,26 +2458,36 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
- //1) allocate and prepare nic
- NicProfile nic = _networkMgr.allocateAndPrepareNic(network, requested, context, vmProfile);
-
- //2) Convert vmProfile to vmTO
- HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
- VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
-
- //3) Convert nicProfile to NicTO
- NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
-
- //4) plug the nic to the vm
- VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
-
- s_logger.debug("Plugging nic for vm " + vm + " in network " + network);
- if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
- s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now");
- return nic;
+ //check vm state
+ if (vm.getState() == State.Running) {
+ //1) allocate and prepare nic
+ NicProfile nic = _networkMgr.createNicForVm(network, requested, context, vmProfile, true);
+
+ //2) Convert vmProfile to vmTO
+ HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
+ VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
+
+ //3) Convert nicProfile to NicTO
+ NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
+
+ //4) plug the nic to the vm
+ VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
+
+ s_logger.debug("Plugging nic for vm " + vm + " in network " + network);
+ if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
+ s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now");
+ return nic;
+ } else {
+ s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
+ return null;
+ }
+ } else if (vm.getState() == State.Stopped) {
+ //1) allocate nic
+ return _networkMgr.createNicForVm(network, requested, context, vmProfile, false);
} else {
- s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
- return null;
+ s_logger.warn("Unable to add vm " + vm + " to network " + network);
+ throw new ResourceUnavailableException("Unable to add vm " + vm + " to network, is not in the right state",
+ DataCenter.class, vm.getDataCenterIdToDeployIn());
}
}
@@ -2506,7 +2516,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
- Nic nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
+ Nic nic = null;
+
+ if (broadcastUri != null) {
+ nic = _nicsDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri.getHost());
+ } else {
+ nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
+ }
+
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
_networkMgr.getNetworkRate(network.getId(), vm.getId()),
_networkMgr.isSecurityGroupSupportedInNetwork(network),
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b407b3be/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
index f4cdb31..e9e05bb 100755
--- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
+++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
@@ -282,7 +282,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
@DB
public void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork) {
if (_routerNetworkDao.findByRouterAndNetwork(router.getId(), guestNetwork.getId()) == null &&
- guestNetwork.getName() != NetworkOffering.SystemPrivateGatewayNetworkOffering) {
+ !guestNetwork.getName().equalsIgnoreCase(NetworkOffering.SystemPrivateGatewayNetworkOffering)) {
Transaction txn = Transaction.currentTxn();
txn.start();
//1) add router to network