Skip to content

Commit 1c5244a

Browse files
committed
Merge remote-tracking branch 'origin/4.12'
2 parents 6946f41 + b2b99ca commit 1c5244a

21 files changed

Lines changed: 203 additions & 19 deletions

File tree

api/src/main/java/com/cloud/network/element/DhcpServiceProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachi
3737
boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException;
3838

3939
boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, String> dhcpOptions);
40+
41+
boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vmProfile) throws ResourceUnavailableException;
4042
}

core/src/main/java/com/cloud/agent/api/routing/DhcpEntryCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public class DhcpEntryCommand extends NetworkElementCommand {
3535
String duid;
3636
private boolean isDefault;
3737
boolean executeInSequence = false;
38+
boolean remove;
39+
40+
public boolean isRemove() {
41+
return remove;
42+
}
43+
44+
public void setRemove(boolean remove) {
45+
this.remove = remove;
46+
}
3847

3948
protected DhcpEntryCommand() {
4049

core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/DhcpEntryConfigItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
3535
final DhcpEntryCommand command = (DhcpEntryCommand) cmd;
3636

3737
final VmDhcpConfig vmDhcpConfig = new VmDhcpConfig(command.getVmName(), command.getVmMac(), command.getVmIpAddress(), command.getVmIp6Address(), command.getDuid(), command.getDefaultDns(),
38-
command.getDefaultRouter(), command.getStaticRoutes(), command.isDefault());
38+
command.getDefaultRouter(), command.getStaticRoutes(), command.isDefault(), command.isRemove());
3939

4040
return generateConfigItems(vmDhcpConfig);
4141
}

