sdk

package
v0.1.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoopFunctionType = map[string]int{
	"Off":             0,
	"Loop Detection":  1,
	"Loop Prevention": 2,
	"Spanning Tree":   3,
}

LoopFunctionType maps human-readable loop function values (like Off, Loop Detection, etc.) to their corresponding integer values needed by the internal system.

Functions

func ConvertTerraformIntList

func ConvertTerraformIntList(intList []types.Int64) []int

ConvertTerraformIntList converts a Terraform []types.Int64 to a native Go int slice.

func ConvertToNativeIntList

func ConvertToNativeIntList(intList []types.Int64) []int

ConvertToNativeIntList converts a Terraform []types.Int64 (used in provider) to a native Go []int (used in SDK).

func ConvertToTFInt64List

func ConvertToTFInt64List(intList []int) []types.Int64

ConvertToTFInt64List converts a native []int to []types.Int64 for Terraform usage.

func FlattenInt64List

func FlattenInt64List(intList []int) []types.Int64

FlattenInt64List normalizes and converts []int to []types.Int64 for use with Terraform.

Types

type BandwidthControl

type BandwidthControl struct {
	Port        string // The port identifier
	IngressRate string // The ingress bandwidth rate
	EgressRate  string // The egress bandwidth rate
}

BandwidthControl holds the ingress and egress rate configuration for a given port.

type HRUIClient

type HRUIClient struct {
	URL        string
	Username   string
	Password   string
	Autosave   bool
	HttpClient *http.Client
}

Client handles communication with the HRUI device, managing VLANs and other networking functionality.

func NewClient

func NewClient(url, username, password string, autosave bool) (*HRUIClient, error)

NewClient initializes and authenticates a new HRUIClient.

func (*HRUIClient) AddStaticMACEntry

func (c *HRUIClient) AddStaticMACEntry(mac string, vlanID int, port int) error

AddStaticMACEntry adds a new static MAC address entry by sending a POST request.

func (*HRUIClient) AddVLAN

func (c *HRUIClient) AddVLAN(vlan *Vlan, totalPorts int) error

AddVLAN creates or updates a VLAN on the switch, computing NotMemberPorts if needed.

func (*HRUIClient) CommitChanges

func (c *HRUIClient) CommitChanges() error

CommitChanges saves the configuration by making a POST request to `/save.cgi`.

func (*HRUIClient) ConfigureBandwidthControl

func (c *HRUIClient) ConfigureBandwidthControl(port string, isIngress, enable bool, rate string) error

ConfigureBandwidthControl configures ingress or egress bandwidth control for a specific port.

func (*HRUIClient) ConfigureIGMPSnooping

func (c *HRUIClient) ConfigureIGMPSnooping(enable bool) error

ConfigureIGMPSnooping updates the global IGMP snooping setting (enable or disable).

func (*HRUIClient) ConfigureLoopProtocol

func (c *HRUIClient) ConfigureLoopProtocol(loopFunction string, intervalTime, recoverTime int, portStatuses []PortStatus) error

ConfigureLoopProtocol updates the loop function and associated settings.

func (*HRUIClient) ConfigurePort

func (c *HRUIClient) ConfigurePort(port *Port) (*Port, error)

ConfigurePort updates the configuration for a single port.

func (*HRUIClient) ConfigurePortIGMPSnooping

func (c *HRUIClient) ConfigurePortIGMPSnooping(port int, enable bool) error

ConfigurePortIGMPSnooping enables or disables IGMP snooping for a specific port.

func (*HRUIClient) ConfigurePortIsolation

func (c *HRUIClient) ConfigurePortIsolation(port string, isolationList []string) error

func (*HRUIClient) ConfigurePortMirror

func (c *HRUIClient) ConfigurePortMirror(p *PortMirror) error

ConfigurePortMirror sets up or updates port mirroring with the given configuration.

func (*HRUIClient) ConfigureTrunk

func (c *HRUIClient) ConfigureTrunk(config *TrunkConfig) error

ConfigureTrunk sends configuration for a Trunk.

func (*HRUIClient) DeletePortIsolation

func (c *HRUIClient) DeletePortIsolation(port string) error

DeletePortIsolation resets the isolation list for a specific port.

func (*HRUIClient) DeletePortMirror

func (c *HRUIClient) DeletePortMirror() error

DeletePortMirror removes the current port mirroring configuration.

func (*HRUIClient) DeleteTrunk

func (c *HRUIClient) DeleteTrunk(id int) error

DeleteTrunk sends a delete request for a Trunk.

func (*HRUIClient) DisableIGMPSnooping

func (c *HRUIClient) DisableIGMPSnooping() error

DisableIGMPSnooping turns off IGMP globally.

func (*HRUIClient) DisablePortIGMPSnooping

func (c *HRUIClient) DisablePortIGMPSnooping(port int) error

DisablePortIGMPSnooping turns off IGMP snooping for a port.

func (*HRUIClient) EnableIGMPSnooping

func (c *HRUIClient) EnableIGMPSnooping() error

EnableIGMPSnooping enables IGMP snooping globally.

func (*HRUIClient) EnablePortIGMPSnooping

func (c *HRUIClient) EnablePortIGMPSnooping(port int) error

EnablePortIGMPSnooping turns on IGMP snooping for a port.

func (*HRUIClient) FetchIGMPConfig

func (c *HRUIClient) FetchIGMPConfig() (*IGMPConfig, error)

FetchIGMPConfig retrieves and parses the full IGMP configuration.

func (*HRUIClient) FormRequest

func (c *HRUIClient) FormRequest(endpoint string, formData url.Values) ([]byte, error)

FormRequest simplifies form submissions via POST and returns the response body as a byte slice.

func (*HRUIClient) GetAllPortsIGMPSnooping

func (c *HRUIClient) GetAllPortsIGMPSnooping() (map[int]string, error)

func (*HRUIClient) GetBandwidthControl

func (c *HRUIClient) GetBandwidthControl() ([]BandwidthControl, error)

GetBandwidthControl retrieves the bandwidth control configuration for each port.

func (*HRUIClient) GetEEE

func (c *HRUIClient) GetEEE() (bool, error)

GetEEE fetches the current EEE (Energy Efficient Ethernet) status from the device. Returns `true` if EEE is enabled, `false` if disabled.

func (*HRUIClient) GetIPAddressSettings

func (c *HRUIClient) GetIPAddressSettings() (*IPAddressSettings, error)

GetIPAddressSettings retrieves the IP address settings from the HRUI server.

func (*HRUIClient) GetJumboFrame

func (c *HRUIClient) GetJumboFrame() (*JumboFrame, error)

GetJumboFrame retrieves the current Jumbo Frame configuration from the HTML page.

func (*HRUIClient) GetLoopProtocol

func (c *HRUIClient) GetLoopProtocol() (*LoopProtocol, error)

GetLoopProtocol fetches the loop protocol settings.

func (*HRUIClient) GetMACAddressTable

func (c *HRUIClient) GetMACAddressTable() ([]MACAddressEntry, error)

GetMACAddressTable fetches and parses the MAC table from the switch.

func (*HRUIClient) GetMACLimits

func (c *HRUIClient) GetMACLimits() ([]MACLimit, error)

GetMACLimits fetches the current MAC limits configuration for all ports.

func (*HRUIClient) GetPort

func (c *HRUIClient) GetPort(portID string) (*Port, error)

func (*HRUIClient) GetPortByName

func (c *HRUIClient) GetPortByName(portName string) (string, error)

GetPortByName fetches port.cgi, parses it, and resolves the numeric port ID for a given port name.

func (*HRUIClient) GetPortIGMPSnooping

func (c *HRUIClient) GetPortIGMPSnooping(portID int) (bool, error)

func (*HRUIClient) GetPortIGMPSnoopingByName

func (c *HRUIClient) GetPortIGMPSnoopingByName(portName string) (bool, error)

func (*HRUIClient) GetPortIsolation

func (c *HRUIClient) GetPortIsolation() ([]PortIsolation, error)

GetPortIsolation fetches the current port isolation configuration.

func (*HRUIClient) GetPortMaxRate

func (c *HRUIClient) GetPortMaxRate(port int) (int64, error)

GetPortMaxRate retrieves the maximum allowed traffic rate (kbps) for a specific port from the "Rate (kbps)" column in the storm control HTML page.

func (*HRUIClient) GetPortMirror

func (c *HRUIClient) GetPortMirror() (*PortMirror, error)

GetPortMirror fetches the current port mirroring configuration (if any).

func (*HRUIClient) GetPortStatistics

func (c *HRUIClient) GetPortStatistics() ([]*PortStatistics, error)

GetPortStatistics retrieves port statistics from the switch.

func (*HRUIClient) GetPortVLANConfig

func (c *HRUIClient) GetPortVLANConfig(port int) (*PortVLANConfig, error)

GetPortVLANConfig fetches the VLAN configuration for a specific port on the switch.

func (*HRUIClient) GetQoSPortQueue

func (c *HRUIClient) GetQoSPortQueue(portID int) (*QoSPortQueue, error)

GetQoSPortQueue fetches the QoS port queue by portID (0-based input).

func (*HRUIClient) GetSTPPort

func (c *HRUIClient) GetSTPPort(portID int) (*STPPort, error)

GetSTPPort fetches a single STP port by its ID from the backend.

func (*HRUIClient) GetSTPPortSettings

func (c *HRUIClient) GetSTPPortSettings() ([]STPPort, error)

GetSTPPortSettings fetches the STP port settings.

func (*HRUIClient) GetSTPSettings

func (c *HRUIClient) GetSTPSettings() (*STPGlobalSettings, error)

GetSTPSettings fetches and parses the STP Global Settings page.

func (*HRUIClient) GetStaticMACAddressTable

func (c *HRUIClient) GetStaticMACAddressTable() ([]StaticMACEntry, error)

GetStaticMACAddressTable retrieves the static MAC address table.

func (*HRUIClient) GetStormControlStatus

func (c *HRUIClient) GetStormControlStatus() (*StormControlConfig, error)

GetStormControlStatus fetches the current storm control status from the HTML page.

func (*HRUIClient) GetSystemInfo

func (c *HRUIClient) GetSystemInfo() (map[string]string, error)

GetSystemInfo retrieves system information from the HRUI server.

func (*HRUIClient) GetTotalPorts

func (c *HRUIClient) GetTotalPorts() (int, error)

GetTotalPorts returns the current number of ports.

func (*HRUIClient) GetTrunk

func (c *HRUIClient) GetTrunk(id int) (*TrunkConfig, error)

GetTrunk fetches details of a configured Trunk by its ID.

func (*HRUIClient) GetTrunkByID

func (c *HRUIClient) GetTrunkByID(id int) (*TrunkConfig, error)

GetTrunkByID fetches details of a configured Trunk by its ID.

func (*HRUIClient) GetVLAN

func (c *HRUIClient) GetVLAN(vlanID int) (*Vlan, error)

GetVLAN fetches a single VLAN by its VLAN ID by filtering results from ListVLANs.

func (*HRUIClient) GetValidPorts

func (c *HRUIClient) GetValidPorts() ([]int, error)

GetValidPorts fetches and returns the list of IDs of all ports available on the system.

func (*HRUIClient) ListAvailableTrunks

func (c *HRUIClient) ListAvailableTrunks() ([]TrunkConfig, error)

ListAvailableTrunks fetches available Trunks on the device.

func (*HRUIClient) ListConfiguredTrunks

func (c *HRUIClient) ListConfiguredTrunks() ([]TrunkConfig, error)

ListConfiguredTrunks fetches configured Trunks from the device.

func (*HRUIClient) ListIGMPPorts

func (c *HRUIClient) ListIGMPPorts() (map[int]string, error)

ListIGMPPorts fetches a list of valid ports with their logical IDs from the backend.

func (*HRUIClient) ListPortVLANConfigs

func (c *HRUIClient) ListPortVLANConfigs() ([]*PortVLANConfig, error)

ListPortVLANConfigs fetches the VLAN configuration for all ports on the switch.

func (*HRUIClient) ListPorts

func (c *HRUIClient) ListPorts() ([]*Port, error)

ListPorts retrieves information about all switch ports.

func (*HRUIClient) ListQoSPortQueues

func (c *HRUIClient) ListQoSPortQueues() ([]QoSPortQueue, error)

ListQoSPortQueues fetches and parses QoS port queues from the HTML page.

func (*HRUIClient) ListQoSQueueWeights

func (c *HRUIClient) ListQoSQueueWeights() ([]QoSQueueWeight, error)

ListQoSQueueWeights fetches the current queues and weights from the HTML page.

func (*HRUIClient) ListVLANs

func (c *HRUIClient) ListVLANs() ([]*Vlan, error)

ListVLANs fetches the list of VLANs, setting member ports directly instead of notmemberports.

func (*HRUIClient) Login

func (c *HRUIClient) Login() error

Login sets the authentication cookie for the HRUI system.

func (*HRUIClient) RemoveStaticMACEntries

func (c *HRUIClient) RemoveStaticMACEntries(macEntries []StaticMACEntry) error

RemoveStaticMACEntries deletes one or more static MAC address entries.

func (*HRUIClient) RemoveVLAN

func (c *HRUIClient) RemoveVLAN(vlanID int) error

RemoveVLAN deletes a VLAN by its VLAN ID from the switch.

func (*HRUIClient) Request

func (c *HRUIClient) Request(method, endpoint string, body io.Reader, headers map[string]string) ([]byte, error)

Request handles all HTTP methods and returns the response body as a byte slice.

func (*HRUIClient) ResolvePortNameToID

func (c *HRUIClient) ResolvePortNameToID(portName string) (int, error)

ResolvePortNameToID maps a port name to its logical ID.

func (*HRUIClient) SetEEE

func (c *HRUIClient) SetEEE(enabled bool) error

SetEEE updates the EEE (Energy Efficient Ethernet) status on the device. Pass `true` to enable EEE or `false` to disable it.

func (*HRUIClient) SetIPAddressSettings

func (c *HRUIClient) SetIPAddressSettings(settings *IPAddressSettings) error

SetIPAddressSettings updates the IP address settings on the HRUI server.

func (*HRUIClient) SetJumboFrame

func (c *HRUIClient) SetJumboFrame(frameSize int) error

SetJumboFrame sets the Jumbo Frame size on the device.

func (*HRUIClient) SetMACLimit

func (c *HRUIClient) SetMACLimit(portID int, enabled bool, limit *int) error

SetMACLimit sets the MAC limit for a specific port.

func (*HRUIClient) SetPortVLANConfig

func (c *HRUIClient) SetPortVLANConfig(config *PortVLANConfig) error

SetPortVLANConfig sets the VLAN configuration for a specific port on the switch.

func (*HRUIClient) SetQoSPortQueue

func (c *HRUIClient) SetQoSPortQueue(portID, queue int) error

SetQoSPortQueue updates the QoS port queue for the given port.

func (*HRUIClient) SetQoSQueueWeight

func (c *HRUIClient) SetQoSQueueWeight(queue, weight int) error

SetQoSQueueWeight updates the weight for a given queue.

func (*HRUIClient) SetSTPPortSettings

func (c *HRUIClient) SetSTPPortSettings(portID, pathCost, priority int, p2p, edge string) error

SetSTPPortSettings updates the STP settings for a specific port.

func (*HRUIClient) SetSTPSettings

func (c *HRUIClient) SetSTPSettings(stp *STPGlobalSettings) error

SetSTPSettings updates the STP global settings.

func (*HRUIClient) SetSTPSettingsAsync

func (c *HRUIClient) SetSTPSettingsAsync(stp *STPGlobalSettings) error

