network

package
v0.0.0-...-bd1a880 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package network provides functionality for Docker network management

Package network provides functionality for Docker network management

Index

Constants

View Source
const (
	// NetworkEventTypeCreate is the event type for network creation
	NetworkEventTypeCreate = "create"

	// NetworkEventTypeConnect is the event type for network connection
	NetworkEventTypeConnect = "connect"

	// NetworkEventTypeDestroy is the event type for network destruction
	NetworkEventTypeDestroy = "destroy"

	// NetworkEventTypeDisconnect is the event type for network disconnection
	NetworkEventTypeDisconnect = "disconnect"

	// NetworkEventTypeRemove is the event type for network removal
	NetworkEventTypeRemove = "remove"
)

Event types for network events

Variables

View Source
var ErrNetworkNotFound = errors.New("network not found")

ErrNetworkNotFound indicates that a network was not found

Functions

This section is empty.

Types

type ConnectOptions

type ConnectOptions struct {
	// EndpointConfig is the endpoint configuration
	EndpointConfig *networktypes.EndpointSettings // Use networktypes alias

	// Force indicates whether to bypass validation and force connection
	Force bool

	// Timeout is the operation timeout
	Timeout time.Duration

	// Logger is the logger
	Logger *logrus.Logger
}

ConnectOptions defines options for connecting a container to a network

type CreateOptions

type CreateOptions struct {
	// Driver is the network driver name
	Driver string

	// IPAM is the IPAM configuration
	IPAM *networktypes.IPAM // Use networktypes alias

	// Options are driver specific options
	Options map[string]string

	// Labels are labels to set on the network
	Labels map[string]string

	// EnableIPv6 indicates whether to enable IPv6
	EnableIPv6 bool

	// Internal indicates whether the network is internal
	Internal bool

	// Attachable indicates whether containers can be attached to this network
	Attachable bool

	// Ingress indicates whether the network is an ingress network
	Ingress bool

	// ConfigOnly indicates whether the network is a configuration only network
	ConfigOnly bool

	// Scope is the network scope
	Scope string

	// CheckDuplicate checks for networks with same name
	CheckDuplicate bool

	// Timeout is the operation timeout
	Timeout time.Duration

	// Logger is the logger
	Logger *logrus.Logger
}

CreateOptions defines options for creating a network

type DisconnectOptions

type DisconnectOptions struct {
	// Force indicates whether to force disconnection
	Force bool

	// Timeout is the operation timeout
	Timeout time.Duration

	// Logger is the logger
	Logger *logrus.Logger
}

DisconnectOptions defines options for disconnecting a container from a network

type GetOptions

type GetOptions struct {
	// Verbose indicates whether to include verbose information
	Verbose bool

	// Scope is the network scope
	Scope string

	// Timeout is the operation timeout
	Timeout time.Duration

	// Logger is the logger
	Logger *logrus.Logger
}

GetOptions defines options for getting a network

type InspectionOptions

type InspectionOptions struct {
	IncludeAll            bool              `json:"include_all"`
	IncludeDriver         string            `json:"include_driver"`
	IncludeSystemNetworks bool              `json:"include_system_networks"`
	IncludeDetailed       bool              `json:"include_detailed"`
	FilterLabels          map[string]string `json:"filter_labels"`
	FilterNames           []string          `json:"filter_names"`
	FilterIDs             []string          `json:"filter_ids"`
	FilterContainers      []string          `json:"filter_containers"`
	FilterScope           string            `json:"filter_scope"`
	FilterSubnet          string            `json:"filter_subnet"`
	FilterIPv6            bool              `json:"filter_ipv6"`
	FilterInternal        bool              `json:"filter_internal"`
	FilterBuiltin         bool              `json:"filter_builtin"`
	Limit                 int               `json:"limit"`
	Offset                int               `json:"offset"`
	SortBy                string            `json:"sort_by"`
	SortDescending        bool              `json:"sort_descending"`
	Timeout               int               `json:"timeout"`
}

InspectionOptions defines options for listing and inspecting networks

type Inspector

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

Inspector provides functionality for listing and inspecting networks

func NewInspector

func NewInspector(client client.APIClient, logger *logrus.Logger) *Inspector

NewInspector creates a new network inspector

func (*Inspector) CountNetworks

func (i *Inspector) CountNetworks(ctx context.Context, opts InspectionOptions) (int, error)

CountNetworks counts networks matching the specified filters

func (*Inspector) FindNetworkByName

func (i *Inspector) FindNetworkByName(ctx context.Context, name string) (*models.Network, error)

FindNetworkByName finds a network by its exact name

func (*Inspector) FindNetworksByContainer

func (i *Inspector) FindNetworksByContainer(ctx context.Context, containerIDOrName string) ([]*models.Network, error)

FindNetworksByContainer finds networks connected to a specific container

func (*Inspector) FindNetworksBySubnet

func (i *Inspector) FindNetworksBySubnet(ctx context.Context, subnet string) ([]*models.Network, error)

FindNetworksBySubnet finds networks by subnet

func (*Inspector) GetAvailableDrivers

func (i *Inspector) GetAvailableDrivers(ctx context.Context) ([]string, error)

GetAvailableDrivers gets the list of available network drivers

func (*Inspector) GetIPAMDrivers

func (i *Inspector) GetIPAMDrivers(ctx context.Context) ([]string, error)

GetIPAMDrivers gets the list of available IPAM drivers

func (*Inspector) GetNetwork

func (i *Inspector) GetNetwork(ctx context.Context, networkID string, opts InspectionOptions) (*models.Network, error)

GetNetwork gets detailed information about a specific network

func (*Inspector) GetNetworkContainers

func (i *Inspector) GetNetworkContainers(ctx context.Context, networkID string) (map[string]models.EndpointResource, error)

GetNetworkContainers gets containers connected to a specific network

func (*Inspector) GetNetworks

func (i *Inspector) GetNetworks(ctx context.Context, opts InspectionOptions) ([]*models.Network, error)

GetNetworks lists networks with filtering options

type ListOptions

type ListOptions struct {
	// Filters are the filters to apply
	Filters filters.Args

	// NameOnly indicates whether to include only the network name
	NameOnly bool

	// Timeout is the operation timeout
	Timeout time.Duration

	// Logger is the logger
	Logger *logrus.Logger
}

ListOptions defines options for listing networks

type NetworkFilter

type NetworkFilter struct {
	// Name is the network name filter
	Name string

	// ID is the network ID filter
	ID string

	// Driver is the driver name filter
	Driver string

	// Scope is the scope filter
	Scope string

	// Type is the type filter
	Type string

	// LabelFilter is the label filter
	LabelFilter string

	// Dangling indicates whether to include only dangling networks
	Dangling bool

	// Custom is a map of custom filters
	Custom map[string][]string
}

NetworkFilter defines filters for looking up networks

func (*NetworkFilter) ToFilters

func (f *NetworkFilter) ToFilters() filters.Args

ToFilters converts a NetworkFilter to filters.Args

type PruneOptions

type PruneOptions struct {
	// Filters are the filters to apply
	Filters filters.Args

	// Timeout is the operation timeout
	Timeout time.Duration

	// Logger is the logger
	Logger *logrus.Logger
}

PruneOptions defines options for pruning networks

type RemoveOptions

type RemoveOptions struct {
	// Force indicates whether to force removal
	Force bool

	// Timeout is the operation timeout
	Timeout time.Duration

	// Logger is the logger
	Logger *logrus.Logger
}

RemoveOptions defines options for removing a network

type Service

type Service interface {
	// Create creates a new network
	Create(ctx context.Context, name string, options CreateOptions) (*models.Network, error)

	// Get gets a network by ID or name
	Get(ctx context.Context, idOrName string, options GetOptions) (*models.Network, error)

	// List lists networks
	List(ctx context.Context, options ListOptions) ([]*models.Network, error)

	// Remove removes a network
	Remove(ctx context.Context, idOrName string, options RemoveOptions) error

	// Prune removes unused networks
	Prune(ctx context.Context, options PruneOptions) (networktypes.PruneReport, error) // Changed dockertypes.NetworksPruneReport -> networktypes.PruneReport

	// Connect connects a container to a network
	Connect(ctx context.Context, networkIDOrName, containerIDOrName string, options ConnectOptions) error

	// Disconnect disconnects a container from a network
	Disconnect(ctx context.Context, networkIDOrName, containerIDOrName string, options DisconnectOptions) error

	// InspectRaw gets the raw information about a network
	InspectRaw(ctx context.Context, idOrName string) (networktypes.Inspect, error) // Changed networktypes.NetworkResource -> networktypes.Inspect

	// GetNetworkDrivers returns the list of available network drivers
	GetNetworkDrivers(ctx context.Context) ([]string, error)

	// FindNetworkByContainer finds networks connected to a container
	FindNetworkByContainer(ctx context.Context, containerIDOrName string, options ListOptions) ([]*models.Network, error)

	// FindNetworkByName finds networks by name pattern
	FindNetworkByName(ctx context.Context, pattern string, options ListOptions) ([]*models.Network, error)

	// FindNetworkBySubnet finds networks by subnet
	FindNetworkBySubnet(ctx context.Context, subnet string, options ListOptions) ([]*models.Network, error)
}

Service defines the interface for Docker network operations

func NewService

func NewService(dockerManager docker.Manager, logger *logrus.Logger) Service

NewService creates a new network service implementation

Directories

Path Synopsis
Package manager provides the implementation of the network service interface
Package manager provides the implementation of the network service interface

Jump to

Keyboard shortcuts

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