oc-lib/models/resources/datacenter/datacenter.go

63 lines
2.0 KiB
Go
Raw Normal View History

2024-07-18 11:51:12 +02:00
package datacenter
import (
2024-07-18 15:02:39 +02:00
"encoding/json"
2024-07-18 13:35:14 +02:00
resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils"
2024-07-18 11:51:12 +02:00
)
2024-07-19 10:54:58 +02:00
type DatacenterResource struct {
2024-07-18 11:51:12 +02:00
resources.AbstractResource
2024-07-22 16:39:26 +02:00
BookingPrice int `bson:"booking_price,omitempty" json:"booking_price,omitempty"`
2024-07-18 11:51:12 +02:00
2024-07-22 15:18:59 +02:00
CPU *DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"`
RAM *DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"`
GPU []DatacenterGpuModel `bson:"gpu,omitempty" json:"gpu,omitempty"`
2024-07-18 11:51:12 +02:00
}
type DatacenterCpuModel struct {
Cores uint `bson:"cores,omitempty" json:"cores,omitempty"` //TODO: validate
Architecture string `bson:"architecture,omitempty" json:"architecture,omitempty"` //TOOD: enum
Shared bool `bson:"shared,omitempty" json:"shared,omitempty"`
MinimumMemory uint `bson:"minimum_memory,omitempty" json:"minimum_memory,omitempty"`
Platform string `bson:"platform,omitempty" json:"platform,omitempty"`
}
type DatacenterMemoryModel struct {
Size uint `bson:"size,omitempty" json:"size,omitempty" description:"Units in MB"`
Ecc bool `bson:"ecc,omitempty" json:"ecc,omitempty"`
}
type DatacenterGpuModel struct {
CudaCores uint `bson:"cuda_cores,omitempty" json:"cuda_cores,omitempty"`
Model string `bson:"model,omitempty" json:"model,omitempty"`
Memory uint `bson:"memory,omitempty" json:"memory,omitempty" description:"Units in MB"`
TensorCores uint `bson:"tensor_cores,omitempty" json:"tensor_cores,omitempty"`
}
2024-07-19 10:54:58 +02:00
func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObject {
2024-07-18 15:02:39 +02:00
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
2024-07-19 10:54:58 +02:00
func (dma *DatacenterResource) Serialize() map[string]interface{} {
2024-07-19 09:32:58 +02:00
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
2024-07-19 10:54:58 +02:00
func (d *DatacenterResource) GetAccessor() utils.Accessor {
2024-07-18 15:02:39 +02:00
data := &DatacenterMongoAccessor{}
2024-07-19 10:54:58 +02:00
data.SetLogger(utils.DATACENTER_RESOURCE)
2024-07-18 11:51:12 +02:00
return data
}