common

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RECENT_STATUS_DETAIL_COUNT defines how many recent status detail records to retrieve when retrieving them as part of other records (e.g. allocation, instance, etc.)
	RECENT_STATUS_DETAIL_COUNT = 20
	DefaultIpxeScript          = "#ipxe\ndefault"

	// Likely to be moved into cloud-db later, similar
	// to machine status.
	MachineHealthStatusHealthy   = "healthy"
	MachineHealthStatusUnhealthy = "unhealthy"
)

Variables

View Source
var (
	// ErrOrgInstrastructureProviderNotFound is returned when the org does not have an infrastructure provider
	ErrOrgInstrastructureProviderNotFound = errors.New("Org does not have an Infrastructure Provider")
	// ErrOrgTenantNotFound is returned when the org does not have a tenant
	ErrOrgTenantNotFound = errors.New("Org does not have a Tenant")
	// ErrAllocationConstraintNotFound
	ErrAllocationConstraintNotFound = errors.New("Allocation does not have an associated Constraint")
	// ErrInstanceTypeMachineNotFound
	ErrInstanceTypeMachineNotFound = errors.New("Instance Type does not have a Machine available for allocation")
	// ErrInvalidFunctionParams
	ErrInvalidFunctionParams = errors.New("invalid function parameters")

	// ErrMsgProviderOrTenantIDQueryRequired is returned when the provider or tenant id query param is not specified
	ErrMsgProviderOrTenantIDQueryRequired = "Either infrastructureProviderId or tenantId query param must be specified"

	// ErrInvalidID
	ErrInvalidID = errors.New("invalid id")

	// RequestAsProvider indicates that the request is being made as a provider
	RequestAsInfrastructureProvider = "InfrastructureProvider"
	// RequestAsTenant indicates that the request is being made as a tenant
	RequestAsTenant = "Tenant"
)

Functions

func AddToValidationErrors

func AddToValidationErrors(errs validation.Errors, key string, err error)

AddToValidationError adds a new error entry or augments an existing one into a validation.Errors{} map

func CheckMachinesForInstanceTypeAllocation

func CheckMachinesForInstanceTypeAllocation(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, logger zerolog.Logger, instanceTypeID uuid.UUID, value int) (bool, error)

CheckMachinesForInstanceTypeAllocation checks the available machines against existing reserved allocations, and the new constraint value - returns true if the constraint value is feasible, false otherwise

func ExecuteBringUpRackWorkflow

func ExecuteBringUpRackWorkflow(
	ctx context.Context,
	c echo.Context,
	logger zerolog.Logger,
	stc tclient.Client,
	targetSpec *rlav1.OperationTargetSpec,
	description string,
	workflowID string,
	entityName string,
) (*rlav1.SubmitTaskResponse, error)

ExecuteBringUpRackWorkflow builds a BringUpRackRequest, executes the BringUpRack workflow via Temporal, and returns the raw SubmitTaskResponse.

func ExecuteFirmwareUpdateWorkflow

func ExecuteFirmwareUpdateWorkflow(
	ctx context.Context,
	c echo.Context,
	logger zerolog.Logger,
	stc tclient.Client,
	targetSpec *rlav1.OperationTargetSpec,
	version *string,
	workflowID string,
	entityName string,
) (*rlav1.SubmitTaskResponse, error)

ExecuteFirmwareUpdateWorkflow builds an UpgradeFirmwareRequest, executes the UpgradeFirmware workflow via Temporal, and returns the raw SubmitTaskResponse.

func ExecutePowerControlWorkflow

func ExecutePowerControlWorkflow(
	ctx context.Context,
	c echo.Context,
	logger zerolog.Logger,
	stc tclient.Client,
	targetSpec *rlav1.OperationTargetSpec,
	state string,
	workflowID string,
	entityName string,
) (*rlav1.SubmitTaskResponse, error)

ExecutePowerControlWorkflow determines the appropriate power control workflow based on state, executes it via Temporal, and returns the raw SubmitTaskResponse.

func ExecuteSyncWorkflow

func ExecuteSyncWorkflow(ctx context.Context, logger zerolog.Logger, tpClient tclient.Client, name string, options tclient.StartWorkflowOptions, request interface{}) *cutil.APIError

