You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/01/30 15:19:51 UTC

[1/3] git commit: docs: Add examples of how to retrieve balance and use ex_avoid.

Updated Branches:
  refs/heads/trunk 37abf99c5 -> feba5a3be


docs: Add examples of how to retrieve balance and use ex_avoid.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/626c881a
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/626c881a
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/626c881a

Branch: refs/heads/trunk
Commit: 626c881a5b3dfe7a3ea35afb32933de13a191c44
Parents: 37abf99
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Jan 30 13:16:36 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Jan 30 13:16:36 2014 +0100

----------------------------------------------------------------------
 docs/compute/drivers/cloudsigma.rst             | 31 ++++++++++++++++++++
 .../compute/cloudsigma/create_node_ex_avoid.py  | 17 +++++++++++
 .../compute/cloudsigma/get_account_balance.py   | 10 +++++++
 3 files changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/626c881a/docs/compute/drivers/cloudsigma.rst
----------------------------------------------------------------------
diff --git a/docs/compute/drivers/cloudsigma.rst b/docs/compute/drivers/cloudsigma.rst
index 8823355..0ea35a2 100644
--- a/docs/compute/drivers/cloudsigma.rst
+++ b/docs/compute/drivers/cloudsigma.rst
@@ -125,6 +125,37 @@ servers tagged with ``database-server``.
 .. literalinclude:: /examples/compute/cloudsigma/attach_firewall_policy.py
    :language: python
 
+7. Starting a server in a different availability group using avoid functionality
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+CloudSigma allows you to specify a list of server UUIDs which to avoid when
+starting a server.
+
+This helps make your infrastructure more highly available and is useful when
+you want to create a server in a different availability zone than the existing
+server.
+
+The example bellow shows how to create a new server in a different availability
+zone from all the existing servers.
+
+Keep in mind that `as noted in the CloudSigma documentation
+<https://zrh.cloudsigma.com/docs/availability_groups.html#general-notes-on-avoid-functionality>`_,
+this functionality uses the best effort mode. This means that the request might
+succeed even if the avoid can not be satisfied and the requested resource ends
+in the same availability group as an avoid resource.
+
+.. literalinclude:: /examples/compute/cloudsigma/create_node_ex_avoid.py
+   :language: python
+
+8. Retrieving the account balance
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This example shows how to retrieve the account balance. The method returns a
+dictionary with two keys - ``balance`` and ``currency``.
+
+.. literalinclude:: /examples/compute/cloudsigma/get_account_balance.py
+   :language: python
+
 API Docs
 --------
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/626c881a/docs/examples/compute/cloudsigma/create_node_ex_avoid.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/cloudsigma/create_node_ex_avoid.py b/docs/examples/compute/cloudsigma/create_node_ex_avoid.py
new file mode 100644
index 0000000..9126d67
--- /dev/null
+++ b/docs/examples/compute/cloudsigma/create_node_ex_avoid.py
@@ -0,0 +1,17 @@
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+cls = get_driver(Provider.CLOUDSIGMA)
+driver = cls('username', 'password', region='zrh', api_version='2.0')
+
+name = 'test node avoid mode'
+size = driver.list_sizes()[0]
+image = driver.list_images()[0]
+
+existing_nodes = driver.list_nodes()
+existing_node_uuids = [node.id for node in existing_nodes]
+
+
+node = driver.create_node(name=name, size=size, image=image,
+                          ex_avoid=existing_node_uuids)
+print(node)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/626c881a/docs/examples/compute/cloudsigma/get_account_balance.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/cloudsigma/get_account_balance.py b/docs/examples/compute/cloudsigma/get_account_balance.py
new file mode 100644
index 0000000..29d55e2
--- /dev/null
+++ b/docs/examples/compute/cloudsigma/get_account_balance.py
@@ -0,0 +1,10 @@
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+cls = get_driver(Provider.CLOUDSIGMA)
+driver = cls('username', 'password', region='zrh', api_version='2.0')
+
+balance = driver.ex_get_balance()
+
+values = {'balance': balance['balance'], 'currency': balance['currency']}
+print('Account balance: %(balance)s %(currency)s' % values)


[3/3] git commit: docs: Add more examples to CloudSigma driver page.

