2025-06-24 11:29:04 +02:00
|
|
|
package live
|
|
|
|
|
|
|
|
import (
|
2025-06-26 15:57:49 +02:00
|
|
|
"slices"
|
|
|
|
|
2025-06-24 11:29:04 +02:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LiveDatacenter is a struct that represents a compute units in your datacenters
|
|
|
|
*/
|
|
|
|
type Credentials struct {
|
|
|
|
Login string `json:"login,omitempty" bson:"login,omitempty"`
|
|
|
|
Pass string `json:"password,omitempty" bson:"password,omitempty"`
|
|
|
|
Token string `json:"token,omitempty" bson:"token,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Certs struct {
|
|
|
|
AuthorityCertificate string `json:"authority_certificate,omitempty" bson:"authority_certificate,omitempty"`
|
|
|
|
ClientCertificate string `json:"client_certificate,omitempty" bson:"client_certificate,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type LiveCerts struct {
|
|
|
|
Host string `json:"host,omitempty" bson:"host,omitempty"`
|
|
|
|
Port string `json:"port,omitempty" bson:"port,omitempty"`
|
|
|
|
|
|
|
|
Certificates *Certs `json:"certs,omitempty" bson:"certs,omitempty"`
|
|
|
|
Credentials *Credentials `json:"creds,omitempty" bson:"creds,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO in the future multiple type of certs depending of infra type
|
|
|
|
|
|
|
|
type AbstractLive struct {
|
|
|
|
utils.AbstractObject
|
|
|
|
Certs LiveCerts `json:"certs,omitempty" bson:"certs,omitempty"`
|
|
|
|
|
|
|
|
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"`
|
|
|
|
ResourcesID []string `json:"resources_id" bson:"resources_id"`
|
|
|
|
}
|
|
|
|
|
2025-06-26 15:57:49 +02:00
|
|
|
func (d *AbstractLive) GetMonitorPath() string {
|
|
|
|
return d.MonitorPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *AbstractLive) GetResourcesID() []string {
|
|
|
|
return d.ResourcesID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *AbstractLive) SetResourcesID(id string) {
|
|
|
|
if !slices.Contains(d.ResourcesID, id) {
|
|
|
|
d.ResourcesID = append(d.ResourcesID, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-06-24 11:29:04 +02:00
|
|
|
func (r *AbstractLive) GetResourceType() tools.DataType {
|
|
|
|
return tools.INVALID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *AbstractLive) StoreDraftDefault() {
|
|
|
|
r.IsDraft = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *AbstractLive) CanDelete() bool {
|
|
|
|
return r.IsDraft // only draft ComputeUnits can be deleted
|
|
|
|
}
|