ExecuteSyncWorkflow is a utility function to execute a Temporal workflow synchronously from a Handler. This function can be used across handlers to reduce duplication of workflow execution logic.

func GenerateAccountNumber

func GenerateAccountNumber() string

GenerateAccountNumber will generate a unique account number this will be deprecated - for now, use a uuid

func GetAllAllocationConstraintsForInstanceType

func GetAllAllocationConstraintsForInstanceType(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, ip *cdbm.InfrastructureProvider, site *cdbm.Site, tenant *cdbm.Tenant, resourceTypeID *uuid.UUID) ([]cdbm.AllocationConstraint, int, error)

GetAllAllocationConstraintsForInstanceType is a utility function to return allocation constraints of type instance type for the tenant at the site a specific instance type ID could be specified as a filter, otherwise, the count is across all instancetypes. NOTE: This could be optimized with better db query..

func GetAllInstanceTypeAllocationStats

func GetAllInstanceTypeAllocationStats(ctx context.Context, dbSession *cdb.Session, siteID *uuid.UUID, instanceTypeIDs []uuid.UUID, logger zerolog.Logger, tenantID *uuid.UUID) (map[uuid.UUID]*cam.APIAllocationStats, *cutil.APIError)

GetAllInstanceTypeAllocationStats is a utility function to get all instance type allocation stats

func GetAllocationConstraintsForInstanceType

func GetAllocationConstraintsForInstanceType(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, tenantID uuid.UUID, instancetype *cdbm.InstanceType, allocations []cdbm.Allocation) ([]cdbm.AllocationConstraint, error)

GetAllocationConstraintsForInstanceType gets allocation constraints for instance type allocation

func GetAllocationIDsForTenantAtSite

func GetAllocationIDsForTenantAtSite(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, ipID uuid.UUID, tenantID uuid.UUID, siteID uuid.UUID) ([]uuid.UUID, error)

GetAllocationIDsForTenantAtSite will return all allocation IDs for the tenant at a site

func GetAllocationResourceTypeMaps

func GetAllocationResourceTypeMaps(ctx context.Context, logger zerolog.Logger, dbSession *cdb.Session, acs []cdbm.AllocationConstraint) (
	map[uuid.UUID]*cdbm.InstanceType, map[uuid.UUID]*cdbm.IPBlock, *cutil.APIError)

GetAllocationResourceTypeMaps is a utility function to get resource info based on resource type in allocation constraints currently its only supports Instance Type and IPBlock

func GetAndValidateQueryRelations

func GetAndValidateQueryRelations(qParams url.Values, relatedEntities map[string]bool) ([]string, string)

GetAndValidateQueryRelations is a utility function to get and validate the query parameters for include relations get/getall request

func GetCountOfMachinesForInstanceType

func GetCountOfMachinesForInstanceType(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, instanceTypeID uuid.UUID) (int, error)

GetCountOfMachinesForInstanceType is a utility function to return count of machines for instance type

func GetDomainFromIDString

func GetDomainFromIDString(ctx context.Context, tx *cdb.Tx, domainID string, dbSession *cdb.Session) (*cdbm.Domain, error)

GetDomainFromIDString gets the domain DB model from the id string

func GetIPBlockFromIDString

func GetIPBlockFromIDString(ctx context.Context, tx *cdb.Tx, idStr string, dbSession *cdb.Session) (*cdbm.IPBlock, error)

GetIPBlockFromIDString gets the ip block from the ip block id string

func GetInfrastructureProviderForOrg

func GetInfrastructureProviderForOrg(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, org string) (*cdbm.InfrastructureProvider, error)

GetInfrastructureProviderForOrg gets the infrastructureProvider for org

func GetInstanceFromIDString

func GetInstanceFromIDString(ctx context.Context, tx *cdb.Tx, instanceID string, dbSession *cdb.Session) (*cdbm.Instance, error)

GetInstanceFromIDString gets the site DB model from the id string

func GetInstanceTypeAllocationStats

