Skip to content

Commit 78b68fd

Browse files
authored
api,server: custom dns for guest network (#6425)
Adds option to provide custom DNS servers for isolated network, shared network and VPC tier. New API parameters added in createNetwork API along with the corresponding response parameters. Doc PR: apache/cloudstack-documentation#276
1 parent cf18549 commit 78b68fd

File tree

64 files changed

+2828
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2828
-351
lines changed

api/src/main/java/com/cloud/agent/api/to/NetworkTO.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class NetworkTO {
4141
protected String ip6address;
4242
protected String ip6gateway;
4343
protected String ip6cidr;
44+
protected String ip6Dns1;
45+
protected String ip6Dns2;
4446

4547
public NetworkTO() {
4648
}
@@ -221,4 +223,12 @@ public void setIsolationuri(URI isolationUri) {
221223
public boolean isSecurityGroupEnabled() {
222224
return this.isSecurityGroupEnabled;
223225
}
226+
227+
public void setIp6Dns1(String ip6Dns1) {
228+
this.ip6Dns1 = ip6Dns1;
229+
}
230+
231+
public void setIp6Dns2(String ip6Dns2) {
232+
this.ip6Dns2 = ip6Dns2;
233+
}
224234
}

api/src/main/java/com/cloud/network/Network.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,5 +483,13 @@ public void setIp6Address(String ip6Address) {
483483

484484
String getRouterIpv6();
485485

486+
String getDns1();
487+
488+
String getDns2();
489+
490+
String getIp6Dns1();
491+
492+
String getIp6Dns2();
493+
486494
Date getCreated();
487495
}

api/src/main/java/com/cloud/network/NetworkModel.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
package com.cloud.network;
1919

20-
import com.google.common.collect.ImmutableMap;
21-
2220
import java.util.ArrayList;
2321
import java.util.List;
2422
import java.util.Map;
2523
import java.util.Set;
2624

25+
import org.apache.cloudstack.framework.config.ConfigKey;
26+
27+
import com.cloud.dc.DataCenter;
2728
import com.cloud.dc.Vlan;
2829
import com.cloud.exception.InsufficientAddressCapacityException;
2930
import com.cloud.exception.InvalidParameterValueException;
@@ -39,10 +40,11 @@
3940
import com.cloud.offering.NetworkOffering;
4041
import com.cloud.offering.NetworkOffering.Detail;
4142
import com.cloud.user.Account;
43+
import com.cloud.utils.Pair;
4244
import com.cloud.vm.Nic;
4345
import com.cloud.vm.NicProfile;
4446
import com.cloud.vm.VirtualMachine;
45-
import org.apache.cloudstack.framework.config.ConfigKey;
47+
import com.google.common.collect.ImmutableMap;
4648

4749
/**
4850
* The NetworkModel presents a read-only view into the Network data such as L2 networks,
@@ -323,4 +325,12 @@ List<String[]> generateVmData(String userData, String serviceOffering, long data
323325

324326
String getValidNetworkCidr(Network guestNetwork);
325327

328+
Pair<String, String> getNetworkIp4Dns(final Network network, final DataCenter zone);
329+
330+
Pair<String, String> getNetworkIp6Dns(final Network network, final DataCenter zone);
331+
332+
void verifyIp4DnsPair(final String ip4Dns1, final String ip4Dns2);
333+
334+
void verifyIp6DnsPair(final String ip6Dns1, final String ip6Dns2);
335+
326336
}

api/src/main/java/com/cloud/network/NetworkProfile.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class NetworkProfile implements Network {
3131
private final long domainId;
3232
private String dns1;
3333
private String dns2;
34+
private String ip6Dns1;
35+
private String ip6Dns2;
3436
private URI broadcastUri;
3537
private final State state;
3638
private boolean isRedundant;
@@ -98,10 +100,12 @@ public NetworkProfile(Network network) {
98100
externalId = network.getExternalId();
99101
}
100102

103+
@Override
101104
public String getDns1() {
102105
return dns1;
103106
}
104107

108+
@Override
105109
public String getDns2() {
106110
return dns2;
107111
}
@@ -114,6 +118,24 @@ public void setDns2(String dns2) {
114118
this.dns2 = dns2;
115119
}
116120

121+
@Override
122+
public String getIp6Dns1() {
123+
return ip6Dns1;
124+
}
125+
126+
@Override
127+
public String getIp6Dns2() {
128+
return ip6Dns2;
129+
}
130+
131+
public void setIp6Dns1(String ip6Dns1) {
132+
this.ip6Dns1 = ip6Dns1;
133+
}
134+
135+
public void setIp6Dns2(String ip6Dns2) {
136+
this.ip6Dns2 = ip6Dns2;
137+
}
138+
117139
@Override
118140
public String getGuruName() {
119141
return guruName;

api/src/main/java/com/cloud/network/vpc/Vpc.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
// under the License.
1717
package com.cloud.network.vpc;
1818

19+
import java.util.Date;
20+
1921
import org.apache.cloudstack.acl.ControlledEntity;
2022
import org.apache.cloudstack.api.Identity;
2123
import org.apache.cloudstack.api.InternalIdentity;
2224

23-
import java.util.Date;
24-
2525
public interface Vpc extends ControlledEntity, Identity, InternalIdentity {
2626

2727
public enum State {
@@ -95,4 +95,12 @@ public enum State {
9595
void setRollingRestart(boolean rollingRestart);
9696

9797
Date getCreated();
98+
99+
String getIp4Dns1();
100+
101+
String getIp4Dns2();
102+
103+
String getIp6Dns1();
104+
105+
String getIp6Dns2();
98106
}

api/src/main/java/com/cloud/network/vpc/VpcService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Map;
2121

2222
import org.apache.cloudstack.api.command.user.vpc.CreatePrivateGatewayCmd;
23+
import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd;
2324
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
2425
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
2526
import org.apache.cloudstack.api.command.user.vpc.RestartVPCCmd;
@@ -36,6 +37,7 @@
3637

3738
public interface VpcService {
3839

40+
public Vpc createVpc(CreateVPCCmd cmd) throws ResourceAllocationException;
3941
/**
4042
* Persists VPC record in the database
4143
*
@@ -50,7 +52,8 @@ public interface VpcService {
5052
* @return
5153
* @throws ResourceAllocationException TODO
5254
*/
53-
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain, Boolean displayVpc)
55+
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain,
56+
String dns1, String dns2, String ip6Dns1, String ip6Dns2, Boolean displayVpc)
5457
throws ResourceAllocationException;
5558