SetSTPSettingsAsync performs a fire-and-forget POST request to update the STP Global Settings. needed due to a bug in the cgi for updating stp global settings that never returns.

func (*HRUIClient) SetStormControlConfig

func (c *HRUIClient) SetStormControlConfig(
	stormType string,
	ports []int,
	state bool,
	rate *int64,
) error

SetStormControlConfig updates the storm control settings for specific ports.

func (*HRUIClient) UpdatePortIGMPSnoopingByName

func (c *HRUIClient) UpdatePortIGMPSnoopingByName(portName string, enable bool) error

func (*HRUIClient) ValidateAuthCookie

func (c *HRUIClient) ValidateAuthCookie() error

ValidateAuthCookie checks whether the authentication was successful.

type IGMPConfig

type IGMPConfig struct {
	Enabled bool
	Ports   map[int]bool
}

IGMPConfig represents the IGMP Snooping configuration.

type IPAddressSettings

type IPAddressSettings struct {
	DHCPEnabled bool
	IPAddress   string
	Netmask     string
	Gateway     string
}

IPAddressSettings represents the IP configuration.

type JumboFrame

type JumboFrame struct {
	FrameSize int
}

JumboFrame represents the current selected Jumbo Frame size.

type LoopProtocol

type LoopProtocol struct {
	LoopFunction string       // "Off", "Loop Detection", "Loop Prevention", "Spanning Tree"
	IntervalTime int          // Interval time (relevant for Loop Prevention)
	RecoverTime  int          // Recovery time (relevant for Loop Prevention)
	PortStatuses []PortStatus // Per-port Loop Prevention statuses
}

LoopProtocol represents loop protocol settings.

type MACAddressEntry

type MACAddressEntry struct {
	ID     int    // Sequence number of the entry
	MAC    string // MAC address in the format xx:xx:xx:xx:xx:xx
	VLANID int    // VLAN ID associated with the MAC address
	Type   string // Type of the entry (e.g., "dynamic" or "static")
	Port   int    // Port number associated with the MAC address
}

MACAddressEntry represents a single entry in the MAC address table.

type MACLimit

type MACLimit struct {
	Port    string
	Enabled bool
	Limit   *int
}

MACLimit represents the MAC entry limit for a specific port.

type ParseOption

type ParseOption func(*ParseOptions)

ParseOption modifies ParseOptions.

func WithDefaultValue

func WithDefaultValue(value int) ParseOption

WithDefaultValue specifies a default value to return on error.

func WithLogging

func WithLogging() ParseOption

WithLogging enables error logging.

func WithOffset

func WithOffset(offset int) ParseOption

WithOffset specifies an offset to apply to parsed values.

func WithReturnNilOnSpecialCases

func WithReturnNilOnSpecialCases() ParseOption

WithReturnNilOnSpecialCases defines that special cases should return nil instead of the default value.

func WithSpecialCases

func WithSpecialCases(cases ...string) ParseOption

WithSpecialCases defines special-case strings that map to the default value.

func WithTrimPrefix

func WithTrimPrefix(prefix string) ParseOption

WithTrimPrefix specifies a prefix to trim.

func WithTrimSuffix

func WithTrimSuffix(suffix string) ParseOption

WithTrimSuffix specifies a suffix to trim.

type ParseOptions

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

ParseOptions defines options for parsing integers.

type Port

type Port struct {
	ID                string
	IsTrunk           bool
	State             int
	SpeedDuplexConfig string
	SpeedDuplexActual string
	FlowControlConfig string
	FlowControlActual string
}

type PortIsolation

type PortIsolation struct {
	Port          string
	IsolationList []string
}

type PortMirror

type PortMirror struct {
	MirrorDirection string
	MirroringPort   string
	MirroredPort    string
}

type PortStatistics

type PortStatistics struct {
	Port       string
	State      int
	LinkStatus string
	TxGoodPkt  int64
	TxBadPkt   int64
	RxGoodPkt  int64
	RxBadPkt   int64
}

type PortStatus

