-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CloudStack DNS framework - Integrate PowerDNS as first plugin #12737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sudo87
wants to merge
55
commits into
apache:main
Choose a base branch
from
shapeblue:dnsProviderFramework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
7b9fc0e
wip: dns provider framework
sudo87 b2d597c
add db schema, vo and dao classes
sudo87 6ef7f9b
add powerdns module in plugins
sudo87 9911c28
Changes done to AddDnsServer, ListDnsServer, DeleteDnsServer and Upda…
sudo87 df21318
1. Setup Dns zone schema
sudo87 f29b8be
following dns zone apis are integrated:
sudo87 9b77c37
Tested following flow:
sudo87 c5972ae
Add associate and disassociate zone to network APIs
sudo87 99f8c7d
following things are done:
sudo87 e011ce1
add missing license, cleanup, log std
sudo87 4a9f66d
following changes are done:
sudo87 c64cf81
include:
sudo87 4df11a4
normalize dns zone and record in svc layer, always use dotless data i…
sudo87 857436e
enable apis for all roles
sudo87 582b687
add ACL annotation, entitytype, minor cleanup
sudo87 add7763
acl related changes, fixes, mistakes
sudo87 1fe79bd
fixes related to acl, dao
sudo87 6ca9d5a
add views for dns_server and dns_zone
sudo87 1c1eef3
Add Listener for VM lifecycle to add dnsrecords for associated dns zone
sudo87 caf8533
1. implement event processing for vm start/stop/destroy, nic create/d…
sudo87 856158c
starting on ui work
sudo87 928db65
resolve merge conflict with main
sudo87 369bb16
fix lint issue
sudo87 0df50ce
fix list dnsservers api, ui screens for dns servers, generate events
sudo87 a9afbce
UI related work and fixes in updateDnsServer cmd
sudo87 6bcfbc6
resolve conflict with main
sudo87 c74a579
resolve build and licensefailure issue
sudo87 7f5e2a7
continue UI component work, fix minor issue with apis
sudo87 d8cca73
resolve conflict with main
sudo87 a1eca74
work on updateDnsServer ui screen, fixed acl issue for dns server and…
sudo87 981bb64
add associate and disassociate dns zone to network ui screens, networ…
sudo87 af7ce8e
fix addDnsRecord and deleteDnsRecord flow for automatic registration …
sudo87 bde9fd9
improve cleanup logic for DNS zone and server
sudo87 5682a5a
modify delete flow for dns zone and server, ask to key in name
sudo87 c6abed1
Following changes are part of this commit:
sudo87 f1dcd00
add unit tests
sudo87 f524bbe
resolve conflict with main
sudo87 9d4e141
unit tests
sudo87 8d10ae1
Following changes are done:
sudo87 3567819
fix automatic dns record registration based on vm and nic lifecycle
sudo87 883dc32
changes:
sudo87 3ae9834
fix normalizing dns record values for mx, srv and other type
sudo87 a036281
split cleanup of old dns urls and new record registration
sudo87 6466362
unit tests
sudo87 9d0884a
add marvin test for powerdns
sudo87 30566d1
merge main changes
sudo87 f96d4cd
trim trailing space
sudo87 2d14c26
rename credentials param in dns server vue files to apikey
sudo87 001a197
rename apikey to dnsapikey, refactor ui and add dig verification in i…
sudo87 172ac67
rename dnsrecordurl -> nicdnsname, DnsNicJoinView -> nicDnsJoinVo
sudo87 5f627aa
changes in this commit:
sudo87 e997f4c
allow nic plug for stopped vm
sudo87 df5c3e6
fix nameserver ui validation
sudo87 dc18aa7
make publicdomainsuffix optional from ui and allow deleting NS record…
sudo87 80f7983
address review comments
sudo87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
api/src/main/java/org/apache/cloudstack/api/command/user/dns/AddDnsServerCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.cloudstack.api.command.user.dns; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.DnsServerResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.dns.DnsProviderType; | ||
| import org.apache.cloudstack.dns.DnsServer; | ||
| import org.apache.commons.lang3.BooleanUtils; | ||
|
|
||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import com.cloud.utils.EnumUtils; | ||
|
|
||
| @APICommand(name = "addDnsServer", | ||
| description = "Adds a new external DNS server", | ||
| responseObject = DnsServerResponse.class, | ||
| entityType = {DnsServer.class}, | ||
| requestHasSensitiveInfo = false, | ||
| responseHasSensitiveInfo = false, | ||
| since = "4.23.0", | ||
| authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| public class AddDnsServerCmd extends BaseCmd { | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| /// | ||
| @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "Name of the DNS server") | ||
| private String name; | ||
|
|
||
| @Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "API URL of the provider") | ||
| private String url; | ||
|
|
||
| @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "Provider type (e.g., PowerDNS)") | ||
| private String provider; | ||
|
|
||
| @Parameter(name = ApiConstants.DNS_USER_NAME, type = CommandType.STRING, | ||
| description = "Username or email associated with the DNS provider account (used for authentication)") | ||
| private String dnsUserName; | ||
|
|
||
| @Parameter(name = ApiConstants.DNS_API_KEY, required = true, type = CommandType.STRING, description = "API key or token for the DNS provider") | ||
| private String dnsApiKey; | ||
|
|
||
| @Parameter(name = ApiConstants.PORT, type = CommandType.INTEGER, description = "Port number of the external DNS server") | ||
| private Integer port; | ||
|
|
||
| @Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, | ||
| description = "Whether this DNS server can be used by accounts other than the owner to create and manage DNS zones") | ||
| private Boolean isPublic; | ||
|
|
||
| @Parameter(name = ApiConstants.PUBLIC_DOMAIN_SUFFIX, type = CommandType.STRING, | ||
| description = "Domain suffix that restricts DNS zones created by non-owner accounts to subdomains of this " + | ||
| "suffix (for example, sub.example.com under example.com)") | ||
| private String publicDomainSuffix; | ||
|
|
||
| @Parameter(name = ApiConstants.NAME_SERVERS, type = CommandType.LIST, collectionType = CommandType.STRING, | ||
| required = true, | ||
| description = "Comma separated list of name servers; used to create NS records for the DNS Zone (for example, ns1.example.com, ns2.example.com)") | ||
| private List<String> nameServers; | ||
|
|
||
| @Parameter(name = "externalserverid", type = CommandType.STRING, | ||
| description = "External server id or hostname for the DNS server, e.g., 'localhost' for PowerDNS") | ||
| private String externalServerId; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| public String getName() { return name; } | ||
|
|
||
| public String getUrl() { return url; } | ||
|
|
||
| public String getDnsApiKey() { | ||
| return dnsApiKey; | ||
| } | ||
|
|
||
| public Integer getPort() { | ||
| return port; | ||
| } | ||
|
|
||
| public Boolean isPublic() { | ||
| return BooleanUtils.isTrue(isPublic); | ||
| } | ||
|
|
||
| public String getPublicDomainSuffix() { | ||
| return publicDomainSuffix; | ||
| } | ||
|
|
||
| public List<String> getNameServers() { | ||
| return nameServers; | ||
| } | ||
|
|
||
| public DnsProviderType getProvider() { | ||
| DnsProviderType dnsProviderType = EnumUtils.getEnumIgnoreCase(DnsProviderType.class, provider, DnsProviderType.PowerDNS); | ||
| if (dnsProviderType == null) { | ||
| throw new InvalidParameterValueException(String.format("Invalid value passed for provider type, valid values are: %s", | ||
| EnumUtils.listValues(DnsProviderType.values()))); | ||
| } | ||
| return dnsProviderType; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccount().getId(); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| try { | ||
| DnsServer server = dnsProviderManager.addDnsServer(this); | ||
| if (server != null) { | ||
| DnsServerResponse response = dnsProviderManager.createDnsServerResponse(server); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } else { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add DNS server"); | ||
| } | ||
| } catch (Exception ex) { | ||
| logger.error("Failed to add DNS server", ex); | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public String getExternalServerId() { | ||
| return externalServerId; | ||
| } | ||
|
|
||
| public String getDnsUserName() { | ||
| return dnsUserName; | ||
| } | ||
| } | ||
94 changes: 94 additions & 0 deletions
94
...rc/main/java/org/apache/cloudstack/api/command/user/dns/AssociateDnsZoneToNetworkCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.cloudstack.api.command.user.dns; | ||
|
|
||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.acl.SecurityChecker; | ||
| import org.apache.cloudstack.api.ACL; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.DnsZoneNetworkMapResponse; | ||
| import org.apache.cloudstack.api.response.DnsZoneResponse; | ||
| import org.apache.cloudstack.api.response.NetworkResponse; | ||
|
|
||
| import com.cloud.exception.ConcurrentOperationException; | ||
| import com.cloud.exception.InsufficientCapacityException; | ||
| import com.cloud.exception.NetworkRuleConflictException; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.network.Network; | ||
| import com.cloud.user.Account; | ||
|
|
||
| @APICommand(name = "associateDnsZoneToNetwork", | ||
| description = "Associates a DNS Zone with a Network for VM auto-registration", | ||
| responseObject = DnsZoneNetworkMapResponse.class, | ||
| requestHasSensitiveInfo = false, | ||
| responseHasSensitiveInfo = false, | ||
| since = "4.23.0", | ||
| authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| public class AssociateDnsZoneToNetworkCmd extends BaseCmd { | ||
|
|
||
| @Parameter(name = ApiConstants.DNS_ZONE_ID, type = CommandType.UUID, entityType = DnsZoneResponse.class, | ||
| required = true, description = "The ID of the DNS zone") | ||
| private Long dnsZoneId; | ||
|
|
||
| @ACL(accessType = SecurityChecker.AccessType.OperateEntry) | ||
| @Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class, | ||
| required = true, description = "The ID of the network") | ||
| private Long networkId; | ||
|
|
||
| @Parameter(name = "subdomain", type = CommandType.STRING, | ||
| description = "Optional subdomain to append (e.g., 'dev' creates vm1.dev.example.com)") | ||
| private String subDomain; | ||
|
|
||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
| try { | ||
| DnsZoneNetworkMapResponse response = dnsProviderManager.associateZoneToNetwork(this); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } catch (Exception e) { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| Network network = _entityMgr.findById(Network.class, networkId); | ||
| if (network != null) { | ||
| return network.getAccountId(); | ||
| } | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
|
|
||
| public Long getDnsZoneId() { | ||
| return dnsZoneId; | ||
| } | ||
|
|
||
| public Long getNetworkId() { | ||
| return networkId; | ||
| } | ||
|
|
||
| public String getSubDomain() { | ||
| return subDomain; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it applicable for PowerDNS only ?
I think we'd better avoid provider-specific parameters