From 1ee8aee52654ef970d2c81dab885f84f4aca7662 Mon Sep 17 00:00:00 2001 From: Marcus Herz Date: Wed, 8 Jan 2025 16:47:48 +0100 Subject: [PATCH] Hook-up cost tracking via vmtemplate service --- v3/protos/vmtemplate/vmtemplate.pb.go | 167 +++++++++++++----- v3/protos/vmtemplate/vmtemplate.proto | 6 + v3/services/vmclaimsvc/internal/controller.go | 6 + v3/services/vmsetsvc/internal/controller.go | 5 + v3/services/vmtemplatesvc/internal/grpc.go | 48 +++-- .../internal/vmtemplateservice.go | 47 +++-- 6 files changed, 207 insertions(+), 72 deletions(-) diff --git a/v3/protos/vmtemplate/vmtemplate.pb.go b/v3/protos/vmtemplate/vmtemplate.pb.go index 1d2c84fc..f3b814aa 100644 --- a/v3/protos/vmtemplate/vmtemplate.pb.go +++ b/v3/protos/vmtemplate/vmtemplate.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.36.1 +// protoc-gen-go v1.36.2 // protoc v3.21.12 // source: vmtemplate/vmtemplate.proto @@ -29,6 +29,8 @@ type VMTemplate struct { Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` Image string `protobuf:"bytes,4,opt,name=image,proto3" json:"image,omitempty"` ConfigMap map[string]string `protobuf:"bytes,5,rep,name=config_map,json=configMap,proto3" json:"config_map,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + CostBasePrice *string `protobuf:"bytes,6,opt,name=cost_base_price,json=costBasePrice,proto3,oneof" json:"cost_base_price,omitempty"` + CostTimeUnit *string `protobuf:"bytes,7,opt,name=cost_time_unit,json=costTimeUnit,proto3,oneof" json:"cost_time_unit,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -98,11 +100,27 @@ func (x *VMTemplate) GetConfigMap() map[string]string { return nil } +func (x *VMTemplate) GetCostBasePrice() string { + if x != nil && x.CostBasePrice != nil { + return *x.CostBasePrice + } + return "" +} + +func (x *VMTemplate) GetCostTimeUnit() string { + if x != nil && x.CostTimeUnit != nil { + return *x.CostTimeUnit + } + return "" +} + type CreateVMTemplateRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Image string `protobuf:"bytes,2,opt,name=image,proto3" json:"image,omitempty"` ConfigMapRaw string `protobuf:"bytes,3,opt,name=config_map_raw,json=configMapRaw,proto3" json:"config_map_raw,omitempty"` + CostBasePrice *string `protobuf:"bytes,4,opt,name=cost_base_price,json=costBasePrice,proto3,oneof" json:"cost_base_price,omitempty"` + CostTimeUnit *string `protobuf:"bytes,5,opt,name=cost_time_unit,json=costTimeUnit,proto3,oneof" json:"cost_time_unit,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -158,12 +176,28 @@ func (x *CreateVMTemplateRequest) GetConfigMapRaw() string { return "" } +func (x *CreateVMTemplateRequest) GetCostBasePrice() string { + if x != nil && x.CostBasePrice != nil { + return *x.CostBasePrice + } + return "" +} + +func (x *CreateVMTemplateRequest) GetCostTimeUnit() string { + if x != nil && x.CostTimeUnit != nil { + return *x.CostTimeUnit + } + return "" +} + type UpdateVMTemplateRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Image string `protobuf:"bytes,3,opt,name=image,proto3" json:"image,omitempty"` ConfigMapRaw string `protobuf:"bytes,4,opt,name=config_map_raw,json=configMapRaw,proto3" json:"config_map_raw,omitempty"` + CostBasePrice *string `protobuf:"bytes,5,opt,name=cost_base_price,json=costBasePrice,proto3,oneof" json:"cost_base_price,omitempty"` + CostTimeUnit *string `protobuf:"bytes,6,opt,name=cost_time_unit,json=costTimeUnit,proto3,oneof" json:"cost_time_unit,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -226,6 +260,20 @@ func (x *UpdateVMTemplateRequest) GetConfigMapRaw() string { return "" } +func (x *UpdateVMTemplateRequest) GetCostBasePrice() string { + if x != nil && x.CostBasePrice != nil { + return *x.CostBasePrice + } + return "" +} + +func (x *UpdateVMTemplateRequest) GetCostTimeUnit() string { + if x != nil && x.CostTimeUnit != nil { + return *x.CostTimeUnit + } + return "" +} + type ListVMTemplatesResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Vmtemplates []*VMTemplate `protobuf:"bytes,1,rep,name=vmtemplates,proto3" json:"vmtemplates,omitempty"` @@ -278,7 +326,7 @@ var file_vmtemplate_vmtemplate_proto_rawDesc = []byte{ 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x1a, 0x15, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdc, 0x01, + 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdb, 0x02, 0x0a, 0x0a, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, @@ -288,18 +336,34 @@ var file_vmtemplate_vmtemplate_proto_rawDesc = []byte{ 0x69, 0x67, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, - 0x74, 0x72, 0x79, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x1a, 0x3c, - 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, - 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, - 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x69, 0x0a, 0x17, + 0x74, 0x72, 0x79, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x12, 0x2b, + 0x0a, 0x0f, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0d, 0x63, 0x6f, 0x73, 0x74, 0x42, + 0x61, 0x73, 0x65, 0x50, 0x72, 0x69, 0x63, 0x65, 0x88, 0x01, 0x01, 0x12, 0x29, 0x0a, 0x0e, 0x63, + 0x6f, 0x73, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x0c, 0x63, 0x6f, 0x73, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x55, + 0x6e, 0x69, 0x74, 0x88, 0x01, 0x01, 0x1a, 0x3c, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x3a, 0x02, 0x38, 0x01, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x62, 0x61, + 0x73, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x63, 0x6f, 0x73, + 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x22, 0xe8, 0x01, 0x0a, 0x17, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x6d, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x77, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x4d, 0x61, 0x70, 0x52, 0x61, 0x77, 0x22, 0x79, 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x67, 0x4d, 0x61, 0x70, 0x52, 0x61, 0x77, 0x12, 0x2b, 0x0a, 0x0f, 0x63, 0x6f, 0x73, 0x74, 0x5f, + 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x48, 0x00, 0x52, 0x0d, 0x63, 0x6f, 0x73, 0x74, 0x42, 0x61, 0x73, 0x65, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x88, 0x01, 0x01, 0x12, 0x29, 0x0a, 0x0e, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x74, 0x69, 0x6d, + 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x0c, + 0x63, 0x6f, 0x73, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x74, 0x88, 0x01, 0x01, 0x42, + 0x12, 0x0a, 0x10, 0x5f, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, 0x72, + 0x69, 0x63, 0x65, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x74, 0x69, 0x6d, + 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x22, 0xf8, 0x01, 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, @@ -307,45 +371,53 @@ var file_vmtemplate_vmtemplate_proto_rawDesc = []byte{ 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x6d, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x77, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4d, 0x61, 0x70, 0x52, - 0x61, 0x77, 0x22, 0x53, 0x0a, 0x17, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, - 0x6c, 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, - 0x0b, 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, - 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x0b, 0x76, 0x6d, 0x74, 0x65, - 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x32, 0xc6, 0x03, 0x0a, 0x0d, 0x56, 0x4d, 0x54, 0x65, - 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x53, 0x76, 0x63, 0x12, 0x4c, 0x0a, 0x10, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x23, 0x2e, - 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2e, 0x52, 0x65, 0x73, - 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x12, 0x3c, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x56, 0x4d, - 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, - 0x61, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, - 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x56, 0x4d, 0x54, 0x65, 0x6d, - 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x4f, 0x0a, 0x10, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, - 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x76, 0x6d, 0x74, 0x65, - 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x4d, 0x54, - 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, + 0x61, 0x77, 0x12, 0x2b, 0x0a, 0x0f, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, + 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0d, 0x63, + 0x6f, 0x73, 0x74, 0x42, 0x61, 0x73, 0x65, 0x50, 0x72, 0x69, 0x63, 0x65, 0x88, 0x01, 0x01, 0x12, + 0x29, 0x0a, 0x0e, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, + 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x0c, 0x63, 0x6f, 0x73, 0x74, 0x54, + 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x74, 0x88, 0x01, 0x01, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x63, + 0x6f, 0x73, 0x74, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x42, 0x11, + 0x0a, 0x0f, 0x5f, 0x63, 0x6f, 0x73, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, + 0x74, 0x22, 0x53, 0x0a, 0x17, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, + 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x0b, + 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x16, 0x2e, 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x56, + 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x0b, 0x76, 0x6d, 0x74, 0x65, 0x6d, + 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x32, 0xc6, 0x03, 0x0a, 0x0d, 0x56, 0x4d, 0x54, 0x65, 0x6d, + 0x70, 0x6c, 0x61, 0x74, 0x65, 0x53, 0x76, 0x63, 0x12, 0x4c, 0x0a, 0x10, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x76, + 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x13, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2e, 0x52, 0x65, 0x73, 0x6f, + 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x12, 0x3c, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x56, 0x4d, 0x54, + 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, + 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x76, + 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, + 0x6c, 0x61, 0x74, 0x65, 0x12, 0x4f, 0x0a, 0x10, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x4d, + 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x23, 0x2e, 0x76, 0x6d, 0x74, 0x65, 0x6d, + 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x4d, 0x54, 0x65, + 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3f, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, + 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x67, 0x65, 0x6e, 0x65, + 0x72, 0x61, 0x6c, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3f, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, - 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x67, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x6c, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x1a, - 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4a, 0x0a, 0x1a, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x56, 0x4d, 0x54, 0x65, 0x6d, - 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2e, - 0x4c, 0x69, 0x73, 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x16, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x12, 0x4b, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x4d, 0x54, 0x65, 0x6d, - 0x70, 0x6c, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2e, - 0x4c, 0x69, 0x73, 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x23, 0x2e, 0x76, 0x6d, - 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x4d, 0x54, - 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x42, 0x42, 0x5a, 0x40, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, - 0x6f, 0x62, 0x62, 0x79, 0x66, 0x61, 0x72, 0x6d, 0x2f, 0x67, 0x61, 0x72, 0x67, 0x61, 0x6e, 0x74, - 0x75, 0x61, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x76, 0x6d, 0x74, - 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x3b, 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, - 0x74, 0x65, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4a, 0x0a, 0x1a, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, + 0x6c, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2e, 0x4c, + 0x69, 0x73, 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x12, 0x4b, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x4d, 0x54, 0x65, 0x6d, 0x70, + 0x6c, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x2e, 0x4c, + 0x69, 0x73, 0x74, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x23, 0x2e, 0x76, 0x6d, 0x74, + 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x4d, 0x54, 0x65, + 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, + 0x42, 0x5a, 0x40, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x6f, + 0x62, 0x62, 0x79, 0x66, 0x61, 0x72, 0x6d, 0x2f, 0x67, 0x61, 0x72, 0x67, 0x61, 0x6e, 0x74, 0x75, + 0x61, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x76, 0x6d, 0x74, 0x65, + 0x6d, 0x70, 0x6c, 0x61, 0x74, 0x65, 0x3b, 0x76, 0x6d, 0x74, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x74, + 0x65, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -399,6 +471,9 @@ func file_vmtemplate_vmtemplate_proto_init() { if File_vmtemplate_vmtemplate_proto != nil { return } + file_vmtemplate_vmtemplate_proto_msgTypes[0].OneofWrappers = []any{} + file_vmtemplate_vmtemplate_proto_msgTypes[1].OneofWrappers = []any{} + file_vmtemplate_vmtemplate_proto_msgTypes[2].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/v3/protos/vmtemplate/vmtemplate.proto b/v3/protos/vmtemplate/vmtemplate.proto index e0c5f3f5..a9cba04d 100644 --- a/v3/protos/vmtemplate/vmtemplate.proto +++ b/v3/protos/vmtemplate/vmtemplate.proto @@ -22,12 +22,16 @@ message VMTemplate { string name = 3; string image = 4; map config_map = 5; + optional string cost_base_price = 6; + optional string cost_time_unit = 7; } message CreateVMTemplateRequest { string name = 1; string image = 2; string config_map_raw = 3; + optional string cost_base_price = 4; + optional string cost_time_unit = 5; } message UpdateVMTemplateRequest { @@ -35,6 +39,8 @@ message UpdateVMTemplateRequest { string name = 2; string image = 3; string config_map_raw = 4; + optional string cost_base_price = 5; + optional string cost_time_unit = 6; } message ListVMTemplatesResponse { diff --git a/v3/services/vmclaimsvc/internal/controller.go b/v3/services/vmclaimsvc/internal/controller.go index 30e79333..80a1eba1 100644 --- a/v3/services/vmclaimsvc/internal/controller.go +++ b/v3/services/vmclaimsvc/internal/controller.go @@ -294,6 +294,12 @@ func (v *VMClaimController) submitVirtualMachines(vmc *vmclaimpb.VMClaim) (err e return err } + if vmt.CostBasePrice != nil && vmt.CostTimeUnit != nil { + vm.Labels[hflabels.CostGroup] = seName + vm.Labels[hflabels.CostBasePrice] = vmt.GetCostBasePrice() + vm.Labels[hflabels.CostGroup] = vmt.GetCostTimeUnit() + } + config := util.GetVMConfig(environment, vmt) protocol, exists := config["protocol"] diff --git a/v3/services/vmsetsvc/internal/controller.go b/v3/services/vmsetsvc/internal/controller.go index cb176147..85a6d5c4 100644 --- a/v3/services/vmsetsvc/internal/controller.go +++ b/v3/services/vmsetsvc/internal/controller.go @@ -165,6 +165,11 @@ func (v *VMSetController) reconcileVirtualMachineSet(vmset *vmsetpb.VMSet) error hflabels.ScheduledEventLabel: vmset.GetLabels()[hflabels.ScheduledEventLabel], "restrictedbind": fmt.Sprintf("%t", restrictedBind), } + if vmt.CostBasePrice != nil && vmt.CostTimeUnit != nil { + vmLabels[hflabels.CostGroup] = vmset.GetLabels()[hflabels.ScheduledEventLabel] + vmLabels[hflabels.CostBasePrice] = vmt.GetCostBasePrice() + vmLabels[hflabels.CostGroup] = vmt.GetCostTimeUnit() + } if restrictedBind { vmLabels["restrictedbindvalue"] = vmset.GetRestrictedBindValue() } diff --git a/v3/services/vmtemplatesvc/internal/grpc.go b/v3/services/vmtemplatesvc/internal/grpc.go index 2354331b..ddc72840 100644 --- a/v3/services/vmtemplatesvc/internal/grpc.go +++ b/v3/services/vmtemplatesvc/internal/grpc.go @@ -4,6 +4,7 @@ import ( "context" "crypto/sha256" "encoding/base32" + "github.com/hobbyfarm/gargantua/v3/pkg/labels" "strings" generalpb "github.com/hobbyfarm/gargantua/v3/protos/general" @@ -76,6 +77,13 @@ func (s *GrpcVMTemplateServer) CreateVMTemplate(ctx context.Context, req *vmtemp vmTemplate.Spec.ConfigMap = configMap } + if req.CostBasePrice != nil && req.CostTimeUnit != nil { + vmTemplate.ObjectMeta.Labels = map[string]string{ + labels.CostBasePrice: req.GetCostBasePrice(), + labels.CostTimeUnit: req.GetCostTimeUnit(), + } + } + _, err := s.vmTemplateClient.Create(ctx, vmTemplate, metav1.CreateOptions{}) if err != nil { return &generalpb.ResourceId{}, hferrors.GrpcError( @@ -94,11 +102,13 @@ func (s *GrpcVMTemplateServer) GetVMTemplate(ctx context.Context, req *generalpb } return &vmtemplatepb.VMTemplate{ - Id: vmTemplate.Name, - Uid: string(vmTemplate.UID), - Name: vmTemplate.Spec.Name, - Image: vmTemplate.Spec.Image, - ConfigMap: vmTemplate.Spec.ConfigMap, + Id: vmTemplate.Name, + Uid: string(vmTemplate.UID), + Name: vmTemplate.Spec.Name, + Image: vmTemplate.Spec.Image, + ConfigMap: vmTemplate.Spec.ConfigMap, + CostBasePrice: util.RefOrNil(vmTemplate.ObjectMeta.Labels[labels.CostBasePrice]), + CostTimeUnit: util.RefOrNil(vmTemplate.ObjectMeta.Labels[labels.CostTimeUnit]), }, nil } @@ -111,6 +121,8 @@ func (s *GrpcVMTemplateServer) UpdateVMTemplate(ctx context.Context, req *vmtemp name := req.GetName() image := req.GetImage() configMapRaw := req.GetConfigMapRaw() + costBasePrice := req.GetCostBasePrice() + costTimeUnit := req.GetCostTimeUnit() retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error { vmTemplate, err := s.vmTemplateClient.Get(ctx, id, metav1.GetOptions{}) @@ -140,6 +152,20 @@ func (s *GrpcVMTemplateServer) UpdateVMTemplate(ctx context.Context, req *vmtemp vmTemplate.Spec.ConfigMap = configMap } + if costBasePrice != "" { + if vmTemplate.ObjectMeta.Labels == nil { + vmTemplate.ObjectMeta.Labels = make(map[string]string) + } + vmTemplate.ObjectMeta.Labels[labels.CostBasePrice] = costBasePrice + } + + if costTimeUnit != "" { + if vmTemplate.ObjectMeta.Labels == nil { + vmTemplate.ObjectMeta.Labels = make(map[string]string) + } + vmTemplate.ObjectMeta.Labels[labels.CostTimeUnit] = costTimeUnit + } + _, updateErr := s.vmTemplateClient.Update(ctx, vmTemplate, metav1.UpdateOptions{}) return updateErr }) @@ -185,11 +211,13 @@ func (s *GrpcVMTemplateServer) ListVMTemplate(ctx context.Context, listOptions * for _, vmTemplate := range vmTemplates { preparedVmTemplates = append(preparedVmTemplates, &vmtemplatepb.VMTemplate{ - Id: vmTemplate.Name, - Uid: string(vmTemplate.UID), - Name: vmTemplate.Spec.Name, - Image: vmTemplate.Spec.Image, - ConfigMap: vmTemplate.Spec.ConfigMap, + Id: vmTemplate.Name, + Uid: string(vmTemplate.UID), + Name: vmTemplate.Spec.Name, + Image: vmTemplate.Spec.Image, + ConfigMap: vmTemplate.Spec.ConfigMap, + CostBasePrice: util.RefOrNil(vmTemplate.ObjectMeta.Labels[labels.CostBasePrice]), + CostTimeUnit: util.RefOrNil(vmTemplate.ObjectMeta.Labels[labels.CostTimeUnit]), }) } diff --git a/v3/services/vmtemplatesvc/internal/vmtemplateservice.go b/v3/services/vmtemplatesvc/internal/vmtemplateservice.go index 971ac692..c0821d6a 100644 --- a/v3/services/vmtemplatesvc/internal/vmtemplateservice.go +++ b/v3/services/vmtemplatesvc/internal/vmtemplateservice.go @@ -24,9 +24,11 @@ const ( // Prepared struct for API endpoints which only need to provide vmt id, name and image type PreparedVMTemplate struct { - Id string `json:"id"` - Name string `json:"name"` - Image string `json:"image"` + Id string `json:"id"` + Name string `json:"name"` + Image string `json:"image"` + CostBasePrice string `json:"cost_base_price,omitempty"` + CostTimeUnit string `json:"cost_time_unit,omitempty"` } // Prepared struct for API endpoints which additionally to the PreparedVMTemplate struct also need to provide config details @@ -73,9 +75,11 @@ func (v VirtualMachineTemplateServer) GetFunc(w http.ResponseWriter, r *http.Req preparedVmt := PreparedVMTemplateWithConfig{ PreparedVMTemplate: PreparedVMTemplate{ - Id: vmtId, - Name: vmt.GetName(), - Image: vmt.GetImage(), + Id: vmtId, + Name: vmt.GetName(), + Image: vmt.GetImage(), + CostBasePrice: vmt.GetCostBasePrice(), + CostTimeUnit: vmt.GetCostTimeUnit(), }, ConfigMap: vmt.GetConfigMap(), } @@ -114,9 +118,11 @@ func (v VirtualMachineTemplateServer) ListFunc(w http.ResponseWriter, r *http.Re for _, vmt := range vmtList.GetVmtemplates() { preparedVirtualMachineTemplates = append(preparedVirtualMachineTemplates, PreparedVMTemplate{ - Id: vmt.GetId(), - Name: vmt.GetName(), - Image: vmt.GetImage(), + Id: vmt.GetId(), + Name: vmt.GetName(), + Image: vmt.GetImage(), + CostBasePrice: vmt.GetCostBasePrice(), + CostTimeUnit: vmt.GetCostTimeUnit(), }) } @@ -157,12 +163,17 @@ func (v VirtualMachineTemplateServer) CreateFunc(w http.ResponseWriter, r *http. configMapRaw := r.PostFormValue("config_map") // no validation, config_map not required + costBasePrice := r.PostFormValue("cost_base_price") + costTimeUnit := r.PostFormValue("cost_time_unit") + glog.V(2).Infof("user %s is creating vmtemplate", user.GetId()) vmTemplateId, err := v.internalVMTemplateServer.CreateVMTemplate(r.Context(), &vmtemplatepb.CreateVMTemplateRequest{ - Name: name, - Image: image, - ConfigMapRaw: configMapRaw, + Name: name, + Image: image, + ConfigMapRaw: configMapRaw, + CostBasePrice: util.RefOrNil(costBasePrice), + CostTimeUnit: util.RefOrNil(costTimeUnit), }) if err != nil { glog.Errorf("error creating vmtemplate: %s", hferrors.GetErrorMessage(err)) @@ -200,12 +211,16 @@ func (v VirtualMachineTemplateServer) UpdateFunc(w http.ResponseWriter, r *http. name := r.PostFormValue("name") image := r.PostFormValue("image") configMapRaw := r.PostFormValue("config_map") + costBasePrice := r.PostFormValue("cost_base_price") + costTimeUnit := r.PostFormValue("cost_time_unit") _, err = v.internalVMTemplateServer.UpdateVMTemplate(r.Context(), &vmtemplatepb.UpdateVMTemplateRequest{ - Id: id, - Name: name, - Image: image, - ConfigMapRaw: configMapRaw, + Id: id, + Name: name, + Image: image, + ConfigMapRaw: configMapRaw, + CostBasePrice: util.RefOrNil(costBasePrice), + CostTimeUnit: util.RefOrNil(costTimeUnit), }) if err != nil {