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

52 lines
1.3 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 14:39:54 +02:00
tool "cloud.o-forge.io/core/oc-lib/utils"
2024-07-18 11:51:12 +02:00
)
type URL struct {
Protocol string `bson:"protocol" json:"protocol"`
Path string `bson:"path" json:"path"`
}
type Storage 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"`
}
2024-07-18 14:39:54 +02:00
func (dma *Storage) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
2024-07-18 11:51:12 +02:00
func (s *Storage) GetType() resources.ResourceType {
return resources.STORAGE
}
2024-07-18 14:39:54 +02:00
func (d *Storage) GetAccessor(driver tool.Driver) utils.Accessor {
2024-07-18 11:51:12 +02:00
var data utils.Accessor
switch driver {
2024-07-18 14:39:54 +02:00
case tool.MONGO:
2024-07-18 11:51:12 +02:00
data = &StorageMongoAccessor{}
default:
data = &StorageMongoAccessor{}
}
data.SetLogger()
return data
}