def create_record()

in libcloud/dns/drivers/powerdns.py [0:0]


    def create_record(self, name, zone, type, data, extra=None):
        """
        Create a new record.

        There are two PowerDNS-specific quirks here. Firstly, this method will
        silently clobber any pre-existing records that might already exist. For
        example, if PowerDNS already contains a "test.example.com" A record,
        and you create that record using this function, then the old A record
        will be replaced with your new one.

        Secondly, PowerDNS requires that you provide a ttl for all new records.
        In other words, the "extra" parameter must be ``{'ttl':
        <some-integer>}`` at a minimum.

        :param name: FQDN of the new record, for example "www.example.com".
        :type  name: ``str``

        :param zone: Zone where the requested record is created.
        :type  zone: :class:`Zone`

        :param type: DNS record type (A, AAAA, ...).
        :type  type: :class:`RecordType`

        :param data: Data for the record (depends on the record type).
        :type  data: ``str``

        :param extra: Extra attributes (driver specific, e.g. 'ttl').
                      Note that PowerDNS *requires* a ttl value for every
                      record.
        :type extra: ``dict``

        :rtype: :class:`Record`
        """
        extra = extra or {}

        action = "{}/servers/{}/zones/{}".format(self.api_root, self.ex_server, zone.id)
        if extra is None or extra.get("ttl", None) is None:
            raise ValueError("PowerDNS requires a ttl value for every record")

        if self._pdns_version() == 3:
            record = {
                "content": data,
                "disabled": False,
                "name": name,
                "ttl": extra["ttl"],
                "type": type,
            }
            payload = {
                "rrsets": [
                    {
                        "name": name,
                        "type": type,
                        "changetype": "REPLACE",
                        "records": [record],
                    }
                ]
            }
        elif self._pdns_version() == 4:
            record = {
                "content": data,
                "disabled": extra.get("disabled", False),
                "set-ptr": False,
            }
            payload = {
                "rrsets": [
                    {
                        "name": name,
                        "type": type,
                        "changetype": "REPLACE",
                        "ttl": extra["ttl"],
                        "records": [record],
                    }
                ]
            }

            if "comment" in extra:
                payload["rrsets"][0]["comments"] = extra["comment"]

        try:
            self.connection.request(action=action, data=json.dumps(payload), method="PATCH")
        except BaseHTTPError as e:
            if e.code == httplib.UNPROCESSABLE_ENTITY and e.message.startswith(
                "Could not find domain"
            ):
                raise ZoneDoesNotExistError(zone_id=zone.id, driver=self, value=e.message)
            raise e
        return Record(
            id=None,
            name=name,
            data=data,
            type=type,
            zone=zone,
            driver=self,
            ttl=extra["ttl"],
        )