Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating DNS samples to use newer gcloud features. #340

Merged
merged 2 commits into from
May 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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