cloudns API python client.
The cloudns API is documented at http://wiki.dev.game.yy.com/moin/DNS
This python client is based on that API.
The major version of this client tries to match the the API version. Thus 1.1.* (or later) supports API v1.1.
defines exception types and constants
Bases: cloudns.base.CloudnsError
Bases: exceptions.Exception
Bases: cloudns.base.CloudnsError, exceptions.RuntimeError
Bases: cloudns.base.CloudnsRuntimeError
an error occurred on cloudns server, not your fault.
Bases: cloudns.base.CloudnsError
Bases: cloudns.base.CloudnsRuntimeError
raised when you want to create a duplicate record.
two records are dup if zone, name, content, isp are all the same.
Bases: cloudns.base.CloudnsRuntimeError
raised when you delete a record that is in PENDING_ACTIVE status.
defines the Record class
Bases: object
a record is a simple object with these attribute:
attr | description |
---|---|
rid | record id |
type | record type |
name | DNS label |
content | DNS value |
isp | tel or uni for China Telecom and China Unicom |
ctime | last modification timestamp |
z | zone name |
ttl | DNS TTL |
prio | MX priority, default is 0 |
status | this is returned from server. 0 means PENDING_ACTIVE, 1 means ACTIVE, 2 means PENDING_REMOVAL. |
It represents a record in cloudns system.
print record in a human readable format.
return a new Record with given values replaced.
rid is not allowed here, because it is used to locate which record to update.
defines the User class
Bases: object
a User in cloudns admin system.
A User can manage any zone or record it has permission with.
A User is identified by his/her passport and is authenticated by a token.
create a new record.
Note
Create duplicate record will result in DuplicateRecord raised.
add a list of records to given zone.
records example:
[{"type": "A",
"name": "test1",
"content": "1.2.3.4",
"isp": "tel",
"ttl": 300},
{"type": "A",
"name": "test1",
"content": "1.2.3.4",
"isp": "uni",
"ttl": 300}]
create a zone.
delete record by id.
if auto_retry is True, continue retry until delete is successful.
if given rid does not exist, py:class:cloudns.RecordNotFound will be raised.
delete records matching given rids.
This differs from delete_record because it sends a single request to remote server.
Delete a record that is in PENDING_ACTIVE status will raise RecordNotReady exception. This is how the cloudns API works.
delete all records that match exactly the given name in given zone.
If auto_retry is True, continue retry until delete is successful.
If given name does not match any record, py:class:cloudns.RecordNotFound will be raised.
delete a zone.
get some/all records under this zone.
offset and limit has the same meaning as in MySQL’s select statement’s limit clause. They are used to limit result to a subset.
If you don’t pass in offset and limit, default behavior is fetch first 20 records.
return all zones current user has permission.
return one Record for given rid or raise RecordNotFound.
return how many records is in given zone.
Note
you can not rely on this. Because user could have added or deleted some records after you call this method.
return a list of Records that exactly match given name.
return zone information for given zone.
return zone information for given zones.
return records that is in given zone and matches given keyword.
You can use * in keyword to match anything. You can use up to two * in keyword. consecutive * is not allowed.
update record by record.rid.
To update a record, first fetch a record with get_records_by_name() or get_record_by_id(), then call Record.update(), finally User.update_record() or Zone.update_record().
Here is an example:
>>> old_record = zone.get_record_by_id(rid)
>>> new_record = old_record.update(content="1.2.3.4")
>>> zone.update_record(new_record)
update record with given rid.
You should usually use update_record() instead of this method.
return a Zone object under this User.
Create a zone object and call methods on it so that you don’t have to pass the zone parameter all the time.
join an iterable maybe.
if obj is a string, do nothing. if obj is an iterable, join it with u’,’.
defines the Zone class.
Bases: object
a Zone can manage records in the zone easier than a User.
a Zone has a zone name (self.zone) and a binded user (self.user).
bulk create/delete records are not defined here, if you wish to use them, please use User.create_records() and User.delete_records().
create a new record.
Note
Create duplicate record will result in DuplicateRecord raised.
delete record by id.
if auto_retry is True, continue retry until delete is successful.
if given rid does not exist, cloudns.RecordNotFound will be raised.
delete all records that match exactly the given name in this zone.
If auto_retry is True, continue retry until delete is successful.
If given name does not match any record, cloudns.RecordNotFound will be raised.
get all records under this zone.
offset and limit has the same meaning as in MySQL’s select statement’s limit clause. They are used to limit result to a subset.
return one Record for given rid.
raise RecordNotFound if record not found.
return how many records in this zone.
Note
you can not rely on this. Because user could have added or deleted some records after you call this method.
return a list of Records that exactly match given name.
return records that is in this zone and matches given keyword.
You can use * in keyword to match anything. You can use up to two * in keyword. consecutive * is not allowed.
update record by record.rid.