func GetInstanceTypeAllocationStats(ctx context.Context, dbSession *cdb.Session, logger zerolog.Logger, it cdbm.InstanceType, tenantID *uuid.UUID) (*cam.APIAllocationStats, *cutil.APIError)

GetInstanceTypeAllocationStats is a utility function to get the allocation stats from allocation constraints and instances based on instancetype

func GetInstanceTypeFromIDString

func GetInstanceTypeFromIDString(ctx context.Context, tx *cdb.Tx, idStr string, dbSession *cdb.Session) (*cdbm.InstanceType, error)

GetInstanceTypeFromIDString gets the instance type from the instance type id string

func GetInstanceTypeIDsFromAllocationConstraints

func GetInstanceTypeIDsFromAllocationConstraints(ctx context.Context, acs []cdbm.AllocationConstraint, constraintType string) []uuid.UUID

GetInstanceTypeIDsFromAllocationConstraints is a utility function to get the instanceTypeIDs from a slice of allocation constraints

func GetIsProviderRequest

func GetIsProviderRequest(ctx context.Context, logger zerolog.Logger, dbSession *cdb.Session, org string, user *cdbm.User, providerRoles []string, tenantRoles []string, queryParams url.Values) (isProviderRequest bool, provider *cdbm.InfrastructureProvider, tenant *cdbm.Tenant, apiError *cutil.APIError)

GetIsProviderRequest is a utility function to check if the request is made from a Provider or Tenant perspective If user only has Provider admin role then we can deduce they are acting as a Provider If user only has Tenant admin role then we can deduce they are acting as a Tenant If user has both Provider and Tenant admin role then we expect the user to specify the query param indicating which role they are acting on This function supports both NGC and Keycloak authentication systems automatically

func GetNVLinkLogicalPartitionCountStats

func GetNVLinkLogicalPartitionCountStats(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, logger zerolog.Logger, nvllpIDs []uuid.UUID) (map[uuid.UUID]*cam.APINVLinkLogicalPartitionStats, error)

GetNVLinkLogicalPartitionCountStats is a utility function to return count of gpus and instances broken down by NVLinkLogicalPartition.

func GetSSHKeyFromIDString

func GetSSHKeyFromIDString(ctx context.Context, tx *cdb.Tx, sshkeyID string, dbSession *cdb.Session) (*cdbm.SSHKey, error)

GetSSHKeyFromIDString gets the sshkey DB model from the id string

func GetSSHKeyGroupFromIDString

func GetSSHKeyGroupFromIDString(ctx context.Context, tx *cdb.Tx, sshkeyGroupID string, dbSession *cdb.Session, includeRelations []string) (*cdbm.SSHKeyGroup, error)

GetSSHKeyGroupFromIDString gets the sshkeygroup DB model from the id string

func GetSiteFromIDString

func GetSiteFromIDString(ctx context.Context, tx *cdb.Tx, siteID string, dbSession *cdb.Session) (*cdbm.Site, error)

GetSiteFromIDString gets the site DB model from the id string

func GetSiteInstanceID

func GetSiteInstanceID(i *cdbm.Instance) *uuid.UUID

func GetSiteMachineCountStats

func GetSiteMachineCountStats(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, logger zerolog.Logger, infrastructureProviderID *uuid.UUID, siteID *uuid.UUID) (map[uuid.UUID]*cam.APISiteMachineStats, error)

GetSiteMachineCountStats is a utility function to return count of machines broken down by site and machine status.

func GetSiteNetworkSegmentID

func GetSiteNetworkSegmentID(s *cdbm.Subnet) *uuid.UUID

func GetSiteOperatingSystemtID

func GetSiteOperatingSystemtID(o *cdbm.OperatingSystem) *uuid.UUID

func GetSiteVpcID

func GetSiteVpcID(v *cdbm.Vpc) *uuid.UUID

func GetTenantForOrg

func GetTenantForOrg(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, org string) (*cdbm.Tenant, error)

GetTenantForOrg gets the tenant for org

func GetTenantFromIDString

func GetTenantFromIDString(ctx context.Context, tx *cdb.Tx, tenantID string, dbSession *cdb.Session) (*cdbm.Tenant, error)

GetTenantFromIDString gets the tenant from the tenant id string

