You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ke...@apache.org on 2013/02/01 02:29:16 UTC

[38/43] git commit: refs/heads/javelin - Merge branch 'ipv6'

Merge branch 'ipv6'

Conflicts:
	api/src/com/cloud/network/NetworkProfile.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/5cb9df91
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/5cb9df91
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/5cb9df91

Branch: refs/heads/javelin
Commit: 5cb9df91a1db8e489e65ac8f43154105875963f2
Parents: 44d1397 ed777bb
Author: Sheng Yang <sh...@citrix.com>
Authored: Thu Jan 31 15:07:33 2013 -0800
Committer: Sheng Yang <sh...@citrix.com>
Committed: Thu Jan 31 15:07:33 2013 -0800

----------------------------------------------------------------------
 .../cloud/agent/api/routing/DhcpEntryCommand.java  |   35 ++-
 api/src/com/cloud/dc/Vlan.java                     |    5 +
 api/src/com/cloud/network/Network.java             |   34 ++-
 api/src/com/cloud/network/NetworkModel.java        |    1 +
 api/src/com/cloud/network/NetworkProfile.java      |   14 +
 api/src/com/cloud/network/Networks.java            |    2 +-
 api/src/com/cloud/vm/Nic.java                      |    6 +
 api/src/com/cloud/vm/NicProfile.java               |   42 ++-
 api/src/com/cloud/vm/UserVmService.java            |   14 +-
 .../org/apache/cloudstack/api/ApiConstants.java    |    5 +
 .../api/command/user/network/CreateNetworkCmd.java |   46 +++-
 .../api/command/user/vm/DeployVMCmd.java           |   45 ++-
 .../cloudstack/api/response/NetworkResponse.java   |   14 +
 .../cloudstack/api/response/NicResponse.java       |   22 ++-
 .../api/response/VlanIpRangeResponse.java          |   33 ++
 client/tomcatconf/components.xml.in                |    1 +
 .../virtualnetwork/VirtualRoutingResource.java     |    9 +-
 patches/systemvm/debian/config/etc/dnsmasq.conf    |  278 ++++++++++++---
 .../debian/config/etc/init.d/cloud-early-config    |   67 +++-
 patches/systemvm/debian/config/etc/sysctl.conf     |    6 +-
 patches/systemvm/debian/config/root/edithosts.sh   |  116 +++++--
 .../networkservice/BaremetalDhcpManagerImpl.java   |    4 +-
 .../hypervisor/vmware/resource/VmwareResource.java |   19 +-
 .../xen/resource/CitrixResourceBase.java           |    9 +-
 pom.xml                                            |    1 +
 scripts/network/domr/dhcp_entry.sh                 |   68 ++--
 server/src/com/cloud/api/ApiResponseHelper.java    |   21 +-
 .../cloud/baremetal/ExternalDhcpManagerImpl.java   |    2 +-
 .../cloud/configuration/ConfigurationManager.java  |    2 +-
 .../configuration/ConfigurationManagerImpl.java    |  245 ++++++++-----
 .../configuration/DefaultComponentLibrary.java     |    4 +
 server/src/com/cloud/dc/VlanVO.java                |   43 +++-
 .../src/com/cloud/network/Ipv6AddressManager.java  |   28 ++
 .../com/cloud/network/Ipv6AddressManagerImpl.java  |  132 +++++++
 server/src/com/cloud/network/NetworkManager.java   |    4 +-
 .../src/com/cloud/network/NetworkManagerImpl.java  |  119 +++++--
 server/src/com/cloud/network/NetworkModelImpl.java |   37 ++-
 .../src/com/cloud/network/NetworkServiceImpl.java  |  143 ++++++--
 server/src/com/cloud/network/NetworkVO.java        |   24 ++
 server/src/com/cloud/network/UserIpv6Address.java  |   52 +++
 .../src/com/cloud/network/UserIpv6AddressVO.java   |  188 ++++++++++
 server/src/com/cloud/network/addr/PublicIp.java    |   15 +
 .../com/cloud/network/dao/UserIpv6AddressDao.java  |   23 ++
 .../cloud/network/dao/UserIpv6AddressDaoImpl.java  |   96 +++++
 .../network/element/VirtualRouterElement.java      |    5 +
 .../com/cloud/network/guru/DirectNetworkGuru.java  |   49 ++-
 .../network/guru/DirectPodBasedNetworkGuru.java    |    2 +-
 .../network/guru/ExternalGuestNetworkGuru.java     |    2 +-
 .../com/cloud/network/guru/GuestNetworkGuru.java   |    4 +-
 .../cloud/network/guru/PodBasedNetworkGuru.java    |    2 +-
 .../com/cloud/network/guru/PublicNetworkGuru.java  |    2 +-
 .../router/VirtualNetworkApplianceManagerImpl.java |   28 ++-
 .../src/com/cloud/network/vpc/VpcManagerImpl.java  |    2 +-
 server/src/com/cloud/vm/NicVO.java                 |   25 ++
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   60 +++-
 .../com/cloud/network/MockNetworkManagerImpl.java  |    4 +-
 .../com/cloud/network/MockNetworkModelImpl.java    |    6 +
 .../test/com/cloud/vm/MockUserVmManagerImpl.java   |    9 +-
 .../cloud/vpc/MockConfigurationManagerImpl.java    |    2 +-
 .../test/com/cloud/vpc/MockNetworkManagerImpl.java |   10 +-
 setup/db/create-schema.sql                         |   32 ++
 utils/pom.xml                                      |    5 +
 utils/src/com/cloud/utils/net/NetUtils.java        |  114 ++++++
 utils/test/com/cloud/utils/net/NetUtilsTest.java   |   35 ++-
 64 files changed, 2082 insertions(+), 390 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/api/src/com/cloud/network/Network.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/api/src/com/cloud/network/NetworkProfile.java
