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