docs: Promote some CloudStack code snippets to full blown code examples which can be run directly and add missing imports and variables.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/94e20cb1 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/94e20cb1 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/94e20cb1 Branch: refs/heads/trunk Commit: 94e20cb1ce28ee206f01c105364a81176f631223 Parents: b262190 Author: Tomaz Muraus <[email protected]> Authored: Fri Dec 13 12:50:05 2013 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Fri Dec 13 12:50:05 2013 +0100 ---------------------------------------------------------------------- .../cloudstack/create_node_advanced_zone.py | 12 +++++++++++- .../deploy_node_with_keypair_security_group.py | 17 +++++++++++------ .../cloudstack/instantiate_driver_host_path.py | 6 ++++++ .../cloudstack/instantiate_driver_insecure_port.py | 6 ++++++ .../compute/cloudstack/instantiate_driver_url.py | 6 ++++++ .../cloudstack/port_forwarding_management.py | 13 ++++++++++++- .../cloudstack/security_groups_management.py | 1 - .../cloudstack/start_interactive_shell_exoscale.py | 4 +++- .../cloudstack/start_interactive_shell_ikoula.py | 4 +++- 9 files changed, 58 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/create_node_advanced_zone.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/create_node_advanced_zone.py b/docs/examples/compute/cloudstack/create_node_advanced_zone.py index a174752..8334ce6 100644 --- a/docs/examples/compute/cloudstack/create_node_advanced_zone.py +++ b/docs/examples/compute/cloudstack/create_node_advanced_zone.py @@ -1,4 +1,14 @@ -# List the guest networks +from pprint import pprint + +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +apikey = 'your api key' +secretkey = 'your secret key' + +Driver = get_driver(Provider.IKOULA) +driver = Driver(key=apikey, secret=secretkey) + # This returns a list of CloudStackNetwork objects nets = driver.ex_list_networks() http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/deploy_node_with_keypair_security_group.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/deploy_node_with_keypair_security_group.py b/docs/examples/compute/cloudstack/deploy_node_with_keypair_security_group.py index d018142..bef682c 100755 --- a/docs/examples/compute/cloudstack/deploy_node_with_keypair_security_group.py +++ b/docs/examples/compute/cloudstack/deploy_node_with_keypair_security_group.py @@ -1,3 +1,5 @@ +from pprint import pprint + from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver @@ -8,14 +10,17 @@ from libcloud.compute.deployment import MultiStepDeployment cls = get_driver(Provider.EXOSCALE) driver = cls('api key', 'api secret key') +image = driver.list_images()[0] +size = driver.list_sizes()[0] + # Define the scripts that you want to run during deployment -script = ScriptDeployment("/bin/date") +script = ScriptDeployment('/bin/date') msd = MultiStepDeployment([script]) -node = conn.deploy_node(name='test', image=image, size=size, - ssh_key='~/.ssh/id_rsa_test', - ex_keyname='test-keypair', - deploy=msd) +node = driver.deploy_node(name='test', image=image, size=size, + ssh_key='~/.ssh/id_rsa_test', + ex_keyname='test-keypair', + deploy=msd) # The stdout of the deployment can be checked on the `script` object -script.stdout +pprint(script.stdout) http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/instantiate_driver_host_path.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/instantiate_driver_host_path.py b/docs/examples/compute/cloudstack/instantiate_driver_host_path.py index 0314ba2..22fb9de 100644 --- a/docs/examples/compute/cloudstack/instantiate_driver_host_path.py +++ b/docs/examples/compute/cloudstack/instantiate_driver_host_path.py @@ -1,4 +1,10 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +apikey = 'your api key' +secretkey = 'your secret key' host = 'example.com' path = '/path/to/api' + Driver = get_driver(Provider.CLOUDSTACK) conn = Driver(key=apikey, secret=secretkey, host=host, path=path) http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/instantiate_driver_insecure_port.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/instantiate_driver_insecure_port.py b/docs/examples/compute/cloudstack/instantiate_driver_insecure_port.py index a3171e3..0acca19 100644 --- a/docs/examples/compute/cloudstack/instantiate_driver_insecure_port.py +++ b/docs/examples/compute/cloudstack/instantiate_driver_insecure_port.py @@ -1,6 +1,12 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +apikey = 'your api key' +secretkey = 'your secret key' host = 'localhost' path = '/path/to/api' port = 8080 + Driver = get_driver(Provider.CLOUDSTACK) conn = Driver(key=apikey, secret=secretkey, host=host, path=path, port=port, secure=False) http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/instantiate_driver_url.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/instantiate_driver_url.py b/docs/examples/compute/cloudstack/instantiate_driver_url.py index 5fc33b9..8307380 100644 --- a/docs/examples/compute/cloudstack/instantiate_driver_url.py +++ b/docs/examples/compute/cloudstack/instantiate_driver_url.py @@ -1,3 +1,9 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +apikey = 'your api key' +secretkey = 'your secret key' url = 'http://example.com/path/to/api' + Driver = get_driver(Provider.CLOUDSTACK) conn = Driver(key=apikey, secret=secretkey, url=url) http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/port_forwarding_management.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/port_forwarding_management.py b/docs/examples/compute/cloudstack/port_forwarding_management.py index 73ec09c..e767dfc 100644 --- a/docs/examples/compute/cloudstack/port_forwarding_management.py +++ b/docs/examples/compute/cloudstack/port_forwarding_management.py @@ -1,3 +1,11 @@ +from pprint import pprint + +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +cls = get_driver(Provider.EXOSCALE) +driver = cls('api key', 'api secret key') + # Allocate a public IP # This returns a CloudStackAddress object driver.ex_allocate_public_ip() @@ -5,11 +13,14 @@ driver.ex_allocate_public_ip() # You can now see this address when listing public IPs ip = driver.ex_list_public_ips()[0] +node = driver.list_nodes()[0] + # Create a port forwarding rule for the node # This returns a CloudStackPortForwardingRule object -rule = conn.ex_create_port_forwarding_rule(ip, 22, 22, 'TCP', node) +rule = driver.ex_create_port_forwarding_rule(ip, 22, 22, 'TCP', node) pprint(rule) + # The node now has a public IP and a rule associated to it print node print node.extra http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/security_groups_management.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/security_groups_management.py b/docs/examples/compute/cloudstack/security_groups_management.py index c8dc37d..5e12a13 100644 --- a/docs/examples/compute/cloudstack/security_groups_management.py +++ b/docs/examples/compute/cloudstack/security_groups_management.py @@ -1,4 +1,3 @@ -import os from pprint import pprint from libcloud.compute.types import Provider http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/start_interactive_shell_exoscale.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/start_interactive_shell_exoscale.py b/docs/examples/compute/cloudstack/start_interactive_shell_exoscale.py index 3a07756..979a6b7 100755 --- a/docs/examples/compute/cloudstack/start_interactive_shell_exoscale.py +++ b/docs/examples/compute/cloudstack/start_interactive_shell_exoscale.py @@ -1,3 +1,5 @@ +import os + from IPython.terminal.embed import InteractiveShellEmbed from libcloud.compute.types import Provider @@ -10,5 +12,5 @@ Driver = get_driver(Provider.EXOSCALE) conn = Driver(key=apikey, secret=secretkey) -shell = InteractiveShellEmbed(banner1="Hello from Libcloud Shell !!") +shell = InteractiveShellEmbed(banner1='Hello from Libcloud Shell !!') shell() http://git-wip-us.apache.org/repos/asf/libcloud/blob/94e20cb1/docs/examples/compute/cloudstack/start_interactive_shell_ikoula.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/cloudstack/start_interactive_shell_ikoula.py b/docs/examples/compute/cloudstack/start_interactive_shell_ikoula.py index 34d554f..895bcae 100755 --- a/docs/examples/compute/cloudstack/start_interactive_shell_ikoula.py +++ b/docs/examples/compute/cloudstack/start_interactive_shell_ikoula.py @@ -1,3 +1,5 @@ +import os + from IPython.terminal.embed import InteractiveShellEmbed from libcloud.compute.types import Provider @@ -13,5 +15,5 @@ Driver = get_driver(Provider.IKOULA) conn = Driver(key=apikey, secret=secretkey) -shell = InteractiveShellEmbed(banner1="Hello from Libcloud Shell !!") +shell = InteractiveShellEmbed(banner1='Hello from Libcloud Shell !!') shell()