Posted by to...@apache.org.
docs: Add more examples to CloudSigma driver page.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/feba5a3b
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/feba5a3b
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/feba5a3b

Branch: refs/heads/trunk
Commit: feba5a3beef44b07868454af80ac46dd769ea3ea
Parents: 4c527c8
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Jan 30 14:55:39 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Jan 30 14:55:39 2014 +0100

----------------------------------------------------------------------
 docs/compute/drivers/cloudsigma.rst             | 40 ++++++++++++++++----
 .../cloudsigma/list_sizes_images_drives.py      | 14 +++++++
 2 files changed, 46 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/feba5a3b/docs/compute/drivers/cloudsigma.rst
----------------------------------------------------------------------
diff --git a/docs/compute/drivers/cloudsigma.rst b/docs/compute/drivers/cloudsigma.rst
index 0ea35a2..241349c 100644
--- a/docs/compute/drivers/cloudsigma.rst
+++ b/docs/compute/drivers/cloudsigma.rst
@@ -42,7 +42,31 @@ here for completeness.
 .. literalinclude:: /examples/compute/cloudsigma/connect_to_api_1_0.py
    :language: python
 
-3. Create a server using a custom node size
+3. Listing available sizes, images and drives
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In Libcloud, a :class:`libcloud.compute.base.NodeSize` represents a physical
+configuration of a server and a :class:`libcloud.compute.base.NodeImage`
+represents an operating system.
+
+To comply with a standard Libcloud API,
+:class:`libcloud.compute.base.NodeDriver.list_images` method only returns
+available pre-installed library images. Those images can be passed directly
+to
+:class:`libcloud.compute.drivers.cloudsigma.CloudSigma_2_0_NodeDriver.create_node`
+method and used to create a server.
+
+If you want to list all the available images and drives, you should use
+:class:`libcloud.compute.drivers.cloudsigma.CloudSigma_2_0_NodeDriver.ex_list_drives`
+method.
+
+The example bellow shows how to list all the available sizes, images and
+drives.
+
+.. literalinclude:: /examples/compute/cloudsigma/list_sizes_images_drives.py
+   :language: python
+
+4. Create a server using a custom node size
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Unlike most of the other cloud providers out there, CloudSigma is not limited
@@ -72,7 +96,7 @@ You can find exact limits and free capacity for your account's location using
 :meth:`libcloud.compute.drivers.cloudsigma.CloudSigma_2_0_NodeDriver.ex_list_capabilities`
 method.
 
-4. Associate metadata with a server upon creation
+5. Associate metadata with a server upon creation
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 CloudSigma allows you to associate arbitrary key / value pairs with each
@@ -81,7 +105,7 @@ server. This examples shows how to do that upon server creation.
 .. literalinclude:: /examples/compute/cloudsigma/create_server_with_metadata.py
    :language: python
 
-4. Add a tag to the server
+6. Add a tag to the server
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 CloudSigma allows you to ogranize resources such as servers and drivers by
@@ -90,7 +114,7 @@ tagging them. This example shows how to do that.
 .. literalinclude:: /examples/compute/cloudsigma/tag_server.py
    :language: python
 
-5. Open a VNC tunnel to the server
+7. Open a VNC tunnel to the server
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 CloudSigma allows you to connect and manage your server using `VNC`_. To
@@ -115,7 +139,7 @@ method.
 .. literalinclude:: /examples/compute/cloudsigma/open_vnc_tunnel.py
    :language: python
 
-6. Attach firewall policy to the server
+8. Attach firewall policy to the server
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 CloudSigma allows you to restrict access to your servers by using firewall
@@ -125,7 +149,7 @@ servers tagged with ``database-server``.
 .. literalinclude:: /examples/compute/cloudsigma/attach_firewall_policy.py
    :language: python
 
-7. Starting a server in a different availability group using avoid functionality
+9. Starting a server in a different availability group using avoid functionality
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 CloudSigma allows you to specify a list of server UUIDs which to avoid when
@@ -147,8 +171,8 @@ in the same availability group as an avoid resource.
 .. literalinclude:: /examples/compute/cloudsigma/create_node_ex_avoid.py
    :language: python
 
