Permalink
Browse files

Merge branch 'trunk' of git://git.apache.org/libcloud into trunk

Conflicts:
	libcloud/compute/drivers/rackspace.py
  • Loading branch information...
2 parents 6e92d24 + 510c36a commit 6259eee83e6157350cbd8ed159bd6c4e9ce9254a @tavisrudd committed Mar 15, 2011
@@ -69,6 +69,14 @@
'disk': 160,
'bandwidth': None,
},
+ 'medium': {
+ 'id': 'medium',
+ 'name': 'Medium instance',
+ 'cpu': 3000,
+ 'memory': 4096,
+ 'disk': 500,
+ 'bandwidth': None,
+ },
'large': {
'id': 'large',
'name': 'Large instance',
@@ -239,6 +247,7 @@ class ElasticHostsBaseNodeDriver(NodeDriver):
"""
type = Provider.ELASTICHOSTS
+ api_name = 'elastichosts'
name = 'ElasticHosts'
connectionCls = ElasticHostsBaseConnection
features = {"create_node": ["generates_password"]}
@@ -281,7 +290,8 @@ def list_sizes(self, location=None):
size = ElasticHostsNodeSize(
id=value['id'],
name=value['name'], cpu=value['cpu'], ram=value['memory'],
- disk=value['disk'], bandwidth=value['bandwidth'], price='',
+ disk=value['disk'], bandwidth=value['bandwidth'],
+ price=self._get_size_price(size_id=value['id']),
driver=self.connection.driver
)
sizes.append(size)
@@ -136,6 +136,7 @@ class RackspaceNodeDriver(NodeDriver):
"""
connectionCls = RackspaceConnection
type = Provider.RACKSPACE
+ api_name = 'rackspace'
name = 'Rackspace'
_rackspace_prices = get_pricing(driver_type='compute',
@@ -446,8 +447,7 @@ def _to_size(self, el):
ram=int(el.get('ram')),
disk=int(el.get('disk')),
bandwidth=None, # XXX: needs hardcode
- price=self._rackspace_prices.get(
- el.get('id')), # Hardcoded,
+ price=self._get_size_price(el.get('id')), # Hardcoded,
driver=self.connection.driver)
return s
@@ -22,6 +22,8 @@
except:
import simplejson as json
+from libcloud.pricing import get_pricing
+
from libcloud.common.base import ConnectionUserAndKey, Response
from libcloud.common.types import InvalidCredsError
from libcloud.compute.providers import Provider
@@ -35,17 +37,7 @@
RAM_PER_NODE = 256
DISK_PER_NODE = 10
BANDWIDTH_PER_NODE = 250
-PRICE_PER_NODE = {1: 20,
- 2: 19,
- 3: 18,
- 4: 17,
- 5: 16,
- 6: 15,
- 7: 14,
- 15: 13,
- 30: 12,
- 60: 11,
- 100: 10}
+
class VPSNetResponse(Response):
@@ -89,6 +81,7 @@ class VPSNetNodeDriver(NodeDriver):
"""
type = Provider.VPSNET
+ api_name = 'vps_net'
name = "vps.net"
connectionCls = VPSNetConnection
@@ -125,13 +118,15 @@ def _to_size(self, num):
return size
def _get_price_per_node(self, num):
+ PRICE_PER_NODE = get_pricing(driver_type='compute',
+ driver_name=self.api_name)
keys = sorted(PRICE_PER_NODE.keys())
if num >= max(keys):
return PRICE_PER_NODE[keys[-1]]
for i in range(0,len(keys)):
- if keys[i] <= num < keys[i+1]:
+ if int(keys[i]) <= num < int(keys[i+1]):
return PRICE_PER_NODE[keys[i]]
def create_node(self, name, image, size, **kwargs):
View
@@ -91,11 +91,34 @@
"high-cpu-extra-large": 0.780
},
+ "elastichosts": {
+ "small": 0.100,
+ "medium": 0.223,
+ "large": 0.378,
+ "extra-large": 0.579,
+ "high-cpu-medium": 0.180,
+ "high-cpu-extra-large": 0.770
+ },
+
"gogrid": {
"512MB": 0.095,
"1GB": 0.19,
"2GB": 0.38,
"4GB": 0.76,
"8GB": 1.52
+ },
+
+ "vps_net": {
+ "1": 20,
+ "2": 19,
+ "3": 18,
+ "4": 17,
+ "5": 16,
+ "6": 15,
+ "7": 14,
+ "15": 13,
+ "30": 12,
+ "60": 11,
+ "100": 10
}
}
View
@@ -32,6 +32,12 @@
'storage': {}
}
+def get_pricing_file_path(file_path=None):
+ pricing_directory = os.path.dirname(os.path.abspath(__file__))
+ pricing_file_path = pjoin(pricing_directory, PRICING_FILE_PATH)
+
+ return pricing_file_path
+
def get_pricing(driver_type, driver_name, pricing_file_path=None):
"""
Return pricing for the provided driver.
@@ -48,14 +54,11 @@ def get_pricing(driver_type, driver_name, pricing_file_path=None):
if not driver_type in [ 'compute', 'storage' ]:
raise AttributeError('Invalid driver type: %s', driver_type)
- driver_name = driver_name.lower().replace('nodedriver', '')
-
if driver_name in PRICING_DATA[driver_type]:
return PRICING_DATA[driver_type][driver_name]
if not pricing_file_path:
- pricing_directory = os.path.dirname(os.path.abspath(__file__))
- pricing_file_path = pjoin(pricing_directory, PRICING_FILE_PATH)
+ pricing_file_path = get_pricing_file_path(file_path=pricing_file_path)
with open(pricing_file_path) as fp:
content = fp.read()
@@ -65,6 +68,22 @@ def get_pricing(driver_type, driver_name, pricing_file_path=None):
PRICING_DATA[driver_type][driver_name] = pricing
return pricing
+def set_pricing(driver_type, driver_name, pricing):
+ """
+ Populate the driver pricing dictionary.
+
+ @type driver_type: C{str}
+ @param driver_type: Driver type ('compute' or 'storage')
+
+ @type driver_name: C{str}
+ @param driver_name: Driver name
+
+ @type pricing: C{dict}
+ @param pricing: Dictionary where a key is a size ID and a value is a price.
+ """
+
+ PRICING_DATA[driver_type][driver_name] = pricing
+
def get_size_price(driver_type, driver_name, size_id):
"""
Return price for the provided size.
View
@@ -147,6 +147,9 @@ def run(self):
'libcloud': 'libcloud',
'libcloud.drivers': 'libcloud/drivers'
},
+ package_data={
+ 'libcloud': ['data/*.json'],
+ },
license='Apache License (2.0)',
url='http://incubator.apache.org/libcloud/',
cmdclass={
@@ -34,29 +34,30 @@ def test_list_nodes(self):
nodes = self.driver.list_nodes()
self.assertTrue(isinstance(nodes, list))
self.assertEqual(len(nodes), 1)
-
+
node = nodes[0]
self.assertEqual(node.public_ip[0], "1.2.3.4")
self.assertEqual(node.public_ip[1], "1.2.3.5")
self.assertEqual(node.extra['smp'], 1)
def test_list_sizes(self):
images = self.driver.list_sizes()
- self.assertEqual(len(images), 5)
- image = images[0]
+ self.assertEqual(len(images), 6)
+ image = [i for i in images if i.id == 'small'][0]
self.assertEqual(image.id, 'small')
self.assertEqual(image.name, 'Small instance')
self.assertEqual(image.cpu, 2000)
self.assertEqual(image.ram, 1700)
self.assertEqual(image.disk, 160)
+ self.assertTrue(isinstance(image.price, float))
def test_list_images(self):
sizes = self.driver.list_images()
self.assertEqual(len(sizes), 8)
size = sizes[0]
self.assertEqual(size.id, '38df0986-4d85-4b76-b502-3878ffc80161')
self.assertEqual(size.name, 'CentOS Linux 5.5')
-
+
def test_list_locations_response(self):
pass
@@ -76,24 +77,24 @@ def test_create_node(self):
class ElasticHostsHttp(MockHttp):
fixtures = ComputeFileFixtures('elastichosts')
-
+
def _servers_b605ca90_c3e6_4cee_85f8_a8ebdf8f9903_reset(self, method, url, body, headers):
return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.NO_CONTENT])
-
+
def _servers_b605ca90_c3e6_4cee_85f8_a8ebdf8f9903_destroy(self, method, url, body, headers):
return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.NO_CONTENT])
-
+
def _drives_create(self, method, url, body, headers):
body = self.fixtures.load('drives_create.json')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
-
+
def _drives_0012e24a_6eae_4279_9912_3432f698cec8_image_38df0986_4d85_4b76_b502_3878ffc80161_gunzip(self, method, url, body, headers):
return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.NO_CONTENT])
def _drives_0012e24a_6eae_4279_9912_3432f698cec8_info(self, method, url, body, headers):
body = self.fixtures.load('drives_info.json')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
-
+
def _servers_create(self, method, url, body, headers):
body = self.fixtures.load('servers_create.json')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
@@ -68,6 +68,7 @@ def test_list_sizes(self):
self.assertEqual(len(ret), 7)
size = ret[0]
self.assertEqual(size.name, '256 slice')
+ self.assertTrue(isinstance(size.price, float))
def test_list_images(self):
ret = self.driver.list_images()

0 comments on commit 6259eee

Please sign in to comment.