Updated Branches:
  refs/heads/trunk 01e12d3e5 -> e1d8dd992

Import DNS API examples.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c5bf1c8c
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c5bf1c8c
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c5bf1c8c

Branch: refs/heads/trunk
Commit: c5bf1c8cd9763fa822c40b197f0fb507bc01f092
Parents: 01e12d3
Author: Tomaz Muraus <[email protected]>
Authored: Sat Aug 3 15:10:27 2013 +0200
Committer: Tomaz Muraus <[email protected]>
Committed: Sat Aug 3 15:10:27 2013 +0200

----------------------------------------------------------------------
 docs/dns/examples.rst                           | 12 ++++++
 .../create_a_record_for_all_rackspace_nodes.py  | 39 ++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5bf1c8c/docs/dns/examples.rst
----------------------------------------------------------------------
diff --git a/docs/dns/examples.rst b/docs/dns/examples.rst
new file mode 100644
index 0000000..a9d9fd5
--- /dev/null
+++ b/docs/dns/examples.rst
@@ -0,0 +1,12 @@
+DNS Examples
+============
+
+Create an 'A' record for all your compute nodes
+-----------------------------------------------
+
+This example creates a new ``mydomain2.com`` zone at Zerigo and an A record
+for all your Rackspace nodes. Value for the A record is the Node's first
+public IP address.
+
+.. literalinclude:: /examples/dns/create_a_record_for_all_rackspace_nodes.py
+   :language: python

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5bf1c8c/docs/examples/dns/create_a_record_for_all_rackspace_nodes.py
----------------------------------------------------------------------
diff --git a/docs/examples/dns/create_a_record_for_all_rackspace_nodes.py 
b/docs/examples/dns/create_a_record_for_all_rackspace_nodes.py
new file mode 100644
index 0000000..d7160ee
--- /dev/null
+++ b/docs/examples/dns/create_a_record_for_all_rackspace_nodes.py
@@ -0,0 +1,39 @@
+from pprint import pprint
+
+from libcloud.compute.providers import get_driver as get_compute_driver
+from libcloud.compute.types import Provider as ComputeProvider
+from libcloud.dns.providers import get_driver as get_dns_driver
+from libcloud.dns.types import Provider as DNSProvider, RecordType
+
+CREDENTIALS_RACKSPACE = ('username', 'api key')
+CREDENTIALS_ZERIGO = ('email', 'api key')
+
+Cls = get_compute_driver(ComputeProvider.RACKSPACE)
+compute_driver = Cls(*CREDENTIALS_RACKSPACE)
+
+Cls = get_dns_driver(DNSProvider.ZERIGO)
+dns_driver = Cls(*CREDENTIALS_ZERIGO)
+
+# Retrieve all the nodes
+nodes = compute_driver.list_nodes()
+
+# Create a new zone
+zone = dns_driver.create_zone(domain='mydomain2.com')
+
+created = []
+for node in nodes:
+    name = node.name
+
+    ips = node.public_ip
+
+    if not ips:
+        continue
+
+    ip = ips[0]
+
+    print 'Creating %s record (data=%s) for node %s' % ('A', ip, name)
+    record = zone.create_record(name=name, type=RecordType.A, data=ip)
+    created.append(record)
+
+print 'Done, created %d records' % (len(created))
+pprint(created)

Reply via email to