Skip to content

Commit 6ee55d7

Browse files
author
Jon Wayne Parrott
committed
Updating DNS samples to use newer gcloud features.
Change-Id: I0714c4abfd0830b11b7c76097766a869db9f410e
1 parent 2a813b9 commit 6ee55d7

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

dns/api/main.py

Lines 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)