func GetTenantFromTenantIDOrOrg

func GetTenantFromTenantIDOrOrg(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, tenantID, org *string) (*cdbm.Tenant, error)

GetTenantFromTenantIDOrOrg gets the tenant from the tenant id or org

func GetTestConfig

func GetTestConfig() *config.Config

GetTestConfig returns a config for tests - each instance of config consumes file descriptors via viper and there is no easy way to clean the file descriptors during tests. hence using this to create once config instance for tests

func GetTotalAllocationConstraintValueForInstanceType

func GetTotalAllocationConstraintValueForInstanceType(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, allocationIDs []uuid.UUID, instanceTypeID *uuid.UUID, constraintType *string) (int, error)

GetTotalAllocationConstraintValueForInstanceType is a utility function to return total constraint value for all allocation constraints for all specified allocations

func GetUnallocatedMachineForInstanceType

func GetUnallocatedMachineForInstanceType(ctx context.Context, tx *cdb.Tx, dbSession *cdb.Session, instancetype *cdbm.InstanceType) (*cdbm.Machine, error)

GetUnallocatedMachineForInstanceType provides unallocatd machine based on instancetype

func GetUserAndEnrichLogger

func GetUserAndEnrichLogger(c echo.Context, logger zerolog.Logger, tracerSpan *cutil.TracerSpan, handlerSpan trace.Span) (*cdbm.User, zerolog.Logger, error)

GetUserAndEnrichLogger retrieves the user from the echo context and enriches the logger and tracer span with user ID information (StarfleetID or AuxiliaryID). This eliminates the repetitive if-else block for user ID logging across handlers. The tracerSpan and handlerSpan parameters are optional and can be nil if tracing is not needed.

func GetVpcFromIDString

func GetVpcFromIDString(ctx context.Context, tx *cdb.Tx, vpcID string, includeRelations []string, dbSession *cdb.Session) (*cdbm.Vpc, error)

GetVpcFromIDString gets the vpc DB model from the id string

func IsProvider

func IsProvider(ctx context.Context, logger zerolog.Logger, dbSession *cdb.Session, org string, user *cdbm.User, allowViewerRole bool) (*cdbm.InfrastructureProvider, *cutil.APIError)

IsProvider ensures that user is authorized to act as a Provider Admin for the org

func IsProviderOrTenant

func IsProviderOrTenant(ctx context.Context, logger zerolog.Logger, dbSession *cdb.Session, org string, user *cdbm.User, allowViewerRole bool, requirePrivilegedTenant bool) (infrastructureProvider *cdbm.InfrastructureProvider, tenant *cdbm.Tenant, apiError *cutil.APIError)

IsProviderOrTenant ensures that user is authorized to act as a Provider Admin or/and Tenant Admin for the org. if authorized it returns the tenant otherwise a relevant error.

func IsTenant

func IsTenant(ctx context.Context, logger zerolog.Logger, dbSession *cdb.Session, org string, user *cdbm.User, requirePrivileged bool) (*cdbm.Tenant, *cutil.APIError)

IsTenant ensures that user is authorized to act as a Tenant Admin for the org. if authorized it returns the tenant otherwise a relevant error.

func MatchInstanceTypeCapabilitiesForMachines

func MatchInstanceTypeCapabilitiesForMachines(ctx context.Context, logger zerolog.Logger, dbSession *cdb.Session, instanceTypeID uuid.UUID, machineIds []string) (bool, *string, *cutil.APIError)

MatchInstanceTypeCapabilitiesForMachines is a utility function to check if Instance Type Capabilities are present in the Capabilities of Machines

func QueryParamHash

func QueryParamHash(params url.Values) string

QueryParamHash builds a deterministic hash from the given query params for workflow ID dedup. Accepts url.Values so callers can pass only the known/valid parameters, preventing unknown query params from polluting the workflow ID.

func QueryTagsFor

func QueryTagsFor(v any) []string

QueryTagsFor returns the `query` struct tag values for all fields of the given struct. Results are cached per type.

func RequestHash

func RequestHash(v interface{}) string

RequestHash builds a deterministic hash from any struct by JSON-marshaling it. Used for workflow ID deduplication when request data comes from JSON body instead of query params.

