Skip to content

Add Resource Distribution Pool support#7

Closed
pavankumar2203 wants to merge 1 commit intoultradns:masterfrom
pavankumar2203:master
Closed

Add Resource Distribution Pool support#7
pavankumar2203 wants to merge 1 commit intoultradns:masterfrom
pavankumar2203:master

Conversation

@pavankumar2203
Copy link

This is to get / create /update Resource Distribution Pools on UltraDNS. ( Multiple A Records )

@sbarbett sbarbett self-assigned this Feb 25, 2025
@sbarbett
Copy link
Contributor

First off, I sincerely apologize that this request sat unacknowledged for so long. Your contribution was valuable, and I appreciate you taking the time to submit it.

While I’m no longer able to merge this code directly due to the project's changes over the years, I wanted to let you know that I’ve incorporated your feedback and code into the upcoming v2.2.5 release. I’ve extended it a bit to support additional parameters, including a description field, and I’ve also added a delete method for RD Pools.

Here’s the updated implementation:

    def _build_rd_rrset(self, rdata_info, ttl, owner_name, order, description):
        """Builds an RD Pool RRSet.
        
        :param rdata_info: List of record data for the records in the pool.
        :param ttl: The TTL value for the RRSet.
        :param owner_name: The owner name for the RRSet.
        :param order: The order in which rdata is served. Used for RD pools.
        :param description: A description for the RD pool. Defaults to owner_name if not provided.
        :return: A dictionary representing the RRSet.
        """
        profile = {
            "@context": "http://schemas.ultradns.com/RDPool.jsonschema",
            "order": order,
            "description": description if description is not None else owner_name
        }
        
        return {"ttl": ttl, "rdata": rdata_info, "profile": profile}

    def create_rd_pool(self, zone_name, owner_name, ttl, rdata_info, order="ROUND_ROBIN", ipv6=False, description=None):
        """Creates a new RD Pool.
        
        :param zone_name: The zone that contains the RRSet. The trailing dot is optional.
        :param owner_name: The owner name for the RRSet.
                          If no trailing dot is supplied, the owner_name is assumed to be relative (foo).
                          If a trailing dot is supplied, the owner name is assumed to be absolute (foo.zonename.com.)
        :param ttl: The TTL value for the RRSet.
        :param rdata_info: List of record data for the records in the pool.
                           Values are strings representing either IPv4 or IPv6 addresses.
        :param order: (Optional) The order in which rdata is served. Default is ROUND_ROBIN.
                      Valid options:
                        - ROUND_ROBIN
                        - FIXED
                        - RANDOM
        :param ipv6: (Optional) Boolean indicating whether to create an AAAA (True) or A (False) RD pool. Default is False.
        :param description: (Optional) A description for the RD pool. Defaults to owner_name if not provided.
        :return: API response from the POST request.
        """
        rtype = "AAAA" if ipv6 else "A"
        rrset = self._build_rd_rrset(rdata_info, ttl, owner_name, order, description)
        return self.rest_api_connection.post(
            f"/v1/zones/{zone_name}/rrsets/{rtype}/{owner_name}",
            json.dumps(rrset)
        )

    def edit_rd_pool(self, zone_name, owner_name, ttl, rdata_info, order="ROUND_ROBIN", ipv6=False, description=None):
        """Updates an existing RD Pool in the specified zone.
        
        :param zone_name: The zone that contains the RRSet. The trailing dot is optional.
        :param owner_name: The owner name for the RRSet.
                          If no trailing dot is supplied, the owner_name is assumed to be relative (foo).
                          If a trailing dot is supplied, the owner name is assumed to be absolute (foo.zonename.com.)
        :param ttl: The TTL value for the RRSet.
        :param rdata_info: List of record data for the records in the pool.
        :param order: (Optional) The order in which rdata is served. Default is ROUND_ROBIN.
        :param ipv6: (Optional) Boolean indicating whether to create an AAAA (True) or A (False) RD pool. Default is False.
        :param description: (Optional) A description for the RD pool. Defaults to owner_name if not provided.
        :return: API response from the PUT request.
        """
        rtype = "AAAA" if ipv6 else "A"
        rrset = self._build_rd_rrset(rdata_info, ttl, owner_name, order, description)
        return self.rest_api_connection.put(
            f"/v1/zones/{zone_name}/rrsets/{rtype}/{owner_name}",
            json.dumps(rrset)
        )

    def get_rd_pools(self, zone_name):
        """Retrieves an RD Pool in the specified zone.
        
        :param zone_name: The zone that contains the RRSet.
        :param owner_name: The owner name for the RRSet.
        :return: API response from the GET request.
        """
        return self.rest_api_connection.get(
            f"/v1/zones/{zone_name}/rrsets?q=kind:RD_POOLS"
        )

    def delete_rd_pool(self, zone_name, owner_name, ipv6=False):
        """Deletes an RD Pool in the specified zone.
        
        :param zone_name: The zone that contains the RRSet.
        :param owner_name: The owner name for the RRSet.
        :param ipv6: (Optional) Boolean indicating whether to delete an AAAA (True) or A (False) RD pool. Default is False.
        :return: API response from the DELETE request.
        """
        rtype = "AAAA" if ipv6 else "A"
        return self.rest_api_connection.delete(
            f"/v1/zones/{zone_name}/rrsets/{rtype}/{owner_name}"
        )

Your original PR helped shape these improvements. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants