mirror of https://github.com/apache/cloudstack.git
VPC: added vpc_id to private_ip_address table to indicate which vpc the ip belongs to
This commit is contained in:
parent
0f575c2ecf
commit
1657486f41
|
|
@ -139,7 +139,7 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
|
|||
Network result = null;
|
||||
try {
|
||||
result = _networkService.createPrivateNetwork(getNetworkName(), getDisplayText(), getPhysicalNetworkId(), getVlan(),
|
||||
getStartIp(), getEndIp(), getGateway(), getNetmask(), getEntityOwnerId());
|
||||
getStartIp(), getEndIp(), getGateway(), getNetmask(), getEntityOwnerId(), null);
|
||||
} catch (InsufficientCapacityException ex){
|
||||
s_logger.info(ex);
|
||||
s_logger.trace(ex);
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{
|
|||
public void execute() {
|
||||
Vpc vpc = null;
|
||||
try {
|
||||
if (_vpcService.startVpc(this.getEntityId())) {
|
||||
if (_vpcService.startVpc(this.getEntityId(), true)) {
|
||||
vpc = _vpcService.getVpc(getEntityId());
|
||||
}
|
||||
} catch (ResourceUnavailableException ex) {
|
||||
|
|
|
|||
|
|
@ -157,13 +157,14 @@ public interface NetworkService {
|
|||
* @param gateway
|
||||
* @param netmask
|
||||
* @param networkOwnerId
|
||||
* @param vpcId TODO
|
||||
* @return
|
||||
* @throws InsufficientCapacityException
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws ResourceAllocationException
|
||||
*/
|
||||
Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan,
|
||||
String startIp, String endIP, String gateway, String netmask, long networkOwnerId)
|
||||
String startIp, String endIP, String gateway, String netmask, long networkOwnerId, Long vpcId)
|
||||
throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException;
|
||||
/**
|
||||
* @param network
|
||||
|
|
|
|||
|
|
@ -118,12 +118,13 @@ public interface VpcService {
|
|||
|
||||
/**
|
||||
* @param vpcId
|
||||
* @param destroyOnFailure TODO
|
||||
* @return
|
||||
* @throws InsufficientCapacityException
|
||||
* @throws ResourceUnavailableException
|
||||
* @throws ConcurrentOperationException
|
||||
*/
|
||||
boolean startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
|
||||
/**
|
||||
* @param vpcId
|
||||
|
|
|
|||
|
|
@ -294,4 +294,5 @@ public class NicProfile {
|
|||
public String toString() {
|
||||
return new StringBuilder("NicProfile[").append(id).append("-").append(vmId).append("-").append(reservationId).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ import com.cloud.vm.ReservationContext;
|
|||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachineProfileImpl;
|
||||
|
||||
/**
|
||||
* NetworkManager manages the network for the different end users.
|
||||
|
|
@ -460,6 +461,22 @@ public interface NetworkManager extends NetworkService {
|
|||
* @return
|
||||
*/
|
||||
boolean isPrivateGateway(Nic guestNic);
|
||||
|
||||
|
||||
/**
|
||||
* @param network
|
||||
* @param requested
|
||||
* @param context
|
||||
* @param vmProfile
|
||||
* @return
|
||||
* @throws InsufficientVirtualNetworkCapcityException
|
||||
* @throws InsufficientAddressCapacityException
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws InsufficientCapacityException
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
NicProfile allocateAndPrepareNic(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfileImpl<VMInstanceVO> vmProfile) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ import com.cloud.exception.PermissionDeniedException;
|
|||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.UnsupportedServiceException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
|
|
@ -208,6 +209,7 @@ import com.cloud.vm.VMInstanceVO;
|
|||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachineProfileImpl;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
|
@ -7248,7 +7250,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
@Override @DB
|
||||
public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId,
|
||||
String vlan, String startIp, String endIp, String gateway, String netmask, long networkOwnerId)
|
||||
String vlan, String startIp, String endIp, String gateway, String netmask, long networkOwnerId, Long vpcId)
|
||||
throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
|
||||
|
||||
Account owner = _accountMgr.getAccount(networkOwnerId);
|
||||
|
|
@ -7313,7 +7315,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
Long nextMac = mac + 1;
|
||||
dc.setMacAddress(nextMac);
|
||||
|
||||
privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac);
|
||||
privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac, vpcId);
|
||||
_privateIpDao.persist(privateIp);
|
||||
|
||||
_dcDao.update(dc.getId(), dc);
|
||||
|
|
@ -7357,4 +7359,56 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicProfile allocateAndPrepareNic(Network network, NicProfile requested, ReservationContext context,
|
||||
VirtualMachineProfileImpl<VMInstanceVO> vmProfile)
|
||||
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException,
|
||||
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
|
||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||
NetworkVO networkVO = _networksDao.findById(network.getId());
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
Host host = _hostDao.findById(vm.getHostId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
||||
|
||||
NicProfile nic = null;
|
||||
String broadcastUri = null;
|
||||
if (requested != null && requested.getBroadCastUri() != null) {
|
||||
broadcastUri = requested.getBroadCastUri().toString();
|
||||
NicVO nicVO = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
|
||||
if (nicVO != null) {
|
||||
nic = getNicProfile(vm, network.getId());
|
||||
}
|
||||
} else {
|
||||
NicVO nicVO = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
|
||||
if (nicVO != null) {
|
||||
nic = getNicProfile(vm, network.getId());
|
||||
}
|
||||
}
|
||||
|
||||
//1) allocate nic (if needed)
|
||||
if (nic == null) {
|
||||
s_logger.debug("Allocating nic for the " + vm + " in network " + network);
|
||||
int deviceId = _nicDao.countNics(vm.getId());
|
||||
|
||||
nic = allocateNic(requested, network, false,
|
||||
deviceId, vmProfile).first();
|
||||
|
||||
if (nic == null) {
|
||||
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
|
||||
}
|
||||
|
||||
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
|
||||
|
||||
|
||||
|
||||
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
|
||||
}
|
||||
|
||||
//2) prepare nic
|
||||
nic = prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
|
||||
|
||||
return nic;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
return null;
|
||||
}
|
||||
|
||||
NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(),
|
||||
NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Vlan, offering.getId(),
|
||||
State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId());
|
||||
if (userSpecified != null) {
|
||||
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
|
||||
|
|
@ -175,10 +175,9 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
|
||||
|
||||
protected void getIp(NicProfile nic, DataCenter dc, Network network)
|
||||
throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
throws InsufficientVirtualNetworkCapcityException,InsufficientAddressCapacityException {
|
||||
if (nic.getIp4Address() == null) {
|
||||
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId());
|
||||
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), null);
|
||||
String vlanTag = network.getBroadcastUri().getHost();
|
||||
String netmask = NetUtils.getCidrNetmask(network.getCidr());
|
||||
PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask, ipVO.getMacAddress());
|
||||
|
|
|
|||
|
|
@ -1257,8 +1257,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
//3) deploy virtual router(s)
|
||||
int count = routerCount - routers.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
List<Pair<NetworkVO, NicProfile>> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork,
|
||||
new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
|
||||
DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId,
|
||||
null, publicNetwork, guestNetwork, new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
|
||||
null, networks);
|
||||
//add router to router network map
|
||||
if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
|
||||
DomainRouterVO routerVO = _routerDao.findById(router.getId());
|
||||
|
|
@ -1276,7 +1278,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
|
||||
protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
|
||||
boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId,
|
||||
Long vpcId, boolean setupPublicNetwork, Network guestNetwork, Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException,
|
||||
Long vpcId, List<Pair<NetworkVO, NicProfile>> networks) throws ConcurrentOperationException,
|
||||
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
|
||||
StorageUnavailableException, ResourceUnavailableException {
|
||||
|
||||
|
|
@ -1284,15 +1286,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Creating the router " + id + " in datacenter " + dest.getDataCenter());
|
||||
}
|
||||
|
||||
//1) Create router networks
|
||||
List<Pair<NetworkVO, NicProfile>> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork,
|
||||
publicNetwork);
|
||||
|
||||
|
||||
ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
|
||||
|
||||
//2) Router is the network element, we don't know the hypervisor type yet.
|
||||
// Router is the network element, we don't know the hypervisor type yet.
|
||||
//Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up
|
||||
List<HypervisorType> supportedHypervisors = new ArrayList<HypervisorType>();
|
||||
HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
|
||||
|
|
@ -1456,7 +1453,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
networks.add(new Pair<NetworkVO, NicProfile>(publicNetworks.get(0), defaultNic));
|
||||
}
|
||||
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ 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.NetworkVO;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.IsolationType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
|
@ -396,10 +398,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
|
||||
StorageUnavailableException, ResourceUnavailableException {
|
||||
|
||||
|
||||
List<Pair<NetworkVO, NicProfile>> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),
|
||||
vpcId);
|
||||
DomainRouterVO router =
|
||||
super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, false,
|
||||
null, new Pair<Boolean, PublicIp>(true, sourceNatIp));
|
||||
super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
|
@ -807,6 +809,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//4) PREPARE PLUG NIC COMMANDS
|
||||
try {
|
||||
//add VPC router to public networks
|
||||
List<PublicIp> sourceNat = new ArrayList<PublicIp>(1);
|
||||
|
|
@ -867,7 +873,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return false;
|
||||
}
|
||||
|
||||
//3) RE-APPLY ALL STATIC ROUTE RULES
|
||||
//5) RE-APPLY ALL STATIC ROUTE RULES
|
||||
List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(router.getVpcId());
|
||||
List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
|
||||
Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
|
||||
|
|
@ -886,9 +892,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
createStaticRouteCommands(staticRouteProfiles, router, cmds);
|
||||
}
|
||||
|
||||
//4) REISSUE VPN CONNECTION
|
||||
//6) REISSUE VPN CONNECTION
|
||||
|
||||
//5) REPROGRAM GUEST NETWORK
|
||||
//7) REPROGRAM GUEST NETWORK
|
||||
boolean reprogramGuestNtwks = true;
|
||||
if (profile.getParameter(Param.ReProgramGuestNetworks) != null
|
||||
&& (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
|
||||
|
|
@ -938,7 +944,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
boolean result = true;
|
||||
try {
|
||||
Network network = _networkMgr.getNetwork(gateway.getNetworkId());
|
||||
NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null);
|
||||
NicProfile requested = createPrivateNicProfile(gateway);
|
||||
|
||||
NicProfile guestNic = _itMgr.addVmToNetwork(router, network, requested);
|
||||
|
||||
//setup source nat
|
||||
if (guestNic != null) {
|
||||
|
|
@ -1174,4 +1182,45 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
cmds.addCommand("IPAssocVpcCommand", cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected List<Pair<NetworkVO, NicProfile>> createVpcRouterNetworks(Account owner, boolean isRedundant,
|
||||
DeploymentPlan plan, Pair<Boolean, PublicIp> publicNetwork, long vpcId) throws ConcurrentOperationException,
|
||||
InsufficientAddressCapacityException {
|
||||
|
||||
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(4);
|
||||
networks = super.createRouterNetworks(owner, isRedundant, plan, null, publicNetwork);
|
||||
|
||||
//allocate nic for private gateway if needed
|
||||
VpcGateway privateGateway = _vpcMgr.getPrivateGatewayForVpc(vpcId);
|
||||
if (privateGateway != null) {
|
||||
NicProfile privateNic = createPrivateNicProfile(privateGateway);
|
||||
Network privateNetwork = _networkMgr.getNetwork(privateGateway.getNetworkId());
|
||||
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork, privateNic));
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
@DB
|
||||
protected NicProfile createPrivateNicProfile(VpcGateway privateGateway) {
|
||||
Network network = _networkMgr.getNetwork(privateGateway.getNetworkId());
|
||||
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), privateGateway.getIp4Address());
|
||||
|
||||
NicProfile privateNic = new NicProfile();
|
||||
String vlanTag = network.getBroadcastUri().getHost();
|
||||
String netmask = NetUtils.getCidrNetmask(network.getCidr());
|
||||
PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask, ipVO.getMacAddress());
|
||||
|
||||
privateNic.setIp4Address(ip.getIpAddress());
|
||||
privateNic.setGateway(ip.getGateway());
|
||||
privateNic.setNetmask(ip.getNetmask());
|
||||
privateNic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
|
||||
privateNic.setBroadcastUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
|
||||
privateNic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
privateNic.setFormat(AddressFormat.Ip4);
|
||||
privateNic.setReservationId(String.valueOf(ip.getVlanTag()));
|
||||
privateNic.setMacAddress(ip.getMacAddress());
|
||||
return privateNic;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ public interface PrivateIpDao extends GenericDao<PrivateIpVO, Long>{
|
|||
/**
|
||||
* @param dcId
|
||||
* @param networkId
|
||||
* @param requestedIp TODO
|
||||
* @return
|
||||
*/
|
||||
PrivateIpVO allocateIpAddress(long dcId, long networkId);
|
||||
PrivateIpVO allocateIpAddress(long dcId, long networkId, String requestedIp);
|
||||
|
||||
/**
|
||||
* @param ipAddress
|
||||
|
|
@ -61,5 +62,13 @@ public interface PrivateIpDao extends GenericDao<PrivateIpVO, Long>{
|
|||
|
||||
int countByNetworkId(long ntwkId);
|
||||
|
||||
/**
|
||||
* @param vpcId
|
||||
* @param ip4Address
|
||||
* @return
|
||||
*/
|
||||
PrivateIpVO findByIpAndVpcId(long vpcId, String ip4Address);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public class PrivateIpDaoImpl extends GenericDaoBase<PrivateIpVO, Long> implemen
|
|||
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
CountAllocatedByNetworkId = createSearchBuilder(Integer.class);
|
||||
|
|
@ -66,11 +67,15 @@ public class PrivateIpDaoImpl extends GenericDaoBase<PrivateIpVO, Long> implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public PrivateIpVO allocateIpAddress(long dcId, long networkId) {
|
||||
public PrivateIpVO allocateIpAddress(long dcId, long networkId, String requestedIp) {
|
||||
SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("networkId", networkId);
|
||||
sc.setParameters("taken", (Date)null);
|
||||
|
||||
if (requestedIp != null) {
|
||||
sc.setParameters("ipAddress", requestedIp);
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
PrivateIpVO vo = lockOneRandomRow(sc, true);
|
||||
|
|
@ -99,9 +104,7 @@ public class PrivateIpDaoImpl extends GenericDaoBase<PrivateIpVO, Long> implemen
|
|||
update(vo, sc);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.network.vpc.Dao.PrivateIpDao#findByIpAndSourceNetworkId(long, java.lang.String)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public PrivateIpVO findByIpAndSourceNetworkId(long networkId, String ip4Address) {
|
||||
SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
|
||||
|
|
@ -110,6 +113,14 @@ public class PrivateIpDaoImpl extends GenericDaoBase<PrivateIpVO, Long> implemen
|
|||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrivateIpVO findByIpAndVpcId(long vpcId, String ip4Address) {
|
||||
SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("ip", ip4Address);
|
||||
sc.setParameters("vpcId", vpcId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrivateIpVO> listByNetworkId(long networkId) {
|
||||
SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
|
||||
|
|
|
|||
|
|
@ -19,5 +19,5 @@ import com.cloud.utils.db.GenericDao;
|
|||
* @author Alena Prokharchyk
|
||||
*/
|
||||
public interface VpcGatewayDao extends GenericDao<VpcGatewayVO, Long>{
|
||||
VpcGatewayVO getPrivateGateway(long vpcId);
|
||||
VpcGatewayVO getPrivateGatewayForVpc(long vpcId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class VpcGatewayDaoImpl extends GenericDaoBase<VpcGatewayVO, Long> implem
|
|||
|
||||
|
||||
@Override
|
||||
public VpcGatewayVO getPrivateGateway(long vpcId) {
|
||||
public VpcGatewayVO getPrivateGatewayForVpc(long vpcId) {
|
||||
SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("vpcId", vpcId);
|
||||
sc.setParameters("type", VpcGateway.Type.Private);
|
||||
|
|
|
|||
|
|
@ -49,13 +49,17 @@ public class PrivateIpVO{
|
|||
@Column(name="network_id", updatable=false, nullable=false)
|
||||
private long networkId;
|
||||
|
||||
@Column(name="vpc_id")
|
||||
private Long vpcId;
|
||||
|
||||
public PrivateIpVO() {
|
||||
}
|
||||
|
||||
public PrivateIpVO(String ipAddress, long networkId, long macAddress) {
|
||||
public PrivateIpVO(String ipAddress, long networkId, long macAddress, long vpcId) {
|
||||
this.ipAddress = ipAddress;
|
||||
this.networkId = networkId;
|
||||
this.macAddress = macAddress;
|
||||
this.vpcId = vpcId;
|
||||
}
|
||||
|
||||
public void setTakenAt(Date takenDate) {
|
||||
|
|
@ -81,4 +85,8 @@ public class PrivateIpVO{
|
|||
public long getMacAddress() {
|
||||
return macAddress;
|
||||
}
|
||||
|
||||
public Long getVpcId() {
|
||||
return vpcId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,4 +102,10 @@ public interface VpcManager extends VpcService{
|
|||
* @return
|
||||
*/
|
||||
boolean vpcProviderEnabledInZone(long zoneId);
|
||||
|
||||
/**
|
||||
* @param vpcId
|
||||
* @return
|
||||
*/
|
||||
VpcGateway getPrivateGatewayForVpc(long vpcId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -801,7 +801,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
public boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
InsufficientCapacityException {
|
||||
UserContext ctx = UserContext.current();
|
||||
Account caller = ctx.getCaller();
|
||||
|
|
@ -835,7 +835,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
result = false;
|
||||
} finally {
|
||||
//do cleanup
|
||||
if (!result) {
|
||||
if (!result && destroyOnFailure) {
|
||||
s_logger.debug("Destroying vpc " + vpc + " that failed to start");
|
||||
if (destroyVpc(vpc)) {
|
||||
s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start");
|
||||
|
|
@ -1032,7 +1032,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
}
|
||||
|
||||
//3) Delete private gateway
|
||||
PrivateGateway gateway = getVpcPrivateGateway(vpcId);
|
||||
VpcGateway gateway = getPrivateGatewayForVpc(vpcId);
|
||||
if (gateway != null) {
|
||||
s_logger.debug("Deleting private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
|
||||
if (!deleteVpcPrivateGateway(gateway.getId())) {
|
||||
|
|
@ -1074,7 +1074,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
}
|
||||
|
||||
s_logger.debug("Starting VPC " + vpc + " as a part of VPC restart process");
|
||||
if (!startVpc(vpcId)) {
|
||||
if (!startVpc(vpcId, false)) {
|
||||
s_logger.warn("Failed to start vpc as a part of VPC " + vpc + " restart process");
|
||||
restartRequired = true;
|
||||
return false;
|
||||
|
|
@ -1130,7 +1130,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
}
|
||||
|
||||
//allow only one private gateway per vpc
|
||||
VpcGatewayVO gatewayVO = _vpcGatewayDao.getPrivateGateway(vpcId);
|
||||
VpcGatewayVO gatewayVO = _vpcGatewayDao.getPrivateGatewayForVpc(vpcId);
|
||||
if (gatewayVO != null) {
|
||||
throw new InvalidParameterValueException("Private ip address already exists for vpc " + vpc);
|
||||
}
|
||||
|
|
@ -1150,7 +1150,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
//1) create private network
|
||||
String networkName = "vpc-" + vpc.getName() + "-privateNetwork";
|
||||
Network privateNtwk = _ntwkMgr.createPrivateNetwork(networkName, networkName, physicalNetworkId,
|
||||
vlan, ipAddress, null, gateway, netmask, gatewayOwnerId);
|
||||
vlan, ipAddress, null, gateway, netmask, gatewayOwnerId, vpcId);
|
||||
|
||||
//2) create gateway entry
|
||||
gatewayVO = new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(),
|
||||
|
|
@ -1220,7 +1220,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
PrivateIpVO ip = _privateIpDao.findByIpAndSourceNetworkId(gateway.getNetworkId(), gateway.getIp4Address());
|
||||
PrivateIpVO ip = _privateIpDao.findByIpAndVpcId(gateway.getVpcId(), gateway.getIp4Address());
|
||||
if (ip != null) {
|
||||
_privateIpDao.remove(ip.getId());
|
||||
s_logger.debug("Deleted private ip " + ip);
|
||||
|
|
@ -1584,4 +1584,9 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VpcGateway getPrivateGatewayForVpc(long vpcId) {
|
||||
return _vpcGatewayDao.getPrivateGatewayForVpc(vpcId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2449,7 +2449,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
s_logger.debug("Adding vm " + vm + " to network " + network);
|
||||
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
|
||||
NetworkVO networkVO = _networkDao.findById(network.getId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
|
||||
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
|
||||
|
||||
|
|
@ -2460,40 +2459,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
Host host = _hostDao.findById(vm.getHostId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
||||
|
||||
NicProfile nic = null;
|
||||
String broadcastUri = null;
|
||||
if (requested != null && requested.getBroadCastUri() != null) {
|
||||
broadcastUri = requested.getBroadCastUri().toString();
|
||||
NicVO nicVO = _nicsDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
|
||||
if (nicVO != null) {
|
||||
nic = _networkMgr.getNicProfile(vm, network.getId());
|
||||
}
|
||||
} else {
|
||||
NicVO nicVO = _nicsDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
|
||||
if (nicVO != null) {
|
||||
nic = _networkMgr.getNicProfile(vm, network.getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (nic == null) {
|
||||
s_logger.debug("Allocating nic for the " + vm + " in network " + network);
|
||||
//1) allocate nic and prepare nic if needed
|
||||
int deviceId = _nicsDao.countNics(vm.getId());
|
||||
|
||||
nic = _networkMgr.allocateNic(requested, network, false,
|
||||
deviceId, vmProfile).first();
|
||||
|
||||
if (nic == null) {
|
||||
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
|
||||
}
|
||||
|
||||
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
|
||||
|
||||
nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
|
||||
|
||||
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
|
||||
|
||||
}
|
||||
//1) allocate and prepare nic
|
||||
NicProfile nic = _networkMgr.allocateAndPrepareNic(network, requested, context, vmProfile);
|
||||
|
||||
//2) Convert vmProfile to vmTO
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||
|
|
@ -2515,6 +2482,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType) {
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(hypervisorType);
|
||||
|
|
|
|||
|
|
@ -880,7 +880,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
|
|||
* @see com.cloud.network.NetworkService#createPrivateNetwork(java.lang.String, java.lang.String, long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, long)
|
||||
*/
|
||||
@Override
|
||||
public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan, String startIp, String endIP, String gateway, String netmask, long networkOwnerId)
|
||||
public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan, String startIp, String endIP, String gateway, String netmask, long networkOwnerId, Long vpcId)
|
||||
throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -2285,8 +2285,10 @@ CREATE TABLE `cloud`.`private_ip_address` (
|
|||
`network_id` bigint unsigned NOT NULL COMMENT 'id of the network ip belongs to',
|
||||
`reservation_id` char(40) COMMENT 'reservation id',
|
||||
`mac_address` varchar(17) COMMENT 'mac address',
|
||||
`vpc_id` bigint unsigned COMMENT 'vpc this ip belongs to',
|
||||
`taken` datetime COMMENT 'Date taken',
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_private_ip_address__vpc_id` FOREIGN KEY `fk_private_ip_address__vpc_id`(`vpc_id`) REFERENCES `vpc`(`id`),
|
||||
CONSTRAINT `fk_private_ip_address__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue