incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [12/51] [abbrv] git commit: VPC: ipAssoc consists of 3 parts: plug nic (if needed), associateIp, enableSourceNat(if ip is source nat ip)
Date Fri, 15 Jun 2012 22:38:02 GMT
VPC: ipAssoc consists of 3 parts: plug nic (if needed), associateIp, enableSourceNat(if ip is source nat ip)

Conflicts:

	server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java


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

Branch: refs/heads/vpc
Commit: 982562b9fbe3eda84713c437f64d8306164544c4
Parents: a7462bb
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Tue Jun 12 10:29:33 2012 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Fri Jun 15 14:31:58 2012 -0700

----------------------------------------------------------------------
 .../com/cloud/agent/api/SetSourceNatAnswer.java    |   24 +
 .../cloud/agent/api/routing/IpAssocVpcCommand.java |   28 +
 .../agent/api/routing/SetSourceNatCommand.java     |   41 ++
 api/src/com/cloud/agent/api/to/IpAddressTO.java    |    3 +-
 .../network/VirtualNetworkApplianceService.java    |   23 -
 .../network/VpcVirtualNetworkApplianceService.java |   11 +
 .../xen/resource/CitrixResourceBase.java           |   22 +-
 server/src/com/cloud/network/NetworkManager.java   |   13 +
 .../src/com/cloud/network/NetworkManagerImpl.java  |   12 +
 .../network/element/VirtualRouterElement.java      |   15 -
 .../network/element/VpcVirtualRouterElement.java   |    1 -
 .../router/VirtualNetworkApplianceManagerImpl.java |  380 +-----------
 .../VpcVirtualNetworkApplianceManagerImpl.java     |  485 ++++++++++++++-
 server/src/com/cloud/vm/VirtualMachineManager.java |    5 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   15 +-
 server/src/com/cloud/vm/dao/NicDao.java            |    2 +
 server/src/com/cloud/vm/dao/NicDaoImpl.java        |   13 +-
 .../cloud/vm/MockVirtualMachineManagerImpl.java    |    2 +-
 wscript                                            |    2 +-
 19 files changed, 682 insertions(+), 415 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/api/src/com/cloud/agent/api/SetSourceNatAnswer.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/SetSourceNatAnswer.java b/api/src/com/cloud/agent/api/SetSourceNatAnswer.java
