Skip to content

Commit

Permalink
Updating DNS samples to use newer gcloud features.
Browse files Browse the repository at this point in the history
Change-Id: I0714c4abfd0830b11b7c76097766a869db9f410e
  • Loading branch information
Jon Wayne Parrott committed May 10, 2016
1 parent 667946d commit 9ab973c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions dns/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
import argparse

from gcloud import dns
from gcloud.exceptions import NotFound


# [START create_zone]
def create_zone(project_id, name, dns_name, description):
client = dns.Client(project=project_id)
zone = client.zone(
name, # examplezonename
dns_name=dns_name) # example.com.
zone.description = description
dns_name=dns_name, # example.com.
description=description)
zone.create()
return zone
# [END create_zone]
Expand All @@ -31,9 +32,13 @@ def create_zone(project_id, name, dns_name, description):
# [START get_zone]
def get_zone(project_id, name):
client = dns.Client(project=project_id)
zones, _ = client.list_zones()
zone = list(filter(lambda zone: zone.name == name, zones))
return zone.pop() if zone else None
zone = client.zone(name=name)

try:
zone.reload()
return zone
except NotFound:
return None
# [END get_zone]


Expand All @@ -48,15 +53,15 @@ def list_zones(project_id):
# [START delete_zone]
def delete_zone(project_id, name):
client = dns.Client(project=project_id)
zone = client.zone(name, None)
zone = client.zone(name)
zone.delete()
# [END delete_zone]


# [START list_resource_records]
def list_resource_records(project_id, zone_name):
client = dns.Client(project=project_id)
zone = client.zone(zone_name, None)
zone = client.zone(zone_name)

records, page_token = zone.list_resource_record_sets()
while page_token is not None:
Expand All @@ -72,7 +77,7 @@ def list_resource_records(project_id, zone_name):
# [START changes]
def list_changes(project_id, zone_name):
client = dns.Client(project=project_id)
zone = client.zone(zone_name, None)
zone = client.zone(zone_name)

changes, _ = zone.list_changes()

Expand Down

0 comments on commit 9ab973c

Please sign in to comment.