func RollbackTx

func RollbackTx(ctx context.Context, tx *cdb.Tx, committed *bool)

RollbackTx is called deferred in functions that create a transaction if transaction was committed, this will do nothing

func SetupHandler

func SetupHandler(modelName, handlerName string, c echo.Context, s *cutil.TracerSpan) (org string, user *cdbm.User, ctx context.Context, logger zerolog.Logger, hs oteltrace.Span)

SetupHandler sets up common tasks for handlers not requiring error handling. WARNING: caller MUST defer handlerSpan.End() if handlerSpan is not nil!!! This function can be used across handlers to reduce duplication of initialization logic.

func TerminateWorkflowOnTimeOut

func TerminateWorkflowOnTimeOut(echoCtx echo.Context, logger zerolog.Logger, temporalClient tclient.Client, workflowID string, originalError error, objectType string, workflowName string) error

func TestBuildAllocation

func TestBuildAllocation(t *testing.T, dbSession *cdb.Session, st *cdbm.Site, tn *cdbm.Tenant, name string, user *cdbm.User) *cdbm.Allocation

TestBuildAllocation creates a test Allocation

func TestBuildAllocationConstraint

func TestBuildAllocationConstraint(t *testing.T, dbSession *cdb.Session, al *cdbm.Allocation, it *cdbm.InstanceType, ipb *cdbm.IPBlock, constraintValue int, user *cdbm.User) *cdbm.AllocationConstraint

TestBuildAllocationConstraint creates a test Allocation Constraint of Instance Type

func TestBuildAuditEntry

func TestBuildAuditEntry(t *testing.T, dbSession *cdb.Session, orgName string, userID *uuid.UUID, statusCode int) *cdbm.AuditEntry

func TestBuildDpuExtensionService

func TestBuildDpuExtensionService(t *testing.T, dbSession *cdb.Session, name string, serviceType string, tenant *cdbm.Tenant, site *cdbm.Site, version string, status string, user *cdbm.User) *cdbm.DpuExtensionService

func TestBuildDpuExtensionServiceDeployment

func TestBuildDpuExtensionServiceDeployment(t *testing.T, dbSession *cdb.Session, dpuExtensionService *cdbm.DpuExtensionService, instanceID uuid.UUID, version string, status string, user *cdbm.User) *cdbm.DpuExtensionServiceDeployment

func TestBuildDpuExtensionServiceUpdateActiveVersions

func TestBuildDpuExtensionServiceUpdateActiveVersions(t *testing.T, dbSession *cdb.Session, dpuExtensionService *cdbm.DpuExtensionService, versions []string) *cdbm.DpuExtensionService

func TestBuildIPBlock

func TestBuildIPBlock(t *testing.T, dbSession *cdb.Session, name string, site *cdbm.Site, tenantID *uuid.UUID, routingType, prefix string, blockSize int, protocolVersion string, user *cdbm.User) *cdbm.IPBlock

TestBuildIPBlock creates a test IP Block

func TestBuildInfrastructureProvider

func TestBuildInfrastructureProvider(t *testing.T, dbSession *cdb.Session, name string, org string, user *cdbm.User) *cdbm.InfrastructureProvider

TestBuildInfrastructureProvider creates a test Infrastructure Provider

func TestBuildInstance

func TestBuildInstance(t *testing.T, dbSession *cdb.Session, name string, alID uuid.UUID, acID uuid.UUID, tnID uuid.UUID, ipID uuid.UUID, stID uuid.UUID, itID uuid.UUID, vpcID uuid.UUID, mID *string, osID uuid.UUID) *cdbm.Instance

TestBuildInstance creates a test instance

func TestBuildInstanceType

func TestBuildInstanceType(t *testing.T, dbSession *cdb.Session, name string, infinityResourceTypeID *uuid.UUID, st *cdbm.Site, labels map[string]string, user *cdbm.User) *cdbm.InstanceType

TestBuildInstanceType creates a test Instance Type

func TestBuildInterface added in v1.2.0

