pmcregistry

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DSType PmcRegisterType
	DSConf cdb.Config
}

Config holds the selected backend type and DB configuration.

type MemRegistry

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

MemRegistry is an in-memory implementation of PmcRegistry, safe for concurrent access.

func NewMemRegistry

func NewMemRegistry() *MemRegistry

NewMemRegistry creates a new in-memory PMC registry.

func (*MemRegistry) GetAllPmcs

func (ms *MemRegistry) GetAllPmcs(ctx context.Context) ([]*pmc.PMC, error)

GetAllPmcs returns all registered PMCs.

func (*MemRegistry) GetPmc

func (ms *MemRegistry) GetPmc(ctx context.Context, mac net.HardwareAddr) (*pmc.PMC, error)

GetPmc returns the PMC by MAC or an error if not found.

func (*MemRegistry) IsPmcRegistered

func (ms *MemRegistry) IsPmcRegistered(ctx context.Context, mac net.HardwareAddr) (bool, error)

IsPmcRegistered checks if a PMC has been registered with the specified MAC.

func (*MemRegistry) RegisterPmc

func (ms *MemRegistry) RegisterPmc(ctx context.Context, pmc *pmc.PMC) error

RegisterPmc creates or updates a PMC entry keyed by MAC.

func (*MemRegistry) Start

func (ms *MemRegistry) Start(ctx context.Context) error

Start MemRegistry (NO-OP)

func (*MemRegistry) Stop

func (ms *MemRegistry) Stop(ctx context.Context) error

Stop MemRegistry (NO-OP)

type PmcRegisterType

type PmcRegisterType string

PmcRegisterType enumerates registry backends.

const (
	RegisterTypePostgres PmcRegisterType = "Postgres"
	RegisterTypeInMemory PmcRegisterType = "InMemory"
)

func StringToDSType

func StringToDSType(s string) (PmcRegisterType, bool)

StringToDSType converts a string to a PmcRegisterType.

type PmcRegistry

type PmcRegistry interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	RegisterPmc(ctx context.Context, pmc *pmc.PMC) error
	IsPmcRegistered(ctx context.Context, mac net.HardwareAddr) (bool, error)
	GetPmc(ctx context.Context, mac net.HardwareAddr) (*pmc.PMC, error)
	GetAllPmcs(ctx context.Context) ([]*pmc.PMC, error)
}

PmcRegistry stores non-sensitive PMC identity (MAC, IP, vendor) and supports CRUD queries.

func New

func New(ctx context.Context, c *Config) (PmcRegistry, error)

New creates a new instance of DataStore based on the given configuration.

type PostgresPmcRegistry

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

PostgresPmcRegistry implements the PmcRegister interface and it uses PostgresQL as the datastore.

func NewPostgresRegistryFromDB

func NewPostgresRegistryFromDB(session *cdb.Session) *PostgresPmcRegistry

NewPostgresRegistryFromDB creates a PostgresPmcRegistry from an existing database connection. This is useful for tests where migrations have already been applied.

func (*PostgresPmcRegistry) GetAllPmcs

func (ps *PostgresPmcRegistry) GetAllPmcs(ctx context.Context) ([]*pmc.PMC, error)

GetAllPmcs returns all PMCs mapped to domain objects.

func (*PostgresPmcRegistry) GetPmc

func (ps *PostgresPmcRegistry) GetPmc(
	ctx context.Context,
	mac net.HardwareAddr,
) (*pmc.PMC, error)

GetPmc queries by MAC and maps DAO → domain.

func (*PostgresPmcRegistry) IsPmcRegistered

func (ps *PostgresPmcRegistry) IsPmcRegistered(ctx context.Context, mac net.HardwareAddr) (bool, error)

IsPmcRegistered returns true if a PMC exists.

func (*PostgresPmcRegistry) RegisterPmc

func (ps *PostgresPmcRegistry) RegisterPmc(ctx context.Context, pmc *pmc.PMC) error

RegisterPmc creates or updates a PMC row via INSERT … ON CONFLICT upsert, which is safe under concurrent registrations of the same MAC.

func (*PostgresPmcRegistry) Start

func (ps *PostgresPmcRegistry) Start(ctx context.Context) error

Start starts the PostgresStore instance. Currently, it is no-op.

func (*PostgresPmcRegistry) Stop

func (ps *PostgresPmcRegistry) Stop(ctx context.Context) error

Stop stops the PostgresStore instance by closing the PostgresQL connection.

Jump to

Keyboard shortcuts

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