Import other compute examples.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/854de0ff Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/854de0ff Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/854de0ff Branch: refs/heads/trunk Commit: 854de0ff85458fb41713f3579de69d08d0df599c Parents: 2648b37 Author: Tomaz Muraus <[email protected]> Authored: Sat Aug 3 14:32:34 2013 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Sat Aug 3 14:32:34 2013 +0200 ---------------------------------------------------------------------- docs/compute/examples.rst | 25 +++++++++++++ docs/examples/compute/openstack_simple.py | 15 ++++++++ docs/examples/compute/vmware_vcloud_1.5.py | 49 +++++++++++++++++++++++++ 3 files changed, 89 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/854de0ff/docs/compute/examples.rst ---------------------------------------------------------------------- diff --git a/docs/compute/examples.rst b/docs/compute/examples.rst index 22b1724..18e9d99 100644 --- a/docs/compute/examples.rst +++ b/docs/compute/examples.rst @@ -12,3 +12,28 @@ using a generic OpenStack driver. :language: python .. _`trystack.org`: http://trystack.org/ + +Create an OpenStack node using a local OpenStack provider +--------------------------------------------------------- + +This example shows how to create a node using a local OpenStack installation. +Don't forget to replace ``your_auth_username``, ``your_auth_password`` and +``ex_force_auth_url`` with the correct values specific to your installation. + +.. note:: + This example works with Libcloud version 0.9.0 and above. + +.. literalinclude:: /examples/compute/openstack_simple.py + :language: python + +Create a VMware vCloud v1.5 node using generic provider +------------------------------------------------------- + +This example demonstrates how to launch a VMware vCloud v1.5 node on a +generic provider such as a test lab. + +.. note:: + This example works with Libcloud version 0.10.1 and above. + +.. literalinclude:: /examples/compute/vmware_vcloud_1.5.py + :language: python http://git-wip-us.apache.org/repos/asf/libcloud/blob/854de0ff/docs/examples/compute/openstack_simple.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/openstack_simple.py b/docs/examples/compute/openstack_simple.py new file mode 100644 index 0000000..65659c9 --- /dev/null +++ b/docs/examples/compute/openstack_simple.py @@ -0,0 +1,15 @@ +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://192.168.1.101:5000/v2.0', + ex_force_auth_version='2.0_password') http://git-wip-us.apache.org/repos/asf/libcloud/blob/854de0ff/docs/examples/compute/vmware_vcloud_1.5.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/vmware_vcloud_1.5.py b/docs/examples/compute/vmware_vcloud_1.5.py new file mode 100644 index 0000000..86461ab --- /dev/null +++ b/docs/examples/compute/vmware_vcloud_1.5.py @@ -0,0 +1,49 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +import libcloud.security + +# Skip this step if you are launching nodes on an official vCloud +# provider. It is intended only for self signed SSL certs in +# vanilla vCloud Director v1.5 test deployments. +# 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 + +vcloud = get_driver(Provider.VCLOUD) + +driver = vcloud('you username@organisation', 'your password', + host='vcloud.local', api_version='1.5') + +# List all instantiated vApps +nodes = driver.list_nodes() +# List all VMs within the first vApp instance +print nodes[0].extra['vms'] + +# List all available vApp Templates +images = driver.list_images() +image = [i for i in images if i.name == 'natty-server-cloudimg-amd64'][0] + +# Create node with minimum set of parameters +node = driver.create_node(name='test node 1', image=image) +# Destroy the node +driver.destroy_node(node) + +# Create node without deploying and powering it on +node = driver.create_node(name='test node 2', image=image, ex_deploy=False) + +# Create node with custom CPU & Memory values +node = driver.create_node(name='test node 3', image=image, ex_vm_cpu=3, ex_vm_memory=1024) + +# Create node with customised networking parameters (eg. for OVF imported images) +node = driver.create_node(name='test node 4', image=image, + ex_vm_network='your vm net name', ex_network='your org net name', + ex_vm_fence='bridged', ex_vm_ipmode='DHCP') + +# Create node in a custom virtual data center +node = driver.create_node(name='test node 4', image=image, ex_vdc='your vdc name') + +# Create node with guest OS customisation script to be run at first boot +node = driver.create_node(name='test node 5', image=image, + ex_vm_script='filesystem path to your script')
