datacenter

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package datacenter manages deployment locations in the control plane. Each datacenter represents a physical or logical deployment target backed by a registered infrastructure provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateTransition

func ValidateTransition(from, to Status) error

ValidateTransition checks if a status transition is allowed.

Types

type Capacity

type Capacity struct {
	MaxInstances int `db:"max_instances"  json:"max_instances"`
	MaxCPUMillis int `db:"max_cpu_millis" json:"max_cpu_millis"`
	MaxMemoryMB  int `db:"max_memory_mb"  json:"max_memory_mb"`
}

Capacity holds optional resource quotas for a datacenter.

type CreateRequest

type CreateRequest struct {
	Name         string            `json:"name"               validate:"required"`
	ProviderName string            `json:"provider_name"      validate:"required"`
	Region       string            `json:"region"             validate:"required"`
	Zone         string            `json:"zone,omitempty"`
	Location     *Location         `json:"location,omitempty"`
	Capacity     *Capacity         `json:"capacity,omitempty"`
	Labels       map[string]string `json:"labels,omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty"`
}

CreateRequest holds the parameters for creating a datacenter.

type Datacenter

type Datacenter struct {
	ctrlplane.Entity

	TenantID      string            `db:"tenant_id"       json:"tenant_id"`
	Name          string            `db:"name"            json:"name"`
	Slug          string            `db:"slug"            json:"slug"`
	ProviderName  string            `db:"provider_name"   json:"provider_name"`
	Region        string            `db:"region"          json:"region"`
	Zone          string            `db:"zone"            json:"zone"`
	Status        Status            `db:"status"          json:"status"`
	Location      Location          `db:"location"        json:"location"`
	Capacity      Capacity          `db:"capacity"        json:"capacity"`
	Labels        map[string]string `db:"labels"          json:"labels,omitempty"`
	Metadata      map[string]string `db:"metadata"        json:"metadata,omitempty"`
	LastCheckedAt *time.Time        `db:"last_checked_at" json:"last_checked_at,omitempty"`
}

Datacenter represents a deployment location backed by a provider.

func NewDatacenter

func NewDatacenter() *Datacenter

NewDatacenter creates a datacenter entity with a fresh ID and timestamps.

type ListOptions

type ListOptions struct {
	Status   string `json:"status,omitempty"`
	Provider string `json:"provider,omitempty"`
	Region   string `json:"region,omitempty"`
	Label    string `json:"label,omitempty"`
	Cursor   string `json:"cursor,omitempty"`
	Limit    int    `json:"limit,omitempty"`
}

ListOptions configures datacenter listing with optional filters and pagination.

type ListResult

type ListResult struct {
	Items      []*Datacenter `json:"items"`
	NextCursor string        `json:"next_cursor,omitempty"`
	Total      int           `json:"total"`
}

ListResult holds a page of datacenters with cursor-based pagination.

type Location

type Location struct {
	Latitude  float64 `db:"latitude"  json:"latitude"`
	Longitude float64 `db:"longitude" json:"longitude"`
	Country   string  `db:"country"   json:"country"`
	City      string  `db:"city"      json:"city"`
}

Location holds geographic coordinates and metadata for a datacenter.

type Service

type Service interface {
	// Create registers a new datacenter backed by a named provider.
	Create(ctx context.Context, req CreateRequest) (*Datacenter, error)

	// Get returns a datacenter by ID, scoped to the tenant in context.
	Get(ctx context.Context, datacenterID id.ID) (*Datacenter, error)

	// GetBySlug returns a datacenter by slug, scoped to the tenant in context.
	GetBySlug(ctx context.Context, slug string) (*Datacenter, error)

	// List returns datacenters for the current tenant with filtering.
	List(ctx context.Context, opts ListOptions) (*ListResult, error)

	// Update modifies a datacenter's configuration.
	Update(ctx context.Context, datacenterID id.ID, req UpdateRequest) (*Datacenter, error)

	// Delete removes a datacenter. Fails if instances still reference it.
	Delete(ctx context.Context, datacenterID id.ID) error

	// SetStatus transitions a datacenter to a new operational status.
	SetStatus(ctx context.Context, datacenterID id.ID, status Status) error

	// ResolveProvider returns the provider name for a given datacenter.
	ResolveProvider(ctx context.Context, datacenterID id.ID) (string, error)
}

Service manages datacenter lifecycle operations.

func NewService

func NewService(store Store, providers *provider.Registry, events event.Bus, auth auth.Provider) Service

NewService creates a new datacenter service.

type Status

type Status string

Status represents the operational state of a datacenter.

const (
	// StatusActive indicates the datacenter is available for new workloads.
	StatusActive Status = "active"

	// StatusMaintenance indicates the datacenter is undergoing maintenance.
	StatusMaintenance Status = "maintenance"

	// StatusDraining indicates the datacenter is being drained of workloads.
	StatusDraining Status = "draining"

	// StatusOffline indicates the datacenter is offline.
	StatusOffline Status = "offline"
)

type Store

type Store interface {
	// InsertDatacenter persists a new datacenter.
	InsertDatacenter(ctx context.Context, dc *Datacenter) error

	// GetDatacenterByID retrieves a datacenter by its ID within a tenant.
	GetDatacenterByID(ctx context.Context, tenantID string, datacenterID id.ID) (*Datacenter, error)

	// GetDatacenterBySlug retrieves a datacenter by its slug within a tenant.
	GetDatacenterBySlug(ctx context.Context, tenantID string, slug string) (*Datacenter, error)

	// ListDatacenters returns a filtered, paginated list of datacenters for a tenant.
	ListDatacenters(ctx context.Context, tenantID string, opts ListOptions) (*ListResult, error)

	// UpdateDatacenter persists changes to an existing datacenter.
	UpdateDatacenter(ctx context.Context, dc *Datacenter) error

	// DeleteDatacenter removes a datacenter from the store.
	DeleteDatacenter(ctx context.Context, tenantID string, datacenterID id.ID) error

	// CountDatacentersByTenant returns the total number of datacenters for a tenant.
	CountDatacentersByTenant(ctx context.Context, tenantID string) (int, error)

	// CountInstancesByDatacenter returns the number of instances linked to a datacenter.
	CountInstancesByDatacenter(ctx context.Context, tenantID string, datacenterID id.ID) (int, error)
}

Store is the persistence interface for datacenters.

type UpdateRequest

type UpdateRequest struct {
	Name     *string           `json:"name,omitempty"`
	Zone     *string           `json:"zone,omitempty"`
	Location *Location         `json:"location,omitempty"`
	Capacity *Capacity         `json:"capacity,omitempty"`
	Labels   map[string]string `json:"labels,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

UpdateRequest holds the parameters for updating a datacenter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL