From cade709d8965834deb6ba9e3454ea0df10b7b20a Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Fri, 1 Dec 2023 17:26:49 +0200 Subject: [PATCH 1/2] scripts, cloud list: add more information to description column in cloud list --- includes/clouds-list.rst | 246 +++++++++++++++++++-------------------- requirements.txt | 3 +- scripts/aiven/clouds.py | 94 +++++++++------ 3 files changed, 181 insertions(+), 162 deletions(-) diff --git a/includes/clouds-list.rst b/includes/clouds-list.rst index 06f25dbafe..a0a9a193c1 100644 --- a/includes/clouds-list.rst +++ b/includes/clouds-list.rst @@ -10,85 +10,85 @@ Amazon Web Services - Description * - Africa - ``aws-af-south-1`` - - Africa, South Africa + - Africa, South Africa: Cape Town * - Asia-Pacific - ``aws-ap-east-1`` - - Asia, Hong Kong + - Asia, Hong Kong: Hong Kong * - Asia-Pacific - ``aws-ap-northeast-1`` - - Asia, Japan + - Asia, Japan: Tokyo * - Asia-Pacific - ``aws-ap-northeast-2`` - - Asia, Korea + - Asia, Korea: Seoul * - Asia-Pacific - ``aws-ap-northeast-3`` - - Asia, Japan + - Asia, Japan: Osaka * - Asia-Pacific - ``aws-ap-south-1`` - - Asia, India + - Asia, India: Mumbai * - Asia-Pacific - ``aws-ap-south-2`` - - Asia, India + - Asia, India: Hyderabad * - Asia-Pacific - ``aws-ap-southeast-1`` - - Asia, Singapore + - Asia, Singapore: Singapore * - Asia-Pacific - ``aws-ap-southeast-3`` - - Asia, Jakarta + - Asia, Jakarta: Jakarta * - Australia - ``aws-ap-southeast-2`` - - Australia, New South Wales + - Australia, New South Wales: Sydney * - Australia - ``aws-ap-southeast-4`` - - Australia, Melbourne + - Australia, Melbourne: Melbourne * - Europe - ``aws-eu-central-1`` - - Europe, Germany + - Europe, Germany: Frankfurt * - Europe - ``aws-eu-central-2`` - - Europe, Switzerland + - Europe, Switzerland: Zurich * - Europe - ``aws-eu-north-1`` - - Europe, Sweden + - Europe, Sweden: Stockholm * - Europe - ``aws-eu-south-1`` - - Europe, Italy + - Europe, Italy: Milan * - Europe - ``aws-eu-south-2`` - - Europe, Spain + - Europe, Spain: Madrid * - Europe - ``aws-eu-west-1`` - - Europe, Ireland + - Europe, Ireland: Ireland * - Europe - ``aws-eu-west-2`` - - Europe, England + - Europe, England: London * - Europe - ``aws-eu-west-3`` - - Europe, France + - Europe, France: Paris * - Middle East - ``aws-me-central-1`` - - Middle East, UAE + - Middle East, UAE: UAE * - Middle East - ``aws-me-south-1`` - - Middle East, Bahrain + - Middle East, Bahrain: Bahrain * - North America - ``aws-ca-central-1`` - - Canada, Quebec + - Canada, Quebec: Canada Central * - North America - ``aws-us-east-1`` - - United States, Virginia + - United States, Virginia: N. Virginia * - North America - ``aws-us-east-2`` - - United States, Ohio + - United States, Ohio: Ohio * - North America - ``aws-us-west-1`` - - United States, California + - United States, California: N. California * - North America - ``aws-us-west-2`` - - United States, Oregon + - United States, Oregon: Oregon * - South America - ``aws-sa-east-1`` - - South America, Brazil + - South America, Brazil: São Paulo Azure ----------------------------------------------------- @@ -100,118 +100,118 @@ Azure - Description * - Africa - ``azure-south-africa-north`` - - Africa, South Africa + - Africa, South Africa: South Africa North * - Asia-Pacific - ``azure-eastasia`` - - Asia, Hong Kong + - Asia, Hong Kong: East Asia * - Asia-Pacific - ``azure-india-central`` - - Asia, India + - Asia, India: Central India * - Asia-Pacific - ``azure-india-south`` - - Asia, India + - Asia, India: South India * - Asia-Pacific - ``azure-india-west`` - - Asia, India + - Asia, India: West India * - Asia-Pacific - ``azure-japaneast`` - - Asia, Japan + - Asia, Japan: Japan East * - Asia-Pacific - ``azure-japanwest`` - - Asia, Japan + - Asia, Japan: Japan West * - Asia-Pacific - ``azure-korea-central`` - - Asia, Korea + - Asia, Korea: Korea Central * - Asia-Pacific - ``azure-korea-south`` - - Asia, Korea + - Asia, Korea: Korea South * - Asia-Pacific - ``azure-southeastasia`` - - Asia, Singapore + - Asia, Singapore: Southeast Asia * - Australia - ``azure-australia-central`` - - Australia, Canberra + - Australia, Canberra: Australia Central * - Australia - ``azure-australiaeast`` - - Australia, New South Wales + - Australia, New South Wales: Australia East * - Australia - ``azure-australiasoutheast`` - - Australia, Victoria + - Australia, Victoria: Australia Southeast * - Europe - ``azure-france-central`` - - Europe, France + - Europe, France: France Central * - Europe - ``azure-germany-north`` - - Europe, Germany + - Europe, Germany: Germany North * - Europe - ``azure-germany-westcentral`` - - Europe, Germany + - Europe, Germany: Germany West Central * - Europe - ``azure-northeurope`` - - Europe, Ireland + - Europe, Ireland: North Europe * - Europe - ``azure-norway-east`` - - Europe, Norway + - Europe, Norway: Norway East * - Europe - ``azure-norway-west`` - - Europe, Norway + - Europe, Norway: Norway West * - Europe - ``azure-sweden-central`` - - Europe, Gävle + - Europe, Gävle: Sweden Central * - Europe - ``azure-switzerland-north`` - - Europe, Switzerland + - Europe, Switzerland: Switzerland North * - Europe - ``azure-uksouth`` - - Europe, England + - Europe, England: UK South * - Europe - ``azure-ukwest`` - - Europe, Wales + - Europe, Wales: UK West * - Europe - ``azure-westeurope`` - - Europe, Netherlands + - Europe, Netherlands: West Europe * - Middle East - ``azure-qatar-central`` - - Middle East, Doha + - Middle East, Doha: Qatar Central * - Middle East - ``azure-uae-north`` - - Middle East, United Arab Emirates + - Middle East, United Arab Emirates: Middle East * - North America - ``azure-canadacentral`` - - Canada, Ontario + - Canada, Ontario: Canada Central * - North America - ``azure-canadaeast`` - - Canada, Quebec + - Canada, Quebec: Canada East * - North America - ``azure-centralus`` - - United States, Iowa + - United States, Iowa: Central US * - North America - ``azure-eastus`` - - United States, Virginia + - United States, Virginia: East US * - North America - ``azure-eastus2`` - - United States, Virginia + - United States, Virginia: East US 2 * - North America - ``azure-northcentralus`` - - United States, Illinois + - United States, Illinois: North Central US * - North America - ``azure-southcentralus`` - - United States, Texas + - United States, Texas: South Central US * - North America - ``azure-westcentralus`` - - United States, Wyoming + - United States, Wyoming: West Central US * - North America - ``azure-westus`` - - United States, California + - United States, California: West US * - North America - ``azure-westus2`` - - United States, Washington + - United States, Washington: West US 2 * - North America - ``azure-westus3`` - - United States, Phoenix + - United States, Phoenix: West US 3 * - South America - ``azure-brazilsouth`` - - South America, Brazil + - South America, Brazil: Brazil South DigitalOcean ----------------------------------------------------- @@ -223,31 +223,31 @@ DigitalOcean - Description * - Asia-Pacific - ``do-blr`` - - Asia, India + - Asia, India: Bangalore * - Asia-Pacific - ``do-sgp`` - - Asia, Singapore + - Asia, Singapore: Singapore * - Australia - ``do-syd`` - - Australia, New South Wales + - Australia, New South Wales: Sydney * - Europe - ``do-ams`` - - Europe, Netherlands + - Europe, Netherlands: Amsterdam * - Europe - ``do-fra`` - - Europe, Germany + - Europe, Germany: Frankfurt * - Europe - ``do-lon`` - - Europe, England + - Europe, England: London * - North America - ``do-nyc`` - - United States, New York + - United States, New York: New York * - North America - ``do-sfo`` - - United States, California + - United States, California: San Francisco * - North America - ``do-tor`` - - Canada, Ontario + - Canada, Ontario: Toronto Google Cloud ----------------------------------------------------- @@ -259,112 +259,112 @@ Google Cloud - Description * - Asia-Pacific - ``google-asia-east1`` - - Asia, Taiwan + - Asia, Taiwan: Taiwan * - Asia-Pacific - ``google-asia-east2`` - - Asia, Hong Kong + - Asia, Hong Kong: Hong Kong * - Asia-Pacific - ``google-asia-northeast1`` - - Asia, Japan + - Asia, Japan: Tokyo * - Asia-Pacific - ``google-asia-northeast2`` - - Asia, Japan + - Asia, Japan: Osaka * - Asia-Pacific - ``google-asia-northeast3`` - - Asia, Korea + - Asia, Korea: Seoul * - Asia-Pacific - ``google-asia-south1`` - - Asia, India + - Asia, India: Mumbai * - Asia-Pacific - ``google-asia-south2`` - - Asia, India + - Asia, India: Delhi * - Asia-Pacific - ``google-asia-southeast1`` - - Asia, Singapore + - Asia, Singapore: Singapore * - Asia-Pacific - ``google-asia-southeast2`` - - Asia, Indonesia + - Asia, Indonesia: Jakarta * - Australia - ``google-australia-southeast1`` - - Australia, New South Wales + - Australia, New South Wales: Sydney * - Australia - ``google-australia-southeast2`` - - Australia, Victoria + - Australia, Victoria: Melbourne * - Europe - ``google-europe-central2`` - - Europe, Poland + - Europe, Poland: Warsaw * - Europe - ``google-europe-north1`` - - Europe, Finland + - Europe, Finland: Finland * - Europe - ``google-europe-southwest1`` - - Europe, Madrid + - Europe, Madrid: Spain * - Europe - ``google-europe-west1`` - - Europe, Belgium + - Europe, Belgium: Belgium * - Europe - ``google-europe-west2`` - - Europe, England + - Europe, England: London * - Europe - ``google-europe-west3`` - - Europe, Germany + - Europe, Germany: Frankfurt * - Europe - ``google-europe-west4`` - - Europe, Netherlands + - Europe, Netherlands: Netherlands * - Europe - ``google-europe-west6`` - - Europe, Switzerland + - Europe, Switzerland: Zürich * - Europe - ``google-europe-west8`` - - Europe, Italy, Milan + - Europe, Italy: Milan * - Europe - ``google-europe-west9`` - - Europe, France + - Europe, France: Paris * - Europe - ``google-europe-west12`` - - Europe, Italy, Turin + - Europe, Italy: Turin * - Middle East - ``google-me-west1`` - - Middle East, Israel + - Middle East, Israel: Tel Aviv * - North America - ``google-northamerica-northeast1`` - - Canada, Quebec + - Canada, Quebec: Montréal * - North America - ``google-northamerica-northeast2`` - - Canada, Ontario + - Canada, Ontario: Toronto * - North America - ``google-us-central1`` - - United States, Iowa + - United States, Iowa: Iowa * - North America - ``google-us-east1`` - - United States, South Carolina + - United States, South Carolina: South Carolina * - North America - ``google-us-east4`` - - United States, Virginia + - United States, Virginia: Northern Virginia * - North America - ``google-us-east5`` - - United States, Ohio + - United States, Ohio: Columbus * - North America - ``google-us-south1`` - - United States, Texas + - United States, Texas: Dallas * - North America - ``google-us-west1`` - - United States, Oregon + - United States, Oregon: Oregon * - North America - ``google-us-west2`` - - United States, California + - United States, California: Los Angeles * - North America - ``google-us-west3`` - - United States, Utah + - United States, Utah: Salt Lake City * - North America - ``google-us-west4`` - - United States, Nevada + - United States, Nevada: Las Vegas * - South America - ``google-southamerica-east1`` - - South America, Brazil + - South America, Brazil: Sao Paulo * - South America - ``google-southamerica-west1`` - - South America, Chile + - South America, Chile: Santiago UpCloud ----------------------------------------------------- @@ -376,40 +376,40 @@ UpCloud - Description * - Asia-Pacific - ``upcloud-sg-sin`` - - Asia, Singapore + - Asia, Singapore: Singapore * - Australia - ``upcloud-au-syd`` - - Australia, New South Wales + - Australia, New South Wales: Sydney * - Europe - ``upcloud-de-fra`` - - Europe, Germany + - Europe, Germany: Frankfurt * - Europe - ``upcloud-es-mad`` - - Europe, Spain + - Europe, Spain: Madrid * - Europe - ``upcloud-fi-hel`` - - Europe, Finland + - Europe, Finland: Helsinki * - Europe - ``upcloud-fi-hel1`` - - Europe, Finland + - Europe, Finland: Helsinki * - Europe - ``upcloud-fi-hel2`` - - Europe, Finland + - Europe, Finland: Helsinki * - Europe - ``upcloud-nl-ams`` - - Europe, Netherlands + - Europe, Netherlands: Amsterdam * - Europe - ``upcloud-pl-waw`` - - Europe, Poland + - Europe, Poland: Warsaw * - Europe - ``upcloud-se-sto`` - - Europe, Sweden + - Europe, Sweden: Stockholm * - North America - ``upcloud-us-chi`` - - United States, Illinois + - United States, Illinois: Chicago * - North America - ``upcloud-us-nyc`` - - United States, New York + - United States, New York: New York * - North America - ``upcloud-us-sjo`` - - United States, California \ No newline at end of file + - United States, California: San Jose \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 660f517c3d..e76a9b9e4f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,5 @@ sphinx-sitemap==2.2.0 sphinx-notfound-page==0.8 pygments==2.15.0 python-dotenv==0.21.0 -algoliasearch==3.0.0 \ No newline at end of file +algoliasearch==3.0.0 +natsort==8.4.0 diff --git a/scripts/aiven/clouds.py b/scripts/aiven/clouds.py index b98f48d414..792f7940af 100644 --- a/scripts/aiven/clouds.py +++ b/scripts/aiven/clouds.py @@ -1,24 +1,54 @@ -import requests import argparse -from typing import Dict +import re +import requests +from dataclasses import dataclass +from typing import Dict, Self +from natsort import natsorted + + +@dataclass +class CloudEntry: + description: str + geo_region: str + name: str + vendor_code: str + vendor_name: str + @classmethod + def from_dict(cls: type[Self], cloud: dict[str, str | float], /) -> Self: + """Create cloud entry from dict -def create_cloud_entry(cloud: Dict) -> str: - """Creates cloud entry with formatted info. + :param cloud: contains relevant info about cloud + :rtype: CloudEntry + """ - :param cloud: contains relevant info about cloud - :returns: formatted string with cloud info - :rtype: str - """ - entry = "" - # Printing in title case to make it look better - entry += f' * - {cloud["geo_region"].title()}' - entry += "\n" - entry += f' - ``{cloud["cloud_name"]}``' - entry += "\n" - prefix = cloud["cloud_description"][0 : cloud["cloud_description"].find("-")] - entry += f" - {prefix}" - return entry + description_parts = [ + description_part.strip() + for description_part in re.split(r"[,:-]", cloud["cloud_description"]) + ] + vendor_name = description_parts.pop(2) + description = f"{description_parts[0]}, {description_parts[1]}: {description_parts[2]}" + cloud_name = cloud["cloud_name"] + vendor_code = cloud_name[0:cloud_name.index("-")] + return cls( + description=description, + geo_region=cloud["geo_region"].title(), # Printing in title case to make it look better + name=cloud_name, + vendor_code=vendor_code, + vendor_name=vendor_name, + ) + + def to_str(self) -> str: + """Creates cloud entry with formatted info. + + :returns: formatted string with cloud info + :rtype: str + """ + result = "" + result += f" * - {self.geo_region}\n" + result += f" - ``{self.name}``\n" + result += f" - {self.description}" + return result def main(): @@ -33,33 +63,21 @@ def main(): response = requests.get("https://api.aiven.io/v1/clouds") data = response.json()["clouds"] - # Sorting the data by vendor and region - # * Vendor is contained in the cloud_name field, between the start and the '-' symbol - # * geographical region is contained in the geo_region field - # * the cloud name itself is contained in the cloud_name field - data = sorted( - data, - key=lambda k: k["cloud_name"][0 : k["cloud_name"].find("-")] - + " " - + k["geo_region"] - + k["cloud_name"], + cloud_entries = natsorted( + (CloudEntry.from_dict(cloud) for cloud in data), + key=lambda cloud: (cloud.vendor_code, cloud.geo_region, cloud.name), ) # This helps creating a new section every time there is a change in the Cloud vendor - prev_cloud = None + prev_cloud_vendor_code = None res = "" - for cloud in data: - # Extracting the cloud vendor information available in the cloud_description field between the `-` symbol and the `:` symbol - curr_cloud = cloud["cloud_description"][ - cloud["cloud_description"].find("-") - + 2 : cloud["cloud_description"].find(":") - ] + for cloud_entry in cloud_entries: res += "\n" # If current_cloud is different than the previous cloud, let's create a new title, section, table - if curr_cloud != prev_cloud: - prev_cloud = curr_cloud + if cloud_entry.vendor_code != prev_cloud_vendor_code: + prev_cloud_vendor_code = cloud_entry.vendor_code res += "\n" - res += curr_cloud + res += cloud_entry.vendor_name res += "\n" res += "-----------------------------------------------------" res += "\n" @@ -76,7 +94,7 @@ def main(): res += " - Description" res += "\n" - res += create_cloud_entry(cloud) + res += cloud_entry.to_str() with open(filename, "w") as text_file: text_file.write(res) From 295ad26f48f6ee4a2a5f5b837fd3863dee9ec8fa Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Fri, 1 Dec 2023 17:51:38 +0200 Subject: [PATCH 2/2] github actions, cloud list: run cloud list job every day --- .github/workflows/cloud-list.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cloud-list.yaml b/.github/workflows/cloud-list.yaml index cf15b180e6..83ded24718 100644 --- a/.github/workflows/cloud-list.yaml +++ b/.github/workflows/cloud-list.yaml @@ -2,7 +2,7 @@ name: Cloud - Create PR to update available list on: schedule: - - cron: "0 6 * * 2" + - cron: "0 6 * * *" workflow_dispatch: jobs: