libcloud.pricing module¶
A class which handles loading the pricing files.
- libcloud.pricing.clear_pricing_data() None [source]¶
Invalidate pricing cache for all the drivers.
Note: This method does the same thing as invalidate_pricing_cache and is here for backward compatibility reasons.
- libcloud.pricing.download_pricing_file(file_url: str = 'https://libcloud-pricing-data.s3.amazonaws.com/pricing.json', file_path: str = '/home/docs/.libcloud/pricing.json') None [source]¶
Download pricing file from the file_url and save it to file_path.
- Parameters:
file_url (
str
) – URL pointing to the pricing file.file_path (
str
) – Path where a download pricing file will be saved.
- libcloud.pricing.get_pricing(driver_type: str, driver_name: str, pricing_file_path: str | None = None, cache_all: bool = False) dict | None [source]¶
Return pricing for the provided driver.
NOTE: This method will also cache data for the requested driver memory.
We intentionally only cache data for the requested driver and not all the pricing data since the whole pricing data is quite large (~2 MB). This way we avoid unnecessary memory overhead.
- Parameters:
driver_type (
str
) – Driver type (‘compute’ or ‘storage’)driver_name (
str
) – Driver namepricing_file_path (
str
) – Custom path to a price file. If not provided it uses a default path.cache_all (
bool
) – True to cache pricing data in memory for all the drivers and not just for the requested one.
- Return type:
dict
- Returns:
Dictionary with pricing where a key name is size ID and the value is a price.
- libcloud.pricing.get_size_price(driver_type: str, driver_name: str, size_id: str | int, region: str | None = None) float | None [source]¶
Return price for the provided size.
- Parameters:
driver_type (
str
) – Driver type (‘compute’ or ‘storage’)driver_name (
str
) – Driver namesize_id (
str
orint
) – Unique size ID (can be an integer or a string - depends on the driver)
- Return type:
float
- Returns:
Size price.
- libcloud.pricing.set_pricing(driver_type: str, driver_name: str, pricing: dict) None [source]¶
Populate the driver pricing dictionary.
- Parameters:
driver_type (
str
) – Driver type (‘compute’ or ‘storage’)driver_name (
str
) – Driver namepricing (
dict
) – Dictionary where a key is a size ID and a value is a price.