Skip to content

Commit 981bb64

Browse files
committed
add associate and disassociate dns zone to network ui screens, network response changes
1 parent a1eca74 commit 981bb64

File tree

10 files changed

+293
-14
lines changed

10 files changed

+293
-14
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,8 @@ public class ApiConstants {
13521352
public static final String DNS_USER_NAME = "dnsusername";
13531353
public static final String CREDENTIALS = "credentials";
13541354
public static final String DNS_ZONE_ID = "dnszoneid";
1355+
public static final String DNS_ZONE = "dnszone";
1356+
public static final String DNS_SUB_DOMAIN = "dnssubdomain";
13551357
public static final String DNS_SERVER_ID = "dnsserverid";
13561358
public static final String CONTENT = "content";
13571359
public static final String CONTENTS = "contents";

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
331331
@Param(description = "The BGP peers for the network", since = "4.20.0")
332332
private Set<BgpPeerResponse> bgpPeers;
333333

334+
@SerializedName(ApiConstants.DNS_ZONE)
335+
@Param(description = "DNS zone associated to the network", since = "4.23.0")
336+
private String dnsZone;
337+
338+
@SerializedName(ApiConstants.DNS_SUB_DOMAIN)
339+
@Param(description = "DNS subdomain associated to the network", since = "4.23.0")
340+
private String dnsSubdomain;
341+
334342
public NetworkResponse() {}
335343

336344
public Boolean getDisplayNetwork() {
@@ -702,4 +710,12 @@ public void setIpv6Dns1(String ipv6Dns1) {
702710
public void setIpv6Dns2(String ipv6Dns2) {
703711
this.ipv6Dns2 = ipv6Dns2;
704712
}
713+
714+
public void setDnsZone(String dnsZone) {
715+
this.dnsZone = dnsZone;
716+
}
717+
718+
public void setDnsSubdomain(String dnsSubdomain) {
719+
this.dnsSubdomain = dnsSubdomain;
720+
}
705721
}

plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/MockAccountManager.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.apache.cloudstack.auth.UserTwoFactorAuthenticator;
4242
import org.apache.cloudstack.backup.BackupOffering;
4343
import org.apache.cloudstack.framework.config.ConfigKey;
44-
import org.apache.cloudstack.dns.DnsServer;
4544

4645
import org.apache.cloudstack.acl.apikeypair.ApiKeyPair;
4746
import org.apache.cloudstack.acl.ControlledEntity;
@@ -511,11 +510,6 @@ public void checkAccess(Account account, BackupOffering bof) throws PermissionDe
511510
// TODO Auto-generated method stub
512511
}
513512

514-
@Override
515-
public void checkAccess(Account account, DnsServer dnsServer) throws PermissionDeniedException {
516-
// NOOP
517-
}
518-
519513
@Override
520514
public Pair<Boolean, Map<String, String>> getKeys(GetUserKeysCmd cmd){
521515
return null;

server/src/main/java/com/cloud/api/ApiDBUtils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
import org.apache.cloudstack.backup.dao.BackupRepositoryDao;
8383
import org.apache.cloudstack.backup.dao.BackupScheduleDao;
8484
import org.apache.cloudstack.context.CallContext;
85+
import org.apache.cloudstack.dns.dao.DnsZoneDao;
86+
import org.apache.cloudstack.dns.dao.DnsZoneNetworkMapDao;
87+
import org.apache.cloudstack.dns.vo.DnsZoneNetworkMapVO;
88+
import org.apache.cloudstack.dns.vo.DnsZoneVO;
8589
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
8690
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
8791
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -365,6 +369,7 @@
365369

366370
import org.apache.logging.log4j.LogManager;
367371
import org.apache.logging.log4j.Logger;
372+
import org.apache.logging.log4j.util.Strings;
368373

369374
public class ApiDBUtils {
370375
private static final Logger log = LogManager.getLogger(ApiDBUtils.class);
@@ -506,6 +511,8 @@ public class ApiDBUtils {
506511
static SharedFSJoinDao s_sharedFSJoinDao;
507512

508513
static BucketDao s_bucketDao;
514+
static DnsZoneDao s_dnsZoneDao;
515+
static DnsZoneNetworkMapDao s_dnsZoneNetworkMapDao;
509516
static VirtualMachineManager s_virtualMachineManager;
510517

511518
@Inject
@@ -778,6 +785,10 @@ public class ApiDBUtils {
778785
private VirtualMachineManager virtualMachineManager;
779786
@Inject
780787
private SharedFSJoinDao sharedFSJoinDao;
788+
@Inject
789+
private DnsZoneDao dnsZoneDao;
790+
@Inject
791+
private DnsZoneNetworkMapDao dnsZoneNetworkMapDao;
781792

782793
@PostConstruct
783794
void init() {
@@ -916,6 +927,8 @@ void init() {
916927
s_bucketDao = bucketDao;
917928
s_virtualMachineManager = virtualMachineManager;
918929
s_sharedFSJoinDao = sharedFSJoinDao;
930+
s_dnsZoneDao = dnsZoneDao;
931+
s_dnsZoneNetworkMapDao = dnsZoneNetworkMapDao;
919932
}
920933

921934
// ///////////////////////////////////////////////////////////
@@ -2294,6 +2307,17 @@ public static Map<String, String> getResourceDetails(long resourceId, ResourceOb
22942307
return details.isEmpty() ? null : details;
22952308
}
22962309

2310+
public static Pair<String, String> findDnsZoneByNetworkId(long networkId) {
2311+
DnsZoneNetworkMapVO dnsNetworkMapVO = s_dnsZoneNetworkMapDao.findByNetworkId(networkId);
2312+
if (dnsNetworkMapVO != null) {
2313+
DnsZoneVO dnsZoneVO = s_dnsZoneDao.findById(dnsNetworkMapVO.getDnsZoneId());
2314+
if (Strings.isNotBlank(dnsZoneVO.getName())) {
2315+
return new Pair<> (dnsZoneVO.getName(), dnsNetworkMapVO.getSubDomain());
2316+
}
2317+
}
2318+
return new Pair<>(null, null);
2319+
}
2320+
22972321
public static boolean isAdmin(Account account) {
22982322
return s_accountService.isAdmin(account.getId());
22992323
}

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ public class ApiResponseHelper implements ResponseGenerator {
543543
@Inject
544544
ResourceIconManager resourceIconManager;
545545

546+
546547
public static String getPrettyDomainPath(String path) {
547548
if (path == null) {
548549
return null;
@@ -2635,6 +2636,14 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)
26352636
response.setDetails(details);
26362637
}
26372638

2639+
Pair<String, String> dnsZoneAndSubDomain = ApiDBUtils.findDnsZoneByNetworkId(network.getId());
2640+
if (StringUtils.isNotBlank(dnsZoneAndSubDomain.first())) {
2641+
response.setDnsZone(dnsZoneAndSubDomain.first());
2642+
}
2643+
if (StringUtils.isNotBlank(dnsZoneAndSubDomain.second())) {
2644+
response.setDnsSubdomain(dnsZoneAndSubDomain.second());
2645+
}
2646+
26382647
DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
26392648
if (zone != null) {
26402649
response.setZoneId(zone.getUuid());

server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ public String processDnsRecordForInstance(VirtualMachine instance, Network netwo
661661
return null;
662662
}
663663
DnsServerVO server = dnsServerDao.findById(dnsZone.getDnsServerId());
664-
// Construct FQDN Prefix (e.g., "instance-id" or "instance-id.subdomain")
664+
// Construct FQDN Prefix (e.g., "instance-id.dnsZoneName" or "instance-id.subdomain.dnsZoneName")
665665
String recordName = String.valueOf(instance.getInstanceName());
666666
if (StringUtils.isNotBlank(dnsZoneNetworkMap.getSubDomain())) {
667-
recordName = recordName + "." + dnsZoneNetworkMap.getSubDomain();
667+
recordName = String.join(".", recordName, dnsZoneNetworkMap.getSubDomain(), dnsZone.getName());
668668
}
669669

670670
try {

ui/public/locales/en.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,15 @@
967967
"label.dns.server": "DNS Server",
968968
"label.dnsserverid": "DNS Server ID",
969969
"label.dnsservername": "DNS Server name",
970+
"label.dnssubdomain": "DNS Subdomain",
970971
"label.dns.servers": "DNS Servers",
971972
"label.dns.zone": "DNS Zone",
972973
"label.dns.zones": "DNS Zones",
973974
"label.dns.update.server": "Update DNS Server",
974975
"label.dns.update.zone": "Update DNS Zone",
976+
"label.dns.zone.select": "Select a DNS zone",
975977
"label.dnsrecords": "DNS Records",
978+
"label.dnszone": "DNS Zone",
976979
"label.domain": "Domain",
977980
"label.domain.id": "Domain ID",
978981
"label.domain.name": "Domain name",
@@ -2498,6 +2501,7 @@
24982501
"label.storagetype": "Storage type",
24992502
"label.storageip": "Storage IP address",
25002503
"label.strict": "Strict",
2504+
"label.subdomain": "Subdomain",
25012505
"label.subdomainaccess": "Subdomain access",
25022506
"label.submit": "Submit",
25032507
"label.subnet": "Subnet",
@@ -2990,6 +2994,9 @@
29902994
"message.confirm.delete.dns.record": "Are you sure you want to delete this DNS record?",
29912995
"message.action.delete.dns.server": "Please confirm you want to delete this DNS server.",
29922996
"message.action.delete.dns.zone": "Please confirm you want to delete this DNS zone.",
2997+
"label.action.associate.dns.zone": "Associate DNS Zone",
2998+
"label.action.disassociate.dns.zone": "Disassociate DNS Zone",
2999+
"message.action.disassociate.dns.zone": "Please confirm you want to disassociate the DNS zone from this network.",
29933000
"message.action.delete.domain": "Please confirm that you want to delete this domain.",
29943001
"message.action.delete.extension": "Please confirm that you want to delete the extension",
29953002
"message.action.delete.external.firewall": "Please confirm that you would like to remove this external firewall. Warning: If you are planning to add back the same external firewall, you must reset usage data on the device.",
@@ -3911,6 +3918,8 @@
39113918
"message.success.update.dns.server": "Successfully updated DNS server",
39123919
"message.success.update.dns.zone": "Successfully updated DNS zone",
39133920
"message.success.delete.dns.record": "Successfully deleted DNS record",
3921+
"message.success.associate.dns.zone": "Successfully associated DNS zone with network",
3922+
"message.error.fetch.dns.zones": "Could not load DNS zones.",
39143923
"message.success.add.guest.network": "Successfully created guest Network",
39153924
"message.success.add.gpu.device": "Successfully added GPU device",
39163925
"message.success.add.interface.static.route": "Successfully added interface Static Route",

ui/src/config/section/network.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { shallowRef, defineAsyncComponent } from 'vue'
1919
import store from '@/store'
2020
import tungsten from '@/assets/icons/tungsten.svg?inline'
21-
import { isAdmin } from '@/role'
21+
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
2222
import { isZoneCreated } from '@/utils/zone'
2323
import { vueProps } from '@/vue-app'
2424

@@ -49,7 +49,10 @@ export default {
4949
return fields
5050
},
5151
details: () => {
52-
var fields = ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'broadcasturi', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'asnumber', 'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'egressdefaultpolicy', 'zonename', 'account', 'domainpath', 'associatednetwork', 'associatednetworkid', 'ip4routing', 'ip6firewall', 'ip6routing', 'ip6routes', 'dns1', 'dns2', 'ip6dns1', 'ip6dns2', 'publicmtu', 'privatemtu']
52+
var fields = ['name', 'id', 'description', 'type', 'traffictype', 'vpcid', 'vlan', 'broadcasturi', 'cidr', 'ip6cidr', 'netmask', 'gateway', 'asnumber',
53+
'aclname', 'ispersistent', 'restartrequired', 'reservediprange', 'redundantrouter', 'networkdomain', 'egressdefaultpolicy', 'zonename', 'account',
54+
'domainpath', 'associatednetwork', 'associatednetworkid', 'ip4routing', 'ip6firewall', 'ip6routing', 'ip6routes', 'dns1', 'dns2', 'ip6dns1', 'ip6dns2',
55+
'publicmtu', 'privatemtu', 'dnszone', 'dnssubdomain']
5356
if (!isAdmin()) {
5457
fields = fields.filter(function (e) { return e !== 'broadcasturi' })
5558
}
@@ -202,6 +205,36 @@ export default {
202205
}
203206
}
204207
},
208+
{
209+
api: 'associateDnsZoneToNetwork',
210+
icon: 'link-outlined',
211+
label: 'label.action.associate.dns.zone',
212+
dataView: true,
213+
show: (record, store) => {
214+
return (record.type === 'Shared' && record.dnszone === undefined &&
215+
(record.account === store.userInfo.account || isAdminOrDomainAdmin(store.userInfo.roletype)))
216+
},
217+
popup: true,
218+
component: shallowRef(defineAsyncComponent(() => import('@/views/network/dns/AssociateDnsZone.vue')))
219+
},
220+
{
221+
api: 'disassociateDnsZoneFromNetwork',
222+
icon: 'disconnect-outlined',
223+
label: 'label.action.disassociate.dns.zone',
224+
message: 'message.action.disassociate.dns.zone',
225+
dataView: true,
226+
popup: true,
227+
args: ['networkid'],
228+
show: (record, store) => {
229+
return record.dnszone !== undefined && record.type === 'Shared' &&
230+
(record.account === store.userInfo.account || isAdminOrDomainAdmin(store.userInfo.roletype))
231+
},
232+
mapping: {
233+
networkid: {
234+
value: (record) => { return record.id }
235+
}
236+
}
237+
},
205238
{
206239
api: 'deleteNetwork',
207240
icon: 'delete-outlined',

ui/src/views/network/NicsTable.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@
5757
<a-descriptions-item :label="$t('label.isolationuri')" v-if="record.isolationuri">
5858
{{ record.isolationuri }}
5959
</a-descriptions-item>
60-
61-
<a-descriptions-item :label="$t('label.dns.record.url')" v-if="record.dnsrecordurl">
62-
{{ record.dnsrecordurl }}
63-
</a-descriptions-item>
6460
</template>
61+
<a-descriptions-item :label="$t('label.dns.record.url')" v-if="record.dnsrecordurl">
62+
{{ record.dnsrecordurl }}
63+
</a-descriptions-item>
6564
</a-descriptions>
6665
</template>
6766
<template #bodyCell="{ column, text, record }">

0 commit comments

Comments
 (0)