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

85 lines
2.5 KiB
Go
Raw Permalink Normal View History

2024-07-18 11:51:12 +02:00
package storage
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-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
)
2024-11-07 12:39:28 +01:00
type StorageSize int
2024-10-02 16:39:13 +02:00
// StorageType - Enum that defines the type of storage
const (
2024-11-07 12:39:28 +01:00
GB StorageSize = iota
2024-10-02 16:39:13 +02:00
MB
KB
)
var argoType = [...]string{
"Gi",
"Mi",
"Ki",
}
// New creates a new instance of the StorageResource struct
2024-11-07 12:46:00 +01:00
func (dma StorageSize) ToArgo() string {
2024-10-02 16:39:13 +02:00
return argoType[dma]
}
2024-11-07 11:05:24 +01:00
// enum of a data type
2024-11-07 11:36:31 +01:00
type StorageType int
2024-11-07 12:39:28 +01:00
2024-11-07 11:05:24 +01:00
const (
2024-11-07 11:36:31 +01:00
FILE = iota
STREAM
API
DATABASE
S3
MEMORY
HARDWARE
2024-11-07 11:05:24 +01:00
)
/*
* StorageResource is a struct that represents a storage resource
* it defines the resource storage
*/
2024-07-19 10:54:58 +02:00
type StorageResource struct {
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
resource_model.WebResource
2024-11-07 12:39:28 +01:00
Type StorageType `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage
Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage
2024-11-07 12:39:28 +01:00
SizeType StorageSize `bson:"size_type" json:"size_type" default:"0"` // SizeType is the type of the storage size
Size uint `bson:"size,omitempty" json:"size,omitempty"` // Size is the size of the storage
Local bool `bson:"local" json:"local"` // Local is a flag that indicates if the storage is local
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"` // Encryption is a flag that indicates if the storage is encrypted
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"` // Redundancy is the redundancy of the storage
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
2024-07-18 11:51:12 +02:00
}
2024-07-19 10:54:58 +02:00
func (dma *StorageResource) 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 *StorageResource) 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 *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
2024-10-02 11:35:22 +02:00
data.Init(tools.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
2024-07-18 11:51:12 +02:00
return data
}