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

51 lines
2.0 KiB
Go
Raw Permalink Normal View History

2024-07-18 11:51:12 +02:00
package processing
import (
2024-07-18 14:39:54 +02:00
"encoding/json"
2024-07-30 12:08:13 +02:00
"cloud.o-forge.io/core/oc-lib/models/resource_model"
2024-07-26 15:19:36 +02:00
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
2024-07-18 13:35:14 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
2024-07-18 11:51:12 +02:00
)
/*
* ProcessingResource is a struct that represents a processing resource
* it defines the resource processing
*/
2024-07-19 10:54:58 +02:00
type ProcessingResource struct {
2024-07-30 12:08:13 +02:00
resource_model.AbstractResource
CPUs []*datacenter.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"` // CPUs is the list of CPUs
GPUs []*datacenter.GPU `bson:"gpus,omitempty" json:"gp_us,omitempty"` // GPUs is the list of GPUs
RAM *datacenter.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
Storage uint `bson:"storage,omitempty" json:"storage,omitempty"` // Storage is the storage
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"` // Parallel is a flag that indicates if the processing is parallel
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"` // ScalingModel is the scaling model
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"` // DiskIO is the disk IO
2024-07-18 11:51:12 +02:00
}
2024-07-19 10:54:58 +02:00
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {
2024-07-18 14:39:54 +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 *ProcessingResource) 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
}
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
data.Init(utils.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
2024-07-18 11:51:12 +02:00
return data
}