Skip to content

Commit 62e27ee

Browse files
committed
Merge pull request googleapis#1137 from tseaver/dns-document_devx
Document DNS developer experience
2 parents 8eda4a0 + abbba33 commit 62e27ee

2 files changed

Lines changed: 180 additions & 0 deletions

File tree

docs/dns-usage.rst

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
Using the API
2+
=============
3+
4+
Client
5+
------
6+
7+
:class:`Client <gcloud.dns.client.Client>` objects provide a means to
8+
configure your DNS applications. Eash instance holds both a ``project``
9+
and an authenticated connection to the DNS service.
10+
11+
For an overview of authentication in ``gcloud-python``, see :doc:`gcloud-auth`.
12+
13+
Assuming your environment is set up as described in that document,
14+
create an instance of :class:`Client <gcloud.dns.client.Client>`.
15+
16+
.. doctest::
17+
18+
>>> from gcloud import dns
19+
>>> client = dns.Client()
20+
21+
Projects
22+
--------
23+
24+
A project is the top-level container in the ``DNS`` API: it is tied
25+
closely to billing, and can provide default access control across all its
26+
datasets. If no ``project`` is passed to the client container, the library
27+
attempts to infer a project using the environment (including explicit
28+
environment variables, GAE, or GCE).
29+
30+
To override the project inferred from the environment, pass an explicit
31+
``project`` to the constructor, or to either of the alternative
32+
``classmethod`` factories:
33+
34+
.. doctest::
35+
36+
>>> from gcloud import dns
37+
>>> client = dns.Client(project='PROJECT_ID')
38+
39+
Project Quotas
40+
--------------
41+
42+
Query the quotas for a given project:
43+
44+
.. doctest::
45+
46+
>>> from gcloud import dns
47+
>>> client = dns.Client(project='PROJECT_ID')
48+
>>> quotas = client.quotas() # API request
49+
>>> for key, value in sorted(quotas.items()):
50+
... print('%s: %s' % (key, value))
51+
managedZones: 10000
52+
resourceRecordsPerRrset: 100
53+
rrsetsPerManagedZone: 10000
54+
rrsetAdditionsPerChange: 100
55+
rrsetDeletionsPerChange: 100
56+
totalRrdataSizePerChange: 10000
57+
58+
59+
Project ACLs
60+
~~~~~~~~~~~~
61+
62+
Each project has an access control list granting reader / writer / owner
63+
permission to one or more entities. This list cannot be queried or set
64+
via the API: it must be managed using the Google Developer Console.
65+
66+
67+
Managed Zones
68+
-------------
69+
70+
A "managed zone" is the container for DNS records for the same DNS name
71+
suffix and has a set of name servers that accept and responds to queries:
72+
73+
.. doctest::
74+
75+
>>> from gcloud import dns
76+
>>> client = dns.Client(project='PROJECT_ID')
77+
>>> zone = client.zone('acme-co', description='Acme Company zone',
78+
... dns_name='example.com')
79+
80+
>>> zone.exists() # API request
81+
False
82+
>>> zone.create() # API request
83+
>>> zone.exists() # API request
84+
True
85+
86+
List the zones for a given project:
87+
88+
.. doctest::
89+
90+
>>> from gcloud import dns
91+
>>> client = dns.Client(project='PROJECT_ID')
92+
>>> zones = client.list_zones() # API request
93+
>>> [zone.name for zone in zones]
94+
['acme-co']
95+
96+
97+
Resource Record Sets
98+
--------------------
99+
100+
Each managed zone exposes a read-only set of resource records:
101+
102+
.. doctest::
103+
104+
>>> from gcloud import dns
105+
>>> client = dns.Client(project='PROJECT_ID')
106+
>>> zone = client.zone('acme-co')
107+
>>> records, page_token = zone.list_resources() # API request
108+
>>> [(record.name, record.type, record.ttl, record.rrdatas) for record in records]
109+
[('example.com.', 'SOA', 21600, ['ns-cloud1.googlecomains.com dns-admin.google.com 1 21600 3600 1209600 300'])]
110+
111+
.. note::
112+
113+
The ``page_token`` returned from ``zone.list_resources()`` will be
114+
an opaque string if there are more resources than can be returned in a
115+
single request. To enumerate them all, repeat calling
116+
``zone.list_resources()``, passing the ``page_token``, until the token
117+
is ``None``. E.g.
118+
119+
.. doctest::
120+
121+
>>> records, page_token = zone.list_resources() # API request
122+
>>> while page_token is not None:
123+
... next_batch, page_token = zone.list_resources(
124+
... page_token=page_token) # API request
125+
... records.extend(next_batch)
126+
127+
128+
Change requests
129+
---------------
130+
131+
Update the resource record set for a zone by creating a change request
132+
bundling additions to or deletions from the set.
133+
134+
.. doctest::
135+
136+
>>> import time
137+
>>> from gcloud import dns
138+
>>> client = dns.Client(project='PROJECT_ID')
139+
>>> zone = client.zone('acme-co')
140+
>>> record = dns.ResourceRecord(name='www.example.com', type='CNAME')
141+
>>> change = zone.change_request(additions=[record])
142+
>>> change.begin() # API request
143+
>>> while change.status != 'done':
144+
... print('Waiting for change to complete')
145+
... time.sleep(60) # or whatever interval is appropriate
146+
... change.reload() # API request
147+
148+
149+
List changes made to the resource record set for a given zone:
150+
151+
.. doctest::
152+
153+
>>> from gcloud import dns
154+
>>> client = dns.Client(project='PROJECT_ID')
155+
>>> zone = client.zone('acme-co')
156+
>>> changes = []
157+
>>> changes, page_token = zone.list_changes() # API request
158+
159+
.. note::
160+
161+
The ``page_token`` returned from ``zone.list_changes()`` will be
162+
an opaque string if there are more changes than can be returned in a
163+
single request. To enumerate them all, repeat calling
164+
``zone.list_changes()``, passing the ``page_token``, until the token
165+
is ``None``. E.g.:
166+
167+
.. doctest::
168+
169+
>>> changes, page_token = zone.list_changes() # API request
170+
>>> while page_token is not None:
171+
... next_batch, page_token = zone.list_changes(
172+
... page_token=page_token) # API request
173+
... changes.extend(next_batch)

docs/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
resource-manager-client
5959
resource-manager-project
6060

61+
.. toctree::
62+
:maxdepth: 0
63+
:hidden:
64+
:caption: DNS
65+
66+
dns-usage
67+
6168
.. toctree::
6269
:maxdepth: 0
6370
:hidden:

0 commit comments

Comments
 (0)