-8. Retrieving the account balance
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+10. Retrieving the account balance
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 This example shows how to retrieve the account balance. The method returns a
 dictionary with two keys - ``balance`` and ``currency``.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/feba5a3b/docs/examples/compute/cloudsigma/list_sizes_images_drives.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/cloudsigma/list_sizes_images_drives.py b/docs/examples/compute/cloudsigma/list_sizes_images_drives.py
new file mode 100644
index 0000000..ae33c59
--- /dev/null
+++ b/docs/examples/compute/cloudsigma/list_sizes_images_drives.py
@@ -0,0 +1,14 @@
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+
+cls = get_driver(Provider.CLOUDSIGMA)
+driver = cls('username', 'password', region='zrh', api_version='2.0')
+
+sizes = driver.list_sizes()
+print(sizes)
+
+images = driver.list_images()
+print(images)
+
+drives = driver.ex_list_drives()
+print(drives)


[2/3] git commit: When creating a CloudSigma node, assign public interface to the node.

Posted by to...@apache.org.
When creating a CloudSigma node, assign public interface to the node.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/4c527c89
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/4c527c89
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/4c527c89

Branch: refs/heads/trunk
Commit: 4c527c8999f065a73699d05f257abe9cb2044530
Parents: 626c881
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Jan 30 14:20:20 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Jan 30 14:24:38 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/cloudsigma.py              | 11 +++++++++++
 .../fixtures/cloudsigma_2_0/servers_create.json     | 16 +++++++++++++++-
 libcloud/test/compute/test_cloudsigma_v2_0.py       |  2 ++
 3 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4c527c89/libcloud/compute/drivers/cloudsigma.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudsigma.py b/libcloud/compute/drivers/cloudsigma.py
index 0b23a85..c50db8b 100644
--- a/libcloud/compute/drivers/cloudsigma.py
+++ b/libcloud/compute/drivers/cloudsigma.py
@@ -1112,6 +1112,17 @@ class CloudSigma_2_0_NodeDriver(CloudSigmaNodeDriver):
         if ex_metadata:
             data['meta'] = ex_metadata
 
+        # Assign 1 public interface (DHCP) to the node
+        data['nics'] = [
+            {
+                'boot_order': None,
+                'ip_v4_conf': {
+                    'conf': 'dhcp',
+                },
+                'ip_v6_conf': None
+            }
+        ]
+
         data['drives'] = [
             {
                 'boot_order': 1,

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4c527c89/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create.json b/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create.json
index 257fb31..4c93a60 100644
--- a/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create.json
+++ b/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create.json
@@ -12,7 +12,21 @@
             "mem": 536870912,
             "meta": {},
             "name": "test node",
-            "nics": [],
+            "nics": [
+                {
+                    "boot_order": null,
+                    "firewall_policy": null,
+                    "ip_v4_conf": {
+                        "conf": "dhcp",
+                        "ip": null
+                    },
+                    "ip_v6_conf": null,
+                    "mac": "22:08:76:b1:ce:41",
+                    "model": "virtio",
+                    "runtime": null,
+                    "vlan": null
+                }
+            ],
             "owner": {
                 "resource_uri": "/api/2.0/user/5b4a69a3-8e78-4c45-a8ba-8b13f0895e23/",
                 "uuid": "5b4a69a3-8e78-4c45-a8ba-8b13f0895e23"

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4c527c89/libcloud/test/compute/test_cloudsigma_v2_0.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudsigma_v2_0.py b/libcloud/test/compute/test_cloudsigma_v2_0.py
index 9e6690c..0b5948f 100644
--- a/libcloud/test/compute/test_cloudsigma_v2_0.py
+++ b/libcloud/test/compute/test_cloudsigma_v2_0.py
@@ -91,6 +91,8 @@ class CloudSigmaAPI20BaseTestCase(object):
         node = self.driver.create_node(name='test node', size=size, image=image,
                                        ex_metadata=metadata)
         self.assertEqual(node.name, 'test node')
+        self.assertEqual(len(node.extra['nics']), 1)
+        self.assertEqual(node.extra['nics'][0]['ip_v4_conf']['conf'], 'dhcp')
 
     def test_destroy_node(self):
         status = self.driver.destroy_node(node=self.node)