Updated Branches:
  refs/heads/trunk b7304a71b -> d26c9a61e

Add example for OpenStack's floating IPs

Signed-off-by: Tomaz Muraus <[email protected]>


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

Branch: refs/heads/trunk
Commit: cf3e7bb92a500cce3c2d522745b56ec68d111eaa
Parents: b7304a7
Author: Ivan Kusalic <[email protected]>
Authored: Fri Aug 23 16:58:11 2013 +0200
Committer: Tomaz Muraus <[email protected]>
Committed: Fri Aug 23 17:34:29 2013 +0200

----------------------------------------------------------------------
 docs/compute/examples.rst                       |  8 +++++
 docs/examples/compute/openstack_floating_ips.py | 33 ++++++++++++++++++++
 2 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cf3e7bb9/docs/compute/examples.rst
----------------------------------------------------------------------
diff --git a/docs/compute/examples.rst b/docs/compute/examples.rst
index 681c041..a9418aa 100644
--- a/docs/compute/examples.rst
+++ b/docs/compute/examples.rst
@@ -111,3 +111,11 @@ Created node also gets added to the provided security 
groups.
 As noted in the example, you use `extra_args` argument to provide a dictionary 
that
 contains the keypair and list of securitygroups. Note that the list of 
securitygroups
 is passed as a string not as a python list.
+
+Create flaoting IP and attach it to a node using a local OpenStack provider
+---------------------------------------------------------------------------
+
+This example demonstrates how to use OpenStack's floating IPs.
+
+.. literalinclude:: /examples/compute/openstack_floating_ips.py
+   :language: python

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cf3e7bb9/docs/examples/compute/openstack_floating_ips.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/openstack_floating_ips.py 
b/docs/examples/compute/openstack_floating_ips.py
new file mode 100644
index 0000000..620326e
--- /dev/null
+++ b/docs/examples/compute/openstack_floating_ips.py
@@ -0,0 +1,33 @@
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+import libcloud.security
+
+# This assumes you don't have SSL set up.
+# Note: Code like this poses a security risk (MITM attack) and
+# that's the reason why you should never use it for anything else
+# besides testing. You have been warned.
+libcloud.security.VERIFY_SSL_CERT = False
+
+OpenStack = get_driver(Provider.OPENSTACK)
+driver = OpenStack('your_auth_username', 'your_auth_password',
+    ex_force_auth_url='http://10.0.4.1:5000/v2.0',
+    ex_force_auth_version='2.0_password', ex_tenant_name='your_tenant')
+
+# get the first pool - public by default
+pool, = driver.ex_list_floating_ip_pools()
+
+# create an ip in the pool
+floating_ip = pool.create_floating_ip()
+
+# get the node, note: change the node id to the some id you have
+node = driver.ex_get_node_details('922a4381-a18c-487f-b816-cc31c9060853')
+
+# attach the ip to the node
+driver.ex_attach_floating_ip_to_node(node, floating_ip)
+
+# remove it from the node
+driver.ex_detach_floating_ip_from_node(node, floating_ip)
+
+# delete the ip
+floating_ip.delete()

Reply via email to