docs: Add another ec2 example.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a3c0479c Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a3c0479c Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a3c0479c Branch: refs/heads/trunk Commit: a3c0479cae45b033d64755da65658d4f7abece3a Parents: adfbce1 Author: Tomaz Muraus <[email protected]> Authored: Thu Aug 15 22:02:09 2013 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Thu Aug 15 22:02:09 2013 +0200 ---------------------------------------------------------------------- docs/compute/examples.rst | 18 ++++++++++++++ .../create_ec2_node_keypair_and_to_secgroup.py | 25 ++++++++++++++++++++ 2 files changed, 43 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/a3c0479c/docs/compute/examples.rst ---------------------------------------------------------------------- diff --git a/docs/compute/examples.rst b/docs/compute/examples.rst index 47167af..719fac4 100644 --- a/docs/compute/examples.rst +++ b/docs/compute/examples.rst @@ -56,6 +56,24 @@ generic provider such as a test lab .. literalinclude:: /examples/compute/vmware_vcloud_1.5.py :language: python +Create EC2 node 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 AWS dashboard, or + :func:`ex_import_keypair` driver method. + +This example demonstrates how to create an EC2 node using an existing key pair. +Created node also gets added to the provided security groups. + +.. literalinclude:: /examples/compute/create_ec2_node_keypair_and_to_secgroup.py + :language: python + +As noted in the example, you use `ex_keyname` argument to specify key pair name +and `ex_securitygroup` to specify a name of a single (``str``) or multiple +groups (``list``) you want this node to be added to. Create EC2 node using a custom AMI ---------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/a3c0479c/docs/examples/compute/create_ec2_node_keypair_and_to_secgroup.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/create_ec2_node_keypair_and_to_secgroup.py b/docs/examples/compute/create_ec2_node_keypair_and_to_secgroup.py new file mode 100644 index 0000000..40f96a4 --- /dev/null +++ b/docs/examples/compute/create_ec2_node_keypair_and_to_secgroup.py @@ -0,0 +1,25 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +ACCESS_ID = 'your access id' +SECRET_KEY = 'your secret key' + +SIZE_ID = 't1.micro' + +# Name of the existing keypair you want to use +KEYPAIR_NAME = 'keypairname' + +# A list of security groups you want this node to be added to +SECURITY_GROUP_NAMES = ['secgroup1', 'secgroup2'] + +cls = get_driver(Provider.EC2) +driver = cls(ACCESS_ID, SECRET_KEY) + +sizes = driver.list_sizes() +images = driver.list_images() +size = [s for s in sizes if s.id == 't1.micro'][0] +image = images[0] + +node = driver.create_node(name='test-node-1', image=image, size=size, + ex_keyname=KEYPAIR_NAME, + ex_securitygroup=SECURITY_GROUP_NAMES)
