Skip to content

Commit 894cd21

Browse files
committed
added RD pool functionality
1 parent 60b5e44 commit 894cd21

File tree

4 files changed

+125
-2
lines changed

4 files changed

+125
-2
lines changed

.plugin-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.2.4
1+
v2.2.5

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ def create_cname_record(client, domain):
200200
"""
201201
return client.create_rrset(domain, "CNAME", f"www.{domain}", 300, [domain])
202202

203+
def create_rd_pool(client, domain):
204+
"""Create a pool of A records in UltraDNS. This function will create an RD pool within the specified domain.
205+
206+
Args:
207+
- client (RestApiClient): An instance of the RestApiClient class.
208+
- domain (str): The domain name.
209+
210+
Returns:
211+
- dict: The response body.
212+
"""
213+
return client.create_rd_pool(
214+
domain,
215+
"pool",
216+
300,
217+
[
218+
"192.0.2.2",
219+
"192.0.2.3"
220+
]
221+
)
222+
203223
def delete_zone(client, domain):
204224
"""Delete the zone from UltraDNS.
205225

src/ultra_rest_client/about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.2.4"
1+
__version__ = "0.0.0"
22
PREFIX = "udns-python-rest-client-"
33

44
def get_client_user_agent():

src/ultra_rest_client/ultra_rest_client.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,109 @@ def batch(self, batch_list):
599599
"""
600600
return self.rest_api_connection.post("/v1/batch", json.dumps(batch_list))
601601

602+
# Create an RD Pool
603+
# Sample JSON for an RD pool -- see the REST API docs for their descriptions
604+
# {
605+
# "ttl": 120,
606+
# "rdata": [
607+
# "4.5.6.7", "199.7.167.22", "1.2.3.4", "5.6.7.8"
608+
# ],
609+
# "profile": {
610+
# "@context": "http://schemas.ultradns.com/RDPool.jsonschema",
611+
# "description": "description",
612+
# "order": "ROUND_ROBIN"
613+
# }
614+
# }
615+
616+
def _build_rd_rrset(self, rdata_info, ttl, owner_name, order, description):
617+
"""Builds an RD Pool RRSet.
618+
619+
:param rdata_info: List of record data for the records in the pool.
620+
:param ttl: The TTL value for the RRSet.
621+
:param owner_name: The owner name for the RRSet.
622+
:param order: The order in which rdata is served. Used for RD pools.
623+
:param description: A description for the RD pool. Defaults to owner_name if not provided.
624+
:return: A dictionary representing the RRSet.
625+
"""
626+
profile = {
627+
"@context": "http://schemas.ultradns.com/RDPool.jsonschema",
628+
"order": order,
629+
"description": description if description is not None else owner_name
630+
}
631+
632+
return {"ttl": ttl, "rdata": rdata_info, "profile": profile}
633+
634+
def create_rd_pool(self, zone_name, owner_name, ttl, rdata_info, order="ROUND_ROBIN", ipv6=False, description=None):
635+
"""Creates a new RD Pool.
636+
637+
:param zone_name: The zone that contains the RRSet. The trailing dot is optional.
638+
:param owner_name: The owner name for the RRSet.
639+
If no trailing dot is supplied, the owner_name is assumed to be relative (foo).
640+
If a trailing dot is supplied, the owner name is assumed to be absolute (foo.zonename.com.)
641+
:param ttl: The TTL value for the RRSet.
642+
:param rdata_info: List of record data for the records in the pool.
643+
Values are strings representing either IPv4 or IPv6 addresses.
644+
:param order: (Optional) The order in which rdata is served. Default is ROUND_ROBIN.
645+
Valid options:
646+
- ROUND_ROBIN
647+
- FIXED
648+
- RANDOM
649+
:param ipv6: (Optional) Boolean indicating whether to create an AAAA (True) or A (False) RD pool. Default is False.
650+
:param description: (Optional) A description for the RD pool. Defaults to owner_name if not provided.
651+
:return: API response from the POST request.
652+
"""
653+
rtype = "AAAA" if ipv6 else "A"
654+
rrset = self._build_rd_rrset(rdata_info, ttl, owner_name, order, description)
655+
return self.rest_api_connection.post(
656+
f"/v1/zones/{zone_name}/rrsets/{rtype}/{owner_name}",
657+
json.dumps(rrset)
658+
)
659+
660+
def edit_rd_pool(self, zone_name, owner_name, ttl, rdata_info, order="ROUND_ROBIN", ipv6=False, description=None):
661+
"""Updates an existing RD Pool in the specified zone.
662+
663+
:param zone_name: The zone that contains the RRSet. The trailing dot is optional.
664+
:param owner_name: The owner name for the RRSet.
665+
If no trailing dot is supplied, the owner_name is assumed to be relative (foo).
666+
If a trailing dot is supplied, the owner name is assumed to be absolute (foo.zonename.com.)
667+
:param ttl: The TTL value for the RRSet.
668+
:param rdata_info: List of record data for the records in the pool.
669+
:param order: (Optional) The order in which rdata is served. Default is ROUND_ROBIN.
670+
:param ipv6: (Optional) Boolean indicating whether to create an AAAA (True) or A (False) RD pool. Default is False.
671+
:param description: (Optional) A description for the RD pool. Defaults to owner_name if not provided.
672+
:return: API response from the PUT request.
673+
"""
674+
rtype = "AAAA" if ipv6 else "A"
675+
rrset = self._build_rd_rrset(rdata_info, ttl, owner_name, order, description)
676+
return self.rest_api_connection.put(
677+
f"/v1/zones/{zone_name}/rrsets/{rtype}/{owner_name}",
678+
json.dumps(rrset)
679+
)
680+
681+
def get_rd_pools(self, zone_name):
682+
"""Retrieves an RD Pool in the specified zone.
683+
684+
:param zone_name: The zone that contains the RRSet.
685+
:param owner_name: The owner name for the RRSet.
686+
:return: API response from the GET request.
687+
"""
688+
return self.rest_api_connection.get(
689+
f"/v1/zones/{zone_name}/rrsets?q=kind:RD_POOLS"
690+
)
691+
692+
def delete_rd_pool(self, zone_name, owner_name, ipv6=False):
693+
"""Deletes an RD Pool in the specified zone.
694+
695+
:param zone_name: The zone that contains the RRSet.
696+
:param owner_name: The owner name for the RRSet.
697+
:param ipv6: (Optional) Boolean indicating whether to delete an AAAA (True) or A (False) RD pool. Default is False.
698+
:return: API response from the DELETE request.
699+
"""
700+
rtype = "AAAA" if ipv6 else "A"
701+
return self.rest_api_connection.delete(
702+
f"/v1/zones/{zone_name}/rrsets/{rtype}/{owner_name}"
703+
)
704+
602705
# Create an SB Pool
603706
# Sample JSON for an SB pool -- see the REST API docs for their descriptions
604707
# {

0 commit comments

Comments
 (0)