core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/VmDhcpConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ public class VmDhcpConfig extends ConfigBase {
3030
private String staticRoutes;
3131
private boolean defaultEntry;
3232

33+
// Indicate if the entry should be removed when set to true
34+
private boolean remove;
35+
3336
public VmDhcpConfig() {
3437
super(VM_DHCP);
3538
}
3639

3740
public VmDhcpConfig(String hostName, String macAddress, String ipv4Address, String ipv6Address, String ipv6Duid, String dnsAddresses, String defaultGateway,
38-
String staticRoutes, boolean defaultEntry) {
41+
String staticRoutes, boolean defaultEntry, boolean remove) {
3942
super(VM_DHCP);
4043
this.hostName = hostName;
4144
this.macAddress = macAddress;
@@ -46,6 +49,7 @@ public VmDhcpConfig(String hostName, String macAddress, String ipv4Address, Stri
4649
this.defaultGateway = defaultGateway;
4750
this.staticRoutes = staticRoutes;
4851
this.defaultEntry = defaultEntry;
52+
this.remove = remove;
4953
}
5054

5155
public String getHostName() {
@@ -64,6 +68,14 @@ public void setMacAddress(String macAddress) {
6468
this.macAddress = macAddress;
6569
}
6670

71+
public boolean isRemove() {
72+
return remove;
73+
}
74+
75+
public void setRemove(boolean remove) {
76+
this.remove = remove;
77+
}
78+
6779
public String getIpv4Address() {
6880
return ipv4Address;
6981
}

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,8 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon
309309
*/
310310
boolean areRoutersRunning(final List<? extends VirtualRouter> routers);
311311

312+
/**
313+
* Remove entry from /etc/dhcphosts and /etc/hosts on virtual routers
314+
*/
315+
void cleanupNicDhcpDnsEntry(Network network, VirtualMachineProfile vmProfile, NicProfile nicProfile);
312316
}

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,6 +2999,34 @@ public boolean areRoutersRunning(final List<? extends VirtualRouter> routers) {
29992999
return true;
30003000
}
30013001

3002+
/**
3003+
* Cleanup entry on VR file specified by type
3004+
*/
3005+
@Override
3006+
public void cleanupNicDhcpDnsEntry(Network network, VirtualMachineProfile vmProfile, NicProfile nicProfile) {
3007+
3008+
final List<Provider> networkProviders = getNetworkProviders(network.getId());
3009+
for (final NetworkElement element : networkElements) {
3010+
if (networkProviders.contains(element.getProvider())) {
3011+
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
3012+
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: "
3013+
+ network.getPhysicalNetworkId());
3014+
}
3015+
if (vmProfile.getType() == Type.User && element.getProvider() != null) {
3016+
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)
3017+
&& _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && element instanceof DhcpServiceProvider) {
3018+
final DhcpServiceProvider sp = (DhcpServiceProvider) element;
3019+
try {
3020+
sp.removeDhcpEntry(network, nicProfile, vmProfile);
3021+
} catch (ResourceUnavailableException e) {
3022+
s_logger.error("Failed to remove dhcp-dns entry due to: ", e);
3023+
}
3024+
}
3025+
}
3026+
}
3027+
}
3028+
}
3029+
30023030
/**
30033031
* rollingRestartRouters performs restart of routers of a network by first
30043032
* deploying a new VR and then destroying old VRs in rolling fashion. For

plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,9 @@ public boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, Str
185185
return false;
186186
}
187187

188+
@Override
189+
public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vmProfile) throws ResourceUnavailableException {
190+
return false;
191+
}
192+
188193
}

plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,9 @@ public boolean removeDhcpSupportForSubnet(Network network)
379379
public boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, String> dhcpOptions) {
380380
return false;
381381
}
382+
383+
@Override
384+
public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vmProfile) {
385+
return false;
386+
}
382387
}

plugins/network-elements/juniper-srx/src/main/java/com/cloud/network/resource/JuniperSrxResource.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,11 +2078,11 @@ private boolean manageStaticNatRule(SrxCommand command, String publicIp, String
20782078
xml = replaceXmlValue(xml, "rule-set", _privateZone);
20792079
xml = replaceXmlValue(xml, "from-zone", _privateZone);
20802080
xml = replaceXmlValue(xml, "rule-name", ruleName_private);
2081-
}
20822081

2083-
if (!sendRequestAndCheckResponse(command, xml, "name", ruleName_private))
2084-
{
2085-
throw new ExecutionException("Failed to delete trust static NAT rule from public IP " + publicIp + " to private IP " + privateIp);
2082+
if (!sendRequestAndCheckResponse(command, xml, "name", ruleName_private))
2083+
{
2084+
throw new ExecutionException("Failed to delete trust static NAT rule from public IP " + publicIp + " to private IP " + privateIp);
2085+
}
20862086
}
20872087
return true;
20882088
}
@@ -3568,6 +3568,7 @@ private boolean sendRequestAndCheckResponse(SrxCommand command, String xmlReques
35683568

35693569
case CHECK_IF_EXISTS:
35703570
case CHECK_IF_IN_USE:
3571+
case CHECK_PRIVATE_IF_EXISTS:
35713572
assert (keyAndValue != null && keyAndValue.length == 2) : "If the SrxCommand is " + command + ", both a key and value must be specified.";
35723573

35733574
key = keyAndValue[0];

server/src/main/java/com/cloud/network/element/VirtualRouterElement.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,34 @@ public boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, Str
946946
return false;
947947
}
948948

949+
@Override
950+
public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vmProfile) throws ResourceUnavailableException {
951+
boolean result = true;
952+
if (canHandle(network, Service.Dhcp)) {
953+
if (vmProfile.getType() != VirtualMachine.Type.User) {
954+
return false;
955+
}
956+
957+
final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
958+
959+
if (CollectionUtils.isEmpty(routers)) {
960+
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
961+
}
962+
963+
final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
964+
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
965+
966+
for (final DomainRouterVO domainRouterVO : routers) {
967+
if (domainRouterVO.getState() != VirtualMachine.State.Running) {
968+
continue;
969+
}
970+
971+
result = result && networkTopology.removeDhcpEntry(network, nic, vmProfile, domainRouterVO);
972+
}
973+
}
974+
return result;
975+
}
976+
949977
@Override
950978
public boolean removeDnsSupportForSubnet(Network network) throws ResourceUnavailableException {
951979
// Ignore if virtual router is already dhcp provider

0 commit comments

Comments
 (0)