add yaml output for exoscale marketplace

This commit is contained in:
Tobias Brunner 2025-05-30 15:44:37 +02:00
parent 86df11505f
commit bfb64efdec
No known key found for this signature in database
3 changed files with 178 additions and 1 deletions

View file

@ -1,5 +1,10 @@
import re
import pyaml
from django.shortcuts import render, get_object_or_404
from django.db.models import Q
from django.http import HttpResponse
from django.template.loader import render_to_string
from hub.services.models import (
ServiceOffering,
CloudProvider,
@ -8,8 +13,8 @@ from hub.services.models import (
ComputePlan,
VSHNAppCatPrice,
)
import re
from collections import defaultdict
from markdownify import markdownify
def natural_sort_key(name):
@ -79,6 +84,10 @@ def offering_detail(request, provider_slug, service_slug):
service__slug=service_slug,
)
# Check if Exoscale marketplace YAML is requested
if request.GET.get("exo_marketplace") == "true":
return generate_exoscale_marketplace_yaml(offering)
pricing_data_by_group_and_service_level = None
# Generate pricing data for VSHN offerings
@ -92,6 +101,92 @@ def offering_detail(request, provider_slug, service_slug):
return render(request, "services/offering_detail.html", context)
def generate_exoscale_marketplace_yaml(offering):
"""Generate YAML structure for Exoscale marketplace"""
# Create service name slug for YAML key
service_slug = offering.service.slug.replace("-", "")
yaml_key = f"marketplace_PRODUCTS_servala-{service_slug}"
# Generate product overview content from service description (convert HTML to Markdown)
product_overview = ""
if offering.service.description:
product_overview = markdownify(
offering.service.description, heading_style="ATX"
)
# Generate highlights content from offering description and offer_description (convert HTML to Markdown)
highlights = ""
if offering.description:
highlights += markdownify(offering.description, heading_style="ATX")
if offering.offer_description:
if highlights:
highlights += "\n\n"
highlights += markdownify(
offering.offer_description.get_full_text(), heading_style="ATX"
)
# Build YAML structure
yaml_structure = {
yaml_key: {
"page_class": "tmpl-marketplace-product",
"html_title": f"Managed {offering.service.name} by VSHN via Servala",
"meta_desc": "Servala is the Open Cloud Native Service Hub. It connects businesses, developers, and cloud service providers on one unique hub with secure, scalable, and easy-to-use cloud-native services.",
"page_header_title": f"Managed {offering.service.name} by VSHN via Servala",
"provider_key": "vshn",
"slug": f"servala-managed-{offering.service.slug}",
"title": f"Managed {offering.service.name} by VSHN via Servala",
"logo": f"img/servala-{offering.service.slug}.svg",
"list_display": [],
"meta": [
{"key": "exoscale-iaas", "value": True},
{"key": "availability", "zones": "all"},
],
"action_link": f"https://servala.com/offering/{offering.cloud_provider.slug}/{offering.service.slug}/?source=exoscale_marketplace",
"action_link_text": "Subscribe now",
"blobs": [
{
"key": "product-overview",
"blob": (
product_overview.strip()
if product_overview
else "Service description not available."
),
},
{
"key": "highlights",
"blob": (
highlights.strip()
if highlights
else "Offering highlights not available."
),
},
"editor",
{
"key": "pricing",
"blob": f"Find all the pricing information on the [Servala website](https://servala.com/offering/{offering.cloud_provider.slug}/{offering.service.slug}/?source=exoscale_marketplace#plans)",
},
{
"key": "service-and-support",
"blob": "Servala is operated by VSHN AG in Zurich, Switzerland.\n\nSeveral SLAs are available on request, offering support 24/7.\n\nMore details can be found in the [VSHN Service Levels Documentation](https://products.vshn.ch/service_levels.html).",
},
{
"key": "terms-of-service",
"blob": "- [Product Description](https://products.vshn.ch/servala/index.html)\n- [General Terms and Conditions](https://products.vshn.ch/legal/gtc_en.html)\n- [SLA](https://products.vshn.ch/service_levels.html)\n- [DPA](https://products.vshn.ch/legal/dpa_en.html)\n- [Privacy Policy](https://products.vshn.ch/legal/privacy_policy_en.html)",
},
],
}
}
# Generate YAML response for browser display
yaml_content = pyaml.dump(yaml_structure, sort_dicts=False)
# Return as plain text for browser display
response = HttpResponse(yaml_content, content_type="text/plain")
return response
def generate_pricing_data(offering):
"""Generate pricing data for a specific offering and cloud provider"""
# Fetch compute plans for this cloud provider