new file mode 100644
index 0000000..089f1f7
--- /dev/null
+++ b/api/src/com/cloud/agent/api/SetSourceNatAnswer.java
@@ -0,0 +1,24 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by the License.
+// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.agent.api;
+
+/**
+ * @author Alena Prokharchyk
+ */
+public class SetSourceNatAnswer extends Answer{
+    public SetSourceNatAnswer() {}
+
+    public SetSourceNatAnswer(PlugNicCommand cmd, boolean success, String result) {
+        super(cmd, success, result);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java b/api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java
new file mode 100644
index 0000000..7ab57b4
--- /dev/null
+++ b/api/src/com/cloud/agent/api/routing/IpAssocVpcCommand.java
@@ -0,0 +1,28 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by the License.
+// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.agent.api.routing;
+
+import com.cloud.agent.api.to.IpAddressTO;
+
+/**
+ * @author Alena Prokharchyk
+ */
+public class IpAssocVpcCommand extends IpAssocCommand{
+    protected IpAssocVpcCommand() {
+        super();
+    }
+    
+    public IpAssocVpcCommand(IpAddressTO[] ips) {
+        super(ips);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java b/api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java
new file mode 100644
index 0000000..59d4856
--- /dev/null
+++ b/api/src/com/cloud/agent/api/routing/SetSourceNatCommand.java
@@ -0,0 +1,41 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by the License.
+// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.agent.api.routing;
+
+import com.cloud.agent.api.to.IpAddressTO;
+
+/**
+ * @author Alena Prokharchyk
+ */
+public class SetSourceNatCommand extends NetworkElementCommand{
+    IpAddressTO ipAddress;
+    boolean add;
+
+    protected SetSourceNatCommand() {
+    }
+    
+    public SetSourceNatCommand(IpAddressTO ip, boolean add) {
+        this.ipAddress = ip;
+        this.add = add;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public IpAddressTO getIpAddress() {
+        return ipAddress;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/api/src/com/cloud/agent/api/to/IpAddressTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/IpAddressTO.java b/api/src/com/cloud/agent/api/to/IpAddressTO.java
index 8c044a3..583892d 100644
--- a/api/src/com/cloud/agent/api/to/IpAddressTO.java
+++ b/api/src/com/cloud/agent/api/to/IpAddressTO.java
@@ -36,7 +36,8 @@ public class IpAddressTO {
     private TrafficType trafficType;
     private String networkName;
 
-    public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, String guestIp, Integer networkRate, boolean isOneToOneNat) {
+    public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId,
+            String vlanGateway, String vlanNetmask, String vifMacAddress, String guestIp, Integer networkRate, boolean isOneToOneNat) {
         this.accountId = accountId;
         this.publicIp = ipAddress;
         this.add = add;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/api/src/com/cloud/network/VirtualNetworkApplianceService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java
index 2642d0f..d0fb527 100644
--- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java
+++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java
@@ -62,27 +62,4 @@ public interface VirtualNetworkApplianceService {
 
     VirtualRouter destroyRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException;
 
-    /**
-     * @param router
-     * @param network
-     * @param isRedundant TODO
-     * @param setupDns TODO
-     * @return
-     * @throws ConcurrentOperationException
-     * @throws ResourceUnavailableException
-     * @throws InsufficientCapacityException
-     */
-    boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) 
-            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
-
-    /**
-     * @param router
-     * @param network
-     * @param isRedundant TODO
-     * @return
-     * @throws ConcurrentOperationException
-     * @throws ResourceUnavailableException
-     */
-    boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant)
-            throws ConcurrentOperationException, ResourceUnavailableException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
index 139de98..b8a3781 100644
--- a/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
+++ b/api/src/com/cloud/network/VpcVirtualNetworkApplianceService.java
@@ -33,4 +33,15 @@ public interface VpcVirtualNetworkApplianceService {
      */
     boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
 
+    /**
+     * @param router
+     * @param network
+     * @param isRedundant
+     * @return
+     * @throws ConcurrentOperationException
+     * @throws ResourceUnavailableException
+     */
+    boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) 
+            throws ConcurrentOperationException, ResourceUnavailableException;
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index d8c8410..2c8666d 100644
--- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -115,6 +115,7 @@ import com.cloud.agent.api.RebootCommand;
 import com.cloud.agent.api.RebootRouterCommand;
 import com.cloud.agent.api.SecurityGroupRuleAnswer;
 import com.cloud.agent.api.SecurityGroupRulesCmd;
+import com.cloud.agent.api.SetSourceNatAnswer;
 import com.cloud.agent.api.SetupAnswer;
 import com.cloud.agent.api.SetupCommand;
 import com.cloud.agent.api.SetupGuestNetworkAnswer;
@@ -140,6 +141,7 @@ import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
 import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
+import com.cloud.agent.api.routing.IpAssocVpcCommand;
 import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand;
@@ -148,6 +150,7 @@ import com.cloud.agent.api.routing.SetFirewallRulesAnswer;
 import com.cloud.agent.api.routing.SetFirewallRulesCommand;
 import com.cloud.agent.api.routing.SetPortForwardingRulesAnswer;
 import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
+import com.cloud.agent.api.routing.SetSourceNatCommand;
 import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
 import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
 import com.cloud.agent.api.routing.VmDataCommand;
@@ -528,7 +531,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
             return execute((PlugNicCommand) cmd);
         } else if (clazz == UnPlugNicCommand.class) {
             return execute((UnPlugNicCommand) cmd);
-        }else {
+        } else if (clazz == IpAssocVpcCommand.class) {
+            return execute((IpAssocVpcCommand) cmd);
+        } else if (clazz == SetSourceNatCommand.class) {
+            return execute((SetSourceNatCommand) cmd);
+        } else {
             return Answer.createUnsupportedCommandAnswer(cmd);
         }
     }
@@ -1818,7 +1825,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 
         return new IpAssocAnswer(cmd, results);
     }
-
+    
     protected GetVncPortAnswer execute(GetVncPortCommand cmd) {
         Connection conn = getConnection();
         try {
@@ -7090,5 +7097,16 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         }
     }
 
+    protected IpAssocAnswer execute(IpAssocVpcCommand cmd) {
+        //FIXME - add implementation here
+        return null;
+    }
+
+    
+    protected SetSourceNatAnswer execute(SetSourceNatCommand cmd) {
+        //FIXME - add implementation here
+        return null;
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/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 18b1154..e66c01d 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -12,6 +12,7 @@
 // Automatically generated by addcopyright.py at 04/03/2012
 package com.cloud.network;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -431,6 +432,18 @@ public interface NetworkManager extends NetworkService {
      * @return
      */
     boolean setupDns(Network network, Provider provider);
+
+
+    /**
+     * @param vmProfile
+     * @param network
+     * @param broadcastUri
+     * @return
+     * @throws ConcurrentOperationException
+     * @throws ResourceUnavailableException
+     */
+    NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri) 
+            throws ConcurrentOperationException, ResourceUnavailableException;
     
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/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 9f11fc5..09bbf22 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -2238,6 +2238,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
         return profile;
     }
     
+    
+    @Override
+    public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri) 
+            throws ConcurrentOperationException, ResourceUnavailableException {
+        NicVO nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vmProfile.getId(), broadcastUri.toString());
+        releaseNic(vmProfile, nic, network);
+        
+        NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, 
+                isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
+        return profile;
+    }
+
 
     protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic, NetworkVO network) 
             throws ConcurrentOperationException, ResourceUnavailableException {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/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 47fd9f8..dc1a247 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -54,7 +54,6 @@ import com.cloud.network.lb.LoadBalancingRule;
 import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
 import com.cloud.network.lb.LoadBalancingRulesManager;
 import com.cloud.network.router.VirtualNetworkApplianceManager;
-import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.router.VirtualRouter.Role;
 import com.cloud.network.rules.FirewallRule;
 import com.cloud.network.rules.LbStickinessMethod;
@@ -80,7 +79,6 @@ import com.cloud.vm.ReservationContext;
 import com.cloud.vm.UserVmManager;
 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;
@@ -208,19 +206,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                     DataCenter.class, network.getDataCenterId());
         }
         
-        if (vm.getType() == Type.User) {
-            for (VirtualRouter router : routers) {
-                if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
-                  //Add router to guest network
-                    if (!_routerMgr.addRouterToGuestNetwork(router, network, false)) {
-                        throw new CloudRuntimeException("Failed to add router " + router + " to guest network " + network);
-                    } else {
-                        s_logger.debug("Successfully added router " + router + " to guest network " + network);
-                    }
-                }
-            }
-        }
-        
         return true;      
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
index 5534e0d..ff0ca36 100644
--- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
@@ -36,7 +36,6 @@ import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
 import com.cloud.network.vpc.Vpc;
 import com.cloud.network.vpc.VpcManager;
 import com.cloud.offering.NetworkOffering;
-import com.cloud.uservm.UserVm;
 import com.cloud.utils.component.Inject;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.DomainRouterVO;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/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 450d228..048e6a5 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -48,19 +48,12 @@ import com.cloud.agent.api.GetDomRVersionCmd;
 import com.cloud.agent.api.ModifySshKeysCommand;
 import com.cloud.agent.api.NetworkUsageAnswer;
 import com.cloud.agent.api.NetworkUsageCommand;
-import com.cloud.agent.api.PlugNicAnswer;
-import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.RebootAnswer;
-import com.cloud.agent.api.SetupGuestNetworkAnswer;
-import com.cloud.agent.api.SetupGuestNetworkCommand;
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StopAnswer;
-import com.cloud.agent.api.UnPlugNicAnswer;
-import com.cloud.agent.api.UnPlugNicCommand;
 import com.cloud.agent.api.check.CheckSshAnswer;
 import com.cloud.agent.api.check.CheckSshCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
-import com.cloud.agent.api.routing.IpAssocAnswer;
 import com.cloud.agent.api.routing.IpAssocCommand;
 import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
@@ -128,8 +121,6 @@ import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkVO;
-import com.cloud.network.Networks.BroadcastDomainType;
-import com.cloud.network.Networks.IsolationType;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PhysicalNetworkServiceProvider;
 import com.cloud.network.PublicIpAddress;
@@ -1384,18 +1375,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
             } finally {
                 startRetry++;
             }
-        } 
-        
-        //3) Plug public nic
-        boolean addToPublicNtwk = true;
-        if (sourceNatIp != null) {
-            Network publicNetwork = _networkDao.listByZoneAndTrafficType(dest.getDataCenter().getId(), TrafficType.Public).get(0);
-            addToPublicNtwk = addRouterToPublicNetwork(router, publicNetwork, sourceNatIp); 
-        }
-        
-        if (!addToPublicNtwk) {
-            s_logger.warn("Failed to add router " + router + " to public network in zone " + dest.getDataCenter() + " cleaninig up");
-            destroyRouter(router.getId());
         }
         
         return router;
@@ -1630,7 +1609,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
         }
 
         String rpFilter = " ";
-        String type = "router";
+        String type = null;
+        if (router.getVpcId() != null) {
+            type = "vpcrouter";
+        } else {
+            type = "router";
+        }
+        
         if (_disable_rp_filter) {
             rpFilter=" disable_rp_filter=true";
         }
@@ -1924,20 +1909,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
             return result;
         }
         
-        //Get guest nic info
-        Map<Nic, Network> guestNics = new HashMap<Nic, Network>();
-        Map<Nic, Network> publicNics = new HashMap<Nic, Network>();
+        //Get guest networks info
         List<Network> guestNetworks = new ArrayList<Network>();
         
         List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
         for (Nic routerNic : routerNics) {
             Network network = _networkMgr.getNetwork(routerNic.getNetworkId());
             if (network.getTrafficType() == TrafficType.Guest) {
-                guestNics.put(routerNic, network);
                 guestNetworks.add(network);
-            } else if (network.getTrafficType() == TrafficType.Public) {
-                publicNics.put(routerNic, network);
-            }
+            } 
         }
         
         answer = cmds.getAnswer("getDomRVersion");
@@ -1951,41 +1931,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
                 router.setScriptsVersion(versionAnswer.getScriptsVersion());
                 router = _routerDao.persist(router, guestNetworks);
             }
-        } else {
-            result = false;
-        }
-        
-        try {
-            //add router to public and guest networks
-            for (Nic publicNic : publicNics.keySet()) {
-                Network publicNtwk = publicNics.get(publicNic);
-                IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), 
-                        publicNic.getIp4Address());
-                PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), 
-                        NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
-                if (!addRouterToPublicNetwork(router, publicNtwk, publicIp)) {
-                    s_logger.warn("Failed to plug nic " + publicNic + " to router " + router);
-                    return false;
-                }
-            }
-            
-            for (Nic guestNic : guestNics.keySet()) {  
-                Network guestNtwk = guestNics.get(guestNic);
-                //FIXME - move vpc code to the vpc manager
-                boolean setupDnsRouter = _networkMgr.setupDns(guestNtwk, Provider.VirtualRouter);
-                boolean setupDnsVpc = _networkMgr.setupDns(guestNtwk, Provider.VPCVirtualRouter);
-                
-                boolean setupDns = setupDnsRouter ? setupDnsRouter : setupDnsVpc;
-                
-                if (!addRouterToGuestNetwork(router, guestNtwk, false, setupDns)) {
-                    s_logger.warn("Failed to plug nic " + guestNic + " to router " + router);
-                    return false;
-                }
-            }
-        } catch (Exception ex) {
-            s_logger.warn("Failed to plug nic for router " + router + " due to exception ", ex);
-            return false;
-        }     
+        }   
 
         return result;
     }
@@ -3019,311 +2965,21 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
     protected String getRouterIpInNetwork(long networkId, long instanceId) {
         return _nicDao.getIpAddress(networkId, instanceId);
     }
-    
-    @Override
-    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, 
-            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
-            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;
-            } 
 
