mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 04:40:05 +01:00
feat: sdk migration in progress
This commit is contained in:
36
internal/models/server.go
Normal file
36
internal/models/server.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
|
||||
OrganizationID uuid.UUID `gorm:"type:uuid;not null" json:"organization_id"`
|
||||
Organization Organization `gorm:"foreignKey:OrganizationID;constraint:OnDelete:CASCADE" json:"organization"`
|
||||
Hostname string `json:"hostname"`
|
||||
PublicIPAddress *string `json:"public_ip_address,omitempty"`
|
||||
PrivateIPAddress string `gorm:"not null" json:"private_ip_address"`
|
||||
SSHUser string `gorm:"not null" json:"ssh_user"`
|
||||
SshKeyID uuid.UUID `gorm:"type:uuid;not null" json:"ssh_key_id"`
|
||||
SshKey SshKey `gorm:"foreignKey:SshKeyID" json:"ssh_key"`
|
||||
Role string `gorm:"not null" json:"role"` // e.g., "master", "worker", "bastion"
|
||||
Status string `gorm:"default:'pending'" json:"status"` // pending, provisioning, ready, failed
|
||||
CreatedAt time.Time `gorm:"not null;default:now()" json:"created_at" format:"date-time"`
|
||||
UpdatedAt time.Time `gorm:"not null;default:now()" json:"updated_at" format:"date-time"`
|
||||
}
|
||||
|
||||
func (s *Server) BeforeSave(tx *gorm.DB) error {
|
||||
role := strings.ToLower(strings.TrimSpace(s.Role))
|
||||
if role == "bastion" {
|
||||
if s.PublicIPAddress == nil || strings.TrimSpace(*s.PublicIPAddress) == "" {
|
||||
return errors.New("public_ip_address is required for role=bastion")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user