compute

package
v0.0.0-...-ccb81e8 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compute is the in-process entrypoint for Nova placement scheduling.

It defines a well-typed, Nova-agnostic PlacementRequest that the filter-weigher pipeline consumes, and a Placement that owns the single shared scheduling lock and runs the pipeline plus caller-provided side-effect closures. Callers that run in the same process (the Nova HTTP adapter, the reservation/commitment/capacity/failover controllers) call the Placement directly instead of POSTing to the external HTTP endpoint.

The spec deliberately contains NO loosely-typed maps or Nova string conventions (flavor extra-spec keys, scheduler-hint keys, image property keys). A Nova spec adapter is responsible for translating Nova's over-the-wire shape into these typed fields; the pipeline only ever sees well-specced values. The Nova vocabulary types those fields use (capabilities, flavor sizing, hypervisor family, …) live in the api/external/nova package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CandidateGatherer

type CandidateGatherer interface {
	// MutateWithAllCandidates overrides the request's hosts and weights with all
	// available placement candidates.
	MutateWithAllCandidates(ctx context.Context, request *PlacementRequest) error
}

CandidateGatherer gathers all placement candidates for a request when the pipeline is configured to ignore the caller's preselection.

type Host

type Host struct {
	// ComputeHost is the Nova compute host name, e.g. nova-compute-bb123.
	ComputeHost string
	// HypervisorHostname is the hypervisor hostname, e.g. domain-c123.<uuid>.
	HypervisorHostname string
}

Host is a placement candidate. For KVM hosts the compute host name and the hypervisor hostname are identical; for others they may differ.

type PipelineProvider

type PipelineProvider interface {
	// GetPipeline returns the initialized pipeline for the given name, if ready.
	GetPipeline(name string) (lib.FilterWeigherPipeline[PlacementRequest], bool)
}

PipelineProvider supplies initialized pipelines by name. The Nova filter-weigher pipeline controller satisfies this interface via its embedded lib.BasePipelineController.

type Placement

type Placement struct {
	// contains filtered or unexported fields
}

Placement is the single in-process owner of Nova placement decisions. It holds the one shared scheduling lock and runs the pipeline plus a caller-provided pre-hook and post-hook. It owns no side-effect policy itself — the caller decides, via the hooks it passes, what happens before and after the run.

func NewPlacement

func NewPlacement(pipelines PipelineProvider, gatherer CandidateGatherer) *Placement

NewPlacement builds a Placement over the given pipeline provider and candidate gatherer.

func (*Placement) Run

func (s *Placement) Run(
	ctx context.Context,
	req PlacementRequest,
	pre PreHook,
	post PostHook,
) (PlacementResult, error)

Run executes the pipeline and hooks while holding the shared scheduling lock across the whole operation, so concurrent runs observe a consistent view of shared scheduling state. The pre-hook runs before the pipeline; the post-hook after. Either hook may be nil. Use this for any run that mutates shared state.

func (*Placement) RunWithoutLock

func (s *Placement) RunWithoutLock(
	ctx context.Context,
	req PlacementRequest,
	pre PreHook,
	post PostHook,
) (PlacementResult, error)

RunWithoutLock executes the pipeline and hooks WITHOUT acquiring the shared lock. Use this only for read-only runs (e.g. capacity probes) that do not mutate shared scheduling state and can safely run concurrently with a locked run. Either hook may be nil.

type PlacementRequest