5659
/**

api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ public class CreateNetworkCmd extends BaseCmd implements UserCmd {
157157
description = "The network this network is associated to. only available if create a Shared network")
158158
private Long associatedNetworkId;
159159

160+
@Parameter(name = ApiConstants.DNS1, type = CommandType.STRING, description = "the first IPv4 DNS for the network", since = "4.18.0")
161+
private String ip4Dns1;
162+
163+
@Parameter(name = ApiConstants.DNS2, type = CommandType.STRING, description = "the second IPv4 DNS for the network", since = "4.18.0")
164+
private String ip4Dns2;
165+
166+
@Parameter(name = ApiConstants.IP6_DNS1, type = CommandType.STRING, description = "the first IPv6 DNS for the network", since = "4.18.0")
167+
private String ip6Dns1;
168+
169+
@Parameter(name = ApiConstants.IP6_DNS2, type = CommandType.STRING, description = "the second IPv6 DNS for the network", since = "4.18.0")
170+
private String ip6Dns2;
171+
160172
/////////////////////////////////////////////////////
161173
/////////////////// Accessors ///////////////////////
162174
/////////////////////////////////////////////////////
@@ -326,6 +338,22 @@ public Long getAclId() {
326338
return aclId;
327339
}
328340

341+
public String getIp4Dns1() {
342+
return ip4Dns1;
343+
}
344+
345+
public String getIp4Dns2() {
346+
return ip4Dns2;
347+
}
348+
349+
public String getIp6Dns1() {
350+
return ip6Dns1;
351+
}
352+
353+
public String getIp6Dns2() {
354+
return ip6Dns2;
355+
}
356+
329357
/////////////////////////////////////////////////////
330358
/////////////// API Implementation///////////////////
331359
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd implements UserCmd {
8484
@Parameter(name= ApiConstants.FORCED, type = CommandType.BOOLEAN, description = "Setting this to true will cause a forced network update,", authorized = {RoleType.Admin})
8585
private Boolean forced;
8686

87+
@Parameter(name = ApiConstants.DNS1, type = CommandType.STRING, description = "the first IPv4 DNS for the network. Empty string will update the first IPv4 DNS with the value from the zone", since = "4.18.0")
88+
private String ip4Dns1;
89+
90+
@Parameter(name = ApiConstants.DNS2, type = CommandType.STRING, description = "the second IPv4 DNS for the network. Empty string will update the second IPv4 DNS with the value from the zone", since = "4.18.0")
91+
private String ip4Dns2;
92+
93+
@Parameter(name = ApiConstants.IP6_DNS1, type = CommandType.STRING, description = "the first IPv6 DNS for the network. Empty string will update the first IPv6 DNS with the value from the zone", since = "4.18.0")
94+
private String ip6Dns1;
95+
96+
@Parameter(name = ApiConstants.IP6_DNS2, type = CommandType.STRING, description = "the second IPv6 DNS for the network. Empty string will update the second IPv6 DNS with the value from the zone", since = "4.18.0")
97+
private String ip6Dns2;
98+
8799
/////////////////////////////////////////////////////
88100
/////////////////// Accessors ///////////////////////
89101
/////////////////////////////////////////////////////
@@ -136,6 +148,23 @@ public boolean getForced(){
136148
}
137149
return forced;
138150
}
151+
152+
public String getIp4Dns1() {
153+
return ip4Dns1;
154+
}
155+
156+
public String getIp4Dns2() {
157+
return ip4Dns2;
158+
}
159+
160+
public String getIp6Dns1() {
161+
return ip6Dns1;
162+
}
163+
164+
public String getIp6Dns2() {
165+
return ip6Dns2;
166+
}
167+
139168
/////////////////////////////////////////////////////
140169
/////////////// API Implementation///////////////////
141170
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd {
9595
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the vpc to the end user or not", since = "4.4", authorized = {RoleType.Admin})
9696
private Boolean display;
9797

98+
@Parameter(name = ApiConstants.DNS1, type = CommandType.STRING, description = "the first IPv4 DNS for the VPC", since = "4.18.0")
99+
private String ip4Dns1;
100+
101+
@Parameter(name = ApiConstants.DNS2, type = CommandType.STRING, description = "the second IPv4 DNS for the VPC", since = "4.18.0")
102+
private String ip4Dns2;
103+
104+
@Parameter(name = ApiConstants.IP6_DNS1, type = CommandType.STRING, description = "the first IPv6 DNS for the VPC", since = "4.18.0")
105+
private String ip6Dns1;
106+
107+
@Parameter(name = ApiConstants.IP6_DNS2, type = CommandType.STRING, description = "the second IPv6 DNS for the VPC", since = "4.18.0")
108+
private String ip6Dns2;
109+
98110
// ///////////////////////////////////////////////////
99111
// ///////////////// Accessors ///////////////////////
100112
// ///////////////////////////////////////////////////
@@ -131,6 +143,22 @@ public String getNetworkDomain() {
131143
return networkDomain;
132144
}
133145

146+
public String getIp4Dns1() {
147+
return ip4Dns1;
148+
}
149+
150+
public String getIp4Dns2() {
151+
return ip4Dns2;
152+
}
153+
154+
public String getIp6Dns1() {
155+
return ip6Dns1;
156+
}
157+
158+
public String getIp6Dns2() {
159+
return ip6Dns2;
160+
}
161+
134162
public boolean isStart() {
135163
if (start != null) {
136164
return start;
@@ -144,7 +172,7 @@ public Boolean getDisplayVpc() {
144172

145173
@Override
146174
public void create() throws ResourceAllocationException {
147-
Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr(), getNetworkDomain(), getDisplayVpc());
175+
Vpc vpc = _vpcService.createVpc(this);
148176
if (vpc != null) {
149177
setEntityId(vpc.getId());
150178
setEntityUuid(vpc.getUuid());

api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
120120
private String broadcastUri;
121121

122122
@SerializedName(ApiConstants.DNS1)
123-
@Param(description = "the first DNS for the network")
123+
@Param(description = "the first IPv4 DNS for the network")
124124
private String dns1;
125125

126126
@SerializedName(ApiConstants.DNS2)
127-
@Param(description = "the second DNS for the network")
127+
@Param(description = "the second IPv4 DNS for the network")
128128
private String dns2;
129129

130130
@SerializedName(ApiConstants.TYPE)
@@ -287,6 +287,14 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
287287
@Param(description = "The routes for the network to ease adding route in upstream router", since = "4.17.0")
288288
private Set<Ipv6RouteResponse> ipv6Routes;
289289

290+
@SerializedName(ApiConstants.IP6_DNS1)
291+
@Param(description = "the first IPv6 DNS for the network", since = "4.18.0")
292+
private String ipv6Dns1;
293+
294+
@SerializedName(ApiConstants.IP6_DNS2)
295+
@Param(description = "the second IPv6 DNS for the network", since = "4.18.0")
296+
private String ipv6Dns2;
297+
290298
public NetworkResponse() {}
291299

292300
public Boolean getDisplayNetwork() {
@@ -586,4 +594,12 @@ public void setIpv6Routes(Set<Ipv6RouteResponse> ipv6Routes) {
586594
public void addIpv6Route(Ipv6RouteResponse ipv6Route) {
587595
this.ipv6Routes.add(ipv6Route);
588596
}
597+
598+
public void setIpv6Dns1(String ipv6Dns1) {
599+
this.ipv6Dns1 = ipv6Dns1;
600+
}
601+
602+
public void setIpv6Dns2(String ipv6Dns2) {
603+
this.ipv6Dns2 = ipv6Dns2;
604+
}
589605
}

0 commit comments

Comments
 (0)