network

package
v3.3.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeAuto     = "auto"
	ModeManual   = "manual"
	ModeDisabled = "disabled"

	// ConfirmTimeout 变更后等待确认的时长,超时未确认自动回滚,
	// 避免配错导致远程失联后无法恢复
	ConfirmTimeout = 30 * time.Second
)

Variables

View Source
var ErrValidation = errors.New("invalid network configuration")

ErrValidation 配置不合法,服务层据此返回 422

Functions

func Validate

func Validate(config Config) error

Types

type Config

type Config struct {
	Name string       `json:"name"`
	MTU  int          `json:"mtu"`
	IPv4 FamilyConfig `json:"ipv4"`
	IPv6 FamilyConfig `json:"ipv6"`
}

type FamilyConfig

type FamilyConfig struct {
	Mode      string   `json:"mode"`
	Addresses []string `json:"addresses"`
	Gateway   string   `json:"gateway"`
	AutoDNS   bool     `json:"auto_dns"`
	DNS       []string `json:"dns"`
}

type FamilyState

type FamilyState struct {
	Addresses []string `json:"addresses"`
	Gateway   string   `json:"gateway"`
	DNS       []string `json:"dns"`
}

FamilyState 网卡当前生效的网络状态,自动获取时配置里没有这些值,用于回填表单

type Interface

type Interface struct {
	Name          string       `json:"name"`
	Type          string       `json:"type"`
	State         string       `json:"state"`
	MAC           string       `json:"mac"`
	CurrentMTU    int          `json:"current_mtu"`
	ConfiguredMTU int          `json:"configured_mtu"`
	CurrentIPv4   FamilyState  `json:"current_ipv4"`
	CurrentIPv6   FamilyState  `json:"current_ipv6"`
	Editable      bool         `json:"editable"`
	Reason        string       `json:"reason"`
	IPv4          FamilyConfig `json:"ipv4"`
	IPv6          FamilyConfig `json:"ipv6"`
}

type Result

type Result struct {
	Manager string      `json:"manager"`
	Items   []Interface `json:"items"`
	// Pending 为真表示有变更等待确认
	Pending bool `json:"pending"`
}

type Service

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

Service 网卡配置管理,同一时间只允许一个变更处于待确认状态

func New

func New() *Service

func (*Service) Confirm

func (s *Service) Confirm() error

func (*Service) Interfaces

func (s *Service) Interfaces(ctx context.Context) (*Result, error)

func (*Service) Rollback

func (s *Service) Rollback(ctx context.Context) error

func (*Service) Update

func (s *Service) Update(ctx context.Context, config Config) error

Update 应用网卡配置,成功后进入待确认状态,超时未确认自动回滚

Jump to

Keyboard shortcuts

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