As keystoneclient's Session and auth plugins have been deprecated in favor of keystoneauth, the documentation examples must reflect that. This patch updates all examples in order to show keystoneauth Session usage instead of deprecated keystoneclient Session. Also, the python API bindings were updated too. Change-Id: I4b64fee4f526cc5b4a5e36cc8edb61164ceded51
13 KiB
Python Bindings - v1 and v2
The python-designateclient package comes with python bindings for both versions of the Designate API: v1 and v2. These can be used to interact with the Designate API from any python program.
Introduction - Bindings v2
To view examples of usage please checkout the doc/examples folder, basic usage is:
#!/usr/bin/env python
from designateclient.v2 import client
from designateclient import shell
from keystoneauth1.identity import generic
from keystoneauth1 import session as keystone_session
= generic.Password(
auth =shell.env('OS_AUTH_URL'),
auth_url=shell.env('OS_USERNAME'),
username=shell.env('OS_PASSWORD'),
password=shell.env('OS_PROJECT_NAME'),
project_name='default',
project_domain_id='default')
user_domain_id
= keystone_session.Session(auth=auth)
session
= client.Client(session=session)
client
= client.zones.create('i.io.', email='i@i.io')
zone
= client.recordsets.create(zone['id'], 'www', 'A', ['10.0.0.1']) rs
Introduction
Below is a simple example of how to instantiate and perform basic tasks using the bindings.
#!/usr/bin/env python
from __future__ import print_function
from designateclient.v1 import Client
# Create an instance of the client, providing the necessary credentials
= Client(
client ="https://example.com:5000/v3/",
auth_url="openstack",
username="yadayada",
password="myproject",
project_name='default',
project_domain_id='default')
user_domain_id
# Fetch a list of the domains this user/tenant has access to
= client.domains.list()
domains
# Iterate the list, printing some useful information
for domain in domains:
print("Domain ID: %s, Name: %s" % (domain.id, domain.name))
And the output this program might produce:
$ python /tmp/example.py
Domain ID: 467f97b4-f074-4839-ae85-1a61fccfb83d, Name: example-one.com.
Domain ID: 6d3bf479-8a93-47ae-8c65-3dff8dba1b0d, Name: example-two.com.
Authentication
Designate supports either Keystone authentication, or no authentication at all.
Keystone Authentication
Below is a sample of standard authentication with keystone using keystoneauth Sessions. For more information on keystoneauth API, see Using Sessions.
#!/usr/bin/env python
from designateclient.v1 import Client
from keystoneauth1.identity import generic
from keystoneauth1 import session as keystone_session
# Create an authentication plugin providing the necessary credentials
= generic.Password(
auth ="https://example.com:5000/v3/",
auth_url="openstack",
username="yadayada",
password="myproject",
project_name='default',
project_domain_id='default'
user_domain_id
)
= keystone_session.Session(auth=auth)
session
# Create an instance of the client, providing a keystoneauth Session
= Client(session=session) client
Below is a sample of standard authentication with keystone, but also explicitly providing the endpoint to use:
Note
This is useful when a development Designate instances authenticates against a production Keystone.
#!/usr/bin/env python
from designateclient.v1 import Client
from keystoneauth1.identity import generic
from keystoneauth1 import session as keystone_session
# Create an authentication plugin providing the necessary credentials
= generic.Password(
auth ="https://example.com:5000/v3/",
auth_url="openstack",
username="yadayada",
password="myproject",
project_name='default',
project_domain_id='default')
user_domain_id
= keystone_session.Session(auth=auth)
session
# Create an instance of the client, providing a keystoneauth Session
= Client(
client =session,
session="https://127.0.0.1:9001/v1/") endpoint
No Authentication
Below is a sample of interaction with a non authenticated designate:
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client, providing the endpoint directly
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint )
Working with Domains
The Domain Object
Object Properties:
Property | Description |
---|---|
id | Domain ID |
name | Domain Name (e.g. example.com.) |
Domain Responsible Person Email (e.g. fred@example.com) | |
ttl | Default TTL for records |
serial | Domain Server Number |
created_at | Date and time this domain was created at |
updated_at | Date and time this domain was last updated |
description | Domain Description |
Listing Domains
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
# List All Domains
= client.domains.list() domains
Fetching a Domain by ID
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id
# Fetch the domain
= client.domains.get(domain_id) domain
Creating a Domain
#!/usr/bin/env python
from designateclient.v1 import Client
from designateclient.v1.domains import Domain
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
# Create a new Domain object
= Domain(name="example.com.", email="fred@example.com")
domain
# Send the Create Domain API call
= client.domains.create(domain) domain
Updating a Domain
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id
# Fetch the domain
= client.domains.get(domain_id)
domain
# Update a value on the Domain
= 300
domain.ttl
# Send the Update Domain API call
= client.domains.update(domain) domain
Deleting a Domain
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id
# Fetch the domain
= client.domains.delete(domain_id) domains
Working with Records
The Record Object
Object Properties:
Property | Description |
---|---|
id | Record ID |
domain_id | Domain ID |
name | Record Name (e.g. example.com.) |
type | Record Type (e.g. A, AAAA, CNAME, MX, SRV etc) |
data | Record Data (e.g. 127.0.0.1) |
priority | Rercord Priority (Valid only for MX and SRV records) |
ttl | Record TTL |
created_at | Date and time this record was created at |
updated_at | Date and time this record was last updated |
description | Record Description |
Listing Records
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id
# List All Records
= client.records.list(domain_id) records
Fetching a Record by ID
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id = 'bd3e8520-25e0-11e3-8224-0800200c9a66'
record_id
# Fetch the record
= client.records.get(domain_id, record_id) records
Creating a Record
#!/usr/bin/env python
from designateclient.v1 import Client
from designateclient.v1.records import Record
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id
# Create a new Record object
= Record(name="www.example.com.", type="A", data="127.0.0.1")
record
# Send the Create Record API call
= client.records.create(domain_id, record) record
Updating a Record
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id = 'bd3e8520-25e0-11e3-8224-0800200c9a66'
record_id
# Fetch the record
= client.records.get(record_id)
record
# Update a value on the Record
= 300
record.ttl
# Send the Update Record API call
= client.records.update(domain_id, record) record
Deleting a Record
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
domain_id = 'bd3e8520-25e0-11e3-8224-0800200c9a66'
record_id
# Fetch the record
= client.records.delete(domain_id, record_id) records
Working with Servers
The Server Object
Object Properties:
Property | Description |
---|---|
id | Server ID |
name | Server Name (e.g. example.com.) |
created_at | Date and time this server was created at |
updated_at | Date and time this server was last updated |
Listing Servers
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
# List All Servers
= client.servers.list() servers
Fetching a Server by ID
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
server_id
# Fetch the server
= client.servers.get(server_id) server
Creating a Server
#!/usr/bin/env python
from designateclient.v1 import Client
from designateclient.v1.servers import Server
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
# Create a new Server object
= Server(name="ns1.example.com.")
server
# Send the Create Server API call
= client.servers.create(server) server
Updating a Server
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
server_id
# Fetch the server
= client.servers.get(server_id)
server
# Update a value on the Server
= "ns2.example.com"
server.name
# Send the Update Server API call
= client.servers.update(server) server
Deleting a Server
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
= Client(
client ="https://127.0.0.1:9001/v1/"
endpoint
)
= 'fb505f10-25df-11e3-8224-0800200c9a66'
server_id
# Fetch the server
= client.servers.delete(server_id) servers