forked from UNIVERSAL-IT-SYSTEMS/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Proposal: gcloud.dns
JJ Geewax edited this page May 1, 2014
·
2 revisions
_____________
| Project |
‾‾‾‾‾‾|‾‾‾‾‾‾
_______/|\_______
| ManagedZone |
‾‾/‾‾‾‾‾‾‾‾‾‾‾\‾‾
_________________/|\___ ___/|\______
| ResourceRecordSet | | Change |
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾‾‾‾‾‾
-
Project(maybe) to keep track of defaults, quota, etc.
- We'd need to juggle this across all the other services in
gcloudthough. -
Projects would have a list ofZones.
-
Zone(notManagedZone).
- We know what a zone is, not worried about confusion here (even if we expose
gcloud.compute.zone). -
Zones would have a list ofRecords.
-
Recordfor the purpose of building a record string.
- The record itself boils down just to a string.
- Note: See if there is a library that already deals with parsing and rendering strings conforming to RFC 1035 (section 5) and RFC 1034 (section 3.6.1).
-
Change(under the hood only) for the purpose of simplifying API calls.
- Users shouldn't deal with this class and we shouldn't expose it if at all possible.
>>> from gcloud import dns
>>> connection = dns.get_connection(client_email, private_key_path)>>> project = connection.get_project(project_id)>>> from gcloud import dns
>>> project = dns.get_project(project_id, client_email, private_key_path)>>> project = ...
>>> zone = project.get_zone('example-zone-name')>>> from gcloud import dns
>>> zone = dns.get_zone('example-zone-name', project_name, client_email, private_key_path)- Can a Zone have multiple DNS names?
- Can we get a zone by it's DNS name?
>>> zone = project.create_zone('example-zone-name', 'example.com.')>>> record = Record()
>>> record.type('A').name('www')
>>> record.ttl(minutes=60)
>>> record.data(['1.2.3.4', '1.2.3.5'])
>>> record.add_data('1.2.3.6')
>>> print record
www 3600 IN A 1.2.3.4 1.2.3.5 1.2.3.6>>> record = Record()
>>> record = record.type('A').name('www')
>>> record = record.ttl(minutes=60)
>>> record = record.data(['1.2.3.4', '1.2.3.5'])
>>> record = record.add_data('1.2.3.6')
>>> print record
www 3600 IN A 1.2.3.4 1.2.3.5 1.2.3.6>>> zone = .... # Get a zone somehow for DNS name = example.org.
>>> zone.add_record(record) # Record as defined above.
>>> zone.add_cname('home', 'c.storage.googleapis.com.', 600)
>>> print zone
example.org. IN SOA <SOA details here>
www.example.org. 3600 IN A 1.2.3.4 1.2.3.5 1.2.3.6
home.example.org. 600 IN CNAME c.storage.googleapis.com.>>> zone.remove_record('www') # Removes all records for `www`.
>>> print zone
example.org. IN SOA <SOA details here>
home.example.org. 600 IN CNAME c.storage.googleapis.com.>>> zone.remove_record('www', '1.2.3.4')
>>> print zone
example.org. IN SOA <SOA details here>
www.example.org. 3600 IN A 1.2.3.5 1.2.3.6
home.example.org. 600 IN CNAME c.storage.googleapis.com.Calling .save() should create a Change under the hood with the deltas from the last persisted state.
>>> zone.save()For example:
- Clients 1 and 2 both load the zone, no records exist.
- Client 1 creates a change that adds
A 9.9.9.9towww. - Client 2 creates a change that adds
A 1.1.1.1towww.
What is the state of the zone?
-
A 1.1.1.1 9.9.9.9? (If we reconcile changes.) -
A 1.1.1.1? (If we overwrite changes.) -
A 9.9.9.9? (If we reject the second change.)
In general, we should try to err on the side of being too permissive on the client side, and catching errors coming back from the Cloud DNS service.
- It's probably worthwhile to check that when setting a type of a record, we throw an error if it's invalid.
- Any character that isn't valid in a DNS name or IP address (v4 or v6) should throw an error.