V2 Bindings
This provides bindings for: - zones - recordsets - tlds - blacklists - limits - nameservers With associated unit tests. Change-Id: Ie9b79340bd327b78916fd038633842da3ace881b
This commit is contained in:
44
doc/examples/recordset_create.py
Normal file
44
doc/examples/recordset_create.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import logging
|
||||
|
||||
from designateclient.v2 import client
|
||||
from designateclient import exceptions
|
||||
from designateclient import shell
|
||||
|
||||
from keystoneclient.auth.identity import generic
|
||||
from keystoneclient import session as keystone_session
|
||||
|
||||
|
||||
logging.basicConfig(level='DEBUG')
|
||||
|
||||
"""
|
||||
Example script to create or get a domain and add some records to it.
|
||||
"""
|
||||
|
||||
|
||||
auth = generic.Password(
|
||||
auth_url=shell.env('OS_AUTH_URL'),
|
||||
username=shell.env('OS_USERNAME'),
|
||||
password=shell.env('OS_PASSWORD'),
|
||||
tenant_name=shell.env('OS_TENANT_NAME'))
|
||||
|
||||
session = keystone_session.Session(auth=auth)
|
||||
|
||||
client = client.Client(session=session)
|
||||
|
||||
|
||||
try:
|
||||
zone = client.zones.create('i.io.', email='i@i.io')
|
||||
except exceptions.RemoteError:
|
||||
zone = dict([(z['name'], z) for z in client.zones.list()])['i.io.']
|
||||
|
||||
print("Recordset list...")
|
||||
for rs in client.recordsets.list(zone['id']):
|
||||
print rs
|
||||
|
||||
# Here's an example of just passing "www" as the record name vs "www.i.io."
|
||||
records = ["10.0.0.1"]
|
||||
rs = client.recordsets.create(zone['id'], 'www', 'A', records)
|
||||
|
||||
# Here we're replacing the records with new ones
|
||||
records = ["10.0.0.1", "10.0.0.5"]
|
||||
client.recordsets.update(zone['id'], rs['id'], {'records': records})
|
||||
72
doc/examples/recordset_crud.py
Normal file
72
doc/examples/recordset_crud.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import logging
|
||||
|
||||
from designateclient.v2 import client
|
||||
from designateclient import exceptions
|
||||
from designateclient import shell
|
||||
|
||||
from keystoneclient.auth.identity import generic
|
||||
from keystoneclient import session as keystone_session
|
||||
|
||||
|
||||
logging.basicConfig(level='DEBUG')
|
||||
|
||||
auth = generic.Password(
|
||||
auth_url=shell.env('OS_AUTH_URL'),
|
||||
username=shell.env('OS_USERNAME'),
|
||||
password=shell.env('OS_PASSWORD'),
|
||||
tenant_name=shell.env('OS_TENANT_NAME'))
|
||||
|
||||
session = keystone_session.Session(auth=auth)
|
||||
|
||||
client = client.Client(session=session)
|
||||
|
||||
|
||||
try:
|
||||
zone = dict([(z['name'], z) for z in client.zones.list()])['i.io.']
|
||||
client.zones.delete(zone['id'])
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
|
||||
zone = client.zones.create(name='i.io.', email='i@i.io')
|
||||
|
||||
# Clean all recordsets first in this zone (for sanity sake)
|
||||
for rrset in client.recordsets.list(zone['id']):
|
||||
if rrset['type'] in ('NS', 'SOA'):
|
||||
continue
|
||||
client.recordsets.delete(zone['id'], rrset['id'])
|
||||
|
||||
# Make some A records
|
||||
www = client.recordsets.create(
|
||||
zone['id'],
|
||||
'www.%s' % zone['name'],
|
||||
'A',
|
||||
['10.0.0.1'])
|
||||
|
||||
values = {
|
||||
'records': ['10.0.1.1', '10.0.0.2']
|
||||
}
|
||||
|
||||
client.recordsets.update(zone['id'], www['id'], values)
|
||||
|
||||
cname = client.recordsets.create(
|
||||
zone['id'],
|
||||
'my-site.%s' % zone['name'],
|
||||
'CNAME',
|
||||
[www['name']])
|
||||
|
||||
# Now let's do some Mailserver examples
|
||||
|
||||
# First create the A record
|
||||
mail1 = client.recordsets.create(
|
||||
zone['id'], 'mail1.' + zone['name'], 'A', ["10.0.0.11"])
|
||||
|
||||
mail2 = client.recordsets.create(
|
||||
zone['id'], 'mail2.' + zone['name'], 'A', ["10.0.0.12"])
|
||||
|
||||
# Create the MX records - it will be 1 recordset with multiple records pointing
|
||||
# to the A records we created above
|
||||
mx_rrset = client.recordsets.create(
|
||||
zone['id'], zone['name'], 'MX',
|
||||
['0 ' + mail1['name'], '5 ' + mail2['name']])
|
||||
|
||||
print(zone['id'])
|
||||
29
doc/examples/zone_create_primary.py
Normal file
29
doc/examples/zone_create_primary.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import logging
|
||||
|
||||
from designateclient import exceptions
|
||||
from designateclient import shell
|
||||
from designateclient.v2 import client
|
||||
|
||||
from keystoneclient.auth.identity import generic
|
||||
from keystoneclient import session as keystone_session
|
||||
|
||||
|
||||
logging.basicConfig(level='DEBUG')
|
||||
|
||||
auth = generic.Password(
|
||||
auth_url=shell.env('OS_AUTH_URL'),
|
||||
username=shell.env('OS_USERNAME'),
|
||||
password=shell.env('OS_PASSWORD'),
|
||||
tenant_name=shell.env('OS_TENANT_NAME'))
|
||||
|
||||
session = keystone_session.Session(auth=auth)
|
||||
|
||||
client = client.Client(session=session)
|
||||
|
||||
|
||||
try:
|
||||
zone = client.zones.create('i.io.', email='i@i.io')
|
||||
except exceptions.RemoteError:
|
||||
zone = dict([(z['name'], z) for z in client.zones.list()])['i.io.']
|
||||
|
||||
print client.recordsets.list(zone['id'])
|
||||
43
doc/examples/zone_create_secondary.py
Normal file
43
doc/examples/zone_create_secondary.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
from keystoneclient.auth.identity import generic
|
||||
from keystoneclient import session as keystone_session
|
||||
|
||||
from designateclient import exceptions
|
||||
from designateclient import shell
|
||||
from designateclient.v2 import client
|
||||
|
||||
|
||||
logging.basicConfig(level='DEBUG')
|
||||
|
||||
auth = generic.Password(
|
||||
auth_url=shell.env('OS_AUTH_URL'),
|
||||
username=shell.env('OS_USERNAME'),
|
||||
password=shell.env('OS_PASSWORD'),
|
||||
tenant_name=shell.env('OS_TENANT_NAME'))
|
||||
|
||||
session = keystone_session.Session(auth=auth)
|
||||
|
||||
client = client.Client(session=session)
|
||||
|
||||
# Primary Zone
|
||||
primary = client.zones.create(
|
||||
'primary-%s.io.' % str(uuid.uuid4()),
|
||||
'PRIMARY',
|
||||
'root@x.com')
|
||||
|
||||
# Secondary Zone
|
||||
slave = client.zones.create(
|
||||
'secondary-%s.io.' % str(uuid.uuid4()),
|
||||
'SECONDARY',
|
||||
masters=["127.0.1.1"])
|
||||
|
||||
# Try updating Masters for the Secondary
|
||||
new_slave = client.zones.update(
|
||||
slave['id'],
|
||||
{"masters": ["10.0.0.1", "10.0.0.10"]}
|
||||
)
|
||||
|
||||
# List all Zones
|
||||
zones = client.zones.list()
|
||||
29
doc/examples/zone_list_nameservers.py
Normal file
29
doc/examples/zone_list_nameservers.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
from designateclient.v2 import client
|
||||
from designateclient import shell
|
||||
from designateclient import utils
|
||||
|
||||
from keystoneclient.auth.identity import generic
|
||||
from keystoneclient import session as keystone_session
|
||||
|
||||
|
||||
logging.basicConfig(level='DEBUG')
|
||||
|
||||
auth = generic.Password(
|
||||
auth_url=shell.env('OS_AUTH_URL'),
|
||||
username=shell.env('OS_USERNAME'),
|
||||
password=shell.env('OS_PASSWORD'),
|
||||
tenant_name=shell.env('OS_TENANT_NAME'))
|
||||
|
||||
session = keystone_session.Session(auth=auth)
|
||||
|
||||
client = client.Client(session=session)
|
||||
|
||||
zone = client.zones.create(
|
||||
'primary-%s.io.' % str(uuid.uuid4()),
|
||||
'PRIMARY',
|
||||
'root@x.com')
|
||||
|
||||
client.nameservers.list(zone['id'])
|
||||
36
doc/examples/zone_list_paging.py
Normal file
36
doc/examples/zone_list_paging.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import logging
|
||||
|
||||
from keystoneclient.auth.identity import generic
|
||||
from keystoneclient import session as keystone_session
|
||||
|
||||
from designateclient import shell
|
||||
from designateclient.v2 import client
|
||||
|
||||
logging.basicConfig(level='DEBUG')
|
||||
|
||||
auth = generic.Password(
|
||||
auth_url=shell.env('OS_AUTH_URL'),
|
||||
username=shell.env('OS_USERNAME'),
|
||||
password=shell.env('OS_PASSWORD'),
|
||||
tenant_name=shell.env('OS_TENANT_NAME'))
|
||||
|
||||
session = keystone_session.Session(auth=auth)
|
||||
|
||||
client = client.Client(session=session)
|
||||
|
||||
|
||||
pages = []
|
||||
|
||||
fetch = 1
|
||||
while fetch:
|
||||
kw = {'limit': 3}
|
||||
if pages:
|
||||
# marker is the latest page with the last item.
|
||||
kw['marker'] = pages[-1][-1]['id']
|
||||
page = client.zones.list(**kw)
|
||||
if not page:
|
||||
break
|
||||
pages.append(page)
|
||||
|
||||
for page in pages:
|
||||
print page
|
||||
Reference in New Issue
Block a user