func TestBuildInterface(t *testing.T, dbSession *cdb.Session, instanceID uuid.UUID, subnetID *uuid.UUID, vpcPrefixID *uuid.UUID, isPhysical bool, device *string, deviceInstance *int, vfID *int, status *string, user *cdbm.User) *cdbm.Interface

func TestBuildMachine

func TestBuildMachine(t *testing.T, dbSession *cdb.Session, ip *cdbm.InfrastructureProvider, site *cdbm.Site, itID *uuid.UUID, controllerMachineType *string, status string) *cdbm.Machine

TestBuildMachine creates a test Machine

func TestBuildMachineCapability

func TestBuildMachineCapability(t *testing.T, dbSession *cdb.Session, mID *string, itID *uuid.UUID, capabilityType string, name string, frequency *string, capacity *string, vendor *string, count *int, deviceType *string, inactiveDevices []int) *cdbm.MachineCapability

TestBuildMachineCapability creates a test Machine Capability

func TestBuildMachineInstanceType

func TestBuildMachineInstanceType(t *testing.T, dbSession *cdb.Session, m *cdbm.Machine, it *cdbm.InstanceType) *cdbm.MachineInstanceType

TestBuildMachineInstanceType creates a test Machine Instance Type

func TestBuildNetworkSecurityGroup

func TestBuildNetworkSecurityGroup(t *testing.T, dbSession *cdb.Session, name string, siteID, tenantID uuid.UUID, status string) *cdbm.NetworkSecurityGroup

TestBuildNetworkSecurityGroup creates a test security group

func TestBuildOperatingSystem

func TestBuildOperatingSystem(t *testing.T, dbSession *cdb.Session, name string, tn *cdbm.Tenant, status string, user *cdbm.User) *cdbm.OperatingSystem

TestBuildOperatingSystem creates a test os

func TestBuildOperatingSystemSiteAssociation

func TestBuildOperatingSystemSiteAssociation(t *testing.T, dbSession *cdb.Session, osID uuid.UUID, siteID uuid.UUID, version *string, status string, user *cdbm.User) *cdbm.OperatingSystemSiteAssociation

func TestBuildSite

func TestBuildSite(t *testing.T, dbSession *cdb.Session, ip *cdbm.InfrastructureProvider, name string, user *cdbm.User) *cdbm.Site

TestBuildSite creates a test Site

func TestBuildStatusDetail

func TestBuildStatusDetail(t *testing.T, dbSession *cdb.Session, entityID string, status string, message *string)

TestBuildStatusDetail creates a test status detail

func TestBuildSubnet

func TestBuildSubnet(t *testing.T, dbSession *cdb.Session, name string, tn *cdbm.Tenant, vpc *cdbm.Vpc, cnsID *uuid.UUID, status string, user *cdbm.User) *cdbm.Subnet

TestBuildSubnet creates a test subnet

func TestBuildTenant

func TestBuildTenant(t *testing.T, dbSession *cdb.Session, name string, org string, user *cdbm.User) *cdbm.Tenant

TestBuildTenant creates a test Tenant

func TestBuildTenantAccount

func TestBuildTenantAccount(t *testing.T, dbSession *cdb.Session, ip *cdbm.InfrastructureProvider, tenantID *uuid.UUID, tenantOrg string, status string, user *cdbm.User) *cdbm.TenantAccount

func TestBuildTenantSite

func TestBuildTenantSite(t *testing.T, dbSession *cdb.Session, tn *cdbm.Tenant, st *cdbm.Site, user *cdbm.User) *cdbm.TenantSite

TestBuildTenantSite creates a test Tenant/Site association

func TestBuildTenantWithDisplayName

func TestBuildTenantWithDisplayName(t *testing.T, dbSession *cdb.Session, name string, org string, user *cdbm.User, displayName string) *cdbm.Tenant

func TestBuildUser

func TestBuildUser(t *testing.T, dbSession *cdb.Session, starfleetID string, org string, roles []string) *cdbm.User

TestBuildUser creates a test User

func TestBuildVPC

func TestBuildVPC(t *testing.T, dbSession *cdb.Session, name string, ip *cdbm.InfrastructureProvider, tn *cdbm.Tenant, st *cdbm.Site, cnvID *uuid.UUID, labels map[string]string, status string, user *cdbm.User) *cdbm.Vpc

