Updated Branches:
  refs/heads/trunk 858de16e3 -> a5fc9d515

LIBCLOUD-379: Adding CloudStack examples to docs

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/a5fc9d51
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a5fc9d51
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a5fc9d51

Branch: refs/heads/trunk
Commit: a5fc9d5150648c97d65736a82249ff4e1795c2a5
Parents: 858de16
Author: Sebastien Goasguen <[email protected]>
Authored: Thu Aug 22 04:26:40 2013 -0400
Committer: Tomaz Muraus <[email protected]>
Committed: Thu Aug 22 18:00:28 2013 +0200

----------------------------------------------------------------------
 docs/compute/examples.rst                       | 19 ++++++++++++
 .../create_cloudstack_node_keypair_secgroup.py  | 32 ++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a5fc9d51/docs/compute/examples.rst
----------------------------------------------------------------------
diff --git a/docs/compute/examples.rst b/docs/compute/examples.rst
index 719fac4..681c041 100644
--- a/docs/compute/examples.rst
+++ b/docs/compute/examples.rst
@@ -92,3 +92,22 @@ supported providers and provider constants, see
 
 .. literalinclude:: /examples/compute/create_ec2_node_custom_ami.py
    :language: python
+
+Create a node on a CloudStack provider using a provided key pair and security 
groups
+------------------------------------------------------------------------------------
+
+.. note::
+
+    This example assumes the provided key pair already exists. If the key pair
+    doesn't exist yet, you can create it using the provider's own UI, or
+    :func:`ex_create_keypair` driver method.
+
+This example demonstrates how to create a node using an existing key pair.
+Created node also gets added to the provided security groups.
+
+.. literalinclude:: 
/examples/compute/create_cloudstack_node_keypair_secgroup.py
+   :language: python
+
+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.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/a5fc9d51/docs/examples/compute/create_cloudstack_node_keypair_secgroup.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/create_cloudstack_node_keypair_secgroup.py 
b/docs/examples/compute/create_cloudstack_node_keypair_secgroup.py
new file mode 100644
index 0000000..d1c8d90
--- /dev/null
+++ b/docs/examples/compute/create_cloudstack_node_keypair_secgroup.py
@@ -0,0 +1,32 @@
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+ACCESS_ID = 'your access id'
+SECRET_KEY = 'your secret key'
+HOST = 'hostname or ip address of your management server'
+PATH = 'path to the api endpoint, e.g: /client/api'
+
+SIZE_ID = 'id of the computer offering you want to use'
+TEMPLATE_ID = 'id of the template you want to use'
+
+# Name of the existing keypair you want to use
+KEYPAIR_NAME = 'keypairname'
+
+# The security groups you want this node to be added to
+SECURITY_GROUP_NAMES = 'secgroup1, secgroup2'
+
+# Extra arguments to pass to node creation
+EXTRA_ARGS = {"keypair": KEYPAIR_NAME,
+              "securitygroupnames": SECURITY_GROUP_NAMES}
+
+cls = get_driver(Provider.CLOUDSTACK)
+driver = cls(key=ACCESS_ID, secret=SECRET_KEY, secure=True,
+             host=HOST, path=PATH, extra_args=EXTRA_ARGS)
+
+sizes = driver.list_sizes()
+images = driver.list_images()
+size = [s for s in sizes if s.id == SIZE_ID][0]
+image = [i for i in images if i.id == IMAGE_ID][0]
+
+node = driver.create_node(name='test-node-1', image=image, size=size,
+                          extra_args=EXTRA_ARGS)

Reply via email to