type PlacementRequest struct {
	// Pipeline is the name of the pipeline to execute. Required: an empty name
	// resolves no pipeline and the run fails with "pipeline not found".
	Pipeline string
	// GatherAllCandidates, when true, tells the Placement to ignore the Hosts and
	// Weights the caller provided and instead gather ALL available placement
	// candidates (via the CandidateGatherer) before filtering. It is set for
	// requests where cortex can enumerate the candidate hosts itself — today the
	// KVM family, whose hypervisors cortex knows from the hypervisor operator;
	// VMware placement leaves it false and relies on the caller's preselection.
	// When true, Hosts/Weights below are overwritten before filtering.
	GatherAllCandidates bool
	// Hosts are the placement candidates. An empty list yields an empty result
	// (no host found), unless GatherAllCandidates is set, in which case Hosts is
	// overwritten before filtering.
	Hosts []Host
	// Weights are the per-host input weights, keyed by compute host name. A host
	// absent from this map is weighed as 0. Empty means every candidate starts
	// equally weighted.
	Weights map[string]float64
	// Options configure the pipeline behavior for this run. The zero value is a
	// normal (non-read-only) run with no candidate limit; see scheduling.Options
	// for per-field defaults.
	Options scheduling.Options

	// Intent is the resolved scheduling intent (replaces the "_nova_check_type"
	// scheduler hint). The zero value is the empty intent; intent-gated
	// filters/weighers treat it like an initial placement (create) and a forced
	// destination is honored (see IsForcedDestination).
	Intent v1alpha1.SchedulingIntent

	// InstanceUUID identifies the instance being placed. Empty is allowed for
	// synthetic runs (e.g. capacity probes); it only appears in logs and side
	// effects, so an empty value disables nothing in the pipeline itself.
	InstanceUUID string
	// ProjectID is the owning OpenStack project. Empty disables project-scoped
	// filtering (e.g. allowed-projects, quota) — those steps treat it as "no
	// project context".
	ProjectID string
	// UserID is the requesting user. Empty only affects trace logging and the VM
	// ownership written by side effects.
	UserID string
	// AvailabilityZone is the target AZ. Empty means no AZ constraint, so the
	// correct-AZ filter keeps all hosts.
	AvailabilityZone string
	// NumInstances is the number of instances this request represents. It is a
	// MULTIPLIER in capacity and bin-pack math, so 0 makes a host look infinitely
	// free and must not be left unset — the adapter always sets it (Nova sends
	// >= 1).
	NumInstances uint64

	// IgnoreHosts are hosts to exclude from placement. Empty/nil means no hosts
	// are excluded.
	IgnoreHosts []string
	// ForceHosts pins placement to these compute hosts. Empty/nil means no host
	// is forced. When set (and the intent does not require filter validation),
	// the pipeline is skipped and only forced hosts are returned.
	ForceHosts []string
	// ForceNodes pins placement to these hypervisor hostnames. Empty/nil means no
	// node is forced. Semantics mirror ForceHosts.
	ForceNodes []string

	// HypervisorFamily is the coarse family (kvm/vmware) used by the pipeline and
	// routing. Empty means unresolved: KVM-only gates (e.g. VM creation) treat it
	// as not-KVM and skip.
	HypervisorFamily api.HypervisorFamily
	// ImageHypervisorType is the hypervisor type declared by the image. The empty
	// value (ImageHypervisorTypeUnset) means the image declared none ("no image
	// constraint"); ImageHypervisorTypeUnparseable means it declared one that
	// could not be parsed, which the image-properties filter surfaces as a
	// diagnostic.
	ImageHypervisorType api.ImageHypervisorType
	// HardwareVersion is resolved from the "quota:hw_version" extra spec. Empty
	// means no hardware-version constraint.
	HardwareVersion string

	// InstanceCapacity is the per-instance capacity the request asks for, keyed
	// by hv1 resource name: hv1.ResourceCPU is the vCPU count (DecimalSI) and
	// hv1.ResourceMemory is memory in bytes (BinarySI). This mirrors the shape the
	// hypervisor operator advertises (hv1.Hypervisor.Status.Capacity) and that
	// reservation slots use, so capacity/bin-pack steps consume it directly. A nil
	// map (or a missing/zero entry) means a zero-sized instance to those steps
	// (fits anywhere) — the adapter always populates it for real placements. Use
	// TotalCapacityDemand for the across-all-instances total.
	InstanceCapacity map[hv1.ResourceName]resource.Quantity

	// RequiredTraits are trait names the host must have (adapter stripped the
	// "trait:" prefix and kept the "required" ones). Empty/nil means no required
	// traits, so the traits filter imposes no inclusion constraint.
	RequiredTraits []string
	// ForbiddenTraits are trait names the host must NOT have. Empty/nil means no
	// forbidden traits. If both trait lists are empty the traits filter is a no-op.
	ForbiddenTraits []string
	// RequestedCapabilities are required (key=value) hypervisor capabilities
	// (adapter stripped the "capabilities:" prefix and rejected unsupported
	// operators). Empty/nil means the capabilities filter is a no-op.
	RequestedCapabilities []api.Capability
	// AcceleratorsRequested reports whether the flavor requests a hardware
	// accelerator (adapter resolves it from the presence of the
	// "accel:device_profile" extra spec). When true, the accelerators filter keeps
	// only hosts carrying the COMPUTE_ACCELERATORS trait; false is a no-op.
	AcceleratorsRequested bool

	// SourceHost is the migration source (was hint "source_host"). Empty means
	// not a host-to-host move, so the live-migratable filter imposes no source
	// constraint.
	SourceHost string
	// DomainName is the customer domain (was hint "domain_name"). Empty means no
	// domain context, so the external-customer filter is skipped.
	DomainName string
	// ResourceGroup is the failover resource group (was hint
	// "_cortex_resource_group"). Empty means no group, so group-consolidation
	// weighing is skipped.
	ResourceGroup string

	// RequestedDestination is the requested target host/aggregate. Nil means no
	// destination constraint (see the type doc).
	RequestedDestination *api.RequestedDestination
	// InstanceGroup is the server group the instance belongs to. Nil means the
	// instance is not grouped, so affinity/anti-affinity steps are skipped (see
	// the type doc).
	InstanceGroup *api.InstanceGroupSpec

	// RequestID identifies this scheduling request for tracing. Empty only
	// affects log correlation.
	RequestID string
	// GlobalRequestID is the cross-service request ID for tracing. Empty only
	// affects log correlation.
	GlobalRequestID string
}