type PortStatus struct {
	Port       int    // Port number
	Enable     bool   // Whether Loop Prevention is enabled on this port
	LoopState  string // Loop state ("Enable", "Disable")
	LoopStatus string // Loop operation status ("Forwarding", "Blocked", etc.)
}

PortStatus represents the status of a port under Loop Protocol control.

type PortVLANConfig

type PortVLANConfig struct {
	PortID          int
	Name            string
	PVID            int
	AcceptFrameType string
}

type QoSPortQueue

type QoSPortQueue struct {
	PortID int
	Queue  int
}

QoSPortQueue represents the QoS queue configuration for a port.

type QoSQueueWeight

type QoSQueueWeight struct {
	Queue  int
	Weight string
}

QoSQueueWeight represents the "Queue Weight" for a queue.

type SDK

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

SDK wraps the underlying client to provide high-level functionality for CRUD operations.

func NewSDK

func NewSDK(client *HRUIClient) *SDK

NewSDK creates a new SDK instance with the provided client.

type STPGlobalSettings

type STPGlobalSettings struct {
	STPStatus        string // Overall STP status ("Enable", "Disable")
	ForceVersion     string // STP version ("STP", "RSTP")
	Priority         int    // Priority for the STP instance (values like 4096, 8192, 32768, etc.)
	MaxAge           int    // Maximum Age (seconds)
	HelloTime        int    // Hello Time (seconds)
	ForwardDelay     int    // Forwarding Delay (seconds)
	RootPriority     int    // Root bridge priority
	RootMAC          string // Root bridge MAC address
	RootPathCost     int    // Root path cost
	RootPort         string // Root port (number or identifier)
	RootMaxAge       int    // Root Maximum Age (seconds)
	RootHelloTime    int    // Root Hello Time (seconds)
	RootForwardDelay int    // Root Forward Delay (seconds)
}

STPGlobalSettings holds the STP global settings.

func (*STPGlobalSettings) GetVersionValue

func (stp *STPGlobalSettings) GetVersionValue() string

GetVersionValue returns a numeric value for the version (STP/RSTP).

type STPPort

type STPPort struct {
	Port           int    // Port ID
	State          string // Port operational state (e.g., Disabled, Forwarding)
	Role           string // Port role in STP (e.g., Designated, Alternate)
	PathCostConfig int    // Configured Path Cost
	PathCostActual int    // Actual Path Cost
	Priority       int    // Port Priority
	P2PConfig      string // Configured P2P setting (True, False, Auto)
	P2PActual      string // Actual P2P state
	EdgeConfig     string // Configured Edge setting (True, False)
	EdgeActual     string // Actual Edge state
}

STPPort represents a switch port's STP settings.

type StaticMACEntry

type StaticMACEntry struct {
	ID         int
	MACAddress string
	VLANID     int
	Port       int
}

StaticMACEntry represents a single entry in the static MAC address table.

type StormControlConfig

type StormControlConfig struct {
	Entries []StormControlEntry `json:"entries"`
}

StormControlConfig represents all the storm control entries in the table.

type StormControlEntry

type StormControlEntry struct {
	Port                     int  `json:"port"`                        // Port number as an integer
	BroadcastRateKbps        *int `json:"broadcast_rate_kbps"`         // Broadcast rate in kbps, nil if "Off"
	KnownMulticastRateKbps   *int `json:"known_multicast_rate_kbps"`   // Known Multicast, nil if "Off"
	UnknownUnicastRateKbps   *int `json:"unknown_unicast_rate_kbps"`   // Unknown Unicast, nil if "Off"
	UnknownMulticastRateKbps *int `json:"unknown_multicast_rate_kbps"` // Unknown Multicast, nil if "Off"
}

StormControlEntry represents the configuration for a specific port.

type TrunkConfig

type TrunkConfig struct {
	ID    int
	Type  string
	Ports []int
}

type Vlan

type Vlan struct {
	VlanID        int
	Name          string
	UntaggedPorts []int
	TaggedPorts   []int
	MemberPorts   []int
}

Jump to

Keyboard shortcuts

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