oc-lib/models/resources/storage/storage.go
2024-07-22 15:18:59 +02:00

51 lines
1.3 KiB
Go

package storage
import (
"encoding/json"
resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type URL struct {
Protocol string `bson:"protocol,omitempty" json:"protocol"`
Path string `bson:"path,omitempty" json:"path"`
}
type StorageResource struct {
resources.AbstractResource
Capacity uint `bson:"capacity,omitempty" json:"capacity,omitempty"`
Url *URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"`
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"`
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"`
BookingPrice uint `bson:"booking_price,omitempty" json:"booking_price,omitempty"`
}
func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
func (dma *StorageResource) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return m
}
func (d *StorageResource) GetAccessor() utils.Accessor {
data := &StorageMongoAccessor{}
data.SetLogger(utils.STORAGE_RESOURCE)
return data
}