mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Added reservation context to the network gurus
This commit is contained in:
parent
433c28fb16
commit
d5d1808488
@ -12,6 +12,7 @@ import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@ -51,7 +52,7 @@ public interface NetworkGuru extends Adapter {
|
||||
* @param destination where were deploying to.
|
||||
* @return a fully implemented NetworkConfiguration.
|
||||
*/
|
||||
NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination);
|
||||
NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination, ReservationContext context);
|
||||
|
||||
/**
|
||||
* reserve a nic for this VM in this network.
|
||||
@ -63,9 +64,11 @@ public interface NetworkGuru extends Adapter {
|
||||
* @throws InsufficientVirtualNetworkCapcityException
|
||||
* @throws InsufficientAddressCapacityException
|
||||
*/
|
||||
String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
|
||||
String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
|
||||
|
||||
boolean release(String uniqueId);
|
||||
|
||||
void deallocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm);
|
||||
|
||||
void destroy(NetworkConfiguration config, NetworkOffering offering);
|
||||
}
|
||||
|
||||
@ -1965,7 +1965,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
|
||||
|
||||
NetworkOfferingVO offering = _networkOfferingDao.findById(config.getNetworkOfferingId());
|
||||
|
||||
NetworkConfiguration result = guru.implement(config, offering, dest);
|
||||
NetworkConfiguration result = guru.implement(config, offering, dest, context);
|
||||
config.setCidr(result.getCidr());
|
||||
config.setBroadcastUri(result.getBroadcastUri());
|
||||
config.setGateway(result.getGateway());
|
||||
@ -2015,7 +2015,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
|
||||
URI isolationUri = nic.getIsolationUri();
|
||||
|
||||
profile = new NicProfile(nic, config, broadcastUri, isolationUri);
|
||||
String reservationId = concierge.reserve(profile, config, vmProfile, dest);
|
||||
String reservationId = concierge.reserve(profile, config, vmProfile, dest, context);
|
||||
nic.setIp4Address(profile.getIp4Address());
|
||||
nic.setIp6Address(profile.getIp6Address());
|
||||
nic.setMacAddress(profile.getMacAddress());
|
||||
|
||||
@ -32,6 +32,8 @@ import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@Local(value={NetworkGuru.class})
|
||||
@ -83,7 +85,7 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
|
||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
if (config.getTrafficType() != TrafficType.Control) {
|
||||
return null;
|
||||
@ -95,9 +97,13 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
|
||||
return new NicProfile(ReservationStrategy.Start, null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deallocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException,
|
||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
String ip = _dcDao.allocateLinkLocalPrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vm.getId());
|
||||
nic.setIp4Address(ip);
|
||||
@ -115,7 +121,7 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination) {
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,7 @@ import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
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;
|
||||
@ -107,7 +108,11 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination dest) {
|
||||
public void deallocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination dest, ReservationContext context) {
|
||||
assert (config.getState() == State.Allocated) : "Why implement are we implementing " + config;
|
||||
|
||||
long dcId = dest.getDataCenter().getId();
|
||||
@ -182,7 +187,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException,
|
||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
|
||||
|
||||
|
||||
@ -27,6 +27,8 @@ import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@Local(value={NetworkGuru.class})
|
||||
@ -52,7 +54,11 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
|
||||
public void deallocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
TrafficType trafficType = config.getTrafficType();
|
||||
if (trafficType != TrafficType.Storage && trafficType != TrafficType.Management) {
|
||||
@ -69,7 +75,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException,
|
||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
Pod pod = dest.getPod();
|
||||
@ -98,7 +104,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination) {
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@ -54,9 +55,29 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
protected PublicNetworkGuru() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException {
|
||||
if (nic.getIp4Address() == null) {
|
||||
Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dc.getId(), vm.getVirtualMachine().getAccountId(), vm.getVirtualMachine().getDomainId(), VlanType.VirtualNetwork, true);
|
||||
if (ipAndVlan == null) {
|
||||
throw new InsufficientVirtualNetworkCapcityException("Unable to get public ip address in " + dc.getId());
|
||||
}
|
||||
VlanVO vlan = ipAndVlan.second();
|
||||
nic.setIp4Address(ipAndVlan.first());
|
||||
nic.setGateway(vlan.getVlanGateway());
|
||||
nic.setNetmask(vlan.getVlanNetmask());
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(vlan.getVlanId()));
|
||||
nic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlan.getVlanId()));
|
||||
nic.setFormat(AddressFormat.Ip4);
|
||||
nic.setReservationId(Long.toString(vlan.getId()));
|
||||
}
|
||||
nic.setDns1(dc.getDns1());
|
||||
nic.setDns2(dc.getDns2());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
|
||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
if (config.getTrafficType() != TrafficType.Public) {
|
||||
return null;
|
||||
@ -74,37 +95,23 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
nic.setMacAddress(mac);
|
||||
|
||||
DataCenter dc = _dcDao.findById(config.getId());
|
||||
getIp(nic, dc, vm);
|
||||
|
||||
return nic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reserve(NicProfile ch, NetworkConfiguration configuration, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
|
||||
if (ch.getReservationId() != null) {
|
||||
return ch.getReservationId();
|
||||
public String reserve(NicProfile nic, NetworkConfiguration configuration, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
|
||||
if (nic.getReservationId() != null) {
|
||||
return nic.getReservationId();
|
||||
}
|
||||
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
long dcId = dc.getId();
|
||||
|
||||
if (ch.getIp4Address() == null) {
|
||||
Pair<String, VlanVO> ipAndVlan = _vlanDao.assignIpAddress(dcId, vm.getVirtualMachine().getAccountId(), vm.getVirtualMachine().getDomainId(), VlanType.VirtualNetwork, true);
|
||||
if (ipAndVlan == null) {
|
||||
throw new InsufficientVirtualNetworkCapcityException("Unable to get public ip address in " + dcId);
|
||||
}
|
||||
VlanVO vlan = ipAndVlan.second();
|
||||
ch.setIp4Address(ipAndVlan.first());
|
||||
ch.setGateway(vlan.getVlanGateway());
|
||||
ch.setNetmask(vlan.getVlanNetmask());
|
||||
ch.setIsolationUri(IsolationType.Vlan.toUri(vlan.getVlanId()));
|
||||
ch.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
ch.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlan.getVlanId()));
|
||||
ch.setFormat(AddressFormat.Ip4);
|
||||
ch.setReservationId(Long.toString(vlan.getId()));
|
||||
if (nic.getIp4Address() == null) {
|
||||
getIp(nic, dest.getDataCenter(), vm);
|
||||
}
|
||||
ch.setDns1(dc.getDns1());
|
||||
ch.setDns2(dc.getDns2());
|
||||
|
||||
return ch.getReservationId();
|
||||
return nic.getReservationId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,10 +120,14 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination) {
|
||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deallocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(NetworkConfiguration config, NetworkOffering offering) {
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user