1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
|
===============
Python Bindings
===============
The python-designateclient package comes with python bindings for the Designate
API. This can be used to interact with the Designate API from any python
program.
Introduction
============
Below is a simple example of how to instantiate and perform basic tasks using
the bindings.
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client, providing the necessary credentials
client = Client(
auth_url="https://example.com:5000/v2.0/",
username="openstack",
password="yadayada",
tenant_id="123456789"
)
# Fetch a list of the domains this user/tenant has access to
domains = client.domains.list()
# 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:
.. code-block:: console
$ 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:
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client, providing the necessary credentials
client = Client(
auth_url="https://example.com:5000/v2.0/",
username="openstack",
password="yadayada",
tenant_id="123456789"
)
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.
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client, providing the necessary credentials
client = Client(
auth_url="https://example.com:5000/v2.0/",
username="openstack",
password="yadayada",
tenant_id="123456789",
endpoint="https://127.0.0.1:9001/v1/"
)
No Authentication
-----------------
Below is a sample of interaction with a non authenticated designate:
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client, providing the endpoint directly
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
Working with Domains
====================
The Domain Object
-----------------
Object Properties:
======================= =======================================================
Property Description
======================= =======================================================
id Domain ID
name Domain Name (e.g. example.com.)
email 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
---------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
# List All Domains
domains = client.domains.list()
Fetching a Domain by ID
-----------------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# Fetch the domain
domain = client.domains.get(domain_id)
Creating a Domain
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
from designateclient.v1.domains import Domain
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
# Create a new Domain object
domain = Domain(name="example.com.", email="fred@example.com")
# Send the Create Domain API call
domain = client.domains.create(domain)
Updating a Domain
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# Fetch the domain
domain = client.domains.get(domain_id)
# Update a value on the Domain
domain.ttl = 300
# Send the Update Domain API call
domain = client.domains.update(domain)
Deleting a Domain
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# Fetch the domain
domains = client.domains.delete(domain_id)
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
---------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# List All Records
records = client.records.list(domain_id)
Fetching a Record by ID
-----------------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
record_id = 'bd3e8520-25e0-11e3-8224-0800200c9a66'
# Fetch the record
records = client.records.get(domain_id, record_id)
Creating a Record
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
from designateclient.v1.records import Record
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# Create a new Record object
record = Record(name="www.example.com.", type="A", data="127.0.0.1")
# Send the Create Record API call
record = client.records.create(domain_id, record)
Updating a Record
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
record_id = 'bd3e8520-25e0-11e3-8224-0800200c9a66'
# Fetch the record
record = client.records.get(record_id)
# Update a value on the Record
record.ttl = 300
# Send the Update Record API call
record = client.records.update(domain_id, record)
Deleting a Record
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
domain_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
record_id = 'bd3e8520-25e0-11e3-8224-0800200c9a66'
# Fetch the record
records = client.records.delete(domain_id, record_id)
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
---------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
# List All Servers
servers = client.servers.list()
Fetching a Server by ID
-----------------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
server_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# Fetch the server
server = client.servers.get(server_id)
Creating a Server
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
from designateclient.v1.servers import Server
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
# Create a new Server object
server = Server(name="ns1.example.com.")
# Send the Create Server API call
server = client.servers.create(server)
Updating a Server
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
server_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# Fetch the server
server = client.servers.get(server_id)
# Update a value on the Server
server.name = "ns2.example.com"
# Send the Update Server API call
server = client.servers.update(server)
Deleting a Server
-----------------
.. code-block:: python
#!/usr/bin/env python
from designateclient.v1 import Client
# Create an instance of the client
client = Client(
endpoint="https://127.0.0.1:9001/v1/"
)
server_id = 'fb505f10-25df-11e3-8224-0800200c9a66'
# Fetch the server
servers = client.servers.delete(server_id)
|