-        } catch (OperationTimedoutException e) {
-            throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName() + " in network " + network,
-                    dest.getHost().getId(), e);
-        }
-        
-        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());
-        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);
-        }
-        
-        return result;
-    }
-    
-    protected boolean setupGuestNetwork(Network network, VirtualRouter router, boolean add, boolean isRedundant,
-            NicProfile guestNic, boolean setupDns) 
-            throws ConcurrentOperationException, ResourceUnavailableException{
-        
-        String networkDomain = network.getNetworkDomain();
-        String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId()));
-        
-        boolean result = true;
-        
-        Nic nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
-        long guestVlanTag = Long.parseLong(nic.getBroadcastUri().getHost());
-        
-        String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask()));
-        Integer priority = null;
-        if (isRedundant) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
-            try {
-                getUpdatedPriority(network, routers, _routerDao.findById(router.getId()));
-            } catch (InsufficientVirtualNetworkCapcityException e) {
-                s_logger.error("Failed to get update priority!", e);
-                throw new CloudRuntimeException("Failed to get update priority!");
-            }
-        }
-        
-        String defaultDns1 = null;
-        String defaultDns2 = null;
-        
-        if (setupDns) {
-            defaultDns1 = guestNic.getDns1();
-            defaultDns2 = guestNic.getDns2();
-        }
-        
-        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 
-                _networkMgr.getNetworkRate(network.getId(), router.getId()), 
-                _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network));
-
-        SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, 
-                defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType()));
-        setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
-        setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId()));
-        setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag));
-        setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway());
-        setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd);
-        setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
-        
-        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;
-    }
-    
-    @Override
-    public boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) 
-            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
-        boolean setupDns = _networkMgr.setupDns(network, Provider.VirtualRouter);
-        
-        return addRouterToGuestNetwork(router, network, isRedundant, setupDns);
-    }
-
-    protected boolean addRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant, boolean setupDns) 
-            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
-        
-        if (network.getTrafficType() != TrafficType.Guest) {
-            s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
-            return false;
-        }
-        
-        //Add router to the Guest network
-        boolean result = true;
-        try {
-            if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
-                DomainRouterVO routerVO = _routerDao.findById(router.getId());
-                _routerDao.addRouterToGuestNetwork(routerVO, network);
-            } 
-            
-            NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null);
-            //setup guest network
-            if (guestNic != null) {
-                result = setupGuestNetwork(network, router, true, isRedundant, guestNic, setupDns);
-            } else {
-                s_logger.warn("Failed to add router " + router + " to guest network " + network);
-                result = false;
-            }
-        } catch (Exception ex) {
-            s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex);
-            result = false;
-        } finally {
-            if (!result) {
-                s_logger.debug("Removing the router " + router + " from network " + network + " as a part of cleanup");
-                if (removeRouterFromGuestNetwork(router, network, isRedundant)) {
-                    s_logger.debug("Removed the router " + router + " from network " + network + " as a part of cleanup");
-                } else {
-                    s_logger.warn("Failed to remove the router " + router + " from network " + network + " as a part of cleanup");
-                }
-            }
-        }
-        
-        return result;
+    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 removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) 
+    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest)
             throws ConcurrentOperationException, ResourceUnavailableException {
-        if (network.getTrafficType() != TrafficType.Guest) {
-            s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
-            return false;
-        }
-        
-        //Check if router is a part of the Guest network
-        if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
-            s_logger.debug("Router " + router + " is not a part of the Guest network " + network);
-            return true;
-        }
-        
-        boolean result = setupGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId()), false);
-        if (!result) {
-            s_logger.warn("Failed to destroy guest network config " + network + " on router " + router);
-            return false;
-        }
-        
-        result = result && _itMgr.removeVmFromNetwork(router, network);
-        
-        if (result) {
-            if (result) {
-                //check if router is already part of network
-                if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
-                    s_logger.debug("Removing router " + router + " from network" + network);
-                    _routerDao.removeRouterFromNetwork(router.getId(), network.getId());
-                }
-            }
-        }
-        return result;
+      //not supported
+        throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
     }
     
-    protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, PublicIp sourceNatIp) 
-            throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException {
-        
-        if (publicNetwork.getTrafficType() != TrafficType.Public) {
-            s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public);
-            return false;
-        }
-        
-        //Add router to the Public network
-        boolean result = true;
-        try {
-            NicProfile defaultNic = new NicProfile();
-
-            defaultNic.setDefaultNic(true);
-            defaultNic.setIp4Address(sourceNatIp.getAddress().addr());
-            defaultNic.setGateway(sourceNatIp.getGateway());
-            defaultNic.setNetmask(sourceNatIp.getNetmask());
-            defaultNic.setMacAddress(sourceNatIp.getMacAddress());
-            defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
-            defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
-            defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
-            
-            NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork, defaultNic);
-            //setup public network
-            if (publicNic != null) {
-                publicNic.setDefaultNic(true);
-                if (sourceNatIp != null) {
-                    IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId());
-                    PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), 
-                            NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
-                    result = setupPublicNetwork(publicNetwork, router, false, publicIp);
-                }
-            } else {
-                result = false;
-                s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork);
-            }
-        } catch (Exception ex) {
-            s_logger.warn("Failed to add router " + router + " to the public network " + publicNetwork + " due to ", ex);
-        } finally {
-            if (!result) {
-                s_logger.debug("Removing the router " + router + " from public network " + publicNetwork + " as a part of cleanup");
-                if (removeRouterFromPublicNetwork(router, publicNetwork)) {
-                    s_logger.debug("Removed the router " + router + " from public network " + publicNetwork + " as a part of cleanup");
-                } else {
-                    s_logger.warn("Failed to remove the router " + router + " from public network " + publicNetwork + " as a part of cleanup");
-                }
-            }
-        }
-        
-        return result;
-    }
-    
-    
-    protected boolean removeRouterFromPublicNetwork(VirtualRouter router, Network publicNetwork) 
-            throws ConcurrentOperationException, ResourceUnavailableException {
-        
-        if (publicNetwork.getTrafficType() != TrafficType.Public) {
-            s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public);
-            return false;
-        }
-        
-        //Check if router is a part of the Guest network
-        if (!_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) {
-            s_logger.debug("Router " + router + " is not a part of the Public network " + publicNetwork);
-            return true;
-        }
-        
-        String routerIpStr = router.getPublicIpAddress();
-        
-        IPAddressVO sourceNatIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNetwork.getId(), routerIpStr);
-        
-        assert sourceNatIp.isSourceNat() : "Ip " + sourceNatIp + " is not source nat";
-        
-        boolean result = true;
-        if (sourceNatIp != null) {
-            IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId());
-            _networkMgr.markIpAsUnavailable(ipVO.getId());
-            PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), 
-                    NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
-            result = setupPublicNetwork(publicNetwork, router, false, publicIp);
-        }
-        
-        if (!result) {
-            s_logger.warn("Failed to destroy public network config " + publicNetwork + " on router " + router);
-            return false;
-        }
-        
-        result = result && _itMgr.removeVmFromNetwork(router, publicNetwork);
-        
-        return result;
-    }
-    
-    protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add, PublicIp ipAddress) 
-            throws ConcurrentOperationException, ResourceUnavailableException{
-        
-        List<PublicIp> publicIps = new ArrayList<PublicIp>(1);
-        publicIps.add(ipAddress);
-        Commands cmds = new Commands(OnError.Stop);
-        createAssociateIPCommands(router, publicIps, cmds, 0);
-        sendCommandsToRouter(router, cmds);
-
-        boolean result = true;
-        IpAssocAnswer ipAssocAnswer = cmds.getAnswer(IpAssocAnswer.class);
-        String setup = add ? "set" : "destroy";
-        if (!(ipAssocAnswer != null && ipAssocAnswer.getResult())) {
-            s_logger.warn("Unable to " + setup + " public network on router " + router);
-            result = false;
-        }
-        
-        return result;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/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 67e37d5..39499aa 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -12,6 +12,9 @@
 // Automatically generated by addcopyright.py at 04/03/2012
 package com.cloud.network.router;
 
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -19,23 +22,51 @@ import javax.ejb.Local;
 
 import org.apache.log4j.Logger;
 
+import com.cloud.agent.AgentManager.OnError;
+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.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.SetSourceNatCommand;
+import com.cloud.agent.api.to.IpAddressTO;
+import com.cloud.agent.api.to.NicTO;
+import com.cloud.agent.api.to.VirtualMachineTO;
+import com.cloud.agent.manager.Commands;
+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.InsufficientVirtualNetworkCapcityException;
+import com.cloud.exception.OperationTimedoutException;
 import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.StorageUnavailableException;
+import com.cloud.network.IPAddressVO;
+import com.cloud.network.IpAddress;
 import com.cloud.network.Network;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
 import com.cloud.network.NetworkService;
+import com.cloud.network.Networks.BroadcastDomainType;
+import com.cloud.network.Networks.IsolationType;
+import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.network.PublicIpAddress;
 import com.cloud.network.VirtualRouterProvider;
 import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.network.VpcVirtualNetworkApplianceService;
 import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.PhysicalNetworkDao;
+import com.cloud.network.router.VirtualRouter.Role;
 import com.cloud.network.vpc.Vpc;
 import com.cloud.network.vpc.Dao.VpcDao;
 import com.cloud.network.vpc.Dao.VpcOfferingDao;
@@ -44,7 +75,12 @@ import com.cloud.utils.Pair;
 import com.cloud.utils.component.Inject;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
 import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.Nic;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.ReservationContext;
+import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VirtualMachineProfile.Param;
 
 /**
@@ -150,7 +186,454 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         
         boolean setupDns = dnsProvided || dhcpProvided;
         
-        return super.addRouterToGuestNetwork(router, network, isRedundant, setupDns);
+        return addVpcRouterToGuestNetwork(router, network, isRedundant, setupDns);
     }
     
+    protected boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant, boolean setupDns) 
+            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
+        
+        if (network.getTrafficType() != TrafficType.Guest) {
+            s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
+            return false;
+        }
+        
+        //Add router to the Guest network
+        boolean result = true;
+        try {
+            if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
+                DomainRouterVO routerVO = _routerDao.findById(router.getId());
+                _routerDao.addRouterToGuestNetwork(routerVO, network);
+            } 
+            
+            NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null);
+            //setup guest network
+            if (guestNic != null) {
+                result = setupVpcGuestNetwork(network, router, true, isRedundant, guestNic, setupDns);
+            } else {
+                s_logger.warn("Failed to add router " + router + " to guest network " + network);
+                result = false;
+            }
+        } catch (Exception ex) {
+            s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex);
+            result = false;
+        } finally {
+            if (!result) {
+                s_logger.debug("Removing the router " + router + " from network " + network + " as a part of cleanup");
+                if (removeRouterFromGuestNetwork(router, network, isRedundant)) {
+                    s_logger.debug("Removed the router " + router + " from network " + network + " as a part of cleanup");
+                } else {
+                    s_logger.warn("Failed to remove the router " + router + " from network " + network + " as a part of cleanup");
+                }
+            }
+        }
+        
+        return result;
+    }
+
+    @Override
+    public boolean removeRouterFromGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) 
+            throws ConcurrentOperationException, ResourceUnavailableException {
+        if (network.getTrafficType() != TrafficType.Guest) {
+            s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
+            return false;
+        }
+        
+        //Check if router is a part of the Guest network
+        if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
+            s_logger.debug("Router " + router + " is not a part of the Guest network " + network);
+            return true;
+        }
+        
+        boolean result = setupVpcGuestNetwork(network, router, false, isRedundant, _networkMgr.getNicProfile(router, network.getId()), false);
+        if (!result) {
+            s_logger.warn("Failed to destroy guest network config " + network + " on router " + router);
+            return false;
+        }
+        
+        result = result && _itMgr.removeVmFromNetwork(router, network, null);
+        
+        if (result) {
+            if (result) {
+                //check if router is already part of network
+                if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
+                    s_logger.debug("Removing router " + router + " from network" + network);
+                    _routerDao.removeRouterFromNetwork(router.getId(), network.getId());
+                }
+            }
+        }
+        return result;
+    }
+    
+    protected boolean addPublicIpToVpc(VirtualRouter router, Network publicNetwork, PublicIp ipAddress) 
+            throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException {
+        
+        if (publicNetwork.getTrafficType() != TrafficType.Public) {
+            s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public);
+            return false;
+        }
+        
+        //Add router to the Public network
+        boolean result = true;
+        try {
+            NicProfile defaultNic = new NicProfile();
+            if (ipAddress.isSourceNat()) {
+                defaultNic.setDefaultNic(true);
+            }
+            defaultNic.setIp4Address(ipAddress.getAddress().addr());
+            defaultNic.setGateway(ipAddress.getGateway());
+            defaultNic.setNetmask(ipAddress.getNetmask());
+            defaultNic.setMacAddress(ipAddress.getMacAddress());
+            defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
+            defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ipAddress.getVlanTag()));
+            defaultNic.setIsolationUri(IsolationType.Vlan.toUri(ipAddress.getVlanTag()));
+            
+            NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork, defaultNic);
+            //setup public network
+            if (publicNic != null) {
+                publicNic.setDefaultNic(true);
+                if (ipAddress != null) {
+                    IPAddressVO ipVO = _ipAddressDao.findById(ipAddress.getId());
+                    PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), 
+                            NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
+                    result = associtePublicIpInVpc(publicNetwork, router, false, publicIp);
+                }
+            } else {
+                result = false;
+                s_logger.warn("Failed to plug nic for " + ipAddress + " to VPC router " + router);
+            }
+        } catch (Exception ex) {
+            s_logger.warn("Failed to add ip address " + ipAddress + " from the public network " + publicNetwork + 
+                    " to VPC router " + router + " due to ", ex);
+            result = false;
+        }
+        
+        return result;
+    }
+    
+    
+    protected boolean removePublicIpFromVpcRouter(VirtualRouter router, Network publicNetwork, PublicIp ipAddress) 
+            throws ConcurrentOperationException, ResourceUnavailableException {
+        
+        if (publicNetwork.getTrafficType() != TrafficType.Public) {
+            s_logger.warn("Network " + publicNetwork + " is not of type " + TrafficType.Public);
+            return false;
+        }
+                        
+        boolean result = true;
+        IPAddressVO ipVO = _ipAddressDao.findById(ipAddress.getId());
+        _networkMgr.markIpAsUnavailable(ipVO.getId());
+        PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()), 
+                NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
+        result = associtePublicIpInVpc(publicNetwork, router, false, publicIp);
+        
+        if (!result) {
+            s_logger.warn("Failed to disassociate public ip " + ipAddress  + " from router " + router);
+            return false;
+        }
+        
+        URI broadcastUri = BroadcastDomainType.Vlan.toUri(ipAddress.getVlanTag());
+        if (_itMgr.removeVmFromNetwork(router, publicNetwork, broadcastUri)) {
+            s_logger.debug("Successfully removed router " + router + " from vlan " + ipAddress.getVlanTag() +" of public network " + publicNetwork);
+            return true;
+        } else {
+            s_logger.warn("Failed to remove router " + router + " from vlan " + ipAddress.getVlanTag() +" of public network " + publicNetwork);
+            return false;
+        }
+    }
+    
+    protected boolean associtePublicIpInVpc(Network network, VirtualRouter router, boolean add, PublicIp ipAddress) 
+            throws ConcurrentOperationException, ResourceUnavailableException{
+        
+        //1) Associate ip addresses
+        List<PublicIp> publicIps = new ArrayList<PublicIp>(1);
+        publicIps.add(ipAddress);
+        Commands cmds = new Commands(OnError.Stop);
+        createVpcAssociateIPCommands(router, publicIps, cmds, 0);
+        String assoc = add ? "Associating " : "Disassociating";
+        StringBuilder debugMsg = new StringBuilder(assoc + " ip address " + ipAddress); 
+        
+        //2) If sourceNat, setup the source nat
+        if (ipAddress.isSourceNat()) {
+            Integer networkRate = _networkMgr.getNetworkRate(ipAddress.getNetworkId(), router.getId());
+            String vmGuestAddress = null;
+
+            IpAddressTO ip = new IpAddressTO(ipAddress.getAccountId(), ipAddress.getAddress().addr(), add, false, 
+                    true, ipAddress.getVlanTag(), ipAddress.getGateway(), ipAddress.getNetmask(), ipAddress.getMacAddress(),
+                    vmGuestAddress, networkRate, ipAddress.isOneToOneNat());
+            
+            
+
+            ip.setTrafficType(network.getTrafficType());
+            ip.setNetworkName(_networkMgr.getNetworkTag(router.getHypervisorType(), network));
+        
+            SetSourceNatCommand cmd = new SetSourceNatCommand(ip, true);
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddress.getNetworkId(), router.getId()));
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
+            DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn());
+            cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
+            String enable = add ? "enabling" : "disabling";
+            debugMsg.append(" and " + enable + " source nat for it");
+        }
+        
+        if (sendCommandsToRouter(router, cmds)) {
+            s_logger.debug("Successfully applied ip associatino for ip " + ipAddress + " in vpc network " + network);
+            return true;
+        } else {
+            s_logger.warn("Failed to associate ip address " + ipAddress + " in vpc network " + network);
+            return false;
+        }
+    }
+    
+    
+    @Override
+    public boolean finalizeStart(VirtualMachineProfile<DomainRouterVO> profile, long hostId, Commands cmds,
+            ReservationContext context) {
+        
+        if (!super.finalizeStart(profile, hostId, cmds, context)) {
+            return false;
+        }
+        
+        DomainRouterVO router = profile.getVirtualMachine();
+        
+        //Get guest nic info
+        Map<Nic, Network> guestNics = new HashMap<Nic, Network>();
+        Map<Nic, Network> publicNics = new HashMap<Nic, Network>();
+        List<Network> guestNetworks = new ArrayList<Network>();
+        
+        List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
+        for (Nic routerNic : routerNics) {
+            Network network = _networkMgr.getNetwork(routerNic.getNetworkId());
+            if (network.getTrafficType() == TrafficType.Guest) {
+                guestNics.put(routerNic, network);
+                guestNetworks.add(network);
+            } else if (network.getTrafficType() == TrafficType.Public) {
+                publicNics.put(routerNic, network);
+            }
+        }
+        
+        try {
+            //add router to public and guest networks
+            for (Nic publicNic : publicNics.keySet()) {
+                Network publicNtwk = publicNics.get(publicNic);
+                IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), 
+                        publicNic.getIp4Address());
+                PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), 
+                        NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
+                if (!addPublicIpToVpc(router, publicNtwk, publicIp)) {
+                    s_logger.warn("Failed to add router router " + router + " to public network " + publicNtwk);
+                    return false;
+                }
+            }
+            
+            for (Nic guestNic : guestNics.keySet()) {  
+                Network guestNtwk = guestNics.get(guestNic);
+                boolean setupDns = _networkMgr.setupDns(guestNtwk, Provider.VPCVirtualRouter);
+                
+                if (!addVpcRouterToGuestNetwork(router, guestNtwk, false, setupDns)) {
+                    s_logger.warn("Failed to add router router " + router + " to guest network " + guestNtwk);
+                    return false;
+                }
+            }
+        } catch (Exception ex) {
+            s_logger.warn("Failed to add router " + router + " to network due to exception ", ex);
+            return false;
+        }     
+
+        return true;
+    }
+    
+    protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
+            boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId,
+            Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, 
+            InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, 
+            StorageUnavailableException, ResourceUnavailableException {
+        
+        DomainRouterVO router = 
+                super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, sourceNatIp);
+        
+        //Plug public nic
+        boolean addToPublicNtwk = true;
+        if (sourceNatIp != null) {
+            Network publicNetwork = _networkDao.listByZoneAndTrafficType(dest.getDataCenter().getId(), TrafficType.Public).get(0);
+            addToPublicNtwk = addPublicIpToVpc(router, publicNetwork, sourceNatIp); 
+        }
+        
+        if (!addToPublicNtwk) {
+            s_logger.warn("Failed to add router " + router + " to public network in zone " + dest.getDataCenter() + " cleaninig up");
+            destroyRouter(router.getId());
+            return null;
+        }
+        
+        return router;
+    }
+    
+    @Override
+    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, 
+            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
+            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;
+            } 
+
+        } catch (OperationTimedoutException e) {
+            throw new AgentUnavailableException("Unable to plug nic for router " + vm.getHostName() + " in network " + network,
+                    dest.getHost().getId(), e);
+        }
+        
+        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());
+        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);
+        }
+        
+        return result;
+    }
+    
+    protected boolean setupVpcGuestNetwork(Network network, VirtualRouter router, boolean add, boolean isRedundant,
+            NicProfile guestNic, boolean setupDns) 
+            throws ConcurrentOperationException, ResourceUnavailableException{
+        
+        String networkDomain = network.getNetworkDomain();
+        String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId()));
+        
+        boolean result = true;
+        
+        Nic nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
+        long guestVlanTag = Long.parseLong(nic.getBroadcastUri().getHost());
+        
+        String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask()));
+        Integer priority = null;
+        if (isRedundant) {
+            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            try {
+                getUpdatedPriority(network, routers, _routerDao.findById(router.getId()));
+            } catch (InsufficientVirtualNetworkCapcityException e) {
+                s_logger.error("Failed to get update priority!", e);
+                throw new CloudRuntimeException("Failed to get update priority!");
+            }
+        }
+        
+        String defaultDns1 = null;
+        String defaultDns2 = null;
+        
+        if (setupDns) {
+            defaultDns1 = guestNic.getDns1();
+            defaultDns2 = guestNic.getDns2();
+        }
+        
+        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 
+                _networkMgr.getNetworkRate(network.getId(), router.getId()), 
+                _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network));
+
+        SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority, 
+                defaultDns1, defaultDns2, add, _itMgr.toNicTO(nicProfile, router.getHypervisorType()));
+        setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
+        setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId()));
+        setupCmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag));
+        setupCmd.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, network.getGateway());
+        setupCmd.setAccessDetail(NetworkElementCommand.GUEST_BRIDGE, brd);
+        setupCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
+        
+        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;
+    }
+    
+    private void createVpcAssociateIPCommands(final VirtualRouter router, final List<? extends PublicIpAddress> ips, Commands cmds, long vmId) {
+
+        // Ensure that in multiple vlans case we first send all ip addresses of vlan1, then all ip addresses of vlan2, etc..
+        Map<String, ArrayList<PublicIpAddress>> vlanIpMap = new HashMap<String, ArrayList<PublicIpAddress>>();
+        for (final PublicIpAddress ipAddress : ips) {
+            String vlanTag = ipAddress.getVlanTag();
+            ArrayList<PublicIpAddress> ipList = vlanIpMap.get(vlanTag);
+            if (ipList == null) {
+                ipList = new ArrayList<PublicIpAddress>();
+            }
+            //VR doesn't support release for sourceNat IP address; so reset the state
+            if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) {
+                ipAddress.setState(IpAddress.State.Allocated);
+            }
+            ipList.add(ipAddress);
+            vlanIpMap.put(vlanTag, ipList);
+        }
+
+        for (Map.Entry<String, ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
+            List<PublicIpAddress> ipAddrList = vlanAndIp.getValue();
+
+            // Get network rate - required for IpAssoc
+            Integer networkRate = _networkMgr.getNetworkRate(ipAddrList.get(0).getNetworkId(), router.getId());
+            Network network = _networkMgr.getNetwork(ipAddrList.get(0).getNetworkId());
+
+            IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()];
+            int i = 0;
+
+            for (final PublicIpAddress ipAddr : ipAddrList) {
+                boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true);
+                boolean sourceNat = ipAddr.isSourceNat();
+                String vlanId = ipAddr.getVlanTag();
+                String vlanGateway = ipAddr.getGateway();
+                String vlanNetmask = ipAddr.getNetmask();
+                String vifMacAddress = ipAddr.getMacAddress();
+
+                String vmGuestAddress = null;
+
+                IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false, 
+                        sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate, ipAddr.isOneToOneNat());
+
+                ip.setTrafficType(network.getTrafficType());
+                ip.setNetworkName(_networkMgr.getNetworkTag(router.getHypervisorType(), network));
+                ipsToSend[i++] = ip;
+            }
+            IpAssocVpcCommand cmd = new IpAssocVpcCommand(ipsToSend);
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(ipAddrList.get(0).getNetworkId(), router.getId()));
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
+            DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn());
+            cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
+
+            cmds.addCommand("IPAssocVpcCommand", cmd);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/server/src/com/cloud/vm/VirtualMachineManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java
index 049875b..56dc483 100644
--- a/server/src/com/cloud/vm/VirtualMachineManager.java
+++ b/server/src/com/cloud/vm/VirtualMachineManager.java
@@ -12,11 +12,11 @@
 // Automatically generated by addcopyright.py at 04/03/2012
 package com.cloud.vm;
 
+import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
 import com.cloud.agent.api.to.NicTO;
-import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.exception.AgentUnavailableException;
@@ -150,11 +150,12 @@ public interface VirtualMachineManager extends Manager {
     /**
      * @param vm
      * @param network
+     * @param broadcastUri TODO
      * @return
      * @throws ResourceUnavailableException 
      * @throws ConcurrentOperationException 
      */
-    boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException;
+    boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException;
 
     /**
      * @param nic

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/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 50990e6..06699ae 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -12,6 +12,7 @@
 // Automatically generated by addcopyright.py at 04/03/2012
 package com.cloud.vm;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -2449,9 +2450,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
         DeployDestination dest = new DeployDestination(dc, null, null, host);
         
         NicProfile nic = null;
-        NicVO nicVO = _nicsDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
-        if (nicVO != null) {
-            nic = _networkMgr.getNicProfile(vm, network.getId());
+        String broadcastUri = null;
+        if (requested != null && requested.getBroadCastUri() != null) {
+            broadcastUri = requested.getBroadCastUri().toString();
+            NicVO nicVO = _nicsDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
+            if (nicVO != null) {
+                nic = _networkMgr.getNicProfile(vm, network.getId());
+            }
         }
         
         if (nic == null) {
@@ -2503,7 +2508,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
     }
     
     @Override
-    public boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException {
+    public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
         VMInstanceVO vmVO = _vmDao.findById(vm.getId());
         NetworkVO networkVO = _networkDao.findById(network.getId());
         ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), 
@@ -2517,7 +2522,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
         DeployDestination dest = new DeployDestination(dc, null, null, host);
         
         //1) Release the nic
-        NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO);
+        NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO, broadcastUri);
         
         //2) Convert vmProfile to vmTO
         VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/server/src/com/cloud/vm/dao/NicDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/NicDao.java b/server/src/com/cloud/vm/dao/NicDao.java
index 9a62467..3dca809 100644
--- a/server/src/com/cloud/vm/dao/NicDao.java
+++ b/server/src/com/cloud/vm/dao/NicDao.java
@@ -48,4 +48,6 @@ public interface NicDao extends GenericDao<NicVO, Long> {
     String getIpAddress(long networkId, long instanceId);
     
     int countNics(long instanceId);
+    
+    NicVO findByInstanceIdNetworkIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/server/src/com/cloud/vm/dao/NicDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java
index baa75cd..77f54ce 100644
--- a/server/src/com/cloud/vm/dao/NicDaoImpl.java
+++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java
@@ -22,8 +22,8 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.vm.Nic.State;
 import com.cloud.vm.Nic;
+import com.cloud.vm.Nic.State;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.VirtualMachine;
 
@@ -44,6 +44,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
         AllFieldsSearch.and("vmType", AllFieldsSearch.entity().getVmType(), Op.EQ);
         AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ);
         AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultNic(), Op.EQ);
+        AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ);
         AllFieldsSearch.done();
         
         IpSearch = createSearchBuilder(String.class);
@@ -166,4 +167,14 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
         return results.get(0);
     }
 
+
+    @Override
+    public NicVO findByInstanceIdNetworkIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri) {
+        SearchCriteria<NicVO> sc = AllFieldsSearch.create();
+        sc.setParameters("network", networkId);
+        sc.setParameters("instance", instanceId);
+        sc.setParameters("broadcastUri", broadcastUri);
+        return findOneBy(sc);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java
index 465a4a4..1338955 100755
--- a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java
+++ b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java
@@ -249,7 +249,7 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager {
      * @see com.cloud.vm.VirtualMachineManager#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network)
      */
     @Override
-    public boolean removeVmFromNetwork(VirtualMachine vm, Network network) {
+    public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) {
         // TODO Auto-generated method stub
         return false;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/982562b9/wscript
----------------------------------------------------------------------
diff --git a/wscript b/wscript
index 7041a99..96c75d0 100644
--- a/wscript
+++ b/wscript
@@ -5,7 +5,7 @@
 # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
 
 
-VERSION = '3.0.3.2012-06-11T22:40:12Z'
+VERSION = '3.0.3.2012-06-12T00:24:56Z'
 APPNAME = 'cloud'
 
 import shutil,os


Mime
View raw message