sc_crawler.vendor_helpers
Helpers shared by the vendor modules of sc_crawler.vendors, e.g. fetching the servers of all regionsregionA geographic area where a cloud vendor runs its data centers, such as Frankfurt or Northern Virginia, made up of one or more availability zones. A server type is offered in some regions only, and its price can differ by region; a region's ID, such as eu-central-1, is unique only within its vendor.Glossary in parallel.
Functions:
- server_status_from_availability_categories – Map vendor availability categories to a single Server/Database status.
- retirement_date_from_rules – Retirement date of the first
(pattern, date)rule fully matching the SKUSKU: Stock Keeping UnitAn identifier of a product a vendor sells, e.g. a server type, or a component that its price is built from, such as a vCPU or a GB of memory in a region. Cloud vendors' price lists are made of SKUs, which the Crawler combines into the price of each server type.Glossaryname. - status_from_retirement_date – Server/Database status from a retirement date.
- fetch_servers – Fetch servers of a region/zone.
- parallel_fetch_servers – Fetch servers of all regions/zones in parallel on 8 threads.
- preprocess_servers – Preprocess servers before inserting into the database.
- add_vendor_id – Adds
vendor_idfield to a dict. - get_region_by_id – Get a region by its ID or alias.
- disk_speed_totals – Server
storage_*speed columns summed over the disks with known values. - split_disk_speed – Speed of one of
disksidentical disks from a published server total.
func server_status_from_availability_categories vendor_helpers.py:13–36
server_status_from_availability_categories(categories, category_to_status, *, missing_status=Status.INACTIVE)
Map vendor availability categories to a single Server/Database status.
Each category is mapped via category_to_status. If more than one
status results, Status.best selects the best. Empty or unmapped
categories return missing_status.
func retirement_date_from_rules vendor_helpers.py:39–50
retirement_date_from_rules(name, rules)
Retirement date of the first (pattern, date) rule fully matching the SKU name.
The rules are the vendor-documented retirement dates, e.g.
_AZURE_RETIREMENT_RULES. Returns None if no rule matches.
func status_from_retirement_date vendor_helpers.py:53–65
status_from_retirement_date(retirement_date, as_of=None)
Server/Database status from a retirement date.
RETIRED from the retirement date (inclusive), PLANNED_FOR_RETIREMENT
before, and ACTIVE without a retirement date.
func fetch_servers vendor_helpers.py:68–86
fetch_servers(fn, where, vendor)
Fetch servers of a region/zone.
Parameters:
- fn (
Callable) – A function that takes the region or zone id as its first and only argument. The returning list must conform with the Server object, or need to be in a format that preprocess_servers'sfncan manage. - where (
str) – A Region or Zoneapi_referenceor similar that is passed tofn. - vendor (
Optional[Vendor]) – Optional Vendor instance used for logging and progress bar updates.
func parallel_fetch_servers vendor_helpers.py:89–121
parallel_fetch_servers(vendor, fn, id_col, by)
Fetch servers of all regions/zones in parallel on 8 threads.
Parameters:
- vendor (
Vendor) – Required Vendor instance used for the regions lookup, logging and progress bar updates. - fn (
Callable) – A function to be passed to fetch_servers. - id_col (
str) – Field name to be used to deduplicate the list of server dicts. - by (
Literal['regions','zones']) – What objects of thevendorto iterate on.
func preprocess_servers vendor_helpers.py:124–144
preprocess_servers(servers, vendor, fn)
Preprocess servers before inserting into the database.
Takes a list of dicts and tranform to a list of dicts that follows the Server schema.
Parameters:
- servers (
List[dict]) – To be passed tofn. - vendor (
Vendor) – The related Vendor instance used for database connection, logging and progress bar updates. - fn (
Callable) – A function that takes a server fromservers(one-by-one) and thevendor.
func add_vendor_id vendor_helpers.py:147–150
add_vendor_id(obj, vendor)
Adds vendor_id field to a dict.
func get_region_by_id vendor_helpers.py:153–170
get_region_by_id(region_id, vendor)
Get a region by its ID or alias.
Parameters:
- region_id (
str) – The ID or alias of the region to get. - vendor (
Vendor) – The vendor to get the region from.
Returns:
func disk_speed_totals vendor_helpers.py:173–181
disk_speed_totals(storages)
Server storage_* speed columns summed over the disks with known values.
func split_disk_speed vendor_helpers.py:184–186
split_disk_speed(total, disks)
Speed of one of disks identical disks from a published server total.