From 6d9496751aff9110963800a05b6577227663c6bd Mon Sep 17 00:00:00 2001 From: Gerrit91 Date: Thu, 14 Dec 2023 10:29:27 +0100 Subject: [PATCH] Updates. --- cmd/billing.go | 31 +++++++++++++++++++++++++++- cmd/completion/completion.go | 40 ++++++++++++++++++++++++++++++++++++ cmd/output/billingprinter.go | 12 +++++------ go.mod | 9 ++++---- go.sum | 18 ++++++++-------- 5 files changed, 91 insertions(+), 19 deletions(-) diff --git a/cmd/billing.go b/cmd/billing.go index bad31b1..b0fc403 100644 --- a/cmd/billing.go +++ b/cmd/billing.go @@ -254,6 +254,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour containerBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering") containerBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file") + must(containerBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(containerBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(containerBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion)) + must(viper.BindPFlags(containerBillingCmd.Flags())) clusterBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account") @@ -265,6 +269,8 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour clusterBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file") must(clusterBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(clusterBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(clusterBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion)) must(viper.BindPFlags(clusterBillingCmd.Flags())) @@ -279,8 +285,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour machineBillingCmd.Flags().String("partition-id", "", "the partition-id to account") must(machineBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(machineBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(machineBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion)) must(machineBillingCmd.RegisterFlagCompletionFunc("partition-id", c.comp.PartitionListCompletion)) - must(machineBillingCmd.RegisterFlagCompletionFunc("machine-id", c.comp.MachineImageListCompletion)) + must(machineBillingCmd.RegisterFlagCompletionFunc("size-id", c.comp.SizeListCompletion)) must(viper.BindPFlags(machineBillingCmd.Flags())) @@ -292,7 +300,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour productOptionBillingCmd.Flags().StringVarP(&billingOpts.ClusterID, "cluster-id", "c", "", "the cluster to account") productOptionBillingCmd.Flags().String("id", "", "the id of the product option to account") + must(productOptionBillingCmd.RegisterFlagCompletionFunc("id", c.comp.ProductOptionsCompletion)) must(productOptionBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(productOptionBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(productOptionBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion)) must(viper.BindPFlags(productOptionBillingCmd.Flags())) @@ -304,6 +315,9 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour ipBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering") ipBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file") + must(ipBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(ipBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(viper.BindPFlags(ipBillingCmd.Flags())) networkTrafficBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account") @@ -315,6 +329,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour networkTrafficBillingCmd.Flags().StringVarP(&billingOpts.Device, "device", "", "", "the device to account") networkTrafficBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file") + must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(networkTrafficBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion)) + must(viper.BindPFlags(networkTrafficBillingCmd.Flags())) s3BillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account") @@ -324,6 +342,9 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour s3BillingCmd.Flags().StringVarP(&billingOpts.ProjectID, "project-id", "p", "", "the project to account") s3BillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file") + must(s3BillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(s3BillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(viper.BindPFlags(s3BillingCmd.Flags())) volumeBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account") @@ -336,6 +357,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour volumeBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering") volumeBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file") + must(volumeBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(volumeBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(volumeBillingCmd.RegisterFlagCompletionFunc("cluster-id", c.comp.ClusterListCompletion)) + must(viper.BindPFlags(volumeBillingCmd.Flags())) postgresBillingCmd.Flags().StringVarP(&billingOpts.Tenant, "tenant", "t", "", "the tenant to account") @@ -347,6 +372,10 @@ export CLOUDCTL_COSTS_STORAGE_GI_HOUR=0.01 # Costs per capacity hour postgresBillingCmd.Flags().StringSliceVar(&billingOpts.Annotations, "annotations", nil, "annotations filtering") postgresBillingCmd.Flags().BoolVarP(&billingOpts.CSV, "csv", "", false, "let the server generate a csv file") + must(postgresBillingCmd.RegisterFlagCompletionFunc("tenant", c.comp.TenantListCompletion)) + must(postgresBillingCmd.RegisterFlagCompletionFunc("project-id", c.comp.ProjectListCompletion)) + must(postgresBillingCmd.RegisterFlagCompletionFunc("uuid", c.comp.PostgresListCompletion)) + must(viper.BindPFlags(postgresBillingCmd.Flags())) return billingCmd diff --git a/cmd/completion/completion.go b/cmd/completion/completion.go index e941778..d0a7bb6 100644 --- a/cmd/completion/completion.go +++ b/cmd/completion/completion.go @@ -3,6 +3,7 @@ package completion import ( "sort" + accountingv1 "github.com/fi-ts/accounting-go/pkg/apis/v1" "github.com/fi-ts/cloud-go/api/client" "github.com/fi-ts/cloud-go/api/client/cluster" "github.com/fi-ts/cloud-go/api/client/database" @@ -280,6 +281,33 @@ func (c *Completion) FirewallImageListCompletion(cmd *cobra.Command, args []stri return sc.Payload.FirewallImages, cobra.ShellCompDirectiveNoFileComp } +func (c *Completion) SizeListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + request := cluster.NewListConstraintsParams() + sc, err := c.cloud.Cluster.ListConstraints(request, nil) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + sizeMap := map[string]bool{} + for _, t := range sc.Payload.MachineTypes { + t := t + sizeMap[t] = true + } + for _, t := range sc.Payload.FirewallTypes { + t := t + sizeMap[t] = true + } + + var sizes []string + for size := range sizeMap { + sizes = append(sizes, size) + } + + sort.Strings(sizes) + + return sizes, cobra.ShellCompDirectiveNoFileComp +} + func (c *Completion) FirewallControllerVersionListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { request := cluster.NewListConstraintsParams() sc, err := c.cloud.Cluster.ListConstraints(request, nil) @@ -350,3 +378,15 @@ func (c *Completion) PostgresListCompletion(cmd *cobra.Command, args []string, t sort.Strings(names) return names, cobra.ShellCompDirectiveNoFileComp } + +func (c *Completion) ProductOptionsCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + var options []string + for o, v := range accountingv1.ProductOption_value { + if v == 0 { + continue + } + options = append(options, o) + } + sort.Strings(options) + return options, cobra.ShellCompDirectiveNoFileComp +} diff --git a/cmd/output/billingprinter.go b/cmd/output/billingprinter.go index 06ea39d..f04279e 100644 --- a/cmd/output/billingprinter.go +++ b/cmd/output/billingprinter.go @@ -205,7 +205,7 @@ func (s ClusterBillingTablePrinter) Print(data *models.V1ClusterUsageResponse) { // Print a machine usage as table func (s MachineBillingTablePrinter) Print(data *models.V1MachineUsageResponse) { - s.wideHeader = []string{"Tenant", "From", "To", "ProjectID", "ProjectName", "Partition", "MachineID", "MachineName", "ClusterID", "ClusterName", "MachineStart", "Lifetime"} + s.wideHeader = []string{"Tenant", "From", "To", "ProjectID", "ProjectName", "Partition", "Size", "MachineID", "MachineName", "ClusterID", "MachineStart", "Lifetime"} s.shortHeader = s.wideHeader if s.order == "" { @@ -246,14 +246,14 @@ func (s MachineBillingTablePrinter) Print(data *models.V1MachineUsageResponse) { if u.Machinename != nil { machineName = *u.Machinename } + var sizeid string + if u.Sizeid != nil { + sizeid = *u.Sizeid + } var clusterID string if u.Clusterid != nil { clusterID = *u.Clusterid } - var clusterName string - if u.Clustername != nil { - clusterName = *u.Clustername - } var machineStart string if u.Machinestart != nil { machineStart = u.Machinestart.String() @@ -270,10 +270,10 @@ func (s MachineBillingTablePrinter) Print(data *models.V1MachineUsageResponse) { projectID, projectName, partition, + sizeid, machineID, machineName, clusterID, - clusterName, machineStart, humanizeDuration(lifetime), } diff --git a/go.mod b/go.mod index 606e905..96e351e 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,8 @@ require ( github.com/dcorbe/termui-dpc v0.0.0-20211125210512-9d2673a82dd6 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.16.0 - github.com/fi-ts/cloud-go v0.23.1-0.20231212152117-ac7cfb24f780 + github.com/fi-ts/accounting-go v0.9.0 + github.com/fi-ts/cloud-go v0.23.1-0.20231213065124-babe293e6a1a github.com/gardener/gardener v1.73.2 github.com/gardener/machine-controller-manager v0.50.1 github.com/go-openapi/runtime v0.26.0 @@ -194,10 +195,10 @@ require ( golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect golang.zx2c4.com/wireguard/windows v0.5.3 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect + google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect - google.golang.org/grpc v1.59.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3 // indirect + google.golang.org/grpc v1.60.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index d7a2c91..351a0c2 100644 --- a/go.sum +++ b/go.sum @@ -103,8 +103,10 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= -github.com/fi-ts/cloud-go v0.23.1-0.20231212152117-ac7cfb24f780 h1:GqY5LB5UXLpcDKXqhEla6rMyHXqAnE86/ZZpWmYEKrQ= -github.com/fi-ts/cloud-go v0.23.1-0.20231212152117-ac7cfb24f780/go.mod h1:z4ZWkDa0EiaAfHy1iiv7vlgoZgJQEsAgQnrvG2cJksw= +github.com/fi-ts/accounting-go v0.9.0 h1:XacEMQtFUd0eh1aTFLo5rrzWKDE9CDJw+smS07zOK/0= +github.com/fi-ts/accounting-go v0.9.0/go.mod h1:8ga8xix70wTxZNwdb0Ye4cEmL1miY6SeUio4vQLMBaI= +github.com/fi-ts/cloud-go v0.23.1-0.20231213065124-babe293e6a1a h1:fAydhtNRPUVWA3GGcY88qVIgnRId+Zhbq1r/7pKOy0g= +github.com/fi-ts/cloud-go v0.23.1-0.20231213065124-babe293e6a1a/go.mod h1:z4ZWkDa0EiaAfHy1iiv7vlgoZgJQEsAgQnrvG2cJksw= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= @@ -656,19 +658,19 @@ google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= +google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f h1:Vn+VyHU5guc9KjB5KrjI2q0wCOWEOIh0OEsleqakHJg= +google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f/go.mod h1:nWSwAFPb+qfNJXsoeO3Io7zf4tMSfN8EA8RlDA04GhY= google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 h1:JpwMPBpFN3uKhdaekDpiNlImDdkUAyiJ6ez/uxGaUSo= google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f h1:ultW7fxlIvee4HYrtnaRPon9HpEgFk5zYpmfMgtKB5I= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3 h1:kzJAXnzZoFbe5bhZd4zjUuHos/I31yH4thfMb/13oVY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3/go.mod h1:eJVxU6o+4G1PSczBr85xmyvSNYAKvAYgkub40YGomFM= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= -google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= +google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k= +google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=