A question refers to the comment ! And if not Ooopsy
This commit is contained in:
@@ -8,11 +8,15 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
/*
|
||||
* DatacenterResource is a struct that represents a datacenter resource
|
||||
* it defines the resource datacenter
|
||||
*/
|
||||
type DatacenterResource struct {
|
||||
resource_model.AbstractResource
|
||||
CPUs []*CPU `bson:"cpus,omitempty" json:"cpus,omitempty"`
|
||||
RAM *RAM `bson:"ram,omitempty" json:"ram,omitempty"`
|
||||
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"`
|
||||
CPUs []*CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs
|
||||
RAM *RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
||||
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
|
||||
}
|
||||
|
||||
func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
@@ -40,6 +44,7 @@ func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accesso
|
||||
return data
|
||||
}
|
||||
|
||||
// CPU is a struct that represents a CPU
|
||||
type CPU struct {
|
||||
Cores uint `bson:"cores,omitempty" json:"cores,omitempty"` //TODO: validate
|
||||
Architecture string `bson:"architecture,omitempty" json:"architecture,omitempty"` //TOOD: enum
|
||||
|
||||
@@ -8,13 +8,18 @@ import (
|
||||
)
|
||||
|
||||
type datacenterMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the datacenterMongoAccessor
|
||||
func New() *datacenterMongoAccessor {
|
||||
return &datacenterMongoAccessor{}
|
||||
}
|
||||
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
|
||||
func (dca *datacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return dca.GenericDeleteOne(id, dca)
|
||||
}
|
||||
@@ -68,7 +73,7 @@ func (wfa datacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
@@ -77,7 +82,7 @@ func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string)
|
||||
objs := []utils.ShallowDBObject{}
|
||||
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
||||
filters = &dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{
|
||||
Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
|
||||
"abstractresource.abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.short_description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
@@ -101,7 +106,7 @@ func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string)
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user