hp1810api

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

README

hp1810api

This is a Go library to enable automated interaction with HP 1810 series switches.

It is experimental and provided without any warranty.

Testing

To run the test suite, login details to a real switch are required. Provide them as environment variables, for example via direnv in .envrc:

export HP1810_HOST="ip address or hostname"
export HP1810_PASSWORD="admin password"

Licensing

You may use this software in accordance with the terms of the GNU General Public License Version 3, which is included in [LICENSE.txt].

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PortID

type PortID int

type PortState

type PortState int
const (
	// Port is not a member of the VLAN in any form.
	PortExcluded PortState = 0

	// Port is tagged in the VLAN.
	PortTagged PortState = 1

	// Port is untagged in the VLAN.
	PortUntagged PortState = 2

	// Port is unavailable for VLAN assignment, likely due to being part of a trunk.
	PortUnavailable PortState = 3
)

type Session

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

An admin login session on a switch.

It is recommended to call Logout when you're done with the session, because 1810 series switches have a limited number of session slots available. When these are used up, they will reject further logins.

func Login

func Login(host string, password string) (*Session, error)

Establish a new admin session.

Remember to `defer session.Logout()`.

func (*Session) CreateVLAN

func (s *Session) CreateVLAN(vid VID) (*http.Response, error)

func (*Session) DeleteVLAN

func (s *Session) DeleteVLAN(vid VID) (*http.Response, error)

func (*Session) FetchSwitchConfig

func (s *Session) FetchSwitchConfig() (*SwitchConfig, error)

Read out the switches configuration.

func (*Session) Logout

func (s *Session) Logout() (*http.Response, error)

Log out of the admin session.

func (*Session) SetVLANMembership

func (s *Session) SetVLANMembership(vid VID, switchConfig *SwitchConfig) (*http.Response, error)

Apply the VLAN membership settings in `switchConfig` for the VLAN identified by `vid`.

The intended usage is to fetch `switchConfig` through `FetchSwitchConfig`, modify it as desired, and to then pass it to this function for any VLANs needing modifications.

func (*Session) SetVLANName

func (s *Session) SetVLANName(vid VID, name string) (*http.Response, error)

type SwitchConfig

type SwitchConfig struct {
	// Port VLANs of all switch ports. Array index corresponds to port number
	// minus one.
	PvidPort []VID

	// Port VLANs of all active trunks.
	PvidTrunk []VID

	// IDs of all active trunks.
	TrunkID []TrunkID

	VLANs  []VlanConfig
	Trunks []TrunkConfig
}

Representation of a switches entire configuration.

For `PvidTrunk` and `TrunkID`, trunks are considered "active" when they have at least one member port.

func (*SwitchConfig) GetTrunk

func (sc *SwitchConfig) GetTrunk(trunkID TrunkID) *TrunkConfig

Look up a `TrunkConfig` by its ID.

func (*SwitchConfig) GetVLAN

func (sc *SwitchConfig) GetVLAN(vid VID) *VlanConfig

Look up a `VlanConfig` by its VLAN ID.

type TrunkConfig

type TrunkConfig struct {
	ID          TrunkID
	Name        string
	Mode        TrunkMode
	MemberPorts []PortID
}

Represents the configuration of a trunk.

type TrunkID

type TrunkID int

type TrunkMode

type TrunkMode int
const (
	TrunkDisabled    TrunkMode = 0 // disabled
	TrunkStatic      TrunkMode = 1 // static
	TrunkLACPActive  TrunkMode = 2 // lacp-active
	TrunkLACPPassive TrunkMode = 3 // lacp-passive
)

func (TrunkMode) String

func (i TrunkMode) String() string

type VID

type VID int

type VlanConfig

type VlanConfig struct {
	Vid         VID
	Name        string
	MemberPort  []PortState
	MemberTrunk []PortState
}

Represents the configuration of a single VLAN.

Jump to

Keyboard shortcuts

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