2024-11-07 11:05:24 +01:00
|
|
|
package compute
|
2024-07-18 11:51:12 +02:00
|
|
|
|
|
|
|
import (
|
2024-07-18 15:02:39 +02:00
|
|
|
"encoding/json"
|
|
|
|
|
2024-07-30 12:08:13 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
2024-07-18 13:35:14 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
2024-08-12 16:11:25 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
2024-07-18 11:51:12 +02:00
|
|
|
)
|
|
|
|
|
2024-11-07 11:36:31 +01:00
|
|
|
type TechnologyEnum int
|
|
|
|
const(
|
|
|
|
DOCKER TechnologyEnum = iota
|
|
|
|
KUBERNETES,
|
|
|
|
SLURM,
|
|
|
|
HW,
|
|
|
|
CONDOR
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccessEnum int
|
|
|
|
const(
|
|
|
|
SSH AccessEnum = iota
|
|
|
|
SSH_KUBE_API,
|
|
|
|
SSH_SLURM,
|
|
|
|
SSH_DOCKER,
|
|
|
|
OPENCLOUD,
|
|
|
|
VPN
|
|
|
|
)
|
|
|
|
|
2024-08-30 14:50:48 +02:00
|
|
|
/*
|
2024-11-07 11:05:24 +01:00
|
|
|
* ComputeResource is a struct that represents a compute resource
|
|
|
|
* it defines the resource compute
|
2024-08-30 14:50:48 +02:00
|
|
|
*/
|
2024-11-07 11:05:24 +01:00
|
|
|
type ComputeResource struct {
|
2024-07-30 12:08:13 +02:00
|
|
|
resource_model.AbstractResource
|
2024-11-07 11:36:31 +01:00
|
|
|
Technology TechnologyEnum `json:"technology,omitempty" bson:"technology,omitempty"` // Technology is the technology
|
|
|
|
Architecture string `json:"architecture,omitempty" bson:"architecture,omitempty"` // Architecture is the architecture
|
|
|
|
Access AccessEnum `json:"access,omitempty" bson:"access,omitempty"` // Access is the access
|
|
|
|
|
|
|
|
Localisation string `json:"localisation,omitempty" bson:"localisation,omitempty"` // Localisation is the localisation
|
|
|
|
|
2024-08-30 14:50:48 +02:00
|
|
|
CPUs []*CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs
|
|
|
|
RAM *RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
|
|
|
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
|
2024-07-18 11:51:12 +02:00
|
|
|
}
|
|
|
|
|
2024-11-07 11:05:24 +01:00
|
|
|
func (dma *ComputeResource) 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-11-07 11:05:24 +01:00
|
|
|
func (dma *ComputeResource) 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
|
|
|
|
}
|
2024-07-24 09:53:30 +02:00
|
|
|
json.Unmarshal(b, &m)
|
2024-07-19 09:32:58 +02:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2024-11-07 11:05:24 +01:00
|
|
|
func (d *ComputeResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
2024-07-31 10:07:55 +02:00
|
|
|
data := New()
|
2024-11-07 11:05:24 +01:00
|
|
|
data.Init(tools.COMPUTE_RESOURCE, caller)
|
2024-07-18 11:51:12 +02:00
|
|
|
return data
|
|
|
|
}
|
2024-07-26 15:19:36 +02:00
|
|
|
|
2024-08-30 14:50:48 +02:00
|
|
|
// CPU is a struct that represents a CPU
|
2024-07-26 15:19:36 +02:00
|
|
|
type CPU 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 RAM struct {
|
|
|
|
Size uint `bson:"size,omitempty" json:"size,omitempty" description:"Units in MB"`
|
|
|
|
Ecc bool `bson:"ecc,omitempty" json:"ecc,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type GPU 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"`
|
|
|
|
}
|