def create_record()

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


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

        :param name: Record name without the domain name (e.g. www).
                     Note: If you want to create a record for a base domain
                     name, you should specify empty string ('') for this
                     argument.
        :type  name: ``str``

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

        :param type: DNS record type (A, MX, TXT).
        :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. 'prio' or 'ttl').
                      (optional)
        :type extra: ``dict``

        :rtype: :class:`Record`
        """
        action = "/app/dns/dyndns.jsp?"
        if name:
            record_name = name + "." + zone.domain
        else:
            record_name = zone.domain
        params = {"action": "SET", "name": record_name, "value": data, "type": type}

        if type == "MX" and extra is not None:
            params["prio"] = extra.get("prio")
        try:
            response = self.connection.request(action=action, params=params)
        except ZonomiException as e:
            if ("ERROR: No zone found for %s" % record_name) in e.message:
                raise ZoneDoesNotExistError(zone_id=zone.id, driver=self, value=e.message)
            raise e

        # we determine if an A or MX record already exists
        # by looking at the response.If the key 'skipped' is present in the
        # response, it means record already exists. If this is True,
        # then raise RecordAlreadyExistsError
        if len(response.objects) != 0 and response.objects[0].get("skipped") == "unchanged":
            raise RecordAlreadyExistsError(record_id=name, driver=self, value="")

        if "DELETED" in response.objects:
            for el in response.objects[:2]:
                if el.get("content") == data:
                    response.objects = [el]
        records = self._to_records(response.objects, zone=zone)
        return records[0]