----------------------------------------------------------------------
diff --cc api/src/com/cloud/network/NetworkProfile.java
index bb59b04,cce4897..e3be941
--- a/api/src/com/cloud/network/NetworkProfile.java
+++ b/api/src/com/cloud/network/NetworkProfile.java
@@@ -226,8 -230,14 +230,18 @@@ public class NetworkProfile implements 
          return vpcId;
      }
  
 +    @Override
 +    public void setTrafficType(TrafficType type) {
 +        this.trafficType = type;
 +    }
++
+ 	@Override
+ 	public String getIp6Gateway() {
+ 		return ip6Gateway;
+ 	}
+ 
+ 	@Override
+ 	public String getIp6Cidr() {
+ 		return ip6Cidr;
+ 	}
 -
  }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/api/src/com/cloud/vm/UserVmService.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/ApiConstants.java
index d242830,1537478..6d2a9a3
mode 100755,100644..100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/api/src/org/apache/cloudstack/api/response/NicResponse.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
----------------------------------------------------------------------
diff --cc plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
index ae8482c,0000000..e20dd0d
mode 100755,000000..100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
@@@ -1,323 -1,0 +1,323 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with 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 01/29/2013
 +// Apache License, Version 2.0 (the "License"); you may not use this
 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 +// 
 +// Automatically generated by addcopyright.py at 04/03/2012
 +package com.cloud.baremetal.networkservice;
 +
 +import java.net.URI;
 +import java.util.ArrayList;
 +import java.util.HashMap;
 +import java.util.List;
 +import java.util.Map;
 +
 +import javax.ejb.Local;
 +import javax.naming.ConfigurationException;
 +
 +import org.apache.log4j.Logger;
 +
 +import com.cloud.agent.AgentManager;
 +import com.cloud.agent.api.Answer;
 +import com.cloud.agent.api.StartupCommand;
 +import com.cloud.agent.api.StartupExternalDhcpCommand;
 +import com.cloud.agent.api.routing.DhcpEntryCommand;
 +import com.cloud.baremetal.database.BaremetalDhcpDao;
 +import com.cloud.baremetal.database.BaremetalDhcpVO;
 +import com.cloud.dc.DataCenter;
 +import com.cloud.dc.DataCenterVO;
 +import com.cloud.dc.HostPodVO;
 +import com.cloud.dc.dao.DataCenterDao;
 +import com.cloud.dc.dao.HostPodDao;
 +import com.cloud.deploy.DeployDestination;
 +import com.cloud.exception.ResourceUnavailableException;
 +import com.cloud.host.Host;
 +import com.cloud.host.Host.Type;
 +import com.cloud.host.HostVO;
 +import com.cloud.host.dao.HostDao;
 +import com.cloud.network.Network;
 +import com.cloud.network.PhysicalNetworkServiceProvider;
 +import com.cloud.network.PhysicalNetworkVO;
 +import com.cloud.network.dao.PhysicalNetworkDao;
 +import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
 +import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
 +import com.cloud.resource.ResourceManager;
 +import com.cloud.resource.ResourceStateAdapter;
 +import com.cloud.resource.ServerResource;
 +import com.cloud.resource.UnableDeleteHostException;
 +import com.cloud.utils.component.Inject;
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.SearchCriteria.Op;
 +import com.cloud.utils.db.SearchCriteria2;
 +import com.cloud.utils.db.SearchCriteriaService;
 +import com.cloud.utils.db.Transaction;
 +import com.cloud.utils.exception.CloudRuntimeException;
 +import com.cloud.vm.NicProfile;
 +import com.cloud.vm.ReservationContext;
 +import com.cloud.vm.VirtualMachine;
 +import com.cloud.vm.VirtualMachineProfile;
 +import com.cloud.vm.dao.NicDao;
 +import com.cloud.vm.dao.UserVmDao;
 +
 +@Local(value = { BaremetalDhcpManager.class })
 +public class BaremetalDhcpManagerImpl implements BaremetalDhcpManager, ResourceStateAdapter {
 +    private static final org.apache.log4j.Logger s_logger = Logger.getLogger(BaremetalDhcpManagerImpl.class);
 +    protected String _name;
 +    @Inject
 +    DataCenterDao _dcDao;
 +    @Inject
 +    HostDao _hostDao;
 +    @Inject
 +    AgentManager _agentMgr;
 +    @Inject
 +    HostPodDao _podDao;
 +    @Inject
 +    UserVmDao _userVmDao;
 +    @Inject
 +    ResourceManager _resourceMgr;
 +    @Inject
 +    NicDao _nicDao;
 +    @Inject
 +    PhysicalNetworkDao _physicalNetworkDao;
 +    @Inject
 +    PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
 +    @Inject
 +    BaremetalDhcpDao _extDhcpDao;
 +
 +    @Override
 +    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
 +        _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
 +        return true;
 +    }
 +
 +    @Override
 +    public boolean start() {
 +        return true;
 +    }
 +
 +    @Override
 +    public boolean stop() {
 +        _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
 +        return true;
 +    }
 +
 +    @Override
 +    public String getName() {
 +        return _name;
 +    }
 +
 +    protected String getDhcpServerGuid(String zoneId, String name, String ip) {
 +        return zoneId + "-" + name + "-" + ip;
 +    }
 +
 +    @Override
 +    public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> profile,
 +            DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
 +        Long zoneId = profile.getVirtualMachine().getDataCenterIdToDeployIn();
 +        Long podId = profile.getVirtualMachine().getPodIdToDeployIn();
 +        List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId);
 +        if (hosts.size() == 0) {
 +            throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId);
 +        }
 +
 +        if (hosts.size() > 1) {
 +            throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId);
 +        }
 +
 +        HostVO h = hosts.get(0);
 +        String dns = nic.getDns1();
 +        if (dns == null) {
 +            dns = nic.getDns2();
 +        }
