sdk

package
v0.0.0-...-65e4e0d Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MPL-2.0 Imports: 14 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 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) AddStaticMACAddress

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

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

func (*HRUIClient) Authenticate

func (c *HRUIClient) Authenticate() error

Authenticate sets the authentication cookie for the HRUI system.

func (*HRUIClient) CreateVLAN

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

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

func (*HRUIClient) DeleteStaticMACAddress

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

DeleteStaticMACAddress deletes one or more static MAC address entries.

func (*HRUIClient) DeleteVLAN

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

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

func (*HRUIClient) GetAllPortVLANConfigs

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

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

func (*HRUIClient) GetAllPorts

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

func (*HRUIClient) GetAllQOSPortQueues

func (client *HRUIClient) GetAllQOSPortQueues() ([]QoSPortQueue, error)

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

func (*HRUIClient) GetAllQOSQueueWeights

func (client *HRUIClient) GetAllQOSQueueWeights() ([]QoSQueueWeight, error)

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

func (*HRUIClient) GetAllVLANs

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

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

func (*HRUIClient) GetIPAddressSettings

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

func (*HRUIClient) GetLoopProtocol

func (client *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) GetPort

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

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 (client *HRUIClient) GetQOSPortQueue(portID int) (*QoSPortQueue, error)

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

func (*HRUIClient) GetSTPPort

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

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

func (*HRUIClient) GetSTPPortSettings

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

func (*HRUIClient) GetSTPSettings

func (client *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 via the "mac.cgi?page=static" endpoint.

func (*HRUIClient) GetSystemInfo

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

func (*HRUIClient) GetTotalPorts

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

func (*HRUIClient) GetVLAN

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

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

func (*HRUIClient) MakeRequest

func (c *HRUIClient) MakeRequest(url string) (*http.Response, error)

MakeRequest performs a simple GET request and returns the response.

func (*HRUIClient) PostForm

func (c *HRUIClient) PostForm(url string, form url.Values) (*http.Response, error)

PostForm submits a form to the specified URL with the given form data.

func (*HRUIClient) SaveConfiguration

func (c *HRUIClient) SaveConfiguration() error

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

func (*HRUIClient) SetPortVLANConfig

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

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

func (*HRUIClient) UpdateIPAddressSettings

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

func (*HRUIClient) UpdateLoopProtocol

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

UpdateLoopProtocol updates the loop function and associated settings.

func (*HRUIClient) UpdatePortSettings

func (c *HRUIClient) UpdatePortSettings(port *Port) error

func (*HRUIClient) UpdateQOSPortQueue

func (client *HRUIClient) UpdateQOSPortQueue(portID, queue int) error

UpdateQOSPortQueue updates the QoS port queue for the given port.

func (*HRUIClient) UpdateQOSQueueWeight

func (client *HRUIClient) UpdateQOSQueueWeight(queue, weight int) error

UpdateQOSQueueWeight updates the weight for a given queue.

func (*HRUIClient) UpdateSTPPortSettings

func (client *HRUIClient) UpdateSTPPortSettings(portID, pathCost, priority int, p2p, edge string) error

UpdateSTPPortSettings updates the STP settings for a specific port.

func (*HRUIClient) UpdateSTPSettings

func (client *HRUIClient) UpdateSTPSettings(stp *STPGlobalSettings) error

UpdateSTPSettings updates the STP global settings.

func (*HRUIClient) UpdateSTPSettingsAsync

func (client *HRUIClient) UpdateSTPSettingsAsync(stp *STPGlobalSettings) error

UpdateSTPSettingsAsync 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.

type IPAddressSettings

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

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 Port

type Port struct {
	ID          int
	State       int
	SpeedDuplex string
	FlowControl string
}

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 {
	Port            int
	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 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