# Django Cloud Provider Regions
[django-cloud-provider-zones](https://pypi.org/project/django-cloud-provider-zones/) on pypi
## Examples
For reference, and for use outside of Django, [region_data/normalized_azs.json](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/region_data/normalized_azs.json) and [region_data/normalized_regions.json](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/region_data/normalized_regions.json) contain all generated region and az names.
All regions and AZs have unique a `short_name` and `short_name_with_provider`
example AZ names:
```json
{ "provider": "aws",
"original_az_name": "ap-northeast-2b",
"original_region_name": "ap-northeast-2",
"short_name": "apne2zb",
"short_name_with_provider": "awsapne2zb",
"az": "b" },
{ "provider": "azu",
"original_az_name": "eastus2-az3",
"original_region_name": "eastus2",
"short_name": "use2z3",
"short_name_with_provider": "azuuse2z3",
"az": "3" },
{ "provider": "azu",
"original_az_name": "francecentral-az1",
"original_region_name": "francecentral",
"short_name": "frcz1",
"short_name_with_provider": "azufrcz1",
"az": "1" },
{ "provider": "gcp",
"original_az_name": "northamerica-northeast2-c",
"original_region_name": "northamerica-northeast2",
"short_name": "nane2zc",
"short_name_with_provider": "gcpnane2zc",
"az": "c" },
{ "provider": "gcp",
"original_az_name": "southamerica-east1-a",
"original_region_name": "southamerica-east1",
"short_name": "sae1za",
"short_name_with_provider": "gcpsae1za",
"az": "a" },
```
## Why
This [Django app](https://docs.djangoproject.com/en/5.0/ref/applications/) provides a static list of region and availability zones for AWS (Amazon Web Services) and GCP (Google Cloud Platform) cloud providers.
The purpose of this app is to provide Cloud Provider Region/AZ lists easily available to Django apps. It provides stable, shortened, versions of names for provisioning naming conventions.
The Regions/AZ list is currrent as of March 2024.
## Features
- Quick and easy access to cloud Region and AZs from other Django apps
- Provides shortened versions of Region and AZ names for use by provisioning tools
- DB primary key fields are stable, will not change as new Regions/AZs are added
## Installation
`pip install django-cloud-provider-zones`
Add to project's settings.py INSTALLED_APPS:
```
'rest_framework',
'django_cloud_provider_zones',
```
Optionally, include the DRF REST urls in your project's `urls.py`:
```python
from django.contrib import admin
from django.urls import path, include
import django_cloud_provider_zones
urlpatterns = [
path('admin/', admin.site.urls),
path('api/cloudzones/', include('django_cloud_provider_zones.urls')),
]
```
Import model data
`./manage.py loaddata django_cloud_provider_zones-CloudProvider django_cloud_provider_zones-CloudRegion django_cloud_provider_zones-CloudAvailabilityZone`
If exposed via the Django admin, it is recommended that these App's models are "read only" so grant only View permissions.
### Models
[model diagram](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/django_models.png)
This app provides the following models:
- `CloudProvider`: Cloud provider names - currently `AWS` or `GCP`
- `CloudRegion`: Cloud regions
- `CloudAvailabilityZone`: Availability zones within a region
Each region and AZ provides, as properties, short name versions with dashes removed. For example, `AWS us-east-1` has names
```
short_name: use1
short_name_with_provider: awsuse1
```
```
## CloudProvider ##
>>> CloudProvider.objects.values().first()
{'provider': 'aws'}
## CloudRegion ##
>>> CloudRegion.objects.values().first()
{'cardinality': 'northeast',
'created': datetime.date(2024, 3, 27),
'geographic_region': 'ap',
'id': 11,
'number': '1',
'original_region_name': 'ap-northeast-1',
'provider_id': 'aws'}
>>> CloudRegion.objects.first().short_name
'apne1'
>>> CloudRegion.objects.first().short_name_with_provider
'awsapne1'
## CloudAvailabilityZone ##
>>> CloudAvailabilityZone.objects.values().first()
{'az': 'a', 'created': datetime.date(2024, 3, 27), 'id': 27, 'region_id': 11}
>>> CloudAvailabilityZone.objects.first().short_name
'apne1a'
>>> CloudAvailabilityZone.objects.first().short_name_with_provider
'awsapne1a'
```
Regions and AZs use Django "natural keys" which allows filtering by the Provider's region name
```
## Region natural key ##
>>> CloudRegion.objects.first().natural_key()
('aws', 'ap-northeast-1')
>>> CloudRegion.objects.get_by_natural_key("aws", "us-east-1")
<CloudRegion: aws-us-east-1>
## AZ natural key ##
>>> CloudAvailabilityZone.objects.first().natural_key()
('a', ('aws', 'ap-northeast-1'))
>>> CloudAvailabilityZone.objects.get_by_natural_key('a', ('aws', 'ap-northeast-1'))
<CloudAvailabilityZone: aws-ap-northeast-1a>
```
### Exported JSON files
All generated names are exported to these files for reference
```
tasks/django_management_commands.py django_serialize_azs > region_data/normalized_azs.json
tasks/django_management_commands.py django_serialize_regions > region_data/normalized_regions.json
```
### API Endpoints
Basic REST Get endpoints available see [urls.py](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/src/django_cloud_provider_zones/urls.py)
### Updating model data
To add a new provider, activate the poetry virtualenv with `poetry shell && poetry install`
Fetch raw json from the provider's API or cli tool, save it to [region_data/PROVIDER_unprocessed.json](https://github.com/yolabingo/django-cloud-provider-zones/tree/main/region_data) see AWS and GCP examples.
Create [tasks/format_json_PROVIDER](https://github.com/yolabingo/django-cloud-provider-zones/tree/main/tasks) which creates properly formatted json files
```
region_data/PROVIDER_provider.json
region_data/PROVIDER_region.json
region_data/PROVIDER_az.json
```
see AWS and GCP examples.
Add new provider `CLOUD_PROVIDERS` in `tasks/update_db_from_json.py` then run
```
tasks/django_management_commands.py django_makemigrations
tasks/django_management_commands.py django_migrate
tasks/django_management_commands.py django_update_fixture_from_json
```
Once that looks good add a couple simple tests to [src/django_cloud_provider_zones/tests.py](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/src/django_cloud_provider_zones/tests.py) then
```tasks/django_management_commands.py django_test```
Bump version, commit and push as needed.
`poetry version patch && poetry publish`
## Contributing
Contributions are welcome! Please feel free to open issues or submit pull requests.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- Thanks to the Django community and Django Software Foundation for Django
- Thanks to the maintainers of all dependencies on this project
- Thanks to Real Python for their [Installable Django App article](https://realpython.com/installable-django-app/)# django-cloud-provider-regions
Raw data
{
"_id": null,
"home_page": "https://github.com/yolabingo/django-cloud-provider-zones",
"name": "django-cloud-provider-zones",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "django, cloud, provider, regions, aws, gcp",
"author": "TJ",
"author_email": "yolabingo@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/17/9f/5e21fff3bc5c23b707766f116ab9690186b6d70f2e66d2eafddef7df1dd4/django_cloud_provider_zones-0.1.13.tar.gz",
"platform": null,
"description": "# Django Cloud Provider Regions\n[django-cloud-provider-zones](https://pypi.org/project/django-cloud-provider-zones/) on pypi\n## Examples\nFor reference, and for use outside of Django, [region_data/normalized_azs.json](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/region_data/normalized_azs.json) and [region_data/normalized_regions.json](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/region_data/normalized_regions.json) contain all generated region and az names.\n\nAll regions and AZs have unique a `short_name` and `short_name_with_provider`\n\nexample AZ names:\n```json\n { \"provider\": \"aws\",\n \"original_az_name\": \"ap-northeast-2b\",\n \"original_region_name\": \"ap-northeast-2\",\n \"short_name\": \"apne2zb\",\n \"short_name_with_provider\": \"awsapne2zb\",\n \"az\": \"b\" },\n { \"provider\": \"azu\",\n \"original_az_name\": \"eastus2-az3\",\n \"original_region_name\": \"eastus2\",\n \"short_name\": \"use2z3\",\n \"short_name_with_provider\": \"azuuse2z3\",\n \"az\": \"3\" },\n { \"provider\": \"azu\",\n \"original_az_name\": \"francecentral-az1\",\n \"original_region_name\": \"francecentral\",\n \"short_name\": \"frcz1\",\n \"short_name_with_provider\": \"azufrcz1\",\n \"az\": \"1\" },\n { \"provider\": \"gcp\",\n \"original_az_name\": \"northamerica-northeast2-c\",\n \"original_region_name\": \"northamerica-northeast2\",\n \"short_name\": \"nane2zc\",\n \"short_name_with_provider\": \"gcpnane2zc\",\n \"az\": \"c\" },\n { \"provider\": \"gcp\",\n \"original_az_name\": \"southamerica-east1-a\",\n \"original_region_name\": \"southamerica-east1\",\n \"short_name\": \"sae1za\",\n \"short_name_with_provider\": \"gcpsae1za\",\n \"az\": \"a\" },\n```\n\n## Why\nThis [Django app](https://docs.djangoproject.com/en/5.0/ref/applications/) provides a static list of region and availability zones for AWS (Amazon Web Services) and GCP (Google Cloud Platform) cloud providers.\n\nThe purpose of this app is to provide Cloud Provider Region/AZ lists easily available to Django apps. It provides stable, shortened, versions of names for provisioning naming conventions.\n\nThe Regions/AZ list is currrent as of March 2024.\n\n## Features\n- Quick and easy access to cloud Region and AZs from other Django apps\n- Provides shortened versions of Region and AZ names for use by provisioning tools\n- DB primary key fields are stable, will not change as new Regions/AZs are added\n\n## Installation\n\n`pip install django-cloud-provider-zones`\n\nAdd to project's settings.py INSTALLED_APPS:\n```\n'rest_framework',\n'django_cloud_provider_zones',\n```\n\nOptionally, include the DRF REST urls in your project's `urls.py`:\n```python\nfrom django.contrib import admin\nfrom django.urls import path, include\nimport django_cloud_provider_zones\n\nurlpatterns = [\n path('admin/', admin.site.urls),\n path('api/cloudzones/', include('django_cloud_provider_zones.urls')),\n]\n```\nImport model data\n\n`./manage.py loaddata django_cloud_provider_zones-CloudProvider django_cloud_provider_zones-CloudRegion django_cloud_provider_zones-CloudAvailabilityZone`\n\nIf exposed via the Django admin, it is recommended that these App's models are \"read only\" so grant only View permissions.\n\n### Models\n[model diagram](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/django_models.png)\n\nThis app provides the following models:\n- `CloudProvider`: Cloud provider names - currently `AWS` or `GCP` \n- `CloudRegion`: Cloud regions\n- `CloudAvailabilityZone`: Availability zones within a region\n\nEach region and AZ provides, as properties, short name versions with dashes removed. For example, `AWS us-east-1` has names\n```\nshort_name: use1\nshort_name_with_provider: awsuse1\n```\n\n```\n## CloudProvider ##\n>>> CloudProvider.objects.values().first()\n{'provider': 'aws'}\n\n## CloudRegion ##\n>>> CloudRegion.objects.values().first()\n{'cardinality': 'northeast',\n 'created': datetime.date(2024, 3, 27),\n 'geographic_region': 'ap',\n 'id': 11,\n 'number': '1',\n 'original_region_name': 'ap-northeast-1',\n 'provider_id': 'aws'}\n\n>>> CloudRegion.objects.first().short_name\n'apne1'\n>>> CloudRegion.objects.first().short_name_with_provider\n'awsapne1'\n\n## CloudAvailabilityZone ##\n>>> CloudAvailabilityZone.objects.values().first()\n{'az': 'a', 'created': datetime.date(2024, 3, 27), 'id': 27, 'region_id': 11}\n\n>>> CloudAvailabilityZone.objects.first().short_name\n'apne1a'\n>>> CloudAvailabilityZone.objects.first().short_name_with_provider\n'awsapne1a'\n```\n\nRegions and AZs use Django \"natural keys\" which allows filtering by the Provider's region name\n```\n## Region natural key ##\n>>> CloudRegion.objects.first().natural_key()\n('aws', 'ap-northeast-1')\n>>> CloudRegion.objects.get_by_natural_key(\"aws\", \"us-east-1\")\n<CloudRegion: aws-us-east-1>\n\n## AZ natural key ##\n>>> CloudAvailabilityZone.objects.first().natural_key()\n('a', ('aws', 'ap-northeast-1'))\n>>> CloudAvailabilityZone.objects.get_by_natural_key('a', ('aws', 'ap-northeast-1'))\n<CloudAvailabilityZone: aws-ap-northeast-1a>\n```\n### Exported JSON files\nAll generated names are exported to these files for reference\n```\ntasks/django_management_commands.py django_serialize_azs > region_data/normalized_azs.json\ntasks/django_management_commands.py django_serialize_regions > region_data/normalized_regions.json\n```\n\n### API Endpoints\n\nBasic REST Get endpoints available see [urls.py](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/src/django_cloud_provider_zones/urls.py)\n\n### Updating model data\nTo add a new provider, activate the poetry virtualenv with `poetry shell && poetry install`\n\nFetch raw json from the provider's API or cli tool, save it to [region_data/PROVIDER_unprocessed.json](https://github.com/yolabingo/django-cloud-provider-zones/tree/main/region_data) see AWS and GCP examples.\nCreate [tasks/format_json_PROVIDER](https://github.com/yolabingo/django-cloud-provider-zones/tree/main/tasks) which creates properly formatted json files\n```\nregion_data/PROVIDER_provider.json\nregion_data/PROVIDER_region.json\nregion_data/PROVIDER_az.json\n```\nsee AWS and GCP examples.\n\nAdd new provider `CLOUD_PROVIDERS` in `tasks/update_db_from_json.py` then run\n```\ntasks/django_management_commands.py django_makemigrations\ntasks/django_management_commands.py django_migrate\ntasks/django_management_commands.py django_update_fixture_from_json\n```\nOnce that looks good add a couple simple tests to [src/django_cloud_provider_zones/tests.py](https://github.com/yolabingo/django-cloud-provider-zones/blob/main/src/django_cloud_provider_zones/tests.py) then \n\n```tasks/django_management_commands.py django_test```\n\nBump version, commit and push as needed.\n\n`poetry version patch && poetry publish`\n\n## Contributing\n\nContributions are welcome! Please feel free to open issues or submit pull requests.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- Thanks to the Django community and Django Software Foundation for Django\n- Thanks to the maintainers of all dependencies on this project\n- Thanks to Real Python for their [Installable Django App article](https://realpython.com/installable-django-app/)# django-cloud-provider-regions\n",
"bugtrack_url": null,
"license": "src/django_cloud_provider_zones/LICENSE",
"summary": "Django app providing a static list of cloud provider regions and AZs",
"version": "0.1.13",
"project_urls": {
"Homepage": "https://github.com/yolabingo/django-cloud-provider-zones",
"Repository": "https://github.com/yolabingo/django-cloud-provider-zones"
},
"split_keywords": [
"django",
" cloud",
" provider",
" regions",
" aws",
" gcp"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3bfa51363aa6420be4c6b13817bbf93ebba5d438d8b609eec33b8d8093385c8f",
"md5": "a99bd7a85eb8c4b97a30a5dc35dffe0f",
"sha256": "112e37bbab4de0eab50a0ac8da27d35c4b06f30729b9c8d991ead0a5b1360837"
},
"downloads": -1,
"filename": "django_cloud_provider_zones-0.1.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a99bd7a85eb8c4b97a30a5dc35dffe0f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 15495,
"upload_time": "2024-08-14T14:58:12",
"upload_time_iso_8601": "2024-08-14T14:58:12.361051Z",
"url": "https://files.pythonhosted.org/packages/3b/fa/51363aa6420be4c6b13817bbf93ebba5d438d8b609eec33b8d8093385c8f/django_cloud_provider_zones-0.1.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "179f5e21fff3bc5c23b707766f116ab9690186b6d70f2e66d2eafddef7df1dd4",
"md5": "9641f393b9ca2168320960a6622b6b5a",
"sha256": "291e4930aff491a6f336836c05cbb0087dd6a964c8c0fe8d6775357921424bac"
},
"downloads": -1,
"filename": "django_cloud_provider_zones-0.1.13.tar.gz",
"has_sig": false,
"md5_digest": "9641f393b9ca2168320960a6622b6b5a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 13845,
"upload_time": "2024-08-14T14:58:13",
"upload_time_iso_8601": "2024-08-14T14:58:13.739826Z",
"url": "https://files.pythonhosted.org/packages/17/9f/5e21fff3bc5c23b707766f116ab9690186b6d70f2e66d2eafddef7df1dd4/django_cloud_provider_zones-0.1.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-14 14:58:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yolabingo",
"github_project": "django-cloud-provider-zones",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "django-cloud-provider-zones"
}