Author: tomaz
Date: Tue May 14 06:59:46 2013
New Revision: 1482232
URL: http://svn.apache.org/r1482232
Log:
Backport commit from trunk.
Modified:
libcloud/branches/0.12.x/ (props changed)
libcloud/branches/0.12.x/CHANGES
libcloud/branches/0.12.x/libcloud/compute/drivers/openstack.py
libcloud/branches/0.12.x/libcloud/test/compute/test_openstack.py
Propchange: libcloud/branches/0.12.x/
------------------------------------------------------------------------------
Merged /libcloud/trunk:r1482230
Modified: libcloud/branches/0.12.x/CHANGES
URL:
http://svn.apache.org/viewvc/libcloud/branches/0.12.x/CHANGES?rev=1482232&r1=1482231&r2=1482232&view=diff
==============================================================================
--- libcloud/branches/0.12.x/CHANGES (original)
+++ libcloud/branches/0.12.x/CHANGES Tue May 14 06:59:46 2013
@@ -28,6 +28,11 @@ Changes with Apache Libcloud in deveplom
- Various improvements and bug-fixes in the VCloud driver. (LIBCLOUD-323)
[Michel Samia]
+ - Modify list_sizes method in the OpenStack driver to include
+ OpenStackNodeSize object which includes 'vcpus' attribute which holds
+ a number of virtual CPUs for this size. (LIBCLOUD-325)
+ [Carlo]
+
*) Load Balancer
- Add ex_list_current_usage method to the Rackspace driver.
Modified: libcloud/branches/0.12.x/libcloud/compute/drivers/openstack.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/compute/drivers/openstack.py?rev=1482232&r1=1482231&r2=1482232&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/compute/drivers/openstack.py (original)
+++ libcloud/branches/0.12.x/libcloud/compute/drivers/openstack.py Tue May 14
06:59:46 2013
@@ -23,8 +23,6 @@ except ImportError:
import warnings
-from itertools import chain
-
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import b
from libcloud.utils.py3 import next
@@ -272,6 +270,30 @@ class OpenStackNodeDriver(NodeDriver, Op
return self._reboot_node(node, reboot_type='HARD')
+class OpenStackNodeSize(NodeSize):
+ """
+ NodeSize class for the OpenStack.org driver.
+
+ Following the example of OpenNebula.org driver
+ and following guidelines:
+ https://issues.apache.org/jira/browse/LIBCLOUD-119
+ """
+
+ def __init__(self, id, name, ram, disk, bandwidth, price, driver,
+ vcpus=None):
+ super(OpenStackNodeSize, self).__init__(id=id, name=name, ram=ram,
+ disk=disk,
+ bandwidth=bandwidth,
+ price=price, driver=driver)
+ self.vcpus = vcpus
+
+ def __repr__(self):
+ return (('<OpenStackNodeSize: id=%s, name=%s, ram=%s, disk=%s, '
+ 'bandwidth=%s, price=%s, driver=%s, vcpus=%s, ...>')
+ % (self.id, self.name, self.ram, self.disk, self.bandwidth,
+ self.price, self.driver.name, self.vcpus))
+
+
class OpenStack_1_0_Response(OpenStackResponse):
def __init__(self, *args, **kwargs):
# done because of a circular reference from
@@ -769,15 +791,17 @@ class OpenStack_1_0_NodeDriver(OpenStack
return [self._to_size(el) for el in elements]
def _to_size(self, el):
- return NodeSize(id=el.get('id'),
- name=el.get('name'),
- ram=int(el.get('ram')),
- disk=int(el.get('disk')),
- # XXX: needs hardcode
- bandwidth=None,
- # Hardcoded
- price=self._get_size_price(el.get('id')),
- driver=self.connection.driver)
+ vcpus = int(el.get('vcpus')) if el.get('vcpus', None) else None
+ return OpenStackNodeSize(id=el.get('id'),
+ name=el.get('name'),
+ ram=int(el.get('ram')),
+ disk=int(el.get('disk')),
+ # XXX: needs hardcode
+ vcpus=vcpus,
+ bandwidth=None,
+ # Hardcoded
+ price=self._get_size_price(el.get('id')),
+ driver=self.connection.driver)
def ex_limits(self):
"""
@@ -1092,7 +1116,8 @@ class OpenStack_1_1_NodeDriver(OpenStack
server_object = server_resp.object['server']
# adminPass is not always present
- #
http://docs.openstack.org/essex/openstack-compute/admin/content/configuring-compute-API.html#d6e1833
+ # http://docs.openstack.org/essex/openstack-compute/admin/
+ # content/configuring-compute-API.html#d6e1833
server_object['adminPass'] = create_response.get('adminPass', None)
return self._to_node(server_object)
@@ -1639,11 +1664,12 @@ class OpenStack_1_1_NodeDriver(OpenStack
if not price:
price = self._get_size_price(str(api_flavor['id']))
- return NodeSize(
+ return OpenStackNodeSize(
id=api_flavor['id'],
name=api_flavor['name'],
ram=api_flavor['ram'],
disk=api_flavor['disk'],
+ vcpus=api_flavor['vcpus'],
bandwidth=bandwidth,
price=price,
driver=self,
Modified: libcloud/branches/0.12.x/libcloud/test/compute/test_openstack.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/0.12.x/libcloud/test/compute/test_openstack.py?rev=1482232&r1=1482231&r2=1482232&view=diff
==============================================================================
--- libcloud/branches/0.12.x/libcloud/test/compute/test_openstack.py (original)
+++ libcloud/branches/0.12.x/libcloud/test/compute/test_openstack.py Tue May 14
06:59:46 2013
@@ -672,6 +672,8 @@ class OpenStack_1_1_Tests(unittest.TestC
self.assertTrue(isinstance(size.price, float),
'Wrong size price type')
+ self.assertEqual(sizes[0].vcpus, 8)
+
def test_list_sizes_with_specified_pricing(self):
pricing = dict((str(i), i * 5.0) for i in range(1, 9))