cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [14/16] git commit: updated refs/heads/vmsync to f49257c
Date Sun, 19 May 2013 16:15:07 GMT
Removed plug and unplug method as they're not appropriate for VirtualMachineGuru


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

Branch: refs/heads/vmsync
Commit: e33bc08a8bce471c2898227b7b44457b086e4de0
Parents: 1c78396
Author: Alex Huang <alex.huang@gmail.com>
Authored: Sat May 18 15:44:48 2013 -0700
Committer: Alex Huang <alex.huang@gmail.com>
Committed: Sat May 18 15:44:48 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/vm/VirtualMachineGuru.java       |   36 -------
 .../cloudstack/engine/vm/VMEntityManagerImpl.java  |    2 +-
 .../engine/vm/VirtualMachineOrchestrator.java      |    2 +-
 .../network/lb/ElasticLoadBalancerManagerImpl.java |   17 ----
 .../lb/InternalLoadBalancerVMManagerImpl.java      |   15 ---
 .../consoleproxy/ConsoleProxyManagerImpl.java      |   19 ----
 .../router/VirtualNetworkApplianceManagerImpl.java |   17 ----
 .../VpcVirtualNetworkApplianceManagerImpl.java     |   75 ---------------
 .../secondary/SecondaryStorageManagerImpl.java     |   19 ----
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   64 ------------
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   75 ++++++++++++++-
 .../test/com/cloud/vm/MockUserVmManagerImpl.java   |   22 ----
 12 files changed, 74 insertions(+), 289 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java b/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
index 99193e0..3c9e53e 100644
--- a/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
+++ b/engine/components-api/src/com/cloud/vm/VirtualMachineGuru.java
@@ -17,15 +17,9 @@
 package com.cloud.vm;
 
 import com.cloud.agent.api.StopAnswer;
-import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.deploy.DeployDestination;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InsufficientNetworkCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.Network;
 
 /**
  * A VirtualMachineGuru knows how to process a certain type of virtual machine.
@@ -80,36 +74,6 @@ public interface VirtualMachineGuru<T extends VirtualMachine> {
     Long convertToId(String vmName);
     
     /**
-     * Prepare for a nic to be plugged into the network.
-     * @param network
-     * @param nic
-     * @param vm
-     * @param context
-     * @param dest TODO
-     * @return
-     * @throws ConcurrentOperationException
-     * @throws ResourceUnavailableException
-     * @throws InsufficientNetworkCapacityException
-     */
-    boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
-            ResourceUnavailableException, InsufficientCapacityException;
-    
-    /**
-     * A nic is unplugged from this network.
-     * @param network
-     * @param nic
-     * @param vm
-     * @param context
-     * @param dest TODO
-     * @return
-     * @throws ConcurrentOperationException
-     * @throws ResourceUnavailableException
-     */
-    boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException;
-
-    /**
      * Prepare Vm for Stop
      * @param profile
      * @return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
index beca6b3..f7d48d5 100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
@@ -134,7 +134,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
         //load vm instance and offerings and call virtualMachineManagerImpl
         //FIXME: profile should work on VirtualMachineEntity
         VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
-        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
+        VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm);
         DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(),
null, null, null, null);
         if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){
             plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(),
planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
index 63d45a3..43e34e4 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VirtualMachineOrchestrator.java
@@ -266,7 +266,7 @@ public class VirtualMachineOrchestrator extends ManagerBase {
         AccountVO owner = _entityMgr.findById(AccountVO.class, new Long(ownerRef));
 
         VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, vm1.getId());
-        VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
+        VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm);
 
         Transaction txn = Transaction.currentTxn();
         txn.start();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
index 98b11ca..21355f8 100644
--- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
+++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
@@ -47,8 +47,6 @@ import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.to.LoadBalancerTO;
-import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
@@ -984,21 +982,6 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO>
{
     }
     
     @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException,
-            InsufficientCapacityException {
-        //not supported
-        throw new UnsupportedOperationException("Plug nic is not supported for vm of type
" + vm.getType());
-    }
-
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException {
-        //not supported
-        throw new UnsupportedOperationException("Unplug nic is not supported for vm of type
" + vm.getType());
-     }
-
-    @Override
     public void prepareStop(VirtualMachineProfile profile) {
     }
     

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
index 0b6e9d8..60a6051 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
@@ -42,8 +42,6 @@ import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.to.LoadBalancerTO;
-import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
@@ -369,19 +367,6 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
     }
 
     @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext
context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
-            InsufficientCapacityException {
-        //not supported
-        throw new UnsupportedOperationException("Plug nic is not supported for vm of type
" + vm.getType());
-    }
-
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext
context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException
{
-        //not supported
-        throw new UnsupportedOperationException("Unplug nic is not supported for vm of type
" + vm.getType());
-    }
-
-    @Override
     public void prepareStop(VirtualMachineProfile profile) {
     }
     

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index ffed715..8ca2917 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -47,8 +47,6 @@ import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.check.CheckSshAnswer;
 import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
-import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.async.AsyncJobExecutionContext;
 import com.cloud.certificate.dao.CertificateDao;
@@ -84,7 +82,6 @@ import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
 import com.cloud.keystore.KeystoreDao;
 import com.cloud.keystore.KeystoreManager;
 import com.cloud.keystore.KeystoreVO;
-import com.cloud.network.Network;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.Networks.TrafficType;
@@ -1722,22 +1719,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements
ConsoleProxy
     }
 
     @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException,
-            InsufficientCapacityException {
-        //not supported
-        throw new UnsupportedOperationException("Plug nic is not supported for vm of type
" + vm.getType());
-    }
-
-
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException {
-        //not supported
-        throw new UnsupportedOperationException("Unplug nic is not supported for vm of type
" + vm.getType());
-    }
-
-    @Override
     public void prepareStop(VirtualMachineProfile profile) {
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/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 4d9dde1..8a53e1d 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -81,10 +81,8 @@ import com.cloud.agent.api.routing.VpnUsersCfgCommand;
 import com.cloud.agent.api.to.FirewallRuleTO;
 import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.LoadBalancerTO;
-import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
 import com.cloud.agent.api.to.StaticNatRuleTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.alert.AlertManager;
 import com.cloud.cluster.ManagementServerHostVO;
@@ -3648,21 +3646,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
     }
 
     @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext
context, DeployDestination dest)
-            throws ConcurrentOperationException, ResourceUnavailableException,
-            InsufficientCapacityException {
-        //not supported
-        throw new UnsupportedOperationException("Plug nic is not supported for vm of type
" + vm.getType());
-    }
-
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext
context, DeployDestination dest)
-            throws ConcurrentOperationException, ResourceUnavailableException {
-        //not supported
-        throw new UnsupportedOperationException("Unplug nic is not supported for vm of type
" + vm.getType());
-    }
-
-    @Override
     public void prepareStop(VirtualMachineProfile profile) {
         //Collect network usage before stopping Vm
         VirtualMachine vm = profile.getVirtualMachine();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/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 82cd97a..8c971f1 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -33,13 +33,10 @@ import org.springframework.stereotype.Component;
 import com.cloud.agent.AgentManager.OnError;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.NetworkUsageCommand;
-import com.cloud.agent.api.PlugNicAnswer;
 import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.SetupGuestNetworkAnswer;
 import com.cloud.agent.api.SetupGuestNetworkCommand;
 import com.cloud.agent.api.StopAnswer;
-import com.cloud.agent.api.UnPlugNicAnswer;
-import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.routing.IpAssocVpcCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.routing.SetNetworkACLCommand;
@@ -49,19 +46,16 @@ import com.cloud.agent.api.routing.Site2SiteVpnCfgCommand;
 import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.NetworkACLTO;
 import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.deploy.DataCenterDeployment;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
-import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.InsufficientServerCapacityException;
-import com.cloud.exception.OperationTimedoutException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.exception.StorageUnavailableException;
 import com.cloud.network.IpAddress;
@@ -325,75 +319,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         return router;
     }
     
-    @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException,
-            InsufficientCapacityException {
-        boolean result = true;
-        
-        DomainRouterVO router = _routerDao.findById(vm.getId());
-        if (router.getState() == State.Running) {
-            try {
-                PlugNicCommand plugNicCmd = new PlugNicCommand(nic, vm.getName());
-                
-                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.getName());
-                    result = false;
-                }
-            } catch (OperationTimedoutException e) {
-                throw new AgentUnavailableException("Unable to plug nic for router " + vm.getName()
+ " in network " + network,
-                        dest.getHost().getId(), e);
-            }
-        } 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.getDataCenterId());
-        }
-        
-        return result;
-    }
-
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException {
-        
-        boolean result = true;
-        DomainRouterVO router = _routerDao.findById(vm.getId());
-        
-        if (router.getState() == State.Running) {
-            try {
-                Commands cmds = new Commands(OnError.Stop);
-                UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, vm.getName());
-                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);
-            }
-        } 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.getDataCenterId());
-        }
-       
-        return result;
-    }
-    
     protected boolean setupVpcGuestNetwork(Network network, VirtualRouter router, boolean
add, NicProfile guestNic)
             throws ConcurrentOperationException, ResourceUnavailableException{
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
index 25b6c05..dcb5d82 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
@@ -48,8 +48,6 @@ import com.cloud.agent.api.StartupStorageCommand;
 import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.check.CheckSshAnswer;
 import com.cloud.agent.api.check.CheckSshCommand;
-import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.async.AsyncJobExecutionContext;
 import com.cloud.capacity.dao.CapacityDao;
@@ -78,7 +76,6 @@ import com.cloud.info.RunningHostCountInfo;
 import com.cloud.info.RunningHostInfoAgregator;
 import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
 import com.cloud.keystore.KeystoreManager;
-import com.cloud.network.Network;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.Networks.TrafficType;
@@ -1462,22 +1459,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements
Secondar
         return null;
     }
 	
-    @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException,
-            InsufficientCapacityException {
-        //not supported
-        throw new UnsupportedOperationException("Plug nic is not supported for vm of type
" + vm.getType());
-    }
-
-
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException {
-        //not supported
-        throw new UnsupportedOperationException("Unplug nic is not supported for vm of type
" + vm.getType());
-    }
-
 	@Override
     public void prepareStop(VirtualMachineProfile profile) {
 	}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/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 ef2ba1e..7dd51b0 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -65,16 +65,11 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 
 import com.cloud.agent.AgentManager;
-import com.cloud.agent.AgentManager.OnError;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.GetVmStatsAnswer;
 import com.cloud.agent.api.GetVmStatsCommand;
-import com.cloud.agent.api.PlugNicAnswer;
-import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.StartAnswer;
 import com.cloud.agent.api.StopAnswer;
-import com.cloud.agent.api.UnPlugNicAnswer;
-import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.VmStatsEntry;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
@@ -106,7 +101,6 @@ import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
 import com.cloud.event.dao.UsageEventDao;
-import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.CloudException;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
@@ -4229,64 +4223,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
     }
 
     @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest)
-                    throws ConcurrentOperationException, ResourceUnavailableException,
-                    InsufficientCapacityException {
-        UserVmVO vmVO = _vmDao.findById(vm.getId());
-        if (vmVO.getState() == State.Running) {
-            try {
-                PlugNicCommand plugNicCmd = new PlugNicCommand(nic,vm.getName());
-                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 " + vmVO + " due to: " + " due
to: " + plugNicAnswer.getDetails());
-                    return false;
-                }
-            } catch (OperationTimedoutException e) {
-                throw new AgentUnavailableException("Unable to plug nic for " + vmVO + "
in network " + network, dest.getHost().getId(), e);
-            }
-        } else if (vmVO.getState() == State.Stopped || vmVO.getState() == State.Stopping)
{
-            s_logger.warn(vmVO + " is Stopped, not sending PlugNicCommand.  Currently " +
vmVO.getState());
-        } else {
-            s_logger.warn("Unable to plug nic, " + vmVO + " is not in the right state " +
vmVO.getState());
-            throw new ResourceUnavailableException("Unable to plug nic on the backend," +
-                    vmVO + " is not in the right state", DataCenter.class, vmVO.getDataCenterId());
-        }
-        return true;
-    }
-
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException {
-        UserVmVO vmVO = _vmDao.findById(vm.getId());
-        if (vmVO.getState() == State.Running) {
-            try {
-                UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic,vm.getName());
-                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 for " + vmVO + " due to: " + unplugNicAnswer.getDetails());
-                    return false;
-                }
-            } catch (OperationTimedoutException e) {
-                throw new AgentUnavailableException("Unable to unplug nic for " + vmVO +
" in network " + network, dest.getHost().getId(), e);
-            }
-        } else if (vmVO.getState() == State.Stopped || vmVO.getState() == State.Stopping)
{
-            s_logger.warn(vmVO + " is Stopped, not sending UnPlugNicCommand.  Currently "
+ vmVO.getState());
-        } else {
-            s_logger.warn("Unable to unplug nic, " + vmVO + " is not in the right state "
+ vmVO.getState());
-            throw new ResourceUnavailableException("Unable to unplug nic on the backend,"
+
-                    vmVO + " is not in the right state", DataCenter.class, vmVO.getDataCenterId());
-        }
-        return true;
-    }
-
-    @Override
     public void prepareStop(VirtualMachineProfile profile) {
     }
     

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/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 2eec196..6545270 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -59,6 +59,8 @@ import com.cloud.agent.api.CheckVirtualMachineCommand;
 import com.cloud.agent.api.ClusterSyncAnswer;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.PingRoutingCommand;
+import com.cloud.agent.api.PlugNicAnswer;
+import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.RebootAnswer;
 import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.StartAnswer;
@@ -67,6 +69,8 @@ import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupRoutingCommand;
 import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.StopCommand;
+import com.cloud.agent.api.UnPlugNicAnswer;
+import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
@@ -3142,6 +3146,71 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         return _vmDao.update(vmId, vmForUpdate);
     }
 
+    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO to, VMInstanceVO
vm,
+            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException,
+            InsufficientCapacityException {
+        boolean result = true;
+
+        if (vm.getState() == State.Running) {
+            try {
+                PlugNicCommand plugNicCmd = new PlugNicCommand(nic, to.getName());
+
+                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 " + to.getName());
+                    result = false;
+                }
+            } catch (OperationTimedoutException e) {
+                throw new AgentUnavailableException("Unable to plug nic for router " + to.getName()
+ " in network " + network,
+                        dest.getHost().getId(), e);
+            }
+        } else {
+            s_logger.warn("Unable to apply PlugNic, vm " + vm + " is not in the right state
" + vm.getState());
+
+            throw new ResourceUnavailableException("Unable to apply PlugNic on the backend,"
+
+                    " vm " + to + " is not in the right state", DataCenter.class, vm.getDataCenterId());
+        }
+
+        return result;
+    }
+
+    protected boolean unplugNic(Network network, NicTO nic, VirtualMachineTO to, VMInstanceVO
vm,
+            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException {
+
+        boolean result = true;
+
+        if (vm.getState() == State.Running) {
+            try {
+                Commands cmds = new Commands(OnError.Stop);
+                UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, to.getName());
+                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 " + vm);
+                    result = false;
+                }
+            } catch (OperationTimedoutException e) {
+                throw new AgentUnavailableException("Unable to unplug nic from rotuer " +
vm + " from network " + network,
+                        dest.getHost().getId(), e);
+            }
+        } else if (vm.getState() == State.Stopped || vm.getState() == State.Stopping) {
+            s_logger.debug("Vm " + vm.getInstanceName() + " is in " + vm.getState() +
+                    ", so not sending unplug nic command to the backend");
+        } else {
+            s_logger.warn("Unable to apply unplug nic, Vm " + vm + " is not in the right
state " + vm.getState());
+
+            throw new ResourceUnavailableException("Unable to apply unplug nic on the backend,"
+
+                    " vm " + vm + " is not in the right state", DataCenter.class, vm.getDataCenterId());
+        }
+
+        return result;
+    }
+
     @Override
     public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested)
throws ConcurrentOperationException,
     ResourceUnavailableException, InsufficientCapacityException {
@@ -3182,7 +3251,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             
             boolean result = false;
             try{
-                result = vmGuru.plugNic(network, nicTO, vmTO, context, dest);
+                result = plugNic(network, nicTO, vmTO, vmVO, context, dest);
                 if (result) {
                 s_logger.debug("Nic is plugged successfully for vm " + vm + " in network
" + network + ". Vm  is a part of network now");
                     long isDefault = (nic.isDefaultNic()) ? 1 : 0;
@@ -3256,7 +3325,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         if (vm.getState() == State.Running) {
             NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
             s_logger.debug("Un-plugging nic " + nic + " for vm " + vm + " from network "
+ network);
-            boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest);
+            boolean result = unplugNic(network, nicTO, vmTO, vmVO, context, dest);
             if (result) {
                 s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network
" + network );
                 long isDefault = (nic.isDefaultNic()) ? 1 : 0;
@@ -3327,7 +3396,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         if (vm.getState() == State.Running) {
             NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
             s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network);
-            boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest);
+            boolean result = unplugNic(network, nicTO, vmTO, vmVO, context, dest);
             if (result) {
                 s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network
" + network );
             } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e33bc08a/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 d70095e..ff115af 100644
--- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java
+++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
@@ -46,8 +46,6 @@ import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
 
 import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.VmStatsEntry;
-import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.api.query.vo.UserVmJoinVO;
 import com.cloud.dc.DataCenter;
@@ -63,7 +61,6 @@ import com.cloud.exception.StorageUnavailableException;
 import com.cloud.exception.VirtualMachineMigrationException;
 import com.cloud.host.Host;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.network.Network;
 import com.cloud.network.Network.IpAddresses;
 import com.cloud.offering.ServiceOffering;
 import com.cloud.projects.Project.ListProjectResourcesCriteria;
@@ -425,25 +422,6 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
 
     }
 
-    /* (non-Javadoc)
-     * @see com.cloud.vm.VirtualMachineGuru#plugNic(com.cloud.network.Network, com.cloud.agent.api.to.NicTO,
com.cloud.agent.api.to.VirtualMachineTO, com.cloud.vm.ReservationContext, com.cloud.deploy.DeployDestination)
-     */
-    @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext
context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
-    InsufficientCapacityException {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    /* (non-Javadoc)
-     * @see com.cloud.vm.VirtualMachineGuru#unplugNic(com.cloud.network.Network, com.cloud.agent.api.to.NicTO,
com.cloud.agent.api.to.VirtualMachineTO, com.cloud.vm.ReservationContext, com.cloud.deploy.DeployDestination)
-     */
-    @Override
-    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext
context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException
{
-        // TODO Auto-generated method stub
-        return false;
-    }
-
     @Override
     public UserVm resetVMSSHKey(ResetVMSSHKeyCmd cmd) throws ResourceUnavailableException,
InsufficientCapacityException {
         // TODO Auto-generated method stub


Mime
View raw message