TestBuildVPC creates a test VPC

func TestBuildVPCPrefix

func TestBuildVPCPrefix(t *testing.T, dbSession *cdb.Session, name string, st *cdbm.Site, tenant *cdbm.Tenant, vpcID uuid.UUID, ipv4BlockID *uuid.UUID, prefix *string, prefixLength *int, status string, user *cdbm.User) *cdbm.VpcPrefix

func TestBuildVpcPeering added in v1.2.0

func TestBuildVpcPeering(t *testing.T, dbSession *cdb.Session, vpc1ID, vpc2ID uuid.UUID, siteID uuid.UUID, infrastructureProviderID *uuid.UUID, tenantID *uuid.UUID, isMultiTenant bool, createdByID uuid.UUID) *cdbm.VpcPeering

TestBuildVpcPeering creates a test VPC peering between two VPCs

func TestBuildVpcPrefixIPBlock

func TestBuildVpcPrefixIPBlock(t *testing.T, dbSession *cdb.Session, name string, site *cdbm.Site, ip *cdbm.InfrastructureProvider, tenantID *uuid.UUID, routingType, prefix string, blockSize int, protocolVersion string, fullGrant bool, status string, user *cdbm.User) *cdbm.IPBlock

func TestCommonBuildMachineCapability

func TestCommonBuildMachineCapability(t *testing.T, dbSession *cdb.Session, machineID *string, instanceTypeID *uuid.UUID, cptype string, name string, freq *string, cap *string, vendor *string, count *int, deviceType *string, info map[string]interface{}) *cdbm.MachineCapability

TestCommonBuildMachineCapability creates a machine capability

func TestCommonTraceProviderSetup

func TestCommonTraceProviderSetup(t *testing.T, ctx context.Context) (trace.Tracer, trace.SpanContext, context.Context)

TestCommonTraceProviderSetup creates a test provider and spanner

func TestInitDB

func TestInitDB(t *testing.T) *cdb.Session

TestInitDB initializes the database

func TestSetupSchema

func TestSetupSchema(t *testing.T, dbSession *cdb.Session)

TestSetupSchema creates/resets the schema

func UnwrapWorkflowError

func UnwrapWorkflowError(err error) (code int, unwrappedError error)

func ValidateKnownQueryParams

func ValidateKnownQueryParams(rawParams url.Values, structs ...any) error

ValidateKnownQueryParams checks that every key in rawParams appears as a `query` struct tag in at least one of the provided structs. Returns an error for the first unknown parameter found.

Types

type QueryOverride

type QueryOverride struct {
	InstanceIDs   []string
	ValueFromPath bool
}

QueryOverride provides values that override query params when delegating from path-scoped endpoints (e.g. instance/{instanceId}/interface, instance/{instanceId}/nvlink-interface) to more general endpoints. When set, error messages in general endpoints will be modulated

type UniqueChecker

type UniqueChecker[T comparable] struct {
	// contains filtered or unexported fields
}

UniqueChecker is a generic struct for tracking uniqueness of values and detecting duplicates. It's designed to validate uniqueness constraints in batch operations (create/update handlers). T is the type of the reference unique ID being checked (usually UUID).

func NewUniqueChecker

func NewUniqueChecker[T comparable]() *UniqueChecker[T]

NewUniqueChecker creates and initializes a new UniqueChecker

func (*UniqueChecker[T]) DoesIDHaveConflict

func (uc *UniqueChecker[T]) DoesIDHaveConflict(id T) bool

func (*UniqueChecker[T]) GetDuplicates

func (uc *UniqueChecker[T]) GetDuplicates() []string

GetDuplicates returns an array of duplicates values. Note: values are in lowercase.

func (*UniqueChecker[T]) HasDuplicates

func (uc *UniqueChecker[T]) HasDuplicates() bool

HasDuplicates returns true if any duplicates have been detected

func (*UniqueChecker[T]) Update

func (uc *UniqueChecker[T]) Update(id T, uniqueValue string)

Update updates or adds a unique value associated with a principal ID, allowing overwrites.

Jump to

Keyboard shortcuts

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