|
| 1 | +from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME |
| 2 | + |
| 3 | + |
| 4 | +class DeploymentPlatform(): |
| 5 | + artifacts_bucket_name = GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME |
| 6 | + |
| 7 | + def full_name(self): |
| 8 | + return "Generic Deployment Platform" |
| 9 | + |
| 10 | + def published_images_by_regions(self, image_metadata): |
| 11 | + published_image_metadata = image_metadata["published_image_metadata"] |
| 12 | + flavor_name = image_metadata["s3_key"].split("/")[-1] |
| 13 | + |
| 14 | + regions = [] |
| 15 | + for pset in published_image_metadata: |
| 16 | + for p in published_image_metadata[pset]: |
| 17 | + regions.append({"region": p["region_id"], "image_id": p["image_id"]}) |
| 18 | + |
| 19 | + return {"flavor": flavor_name, "regions": regions} |
| 20 | + |
| 21 | + def image_extension(self): |
| 22 | + return "raw" |
| 23 | + |
| 24 | + def artifact_for_flavor(self, flavor): |
| 25 | + base_url = f"https://{self.__class__.artifacts_bucket_name}.s3.amazonaws.com/objects" |
| 26 | + filename = f"{flavor}.{self.image_extension()}" |
| 27 | + download_url = f"{base_url}/{flavor}/{filename}" |
| 28 | + return f"[{filename}]({download_url})" |
| 29 | + |
| 30 | + def region_details(self): |
| 31 | + """ |
| 32 | + Generate the detailed region information for the collapsible section |
| 33 | + """ |
| 34 | + details = "" |
| 35 | + |
| 36 | + match self.published_images_by_regions(): |
| 37 | + case {"regions": regions}: |
| 38 | + for region in regions: |
| 39 | + match region: |
| 40 | + case { |
| 41 | + "region": region_name, |
| 42 | + "image_id": image_id, |
| 43 | + "image_name": image_name, |
| 44 | + }: |
| 45 | + details += f"**{region_name}:** {image_id} ({image_name})<br>" |
| 46 | + case {"region": region_name, "image_id": image_id}: |
| 47 | + details += f"**{region_name}:** {image_id}<br>" |
| 48 | + case {"details": details_dict}: |
| 49 | + for key, value in details_dict.items(): |
| 50 | + details += f"**{key.replace('_', ' ').title()}:** {value}<br>" |
| 51 | + case { |
| 52 | + "gallery_images": gallery_images, |
| 53 | + "marketplace_images": marketplace_images, |
| 54 | + }: |
| 55 | + if gallery_images: |
| 56 | + details += "**Gallery Images:**<br>" |
| 57 | + for img in gallery_images: |
| 58 | + details += f"• {img['hyper_v_generation']} ({img['azure_cloud']}): {img['image_id']}<br>" |
| 59 | + if marketplace_images: |
| 60 | + details += "**Marketplace Images:**<br>" |
| 61 | + for img in marketplace_images: |
| 62 | + details += f"• {img['hyper_v_generation']}: {img['urn']}<br>" |
| 63 | + case {"gallery_images": gallery_images}: |
| 64 | + details += "**Gallery Images:**<br>" |
| 65 | + for img in gallery_images: |
| 66 | + details += f"• {img['hyper_v_generation']} ({img['azure_cloud']}): {img['image_id']}<br>" |
| 67 | + case {"marketplace_images": marketplace_images}: |
| 68 | + details += "**Marketplace Images:**<br>" |
| 69 | + for img in marketplace_images: |
| 70 | + details += f"• {img['hyper_v_generation']}: {img['urn']}<br>" |
| 71 | + |
| 72 | + return details |
| 73 | + |
| 74 | + def summary_text(self): |
| 75 | + """ |
| 76 | + Generate the summary text for the collapsible section |
| 77 | + """ |
| 78 | + match self.published_images_by_regions(): |
| 79 | + case {"regions": regions}: |
| 80 | + count = len(regions) |
| 81 | + return f"{count} regions" |
| 82 | + case {"details": _}: |
| 83 | + return "Global availability" |
| 84 | + case { |
| 85 | + "gallery_images": gallery_images, |
| 86 | + "marketplace_images": marketplace_images, |
| 87 | + }: |
| 88 | + gallery_count = len(gallery_images) |
| 89 | + marketplace_count = len(marketplace_images) |
| 90 | + return f"{gallery_count} gallery + {marketplace_count} marketplace images" |
| 91 | + case {"gallery_images": gallery_images}: |
| 92 | + gallery_count = len(gallery_images) |
| 93 | + return f"{gallery_count} gallery images" |
| 94 | + case {"marketplace_images": marketplace_images}: |
| 95 | + marketplace_count = len(marketplace_images) |
| 96 | + return f"{marketplace_count} marketplace images" |
| 97 | + case _: |
| 98 | + return "Details available" |
0 commit comments