cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: VPC: allow adding private gateway to the VPC when the VR is in Stopped state
Date Fri, 06 Jul 2012 22:25:56 GMT
Updated Branches:
  refs/heads/vpc 818a3c72a -> c9eb0c59b


VPC: allow adding private gateway to the VPC when the VR is in Stopped state


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/c9eb0c59
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/c9eb0c59
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/c9eb0c59

Branch: refs/heads/vpc
Commit: c9eb0c59bf5ce861ce7ddd0f526de6308a2cec06
Parents: 818a3c7
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Fri Jul 6 15:26:07 2012 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Fri Jul 6 15:28:07 2012 -0700

----------------------------------------------------------------------
 .../cloud/network/element/BareMetalElement.java    |    2 +-
 .../VpcVirtualNetworkApplianceManagerImpl.java     |  131 +++++++++------
 2 files changed, 84 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c9eb0c59/server/src/com/cloud/network/element/BareMetalElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/BareMetalElement.java b/server/src/com/cloud/network/element/BareMetalElement.java
index ab50ed6..fee411a 100644
--- a/server/src/com/cloud/network/element/BareMetalElement.java
+++ b/server/src/com/cloud/network/element/BareMetalElement.java
@@ -73,7 +73,7 @@ public class BareMetalElement extends AdapterBase implements NetworkElement
{
 	public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends
VirtualMachine> vm, DeployDestination dest,
 			ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
 		Host host = dest.getHost();
-		if (host.getHypervisorType() != HypervisorType.BareMetal) {
+		if (host == null || host.getHypervisorType() != HypervisorType.BareMetal) {
 			return true;
 		}
 		

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c9eb0c59/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 37aa6ff..c1ce80d 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -418,22 +418,33 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
             InsufficientCapacityException {     
         boolean result = true;
         
-        try {
-            PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic);
-            
-            Commands cmds = new Commands(OnError.Stop);
-            cmds.addCommand("plugnic", plugNicCmd);
-            _agentMgr.send(dest.getHost().getId(), cmds);
-            
-            PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
-            if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
-                s_logger.warn("Unable to plug nic for vm " + vm.getHostName());
-                result = false;
-            } 
+        DomainRouterVO router = _routerDao.findById(vm.getId());
+        if (router.getState() == State.Running) {
+            try {
+                PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic);
+                
+                Commands cmds = new Commands(OnError.Stop);
+                cmds.addCommand("plugnic", plugNicCmd);
+                _agentMgr.send(dest.getHost().getId(), cmds);
+                
+                PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
+                if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
+                    s_logger.warn("Unable to plug nic for vm " + vm.getHostName());
+                    result = false;
+                } 
 
-        } catch (OperationTimedoutException e) {
-            throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName()
+ " in network " + network,
-                    dest.getHost().getId(), e);
+            } catch (OperationTimedoutException e) {
+                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());
+            
+            throw new ResourceUnavailableException("Unable to apply PlugNic on the backend,"
+
+                    " vm " + vm + " is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn());
         }
         
         return result;
@@ -445,23 +456,34 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         
         boolean result = true;
         DomainRouterVO router = _routerDao.findById(vm.getId());
-        try {
-            UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic);
-            Commands cmds = new Commands(OnError.Stop);
-            cmds.addCommand("unplugnic", unplugNicCmd);
-            _agentMgr.send(dest.getHost().getId(), cmds);
-            
-            UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class);
-            if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
-                s_logger.warn("Unable to unplug nic from router " + router);
-                result = false;
-            } 
+        
+        if (router.getState() == State.Running) {
+            try {
+                UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic);
+                Commands cmds = new Commands(OnError.Stop);
+                cmds.addCommand("unplugnic", unplugNicCmd);
+                _agentMgr.send(dest.getHost().getId(), cmds);
+                
+                UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class);
+                if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
+                    s_logger.warn("Unable to unplug nic from router " + router);
+                    result = false;
+                } 
 
-        } catch (OperationTimedoutException e) {
-            throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router
+ " from network " + network,
-                    dest.getHost().getId(), e);
+            } catch (OperationTimedoutException e) {
+                throw new AgentUnavailableException("Unable to unplug nic from rotuer " +
router + " from network " + network,
+                        dest.getHost().getId(), e);
+            }
+        } else if (router.getState() == State.Stopped || router.getState() == State.Stopping)
{
+            s_logger.debug("Vm " + router.getInstanceName() + " is in " + router.getState()
+ 
+                    ", so not sending unplug nic command to the backend");
+        } else {
+            s_logger.warn("Unable to apply unplug nic, Vm " + router + " is not in the right
state " + router.getState());
+            
+            throw new ResourceUnavailableException("Unable to apply unplug nic on the backend,"
+
+                    " vm " + router +" is not in the right state", DataCenter.class, router.getDataCenterIdToDeployIn());
         }
-        
+       
         return result;
     }
     
@@ -945,29 +967,43 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
      * @param add
      * @param privateNic
      * @return
-     * @throws AgentUnavailableException 
+     * @throws ResourceUnavailableException TODO
      */
     protected boolean setupVpcPrivateNetwork(VirtualRouter router, boolean add, NicProfile
privateNic) 
-            throws AgentUnavailableException {
-        
-        PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(),
privateNic.getIp4Address());
-        Network network = _networkDao.findById(privateNic.getNetworkId());
-        String vlanTag = network.getBroadcastUri().getHost();
-        String netmask = NetUtils.getCidrNetmask(network.getCidr());
-        PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask,
ipVO.getMacAddress());
+            throws ResourceUnavailableException {
         
-        List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
-        privateIps.add(ip);
-        Commands cmds = new Commands(OnError.Stop);
-        createVpcAssociatePrivateIPCommands(router, privateIps, cmds, add);
         
-        if (sendCommandsToRouter(router, cmds)) {
-            s_logger.debug("Successfully applied ip association for ip " + ip + " in vpc
network " + network);
-            return true;
+        if (router.getState() == State.Running) {
+            
+            PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(),
privateNic.getIp4Address());
+            Network network = _networkDao.findById(privateNic.getNetworkId());
+            String vlanTag = network.getBroadcastUri().getHost();
+            String netmask = NetUtils.getCidrNetmask(network.getCidr());
+            PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, network.getGateway(),
netmask, ipVO.getMacAddress());
+            
+            List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
+            privateIps.add(ip);
+            Commands cmds = new Commands(OnError.Stop);
+            createVpcAssociatePrivateIPCommands(router, privateIps, cmds, add);
+            
+            if (sendCommandsToRouter(router, cmds)) {
+                s_logger.debug("Successfully applied ip association for ip " + ip + " in
vpc network " + network);
+                return true;
+            } else {
+                s_logger.warn("Failed to associate ip address " + ip + " in vpc network "
+ network);
+                return false;
+            }
+        } else if (router.getState() == State.Stopped || router.getState() == State.Stopping)
{
+            s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState()
+ 
+                    ", so not sending setup private network command to the backend");
         } else {
-            s_logger.warn("Failed to associate ip address " + ip + " in vpc network " + network);
-            return false;
+            s_logger.warn("Unable to setup private gateway, virtual router " + router + "
is not in the right state " + router.getState());
+            
+            throw new ResourceUnavailableException("Unable to setup Private gateway on the
backend," +
+                    " virtual router " + router + " is not in the right state", DataCenter.class,
router.getDataCenterIdToDeployIn());
         }
+        return true;
+      
     }
 
     @Override
@@ -1020,7 +1056,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         for (VirtualRouter router : routers) {
             if (router.getState() == State.Running) {
                 result = result && sendStaticRoutes(staticRoutes, routers.get(0));
    
-
             } else if (router.getState() == State.Stopped || router.getState() == State.Stopping)
{
                 s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState()
+ 
                         ", so not sending StaticRoute command to the backend");


Mime
View raw message