Documentation
¶
Index ¶
- Constants
- Variables
- func CanonicalHypervisorType(value string) string
- func CapacityFromVCPUsMemoryMB(vcpus, memoryMB uint64) map[hv1.ResourceName]resource.Quantity
- func RequestsAccelerators(extraSpecs map[string]string) bool
- func SplitTraits(extraSpecs map[string]string) (required, forbidden []string)
- type Capability
- type ExternalSchedulerHost
- type ExternalSchedulerRequest
- func (r ExternalSchedulerRequest) Filter(includedHosts map[string]float64) lib.FilterWeigherPipelineRequest
- func (r ExternalSchedulerRequest) ForcedHosts() []string
- func (r ExternalSchedulerRequest) GetFlavorType() (FlavorType, error)
- func (r ExternalSchedulerRequest) GetHosts() []string
- func (req ExternalSchedulerRequest) GetHypervisorType() (HypervisorType, error)
- func (req ExternalSchedulerRequest) GetIntent() (v1alpha1.SchedulingIntent, error)
- func (r ExternalSchedulerRequest) GetOptions() scheduling.Options
- func (r ExternalSchedulerRequest) GetTraceLogArgs() []any
- func (r ExternalSchedulerRequest) GetWeights() map[string]float64
- func (r ExternalSchedulerRequest) IsForcedDestination() bool
- func (req ExternalSchedulerRequest) IsKVMRequest() bool
- type ExternalSchedulerResponse
- type FlavorType
- type HypervisorFamily
- type HypervisorType
- type ImageHypervisorType
- type InstanceGroupSpec
- type NovaFlavor
- type NovaImageMeta
- type NovaImageMetaHVType
- type NovaInstanceGroup
- type NovaNumaTopology
- type NovaObject
- type NovaObjectList
- type NovaRequestContext
- type NovaRequestLevelParams
- type NovaRequestedDestination
- type NovaSpec
- type RequestedDestination
Constants ¶
const ( // LiveMigrationIntent indicates that the request is intended for live migration. LiveMigrationIntent v1alpha1.SchedulingIntent = "live_migration" // RebuildIntent indicates that the request is intended for rebuilding a VM. RebuildIntent v1alpha1.SchedulingIntent = "rebuild" // ResizeIntent indicates that the request is intended for resizing a VM. ResizeIntent v1alpha1.SchedulingIntent = "resize" // EvacuateIntent indicates that the request is intended for evacuating a VM. EvacuateIntent v1alpha1.SchedulingIntent = "evacuate" // CreateIntent indicates that the request is intended for creating a new VM. CreateIntent v1alpha1.SchedulingIntent = "create" // ReserveForFailoverIntent indicates that the request is for creating a new failover reservation slot. ReserveForFailoverIntent v1alpha1.SchedulingIntent = "reserve_for_failover" // ReuseFailoverReservationIntent indicates that the request is checking whether an existing // failover reservation slot can be reused by a VM (compatibility check, not a new slot). ReuseFailoverReservationIntent v1alpha1.SchedulingIntent = "reuse_failover_reservation" // ReserveForCommittedResourceIntent indicates that the request is for CR reservation scheduling. ReserveForCommittedResourceIntent v1alpha1.SchedulingIntent = "reserve_for_committed_resource" // CapacityProbeIntent indicates that the request is a synthetic capacity probe (not a real VM placement). CapacityProbeIntent v1alpha1.SchedulingIntent = "capacity_probe" // HintKeyResourceGroup is the scheduler hint key used to pass the resource group // (e.g., flavor group name) for failover reservation scheduling. // The weigher uses this to compare against existing reservations' ResourceGroup. HintKeyResourceGroup = "_cortex_resource_group" )
Variables ¶
var NovaIntents = []v1alpha1.SchedulingIntent{ LiveMigrationIntent, RebuildIntent, ResizeIntent, EvacuateIntent, CreateIntent, }
NovaIntents lists all scheduling intents relevant to Nova.
Functions ¶
func CanonicalHypervisorType ¶
CanonicalHypervisorType normalizes a flavor's capabilities:hypervisor_type value to the casing hypervisors advertise (QEMU/CH), since filter_capabilities compares values case-sensitively. Unrecognized values pass through unchanged.
func CapacityFromVCPUsMemoryMB ¶
func CapacityFromVCPUsMemoryMB(vcpus, memoryMB uint64) map[hv1.ResourceName]resource.Quantity
CapacityFromVCPUsMemoryMB builds the per-instance capacity map the scheduling pipeline consumes (PlacementRequest.InstanceCapacity) from a flavor's vCPU count and memory in MiB. Memory is stored in bytes (BinarySI) to match what hypervisors advertise and what reservation slots use; cpu is a plain count (DecimalSI). Every caller that resolves a Nova/OpenStack flavor into a placement request funnels through here so the MiB->bytes conversion lives in one place.
func RequestsAccelerators ¶
RequestsAccelerators reports whether a flavor requests a hardware accelerator, resolved from the presence of the "accel:device_profile" extra spec.
func SplitTraits ¶
SplitTraits splits a flavor's "trait:<name>" extra specs into required and forbidden trait names, classified by the "required"/"forbidden" value.
Types ¶
type Capability ¶
type Capability struct {
// Name is the capability key without the "capabilities:" prefix.
Name string
// Value is the required exact value.
Value string
}
Capability is a single required hypervisor capability as a typed key/value equality, e.g. {Name: "cpu_arch", Value: "x86_64"}. The adapter resolves these from Nova's "capabilities:<key>" flavor extra specs and rejects any entry that uses an unsupported comparison operator before it reaches the pipeline.
func HypervisorTypeCapability ¶
func HypervisorTypeCapability(extraSpecs map[string]string, defaultQEMU bool) []Capability
HypervisorTypeCapability returns the required (key=value) hypervisor capabilities for a reservation scheduler request, so filter_capabilities keeps a workload off incompatible hosts. The reservation controllers build the typed placement request directly (not via the Nova wire adapter), yet their flavors still carry Nova's extra-spec string conventions, so they reuse SplitCapabilities here and layer the reservation-specific defaultQEMU seeding on top. It extracts ALL of the flavor's "capabilities:<key>" extra specs (canonicalizing the hypervisor_type casing and dropping everything on an unsupported operator) — not just hypervisor_type.
When the flavor names no hypervisor type and defaultQEMU is set (the failover controller seeds from running VMs whose flavor may omit it), the canonical "QEMU" hypervisor_type is added. Without defaultQEMU, a missing hypervisor type adds no hypervisor_type constraint.
func SplitCapabilities ¶
func SplitCapabilities(extraSpecs map[string]string) []Capability
SplitCapabilities extracts a flavor's "capabilities:<key>" extra specs as typed Capability equalities (prefix stripped). The "hypervisor_type" value is canonicalized (qemu->QEMU, ch->CH) so it matches what hypervisors advertise (filter_capabilities compares case-sensitively); all other values pass through unchanged. If any value uses an unsupported comparison operator it returns nil so the capabilities filter is skipped entirely (matching Nova behavior).
type ExternalSchedulerHost ¶
type ExternalSchedulerHost struct {
// Name of the Nova compute host, e.g. nova-compute-bb123.
ComputeHost string `json:"host"`
// Name of the hypervisor hostname, e.g. domain-c123.<uuid>
HypervisorHostname string `json:"hypervisor_hostname"`
}
Host object from the Nova scheduler pipeline. See: https://github.com/sapcc/nova/blob/stable/xena-m3/nova/scheduler/host_manager.py class HostState
type ExternalSchedulerRequest ¶
type ExternalSchedulerRequest struct {
Spec NovaObject[NovaSpec] `json:"spec"`
// Request context from Nova that contains additional meta information.
Context NovaRequestContext `json:"context"`
Hosts []ExternalSchedulerHost `json:"hosts"`
Weights map[string]float64 `json:"weights"`
// The name of the pipeline to execute.
Pipeline string `json:"pipeline"`
// Options configure the pipeline behavior for this scheduling call.
// Set by the caller (CR controller, failover controller, Nova).
// Nova does not set these; Cortex fills in config-derived defaults server-side.
Options scheduling.Options `json:"options,omitempty"`
}
Request generated by the Nova scheduler when calling cortex. The request contains a spec of the VM to be scheduled, a list of hosts and their status, and a map of weights that were calculated by the Nova weigher pipeline. Some additional flags are also included.
func (ExternalSchedulerRequest) Filter ¶
func (r ExternalSchedulerRequest) Filter(includedHosts map[string]float64) lib.FilterWeigherPipelineRequest
func (ExternalSchedulerRequest) ForcedHosts ¶
func (r ExternalSchedulerRequest) ForcedHosts() []string
ForcedHosts returns the subset of request hosts that match the forced destinations (force_hosts / force_nodes). Matching mirrors Nova:
- force_hosts matches on the compute host name, case-insensitive.
- force_nodes matches on the hypervisor hostname, case-sensitive.
- When both are set, a host must match both (intersection).
The returned slice preserves the order of the request hosts. If nothing matches, an empty slice is returned (Nova would then raise NoValidHost).
func (ExternalSchedulerRequest) GetFlavorType ¶
func (r ExternalSchedulerRequest) GetFlavorType() (FlavorType, error)
GetFlavorType determines the flavor type based on the requested flavor's extra specs.
func (ExternalSchedulerRequest) GetHosts ¶
func (r ExternalSchedulerRequest) GetHosts() []string
func (ExternalSchedulerRequest) GetHypervisorType ¶
func (req ExternalSchedulerRequest) GetHypervisorType() (HypervisorType, error)
GetHypervisorType determines the hypervisor type based on the requested flavor.
func (ExternalSchedulerRequest) GetIntent ¶
func (req ExternalSchedulerRequest) GetIntent() (v1alpha1.SchedulingIntent, error)
GetIntent analyzes the request spec and determines the intent of the scheduling request.
func (ExternalSchedulerRequest) GetOptions ¶
func (r ExternalSchedulerRequest) GetOptions() scheduling.Options
func (ExternalSchedulerRequest) GetTraceLogArgs ¶
func (r ExternalSchedulerRequest) GetTraceLogArgs() []any
func (ExternalSchedulerRequest) GetWeights ¶
func (r ExternalSchedulerRequest) GetWeights() map[string]float64
func (ExternalSchedulerRequest) IsForcedDestination ¶
func (r ExternalSchedulerRequest) IsForcedDestination() bool
IsForcedDestination reports whether Nova forced this request onto specific hosts/nodes and the scheduler filters should be skipped entirely.
This replicates Nova's native behavior: when force_hosts or force_nodes is set and the scheduler hint "_nova_check_type" is not set, Nova skips the filters and returns only the forced destinations. See: https://github.com/sapcc/nova/blob/05f384a938e3d6a8740a8f404d79d767d6ebdbd7/nova/scheduler/host_manager.py#L610-L620
func (ExternalSchedulerRequest) IsKVMRequest ¶
func (req ExternalSchedulerRequest) IsKVMRequest() bool
IsKVMRequest determines whether the request is intended for a KVM-based hypervisor. If no hypervisor type is specified or an error occurs, it returns false.
type ExternalSchedulerResponse ¶
type ExternalSchedulerResponse struct {
Hosts []string `json:"hosts"`
}
Response generated by cortex for the Nova scheduler. Cortex returns an ordered list of hosts that the VM should be scheduled on.
type FlavorType ¶
type FlavorType string
const ( // FlavorTypeGeneralPurpose represents general purpose workloads. FlavorTypeGeneralPurpose FlavorType = "general-purpose" // FlavorTypeHANA represents HANA workloads. FlavorTypeHANA FlavorType = "hana" )
func FlavorTypeFromExtraSpecs ¶
func FlavorTypeFromExtraSpecs(extraSpecs map[string]string) (FlavorType, error)
FlavorTypeFromExtraSpecs determines the flavor type from a flavor's extra specs.
The trait:CUSTOM_HANA_EXCLUSIVE_HOST extra spec is the canonical signal that a flavor targets HANA workloads: when set to "required" the VM must land on a HANA-exclusive host, so the flavor is a HANA flavor; when set to "forbidden" (or absent) it is a general-purpose flavor. The value is compared case-insensitively. Any other explicit value is rejected as an error, since it indicates a malformed flavor rather than a type we can safely default.
Callers that only hold the raw extra specs map (e.g. failover reservation scheduling) should use this helper instead of re-implementing the trait check, so the HANA-detection logic stays in one place.
type HypervisorFamily ¶
type HypervisorFamily string
HypervisorFamily is the coarse hypervisor family a request targets. It is the distinction the pipeline and request routing care about. The adapter resolves the family from Nova's "capabilities:hypervisor_type" flavor extra spec.
const ( // HypervisorFamilyKVM covers KVM-based hypervisors (QEMU and CH). HypervisorFamilyKVM HypervisorFamily = "kvm" // HypervisorFamilyVMware covers VMware hypervisors. HypervisorFamilyVMware HypervisorFamily = "vmware" )
type HypervisorType ¶
type HypervisorType string
const ( // HypervisorTypeQEMU represents QEMU/KVM hypervisors. HypervisorTypeQEMU HypervisorType = "qemu" // HypervisorTypeCH represents Cloud-Hypervisor/KVM hypervisors. HypervisorTypeCH HypervisorType = "ch" // HypervisorTypeVMware represents VMware hypervisors. HypervisorTypeVMware HypervisorType = "vmware" )
type ImageHypervisorType ¶
type ImageHypervisorType string
ImageHypervisorType is the hypervisor type declared by the image. The adapter resolves it from Nova's image properties ("img_hv_type"/"hypervisor_type").
const ( // ImageHypervisorTypeVMware indicates a VMware image. ImageHypervisorTypeVMware ImageHypervisorType = "vmware" // ImageHypervisorTypeBaremetal indicates a baremetal image. ImageHypervisorTypeBaremetal ImageHypervisorType = "baremetal" // ImageHypervisorTypeKVM indicates a KVM image. ImageHypervisorTypeKVM ImageHypervisorType = "kvm" // ImageHypervisorTypeUnset indicates no image hypervisor type was declared. ImageHypervisorTypeUnset ImageHypervisorType = "" // ImageHypervisorTypeUnparseable indicates an image hypervisor type was declared but could not be parsed. ImageHypervisorTypeUnparseable ImageHypervisorType = "unparseable" )
type InstanceGroupSpec ¶
type InstanceGroupSpec struct {
// UUID identifies the server group. Empty if unknown.
UUID string
// Policy is the group policy (e.g. "anti-affinity", "soft-affinity"). Empty
// means no policy-specific filter/weigher applies.
Policy string
// Hosts are the hosts already occupied by members of this group. Empty/nil
// means the group currently occupies no hosts.
Hosts []string
// Members are the instance UUIDs already in the group. Empty/nil means the
// group has no members yet, so anti-affinity has nothing to exclude.
Members []string
// MaxServerPerHost caps how many group members may share a host. 0 means
// unset, which the anti-affinity filter treats as the Nova default of 1.
MaxServerPerHost int
}
InstanceGroupSpec is the typed subset of a Nova server group the pipeline reads. A nil *InstanceGroupSpec on the request means the instance is not part of a server group, so group affinity/anti-affinity filters are skipped.
type NovaFlavor ¶
type NovaFlavor struct {
ID int `json:"id"`
Name string `json:"name"`
MemoryMB uint64 `json:"memory_mb"`
VCPUs uint64 `json:"vcpus"`
RootGB uint64 `json:"root_gb"`
EphemeralGB uint64 `json:"ephemeral_gb"`
FlavorID string `json:"flavorid"`
Swap int `json:"swap"`
RXTXFactor float64 `json:"rxtx_factor"`
VCPUWeight int `json:"vcpu_weight"`
Disabled bool `json:"disabled"`
IsPublic bool `json:"is_public"`
ExtraSpecs map[string]string `json:"extra_specs"`
Description *string `json:"description"`
CreatedAt string `json:"created_at"`
UpdatedAt *string `json:"updated_at"`
DeletedAt *string `json:"deleted_at"`
Deleted bool `json:"deleted"`
}
Nova flavor metadata for the specified VM.
type NovaImageMeta ¶
type NovaImageMeta struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Checksum string `json:"checksum"`
Owner string `json:"owner"`
Size int `json:"size"`
ContainerFormat string `json:"container_format"`
DiskFormat string `json:"disk_format"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
MinRAM int `json:"min_ram"`
MinDisk int `json:"min_disk"`
Properties NovaObject[map[string]any] `json:"properties"`
}
Nova image metadata for the specified VM.
func (NovaImageMeta) GetHypervisorType ¶
func (m NovaImageMeta) GetHypervisorType() (NovaImageMetaHVType, error)
GetHypervisorType determines the hypervisor type based on the image properties.
type NovaImageMetaHVType ¶
type NovaImageMetaHVType string
const ( NovaImageMetaHVTypeVMware NovaImageMetaHVType = "vmware" NovaImageMetaHVTypeBaremetal NovaImageMetaHVType = "baremetal" NovaImageMetaHVTypeKVM NovaImageMetaHVType = "kvm" )
type NovaInstanceGroup ¶
type NovaInstanceGroup struct {
UserID string `json:"user_id"`
ProjectID string `json:"project_id"`
UUID string `json:"uuid"`
Name string `json:"name"`
Policies []string `json:"policies"`
Members []string `json:"members"`
Hosts []string `json:"hosts"`
Policy string `json:"policy"`
Rules map[string]any `json:"_rules"`
CreatedAt string `json:"created_at"`
UpdatedAt *string `json:"updated_at"`
DeletedAt *string `json:"deleted_at"`
Deleted bool `json:"deleted"`
}
type NovaNumaTopology ¶
type NovaNumaTopology struct {
Cells []NovaObject[map[string]any] `json:"cells"`
}
Nova NUMA topology for the specified VM.
type NovaObject ¶
type NovaObject[V any] struct { Name string `json:"nova_object.name"` Namespace string `json:"nova_object.namespace"` Version string `json:"nova_object.version"` Data V `json:"nova_object.data"` Changes []string `json:"nova_object.changes"` }
Wrapped Nova object. Nova returns objects in this format.
type NovaObjectList ¶
type NovaObjectList[V any] struct { Objects []NovaObject[V] `json:"objects"` }
type NovaRequestContext ¶
type NovaRequestContext struct {
UserID string `json:"user"`
ProjectID string `json:"project_id"`
SystemScope *string `json:"system_scope"`
Project string `json:"project"`
DomainID *string `json:"domain"`
UserDomainID string `json:"user_domain"`
ProjectDomainID string `json:"project_domain"`
IsAdmin bool `json:"is_admin"`
ReadOnly bool `json:"read_only"`
ShowDeleted bool `json:"show_deleted"`
RequestID string `json:"request_id"`
GlobalRequestID *string `json:"global_request_id"`
ResourceUUID *string `json:"resource_uuid"`
Roles []string `json:"roles"`
UserIdentity string `json:"user_identity"`
IsAdminProject bool `json:"is_admin_project"`
ReadDeleted string `json:"read_deleted"`
RemoteAddress string `json:"remote_address"`
Timestamp string `json:"timestamp"`
QuotaClass *string `json:"quota_class"`
UserName string `json:"user_name"`
ProjectName string `json:"project_name"`
}
Nova request context object. For the spec of this object, see:
- This: https://github.com/sapcc/nova/blob/a56409/nova/context.py#L166 - And: https://github.com/openstack/oslo.context/blob/db20dd/oslo_context/context.py#L329
Some fields are omitted: "service_catalog", "read_deleted" (same as "show_deleted")
type NovaRequestLevelParams ¶
type NovaSpec ¶
type NovaSpec struct {
ProjectID string `json:"project_id"`
UserID string `json:"user_id"`
InstanceUUID string `json:"instance_uuid"`
AvailabilityZone string `json:"availability_zone"`
NumInstances uint64 `json:"num_instances"`
IsBfv bool `json:"is_bfv"`
// Consider using GetSchedulerHintStr.
SchedulerHints map[string]any `json:"scheduler_hints"`
IgnoreHosts *[]string `json:"ignore_hosts"`
ForceHosts *[]string `json:"force_hosts"`
ForceNodes *[]string `json:"force_nodes"`
Image NovaObject[NovaImageMeta] `json:"image"`
Flavor NovaObject[NovaFlavor] `json:"flavor"`
RequestLevelParams NovaObject[NovaRequestLevelParams] `json:"request_level_params"`
NetworkMetadata NovaObject[map[string]any] `json:"network_metadata"`
Limits NovaObject[map[string]any] `json:"limits"`
RequestedNetworks NovaObjectList[map[string]any] `json:"requested_networks"`
SecurityGroups NovaObjectList[map[string]any] `json:"security_groups"`
NumaTopology *NovaObject[NovaNumaTopology] `json:"numa_topology"`
RequestedDestination *NovaObject[NovaRequestedDestination] `json:"requested_destination"`
InstanceGroup *NovaObject[NovaInstanceGroup] `json:"instance_group"`
}
Spec object from the Nova scheduler pipeline. Fields unused by Nova are omitted. See: https://github.com/sapcc/nova/blob/stable/xena-m3/nova/objects/request_spec.py
func (NovaSpec) GetSchedulerHintStr ¶
Hints can be a one-element list or a direct value. See: https://github.com/sapcc/nova/blob/3e715db/nova/objects/request_spec.py#L382
This function is a convenience to extract the first element from the hints list or return the value directly if it's not a list.
type RequestedDestination ¶
type RequestedDestination struct {
// Host is the requested target host. Empty means no host was pinned (only an
// aggregate constraint applies).
Host string
// Aggregates are the host-aggregate names the destination must belong to.
// Empty/nil means no aggregate constraint.
Aggregates []string
}
RequestedDestination mirrors the subset of Nova's requested_destination that the pipeline reads. A nil *RequestedDestination on the request means no destination constraint was requested.