-         DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName(), dns,
-                 nic.getGateway());
++        DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName(), null, dns,
++                nic.getGateway(), null);
 +        String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(),
 +                nic.getIp4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName());
 +        // prepareBareMetalDhcpEntry(nic, dhcpCommand);
 +        try {
 +            Answer ans = _agentMgr.send(h.getId(), dhcpCommand);
 +            if (ans.getResult()) {
 +                s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(),
 +                        nic.getIp4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
 +                return true;
 +            } else {
 +                s_logger.debug(errMsg + " " + ans.getDetails());
 +                throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId);
 +            }
 +        } catch (Exception e) {
 +            s_logger.debug(errMsg, e);
 +            throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId);
 +        }
 +    }
 +
 +    @Override
 +    public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
 +        // TODO Auto-generated method stub
 +        return null;
 +    }
 +
 +    @Override
 +    public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details,
 +            List<String> hostTags) {
 +        if (!(startup[0] instanceof StartupExternalDhcpCommand)) {
 +            return null;
 +        }
 +
 +        host.setType(Host.Type.BaremetalDhcp);
 +        return host;
 +    }
 +
 +    @Override
 +    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
 +        // TODO Auto-generated method stub
 +        return null;
 +    }
 +
 +
 +    @Override
 +    @DB
 +    public BaremetalDhcpVO addDchpServer(AddBaremetalDhcpCmd cmd) {
 +        PhysicalNetworkVO pNetwork = null;
 +        long zoneId;
 +
 +        if (cmd.getPhysicalNetworkId() == null || cmd.getUrl() == null || cmd.getUsername() == null || cmd.getPassword() == null) {
 +            throw new IllegalArgumentException("At least one of the required parameters(physical network id, url, username, password) is null");
 +        }
 +
 +        pNetwork = _physicalNetworkDao.findById(cmd.getPhysicalNetworkId());
 +        if (pNetwork == null) {
 +            throw new IllegalArgumentException("Could not find phyical network with ID: " + cmd.getPhysicalNetworkId());
 +        }
 +        zoneId = pNetwork.getDataCenterId();
 +        DataCenterVO zone = _dcDao.findById(zoneId);
 +
 +        PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(),
 +        		BaremetalDhcpManager.BAREMETAL_DHCP_SERVICE_PROVIDER.getName());
 +        if (ntwkSvcProvider == null) {
 +            throw new CloudRuntimeException("Network Service Provider: " + BaremetalDhcpManager.BAREMETAL_DHCP_SERVICE_PROVIDER.getName() + " is not enabled in the physical network: "
 +                    + cmd.getPhysicalNetworkId() + "to add this device");
 +        } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
 +            throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName()
 +                    + " is in shutdown state in the physical network: " + cmd.getPhysicalNetworkId() + "to add this device");
 +        }
 +
 +        HostPodVO pod = _podDao.findById(cmd.getPodId());
 +        if (pod == null) {
 +            throw new IllegalArgumentException("Could not find pod with ID: " + cmd.getPodId());
 +        }
 +
 +        List<HostVO> dhcps = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.BaremetalDhcp, null, cmd.getPodId(), zoneId);
 +        if (dhcps.size() != 0) {
 +            throw new IllegalArgumentException("Already had a DHCP server in Pod: " + cmd.getPodId() + " zone: " + zoneId);
 +        }
 +
 +        URI uri;
 +        try {
 +            uri = new URI(cmd.getUrl());
 +        } catch (Exception e) {
 +            s_logger.debug(e);
 +            throw new IllegalArgumentException(e.getMessage());
 +        }
 +
 +        String ipAddress = uri.getHost();
 +        String guid = getDhcpServerGuid(Long.toString(zoneId) + "-" + Long.toString(cmd.getPodId()), "ExternalDhcp", ipAddress);
 +        Map params = new HashMap<String, String>();
 +        params.put("type", cmd.getDhcpType());
 +        params.put("zone", Long.toString(zoneId));
 +        params.put("pod", cmd.getPodId().toString());
 +        params.put("ip", ipAddress);
 +        params.put("username", cmd.getUsername());
 +        params.put("password", cmd.getPassword());
 +        params.put("guid", guid);
 +        params.put("gateway", pod.getGateway());
 +        String dns = zone.getDns1();
 +        if (dns == null) {
 +            dns = zone.getDns2();
 +        }
 +        params.put("dns", dns);
 +
 +        ServerResource resource = null;
 +        try {
 +            if (cmd.getDhcpType().equalsIgnoreCase(BaremetalDhcpType.DNSMASQ.toString())) {
 +                resource = new BaremetalDnsmasqResource();
 +                resource.configure("Dnsmasq resource", params);
 +            } else if (cmd.getDhcpType().equalsIgnoreCase(BaremetalDhcpType.DHCPD.toString())) {
 +                resource = new BaremetalDhcpdResource();
 +                resource.configure("Dhcpd resource", params);
 +            } else {
 +                throw new CloudRuntimeException("Unsupport DHCP server type: " + cmd.getDhcpType());
 +            }
 +        } catch (Exception e) {
 +            s_logger.debug(e);
 +            throw new CloudRuntimeException(e.getMessage());
 +        }
 +
 +        Host dhcpServer = _resourceMgr.addHost(zoneId, resource, Host.Type.BaremetalDhcp, params);
 +        if (dhcpServer == null) {
 +            throw new CloudRuntimeException("Cannot add external Dhcp server as a host");
 +        }
 +
 +        BaremetalDhcpVO vo = new BaremetalDhcpVO();
 +        vo.setDeviceType(cmd.getDhcpType());
 +        vo.setHostId(dhcpServer.getId());
 +        vo.setNetworkServiceProviderId(ntwkSvcProvider.getId());
 +        vo.setPhysicalNetworkId(cmd.getPhysicalNetworkId());
 +        vo.setPodId(cmd.getPodId());
 +        Transaction txn = Transaction.currentTxn();
 +        txn.start();
 +        _extDhcpDao.persist(vo);
 +        txn.commit();
 +        return vo;
 +    }
 +
 +    @Override
 +    public BaremetalDhcpResponse generateApiResponse(BaremetalDhcpVO vo) {
 +        BaremetalDhcpResponse response = new BaremetalDhcpResponse();
 +        response.setDeviceType(vo.getDeviceType());
 +        response.setId(String.valueOf(vo.getId()));
 +        response.setPhysicalNetworkId(String.valueOf(vo.getPhysicalNetworkId()));
 +        response.setProviderId(String.valueOf(vo.getNetworkServiceProviderId()));
 +        return response;
 +    }
 +
 +    @Override
 +    public List<BaremetalDhcpResponse> listBaremetalDhcps(ListBaremetalDhcpCmd cmd) {
 +        SearchCriteriaService<BaremetalDhcpVO, BaremetalDhcpVO> sc = SearchCriteria2.create(BaremetalDhcpVO.class);
 +        if (cmd.getDeviceType() != null) {
 +        	sc.addAnd(sc.getEntity().getDeviceType(), Op.EQ, cmd.getDeviceType());
 +        }
 +        if (cmd.getPodId() != null) {
 +            sc.addAnd(sc.getEntity().getPodId(), Op.EQ, cmd.getPodId());
 +            if (cmd.getId() != null) {
 +                sc.addAnd(sc.getEntity().getId(), Op.EQ, cmd.getId());
 +            }
 +        }
 +        List<BaremetalDhcpVO> vos = sc.list();
 +        List<BaremetalDhcpResponse> responses = new ArrayList<BaremetalDhcpResponse>(vos.size());
 +        for (BaremetalDhcpVO vo : vos) {
 +            responses.add(generateApiResponse(vo));
 +        }
 +        return responses;
 +    }
 +
 +	@Override
 +	public List<Class<?>> getCommands() {
 +		return null;
 +	}
 +}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/src/com/cloud/network/NetworkManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index 3737450,1bc7edb..655d6c8
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -1031,237 -917,6 +1032,237 @@@ public class UserVmManagerImpl implemen
          return _vmDao.findById(vmInstance.getId());
      }
  
 +    @Override
 +    public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, CloudRuntimeException {
 +        Long vmId = cmd.getVmId();
 +        Long networkId = cmd.getNetworkId();
 +        String ipAddress = cmd.getIpAddress();
 +        Account caller = UserContext.current().getCaller();
 +
 +        UserVmVO vmInstance = _vmDao.findById(vmId);
 +        if(vmInstance == null) {
 +            throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
 +        }
 +        NetworkVO network = _networkDao.findById(networkId);
 +        if(network == null) {
 +            throw new InvalidParameterValueException("unable to find a network with id " + networkId);
 +        }
-         NicProfile profile = new NicProfile(null);
++        NicProfile profile = new NicProfile(null, null);
 +        if(ipAddress != null) {
-           profile = new NicProfile(ipAddress);
++          profile = new NicProfile(ipAddress, null);
 +        }
 +
 +        // Perform permission check on VM
 +        _accountMgr.checkAccess(caller, null, true, vmInstance);
 +
 +        // Verify that zone is not Basic
 +        DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterIdToDeployIn());
 +        if (dc.getNetworkType() == DataCenter.NetworkType.Basic) {
 +            throw new CloudRuntimeException("Zone " + vmInstance.getDataCenterIdToDeployIn() + ", has a NetworkType of Basic. Can't add a new NIC to a VM on a Basic Network");
 +        }
 +
 +        // Perform account permission check on network
 +        if (network.getGuestType() != Network.GuestType.Shared) {
 +            // Check account permissions
 +            List<NetworkVO> networkMap = _networkDao.listBy(caller.getId(), network.getId());
 +            if ((networkMap == null || networkMap.isEmpty() ) && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
 +                throw new PermissionDeniedException("Unable to modify a vm using network with id " + network.getId() + ", permission denied");
 +            }
 +        }
 +        
 +        //ensure network belongs in zone
 +        if (network.getDataCenterId() != vmInstance.getDataCenterIdToDeployIn()) {
 +            throw new CloudRuntimeException(vmInstance + " is in zone:" + vmInstance.getDataCenterIdToDeployIn() + " but " + network + " is in zone:" + network.getDataCenterId());
 +        }
 +
 +        if(_networkModel.getNicInNetwork(vmInstance.getId(),network.getId()) != null){
 +            s_logger.debug(vmInstance + " already in " + network + " going to add another NIC");
 +        } else {
 +            //* get all vms hostNames in the network
 +            List<String> hostNames = _vmInstanceDao.listDistinctHostNames(network.getId());
 +            //* verify that there are no duplicates
 +            if (hostNames.contains(vmInstance.getHostName())) {
 +                throw new CloudRuntimeException(network + " already has a vm with host name: '" + vmInstance.getHostName());
 +            }
 +        }
 +        
 +        NicProfile guestNic = null;
 +
 +        try {
 +            guestNic = _itMgr.addVmToNetwork(vmInstance, network, profile);
 +        } catch (ResourceUnavailableException e) {
 +            throw new CloudRuntimeException("Unable to add NIC to " + vmInstance + ": " + e);
 +        } catch (InsufficientCapacityException e) {
 +            throw new CloudRuntimeException("Insufficient capacity when adding NIC to " + vmInstance + ": " + e);
 +        } catch (ConcurrentOperationException e) {
 +            throw new CloudRuntimeException("Concurrent operations on adding NIC to " + vmInstance + ": " +e);
 +        }
 +        if (guestNic == null) {
 +            throw new CloudRuntimeException("Unable to add NIC to " + vmInstance);
 +        }
 +
 +        s_logger.debug("Successful addition of " + network + " from " + vmInstance);
 +        return _vmDao.findById(vmInstance.getId());
 +    }
 +
 +    @Override
 +    public UserVm removeNicFromVirtualMachine(RemoveNicFromVMCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, CloudRuntimeException {
 +        Long vmId = cmd.getVmId();
 +        Long nicId = cmd.getNicId();
 +        Account caller = UserContext.current().getCaller();
 +
 +        UserVmVO vmInstance = _vmDao.findById(vmId);
 +        if(vmInstance == null) {
 +            throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
 +        }
 +        NicVO nic = _nicDao.findById(nicId);
 +        if (nic == null){
 +            throw new InvalidParameterValueException("unable to find a nic with id " + nicId);
 +        }
 +        NetworkVO network = _networkDao.findById(nic.getNetworkId());
 +        if(network == null) {
 +            throw new InvalidParameterValueException("unable to find a network with id " + nic.getNetworkId());
 +        }
 +
 +        // Perform permission check on VM
 +        _accountMgr.checkAccess(caller, null, true, vmInstance);
 +
 +        // Verify that zone is not Basic
 +        DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterIdToDeployIn());
 +        if (dc.getNetworkType() == DataCenter.NetworkType.Basic) {
 +            throw new CloudRuntimeException("Zone " + vmInstance.getDataCenterIdToDeployIn() + ", has a NetworkType of Basic. Can't remove a NIC from a VM on a Basic Network");
 +        }
 +
 +        //check to see if nic is attached to VM
 +        if (nic.getInstanceId() != vmId) {
 +            throw new InvalidParameterValueException(nic + " is not a nic on  " + vmInstance);
 +        }
 +
 +        // Perform account permission check on network
 +        if (network.getGuestType() != Network.GuestType.Shared) {
 +            // Check account permissions
 +            List<NetworkVO> networkMap = _networkDao.listBy(caller.getId(), network.getId());
 +            if ((networkMap == null || networkMap.isEmpty() ) && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
 +                throw new PermissionDeniedException("Unable to modify a vm using network with id " + network.getId() + ", permission denied");
 +            }
 +        }
 +        
 +        boolean nicremoved = false;
 +
 +        try {
 +            nicremoved = _itMgr.removeNicFromVm(vmInstance, nic);
 +        } catch (ResourceUnavailableException e) {
 +            throw new CloudRuntimeException("Unable to remove " + network + " from " + vmInstance +": " + e);
 +            
 +        } catch (ConcurrentOperationException e) {
 +            throw new CloudRuntimeException("Concurrent operations on removing " + network + " from " + vmInstance + ": " + e);
 +        }
 +
 +        if (!nicremoved) {
 +            throw new CloudRuntimeException("Unable to remove " + network +  " from " + vmInstance );
 +        }
 +            
 +        s_logger.debug("Successful removal of " + network + " from " + vmInstance);
 +        return _vmDao.findById(vmInstance.getId());
 +
 +        
 +    }
 +    
 +    @Override
 +    public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) throws InvalidParameterValueException, CloudRuntimeException {
 +        Long vmId = cmd.getVmId();
 +        Long nicId = cmd.getNicId();
 +        Account caller = UserContext.current().getCaller();
 +        
 +        UserVmVO vmInstance = _vmDao.findById(vmId);
 +        if (vmInstance == null){
 +            throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
 +        }
 +        NicVO nic = _nicDao.findById(nicId);
 +        if (nic == null){
 +            throw new InvalidParameterValueException("unable to find a nic with id " + nicId);
 +        }
 +        NetworkVO network = _networkDao.findById(nic.getNetworkId());
 +        if (network == null){
 +            throw new InvalidParameterValueException("unable to find a network with id " + nic.getNetworkId());
 +        }
 +        
 +        // Perform permission check on VM
 +        _accountMgr.checkAccess(caller, null, true, vmInstance);
 +
 +        // Verify that zone is not Basic
 +        DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterIdToDeployIn());
 +        if (dc.getNetworkType() == DataCenter.NetworkType.Basic) {
 +            throw new CloudRuntimeException("Zone " + vmInstance.getDataCenterIdToDeployIn() + ", has a NetworkType of Basic. Can't change default NIC on a Basic Network");
 +        }
 +
 +        // no need to check permissions for network, we'll enumerate the ones they already have access to
 +        Network existingdefaultnet = _networkModel.getDefaultNetworkForVm(vmId);
 +        
 +        //check to see if nic is attached to VM
 +        if (nic.getInstanceId() != vmId) {
 +            throw new InvalidParameterValueException(nic + " is not a nic on  " + vmInstance);
 +        }
 +        // if current default equals chosen new default, Throw an exception
 +        if (nic.isDefaultNic()){
 +            throw new CloudRuntimeException("refusing to set default nic because chosen nic is already the default");
 +        }
 +
 +        //make sure the VM is Running or Stopped
 +        if ((vmInstance.getState() != State.Running) && (vmInstance.getState() != State.Stopped)) {
 +            throw new CloudRuntimeException("refusing to set default " + vmInstance + " is not Running or Stopped");
 +        }
 +        
 +        NicProfile existing = null;
 +        List<NicProfile> nicProfiles = _networkMgr.getNicProfiles(vmInstance);
 +        for (NicProfile nicProfile : nicProfiles) {
 +            if(nicProfile.isDefaultNic() && nicProfile.getNetworkId() == existingdefaultnet.getId()){
 +                existing = nicProfile;
 +                continue;
 +            }
 +        }
 +
 +        if (existing == null){
 +            s_logger.warn("Failed to update default nic, no nic profile found for existing default network");
 +            throw new CloudRuntimeException("Failed to find a nic profile for the existing default network. This is bad and probably means some sort of configuration corruption");
 +        }
 +
 +        NicVO existingVO = _nicDao.findById(existing.id);
 +        Integer chosenID = nic.getDeviceId();
 +        Integer existingID = existing.getDeviceId();
 +
 +        nic.setDefaultNic(true);
 +        nic.setDeviceId(existingID);
 +        existingVO.setDefaultNic(false);
 +        existingVO.setDeviceId(chosenID);
 +
 +        nic = _nicDao.persist(nic);
 +        existingVO = _nicDao.persist(existingVO);
 +
 +        Network newdefault = null;
 +        newdefault = _networkModel.getDefaultNetworkForVm(vmId);
 +        
 +        if (newdefault == null){
 +             nic.setDefaultNic(false);
 +             nic.setDeviceId(chosenID);
 +             existingVO.setDefaultNic(true);
 +             existingVO.setDeviceId(existingID);
 +
 +             nic = _nicDao.persist(nic);
 +             existingVO = _nicDao.persist(existingVO);
 +             
 +             newdefault = _networkModel.getDefaultNetworkForVm(vmId);
 +             if (newdefault.getId() == existingdefaultnet.getId()) {
 +                    throw new CloudRuntimeException("Setting a default nic failed, and we had no default nic, but we were able to set it back to the original");
 +             }
 +             throw new CloudRuntimeException("Failed to change default nic to " + nic + " and now we have no default");
 +        } else if (newdefault.getId() == nic.getNetworkId()) {
 +            s_logger.debug("successfully set default network to " + network + " for " + vmInstance);
 +            return _vmDao.findById(vmInstance.getId());
 +        }
 + 
 +        throw new CloudRuntimeException("something strange happened, new default network(" + newdefault.getId() + ") is not null, and is not equal to the network(" + nic.getNetworkId() + ") of the chosen nic");
 +    }
  
      @Override
      public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, String hostName, List<Long> vmIds) throws CloudRuntimeException {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/test/com/cloud/vm/MockUserVmManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5cb9df91/setup/db/create-schema.sql
----------------------------------------------------------------------