Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions internal/namespaces/baremetal/v1/custom_offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package baremetal

import (
"context"
"slices"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -62,8 +63,9 @@ func listOfferMarshalerFunc(i any, opt *human.MarshalOpt) (string, error) {

type customOffer struct {
*baremetal.Offer
KgCo2Equivalent *float32 `json:"kg_co2_equivalent"`
M3WaterUsage *float32 `json:"m3_water_usage"`
KgCo2Equivalent *float32 `json:"kg_co2_equivalent"`
M3WaterUsage *float32 `json:"m3_water_usage"`
CloudInitSupported bool `json:"cloud_init_supported"`
}

func serverOfferListBuilder(c *core.Command) *core.Command {
Expand All @@ -75,9 +77,9 @@ func serverOfferListBuilder(c *core.Command) *core.Command {
{Label: "Disks", FieldName: "Disks"},
{Label: "CPUs", FieldName: "CPUs"},
{Label: "Memories", FieldName: "Memories"},
{Label: "Options", FieldName: "Options"},
{Label: "Bandwidth", FieldName: "Bandwidth"},
{Label: "PrivateBandwidth", FieldName: "PrivateBandwidth"},
{Label: "CloudInit supported", FieldName: "CloudInitSupported"},
},
}

Expand Down Expand Up @@ -126,21 +128,24 @@ func serverOfferListBuilder(c *core.Command) *core.Command {

var customOfferRes []customOffer
for _, offer := range offers.Offers {
cloudInitSupported := slices.Contains(offer.Tags, "cloud-init")
impact, ok := impactMap[offer.Name]
if !ok {
customOfferRes = append(customOfferRes, customOffer{
Offer: offer,
KgCo2Equivalent: nil,
M3WaterUsage: nil,
Offer: offer,
KgCo2Equivalent: nil,
M3WaterUsage: nil,
CloudInitSupported: cloudInitSupported,
})

continue
}

customOfferRes = append(customOfferRes, customOffer{
Offer: offer,
KgCo2Equivalent: impact.EnvironmentalImpactEstimation.KgCo2Equivalent,
M3WaterUsage: impact.EnvironmentalImpactEstimation.M3WaterUsage,
Offer: offer,
KgCo2Equivalent: impact.EnvironmentalImpactEstimation.KgCo2Equivalent,
M3WaterUsage: impact.EnvironmentalImpactEstimation.M3WaterUsage,
CloudInitSupported: cloudInitSupported,
})
}

Expand Down
Loading
Loading