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

51 lines
1.4 KiB
Go
Raw 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-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
)
type URL struct {
2024-07-22 16:39:26 +02:00
Protocol string `bson:"protocol,omitempty" json:"protocol,omitempty"`
Path string `bson:"path,omitempty" json:"path,omitempty"`
2024-07-18 11:51:12 +02:00
}
2024-07-19 10:54:58 +02:00
type StorageResource struct {
2024-07-18 11:51:12 +02:00
resources.AbstractResource
Capacity uint `bson:"capacity,omitempty" json:"capacity,omitempty"`
2024-07-22 15:18:59 +02:00
Url *URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
2024-07-18 11:51:12 +02:00
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"`
}
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
}
json.Unmarshal(b, dma)
return m
}
2024-07-19 10:54:58 +02:00
func (d *StorageResource) GetAccessor() utils.Accessor {
2024-07-18 15:02:39 +02:00
data := &StorageMongoAccessor{}
2024-07-19 10:54:58 +02:00
data.SetLogger(utils.STORAGE_RESOURCE)
2024-07-18 11:51:12 +02:00
return data
}