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 2020/07/11 15:19:27 UTC
[libcloud] 01/08: Added region argument in get_size_price and
change ec2 driver accordingly
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit d3df881afc3f44886ed8db41e0d7391a78657722
Author: Eis <mo...@gmail.com>
AuthorDate: Mon Jul 6 18:11:49 2020 +0300
Added region argument in get_size_price and change ec2 driver accordingly
---
libcloud/compute/drivers/ec2.py | 10 ++++++----
libcloud/pricing.py | 7 +++++--
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index b8f4815..259f797 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1695,12 +1695,13 @@ class BaseEC2NodeDriver(NodeDriver):
# we are only interested in pure size price so linux
price = get_size_price(driver_type='compute',
driver_name='ec2_linux',
- size_id=instance_type)
+ size_id=instance_type,
+ region=self.region_name)
if price is None:
# it is a weird bare metal instance
attributes['price'] = None
else:
- attributes['price'] = price[self.region_name]
+ attributes['price'] = price
except KeyError:
attributes['price'] = None # pricing not available
sizes.append(NodeSize(driver=self, **attributes))
@@ -6207,11 +6208,12 @@ class OutscaleNodeDriver(BaseEC2NodeDriver):
attributes = copy.deepcopy(attributes)
price = get_size_price(driver_type='compute',
driver_name='ec2_linux',
- size_id=instance_type)
+ size_id=instance_type,
+ region=self.region_name)
if price is None:
attributes['price'] = None
else:
- attributes['price'] = price[self.region_name]
+ attributes['price'] = price
attributes.update({'price': price})
sizes.append(NodeSize(driver=self, **attributes))
return sizes
diff --git a/libcloud/pricing.py b/libcloud/pricing.py
index a9d4701..695c1c6 100644
--- a/libcloud/pricing.py
+++ b/libcloud/pricing.py
@@ -127,7 +127,7 @@ def set_pricing(driver_type, driver_name, pricing):
PRICING_DATA[driver_type][driver_name] = pricing
-def get_size_price(driver_type, driver_name, size_id):
+def get_size_price(driver_type, driver_name, size_id, region=None):
"""
Return price for the provided size.
@@ -147,7 +147,10 @@ def get_size_price(driver_type, driver_name, size_id):
pricing = get_pricing(driver_type=driver_type, driver_name=driver_name)
try:
- price = float(pricing[size_id])
+ if region is None:
+ price = float(pricing[size_id])
+ else:
+ price = float(pricing[size_id][region])
except KeyError:
# Price not available
price = None