PlacementRequest is the well-typed, Nova-agnostic input to the scheduling pipeline. Every field is a resolved scalar, enum, or typed collection — there are no maps of Nova-specific string keys and no values the pipeline must parse.

Each field documents what leaving it at its zero value means, so the Nova spec adapter (and any other caller) can see exactly which fields are load-bearing.

PlacementRequest implements lib.FilterWeigherPipelineRequest so it can be the RequestType of the filter-weigher pipeline.

func (PlacementRequest) Filter

func (r PlacementRequest) Filter(includedHosts map[string]float64) lib.FilterWeigherPipelineRequest

Filter returns a copy of the request narrowed to the given hosts, with the weights updated to the provided values. Hosts not present in includedHosts are dropped and won't be reconsidered by later steps.

func (PlacementRequest) ForcedHosts

func (r PlacementRequest) ForcedHosts() []string

ForcedHosts returns the subset of request hosts matching the forced destinations. force_hosts matches on compute host name (case-insensitive); force_nodes matches on hypervisor hostname (case-sensitive); when both are set a host must match both. Order is preserved and compute hosts are deduplicated.

func (PlacementRequest) GetHosts

func (r PlacementRequest) GetHosts() []string

GetHosts returns the compute host names of all candidates.

func (PlacementRequest) GetIntent

GetIntent returns the resolved scheduling intent.

func (PlacementRequest) GetOptions

func (r PlacementRequest) GetOptions() scheduling.Options

GetOptions returns the call-time options for this run.

func (PlacementRequest) GetTraceLogArgs

func (r PlacementRequest) GetTraceLogArgs() []any

GetTraceLogArgs returns alternating key/value pairs for the step trace log.

func (PlacementRequest) GetWeights

func (r PlacementRequest) GetWeights() map[string]float64

GetWeights returns the per-host input weights.

func (PlacementRequest) IsForcedDestination

func (r PlacementRequest) IsForcedDestination() bool

IsForcedDestination reports whether the request is forced onto specific hosts/nodes and the scheduler filters should be skipped entirely. A forced request that still carries a non-create intent (rebuild/evacuate/resize) must be validated by the filters, so it is not treated as forced here. Intent resolution happens in the adapter; this only inspects the typed Intent field.

func (PlacementRequest) TotalCapacityDemand

func (r PlacementRequest) TotalCapacityDemand() map[hv1.ResourceName]resource.Quantity

TotalCapacityDemand returns InstanceCapacity scaled by NumInstances, i.e. the total capacity across all instances this request represents. Each quantity keeps its source format (DecimalSI for cpu, BinarySI for memory). NumInstances is the single source of truth for the multiplier; the adapter always sets it >= 1. A nil InstanceCapacity yields an empty map.

type PlacementResult

type PlacementResult = lib.PipelineResult

PlacementResult is the well-defined output of a scheduling pipeline run: ordered hosts, the target host, and the input/output weights plus per-step activations used to rank them. It is an alias of lib.PipelineResult, the domain-neutral type the generic pipeline returns. The human-readable explanation is NOT part of the result — it is a concern of writing the decision onto the scheduled resource (e.g. the Nova VM's CortexSpec), so the relevant side effect generates it from the result via lib.GenerateExplanation.

type PostHook

type PostHook func(ctx context.Context, req PlacementRequest, result PlacementResult) error

PostHook is a caller-provided side effect executed after the pipeline run, under the scheduling lock (e.g. upserting the VM resource, recording the decision). It receives the typed pipeline result. Returning an error aborts the run; non-fatal side effects should log and return nil so the placement decision still stands. A nil PostHook is a no-op.

type PreHook

type PreHook func(ctx context.Context, req *PlacementRequest) error

PreHook is a caller-provided hook executed under the scheduling lock before the pipeline runs. It may mutate the request (e.g. to create a pessimistic in-flight reservation and narrow the candidate set). Returning an error aborts the run before the pipeline executes. A nil PreHook is a no-op.

Jump to

Keyboard shortcuts

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