2025-06-17 14:21:37 +02:00
|
|
|
package compute_units
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
|
|
|
"github.com/biter777/countries"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ComputeUnits is a struct that represents a compute units in your datacenters
|
|
|
|
*/
|
|
|
|
|
2025-06-17 14:57:36 +02:00
|
|
|
type ComputeUnitsCerts struct {
|
|
|
|
Host string `json:"host,omitempty" bson:"host,omitempty"`
|
|
|
|
Port string `json:"port,omitempty" bson:"port,omitempty"`
|
|
|
|
|
|
|
|
// for now only Kubernetes
|
|
|
|
CAData string `json:"ca_data,omitempty" bson:"ca_data,omitempty"`
|
|
|
|
CertData string `json:"cert_data,omitempty" bson:"cert_data,omitempty"`
|
|
|
|
KeyData string `json:"key_data,omitempty" bson:"key_data,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO in the future multiple type of certs depending of infra type
|
|
|
|
|
2025-06-17 14:21:37 +02:00
|
|
|
type ComputeUnits struct {
|
|
|
|
utils.AbstractObject
|
2025-06-17 14:57:36 +02:00
|
|
|
Certs ComputeUnitsCerts `json:"certs,omitempty" bson:"certs,omitempty"`
|
|
|
|
|
2025-06-17 14:21:37 +02:00
|
|
|
MonitorPath string `json:"monitor_path,omitempty" bson:"monitor_path,omitempty"`
|
|
|
|
Location resources.GeoPoint `json:"location,omitempty" bson:"location,omitempty"`
|
|
|
|
Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"`
|
|
|
|
AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"`
|
|
|
|
Architecture string `json:"architecture,omitempty" bson:"architecture,omitempty"` // Architecture is the architecture
|
|
|
|
Infrastructure enum.InfrastructureType `json:"infrastructure" bson:"infrastructure" default:"-1"` // Infrastructure is the infrastructure
|
|
|
|
Source string `json:"source,omitempty" bson:"source,omitempty"` // Source is the source of the resource
|
|
|
|
SecurityLevel string `json:"security_level,omitempty" bson:"security_level,omitempty"`
|
|
|
|
PowerSources []string `json:"power_sources,omitempty" bson:"power_sources,omitempty"`
|
|
|
|
AnnualCO2Emissions float64 `json:"annual_co2_emissions,omitempty" bson:"co2_emissions,omitempty"`
|
|
|
|
CPUs map[string]*models.CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs key is model
|
|
|
|
GPUs map[string]*models.GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs key is model
|
|
|
|
Nodes []*resources.ComputeNode `json:"nodes,omitempty" bson:"nodes,omitempty"`
|
2025-06-17 14:57:36 +02:00
|
|
|
ResourceID string `json:"resource_id" bson:"resource_id"`
|
2025-06-17 14:21:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ComputeUnits) StoreDraftDefault() {
|
|
|
|
r.IsDraft = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ComputeUnits) CanDelete() bool {
|
|
|
|
return r.IsDraft // only draft ComputeUnits can be deleted
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *ComputeUnits) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
|
|
|
return NewAccessor(request) // Create a new instance of the accessor
|
|
|
|
}
|