mirror of https://github.com/apache/cloudstack.git
Release vnet during network shutdown for guest networks only
This commit is contained in:
parent
6424042cac
commit
1f1e393b03
|
|
@ -1,27 +1,59 @@
|
|||
package com.cloud.network;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class NetworkProfile{
|
||||
private Network network;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.Mode;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
||||
|
||||
public class NetworkProfile implements Network{
|
||||
private long id;
|
||||
private long dataCenterId;
|
||||
private long ownerId;
|
||||
private long domainId;
|
||||
private String dns1;
|
||||
private String dns2;
|
||||
private URI broadcastUri;
|
||||
private State state;
|
||||
private String name;
|
||||
private Mode mode;
|
||||
private BroadcastDomainType broadcastDomainType;
|
||||
private TrafficType trafficType;
|
||||
private String gateway;
|
||||
private String cidr;
|
||||
private long networkOfferingId;
|
||||
private long related;
|
||||
private GuestIpType guestIpType;
|
||||
private String displayText;
|
||||
private boolean isShared;
|
||||
private String reservationId;
|
||||
private boolean isDefault;
|
||||
private String networkDomain;
|
||||
private boolean isSecurityGroupEnabled;
|
||||
|
||||
public NetworkProfile(Network network, String dns1, String dns2) {
|
||||
this.network = network;
|
||||
this.dns1 = dns1;
|
||||
this.dns2 = dns2;
|
||||
}
|
||||
|
||||
public NetworkProfile() {
|
||||
|
||||
}
|
||||
|
||||
public Network getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public void setNetwork(Network network){
|
||||
this.network = network;
|
||||
public NetworkProfile(Network network) {
|
||||
this.id = network.getId();
|
||||
this.broadcastUri = network.getBroadcastUri();
|
||||
this.dataCenterId = network.getDataCenterId();
|
||||
this.ownerId = network.getAccountId();
|
||||
this.state = network.getState();
|
||||
this.name = network.getName();
|
||||
this.mode = network.getMode();
|
||||
this.broadcastDomainType = network.getBroadcastDomainType();
|
||||
this.trafficType = network.getTrafficType();
|
||||
this.gateway = network.getGateway();
|
||||
this.cidr = network.getCidr();
|
||||
this.networkOfferingId = network.getNetworkOfferingId();
|
||||
this.related = network.getRelated();
|
||||
this.guestIpType = network.getGuestType();
|
||||
this.displayText = network.getDisplayText();
|
||||
this.isShared = network.isShared();
|
||||
this.reservationId = network.getReservationId();
|
||||
this.isDefault = network.isDefault();
|
||||
this.networkDomain = network.getNetworkDomain();
|
||||
this.domainId = network.getDomainId();
|
||||
this.isSecurityGroupEnabled = network.isSecurityGroupEnabled();
|
||||
}
|
||||
|
||||
public String getDns1() {
|
||||
|
|
@ -40,5 +72,112 @@ public class NetworkProfile{
|
|||
this.dns2 = dns2;
|
||||
}
|
||||
|
||||
public void setBroadcastUri(URI broadcastUri) {
|
||||
this.broadcastUri = broadcastUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getBroadcastUri() {
|
||||
return broadcastUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataCenterId() {
|
||||
return dataCenterId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BroadcastDomainType getBroadcastDomainType() {
|
||||
return broadcastDomainType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrafficType getTrafficType() {
|
||||
return trafficType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCidr() {
|
||||
return cidr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNetworkOfferingId() {
|
||||
return networkOfferingId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRelated() {
|
||||
return related;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuestIpType getGuestType() {
|
||||
return guestIpType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShared() {
|
||||
return isShared;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReservationId() {
|
||||
return reservationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetworkDomain() {
|
||||
return networkDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecurityGroupEnabled() {
|
||||
return isSecurityGroupEnabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public interface NetworkService {
|
|||
|
||||
IpAddress getIp(long id);
|
||||
|
||||
NetworkProfile getNetworkProfile(long networkId);
|
||||
NetworkProfile convertNetworkToNetworkProfile(long networkId);
|
||||
|
||||
Map<Service, Map<Capability, String>> getZoneCapabilities(long zoneId);
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public interface NetworkGuru extends Adapter {
|
|||
|
||||
void updateNicProfile(NicProfile profile, Network network);
|
||||
|
||||
void destroy(Network network, NetworkOffering offering);
|
||||
void shutdown(NetworkProfile network, NetworkOffering offering);
|
||||
|
||||
/**
|
||||
* Throw away the design.
|
||||
|
|
|
|||
|
|
@ -501,7 +501,7 @@ public class ApiDBUtils {
|
|||
}
|
||||
|
||||
public static NetworkProfile getNetworkProfile(long networkId) {
|
||||
return _networkMgr.getNetworkProfile(networkId);
|
||||
return _networkMgr.convertNetworkToNetworkProfile(networkId);
|
||||
}
|
||||
|
||||
public static NetworkOfferingVO findNetworkOfferingById(long networkOfferingId) {
|
||||
|
|
|
|||
|
|
@ -2246,8 +2246,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
@Override
|
||||
public NetworkResponse createNetworkResponse(Network network) {
|
||||
NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
|
||||
network = profile.getNetwork();
|
||||
//need to get network profile in order to retrieve dns information from there
|
||||
NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
|
||||
NetworkResponse response = new NetworkResponse();
|
||||
response.setId(network.getId());
|
||||
response.setName(network.getName());
|
||||
|
|
|
|||
|
|
@ -1028,6 +1028,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
vo.setIsolationUri(profile.getIsolationUri());
|
||||
vo.setNetmask(profile.getNetmask());
|
||||
}
|
||||
|
||||
protected void applyProfileToNetwork(NetworkVO network, NetworkProfile profile) {
|
||||
network.setBroadcastUri(profile.getBroadcastUri());
|
||||
network.setDns1(profile.getDns1());
|
||||
network.setDns2(profile.getDns2());
|
||||
}
|
||||
|
||||
protected NicTO toNicTO(NicVO nic, NicProfile profile, NetworkVO config) {
|
||||
NicTO to = new NicTO();
|
||||
|
|
@ -1819,6 +1825,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
s_logger.debug("Network is not implemented: " + network);
|
||||
return;
|
||||
}
|
||||
|
||||
network.setState(Network.State.Shutdown);
|
||||
_networksDao.update(network.getId(), network);
|
||||
txn.commit();
|
||||
|
|
@ -1849,11 +1856,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
|
||||
}
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
guru.destroy(network, _networkOfferingDao.findById(network.getNetworkOfferingId()));
|
||||
network.setBroadcastUri(null);
|
||||
NetworkProfile profile = convertNetworkToNetworkProfile(network.getId());
|
||||
guru.shutdown(profile, _networkOfferingDao.findById(network.getNetworkOfferingId()));
|
||||
|
||||
applyProfileToNetwork(network, profile);
|
||||
|
||||
network.setState(Network.State.Allocated);
|
||||
_networksDao.update(network.getId(), network);
|
||||
_networksDao.clearCheckForGc(networkId);
|
||||
|
||||
} else {
|
||||
network.setState(Network.State.Implemented);
|
||||
_networksDao.update(network.getId(), network);
|
||||
|
|
@ -2303,10 +2314,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
|
||||
@Override
|
||||
public NetworkProfile getNetworkProfile(long networkId) {
|
||||
public NetworkProfile convertNetworkToNetworkProfile(long networkId) {
|
||||
NetworkVO network = _networksDao.findById(networkId);
|
||||
NetworkGuru concierge = _networkGurus.get(network.getGuruName());
|
||||
NetworkProfile profile = new NetworkProfile(network, null, null);
|
||||
NetworkProfile profile = new NetworkProfile(network);
|
||||
concierge.updateNetworkProfile(profile);
|
||||
|
||||
return profile;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import com.cloud.exception.InsufficientAddressCapacityException;
|
|||
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkProfile;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
|
|
@ -156,7 +157,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
|
|||
}
|
||||
|
||||
@Override
|
||||
public void destroy(Network config, NetworkOffering offering) {
|
||||
public void shutdown(NetworkProfile config, NetworkOffering offering) {
|
||||
assert false : "Destroying a link local...Either you're out of your mind or something has changed.";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void destroy(Network network, NetworkOffering offering) {
|
||||
public void shutdown(NetworkProfile network, NetworkOffering offering) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -206,7 +206,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
|
||||
@Override
|
||||
public void updateNetworkProfile(NetworkProfile networkProfile) {
|
||||
DataCenter dc = _dcDao.findById(networkProfile.getNetwork().getDataCenterId());
|
||||
DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId());
|
||||
networkProfile.setDns1(dc.getDns1());
|
||||
networkProfile.setDns2(dc.getDns2());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,9 +243,10 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void destroy(Network network, NetworkOffering offering) {
|
||||
s_logger.debug("Releasing vnet for the network id=" + network.getId());
|
||||
_dcDao.releaseVnet(network.getBroadcastUri().getHost(), network.getDataCenterId(), network.getAccountId(), network.getReservationId());
|
||||
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
|
||||
s_logger.debug("Releasing vnet for the network id=" + profile.getId());
|
||||
_dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(), profile.getAccountId(), profile.getReservationId());
|
||||
profile.setBroadcastUri(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -255,7 +256,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
|
||||
@Override
|
||||
public void updateNetworkProfile(NetworkProfile networkProfile) {
|
||||
DataCenter dc = _dcDao.findById(networkProfile.getNetwork().getDataCenterId());
|
||||
DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId());
|
||||
networkProfile.setDns1(dc.getDns1());
|
||||
networkProfile.setDns2(dc.getDns2());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void destroy(Network config, NetworkOffering offering) {
|
||||
public void shutdown(NetworkProfile config, NetworkOffering offering) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void destroy(Network network, NetworkOffering offering) {
|
||||
public void shutdown(NetworkProfile network, NetworkOffering offering) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -184,7 +184,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
|
||||
@Override
|
||||
public void updateNetworkProfile(NetworkProfile networkProfile) {
|
||||
DataCenter dc = _dcDao.findById(networkProfile.getNetwork().getDataCenterId());
|
||||
DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId());
|
||||
networkProfile.setDns1(dc.getDns1());
|
||||
networkProfile.setDns2(dc.getDns2());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue