From 8ea05d395c8c0550e0b4fba03537ed9583bd276b Mon Sep 17 00:00:00 2001 From: Sebastien Goasguen Date: Thu, 22 Aug 2013 04:26:40 -0400 Subject: [PATCH] LIBCLOUD-379: Adding CloudStack examples to docs --- docs/compute/examples.rst | 19 +++++++++++++ .../create_cloudstack_node_keypair_secgroup.py | 32 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 docs/examples/compute/create_cloudstack_node_keypair_secgroup.py 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. 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) -- 1.8.2.3