Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5b396e9

Browse filesBrowse files
author
Jon Wayne Parrott
committed
Updating DNS samples to use newer gcloud features. (GoogleCloudPlatform#340)
1 parent 730343e commit 5b396e9
Copy full SHA for 5b396e9

File tree

Expand file treeCollapse file tree

1 file changed

+13
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-8
lines changed

‎dns/api/main.py

Copy file name to clipboardExpand all lines: dns/api/main.py
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
import argparse
1515

1616
from gcloud import dns
17+
from gcloud.exceptions import NotFound
1718

1819

1920
# [START create_zone]
2021
def create_zone(project_id, name, dns_name, description):
2122
client = dns.Client(project=project_id)
2223
zone = client.zone(
2324
name, # examplezonename
24-
dns_name=dns_name) # example.com.
25-
zone.description = description
25+
dns_name=dns_name, # example.com.
26+
description=description)
2627
zone.create()
2728
return zone
2829
# [END create_zone]
@@ -31,9 +32,13 @@ def create_zone(project_id, name, dns_name, description):
3132
# [START get_zone]
3233
def get_zone(project_id, name):
3334
client = dns.Client(project=project_id)
34-
zones, _ = client.list_zones()
35-
zone = list(filter(lambda zone: zone.name == name, zones))
36-
return zone.pop() if zone else None
35+
zone = client.zone(name=name)
36+
37+
try:
38+
zone.reload()
39+
return zone
40+
except NotFound:
41+
return None
3742
# [END get_zone]
3843

3944

@@ -48,15 +53,15 @@ def list_zones(project_id):
4853
# [START delete_zone]
4954
def delete_zone(project_id, name):
5055
client = dns.Client(project=project_id)
51-
zone = client.zone(name, None)
56+
zone = client.zone(name)
5257
zone.delete()
5358
# [END delete_zone]
5459

5560

5661
# [START list_resource_records]
5762
def list_resource_records(project_id, zone_name):
5863
client = dns.Client(project=project_id)
59-
zone = client.zone(zone_name, None)
64+
zone = client.zone(zone_name)
6065

6166
records, page_token = zone.list_resource_record_sets()
6267
while page_token is not None:
@@ -72,7 +77,7 @@ def list_resource_records(project_id, zone_name):
7277
# [START changes]
7378
def list_changes(project_id, zone_name):
7479
client = dns.Client(project=project_id)
75-
zone = client.zone(zone_name, None)
80+
zone = client.zone(zone_name)
7681

7782
changes, _ = zone.list_changes()
7883

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.