aoscxgo

package module
v0.0.0-...-03f12fc Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 11 Imported by: 0

README

aoscxgo

aoscxgo is a golang package that allows users to connect to and configure AOS-CX switches using REST API. The minimum supported firmware version is 10.09.

This package is forked from Arubas own aoscxgo with some improvements.

Using aoscxgo

To login to the switch and create a client connection:

package main

import (
	"log"

	"github.com/aruba/aoscxgo"
)

func main() {
	sw, err := aoscxgo.Connect(
		&aoscxgo.Client{
			Hostname:          "10.0.0.1",
			Username:          "admin",
			Password:          "admin",
			VerifyCertificate: false,
		},
	)

	if (sw.Cookie == nil) || (err != nil) {
		log.Printf("Failed to login to switch: %s", err)
		return
	}
	log.Printf("Login Success")

}

This will login to the switch and create a cookie to use for authentication in further calls. This cookie is stored within the aoscxgo.

Work with VLAN's
	vlan100 := aoscxgo.Vlan{
		VlanId:      100,
		Name:        "uplink VLAN",
		Description: "uplink VLAN",
		AdminState:  "up",
	}

	// if the vlan exists use
	// err = vlan100.Update(sw)
	err = vlan100.Create(sw)

	if err != nil {
		log.Printf("Error in creating VLAN 100: %s", err)
		return
	}

	log.Printf("VLAN Create Success")
Get some switch information
    result, err := sw.GetChassis(1)
    if err == nil {
        log.Printf("Model %s, serial %s\n", result.ProductInfo.ProductName, result.ProductInfo.SerialNumber)
    }

Documentation

Overview

aoscxgo is a golang package that allows users to connect to and configure AOS-CX switches using REST API. The minimum supported firmware version is 10.09.

To login to the switch and create a client connection:

package main

import (

"log"

"github.com/aruba/aoscxgo"

)

func main() {
	sw, err := aoscxgo.Connect(
		&aoscxgo.Client{
			Hostname:          "10.0.0.1",
			Username:          "admin",
			Password:          "admin",
		},
	)

	if (sw.Cookie == nil) || (err != nil) {
		log.Printf("Failed to login to switch: %s", err)
		return
	}
	log.Printf("Login Success")

}

This will login to the switch and create a cookie to use for authentication in further calls. This cookie is stored within the aoscxgo.Client object that will be passed into configuration modules like so:

vlan100 := aoscxgo.Vlan{
	VlanId:      100,
	Name:        "uplink VLAN",
	Description: "uplink VLAN",
	AdminState:  "up",
}

// if the vlan exists use
// err = vlan100.Update(sw)
err = vlan100.Create(sw)

if err != nil {
	log.Printf("Error in creating VLAN 100: %s", err)
	return
}

log.Printf("VLAN Create Success")

Each API resource will have the following functions (exceptions may vary):

  • Create
  • Update
  • Get
  • GetStatus
  • Delete

Index

Constants

View Source
const Version = "0.0.2"

Variables

This section is empty.

Functions

This section is empty.

Types

type Chassis

type Chassis struct {
	AclInitStatus string `json:"acl_init_status"`
	AdminState    string `json:"admin_state"`
	AsicInfo      struct {
	} `json:"asic_info"`
	Buttons      string   `json:"buttons"`
	Capabilities []string `json:"capabilities"`
	Capacities   struct {
		PsuSlots int `json:"psu_slots"`
	} `json:"capacities"`
	Daemons                    string `json:"daemons"`
	DataPlaneConnectivityState struct {
	} `json:"data_plane_connectivity_state"`
	DataPlaneConnectivityTargetState struct {
	} `json:"data_plane_connectivity_target_state"`
	DataPlaneError struct {
	} `json:"data_plane_error"`
	DataPlaneState             interface{} `json:"data_plane_state"`
	DataPlaneTargetState       interface{} `json:"data_plane_target_state"`
	DataPlanes                 string      `json:"data_planes"`
	DiagTestResults            string      `json:"diag_test_results"`
	DiagnosticDisable          bool        `json:"diagnostic_disable"`
	DiagnosticLastRunTimestamp int         `json:"diagnostic_last_run_timestamp"`
	DiagnosticPerformed        int         `json:"diagnostic_performed"`
	DiagnosticRequested        int         `json:"diagnostic_requested"`
	EntityState                struct {
	} `json:"entity_state"`
	FanConfigurationState interface{} `json:"fan_configuration_state"`
	Fans                  string      `json:"fans"`
	Interfaces            struct {
	} `json:"interfaces"`
	Leds             string      `json:"leds"`
	MacsRemaining    int         `json:"macs_remaining"`
	Name             string      `json:"name"`
	NextMacAddress   string      `json:"next_mac_address"`
	PacGbpInitStatus string      `json:"pac_gbp_init_status"`
	PartNumberCfg    interface{} `json:"part_number_cfg"`
	PoePower         struct {
		AvailablePower              int `json:"available_power"`
		FailoverPower               int `json:"failover_power"`
		PowerStatusRefreshTimestamp int `json:"power_status_refresh_timestamp"`
		PowerStatusUpdateTimestamp  int `json:"power_status_update_timestamp"`
		RedundantPower              int `json:"redundant_power"`
	} `json:"poe_power"`
	PolicyInitStatus string      `json:"policy_init_status"`
	PowerConsumed    interface{} `json:"power_consumed"`
	PowerSupplies    string      `json:"power_supplies"`
	ProductInfo      struct {
		BaseMacAddress     string `json:"base_mac_address"`
		DeviceVersion      string `json:"device_version"`
		Instance           string `json:"instance"`
		NumberOfMacs       string `json:"number_of_macs"`
		PartNumber         string `json:"part_number"`
		ProductDescription string `json:"product_description"`
		ProductName        string `json:"product_name"`
		SerialNumber       string `json:"serial_number"`
		Vendor             string `json:"vendor"`
	} `json:"product_info"`
	PsuRedundancyOper string `json:"psu_redundancy_oper"`
	PsuRedundancySet  string `json:"psu_redundancy_set"`
	RebootStatistics  struct {
		Configuration int `json:"configuration"`
		Error         int `json:"error"`
		Hotswap       int `json:"hotswap"`
		Isp           int `json:"isp"`
		Thermal       int `json:"thermal"`
		User          int `json:"user"`
	} `json:"reboot_statistics"`
	ResetsPerformed struct {
	} `json:"resets_performed"`
	ResetsRequested struct {
	} `json:"resets_requested"`
	ResourceCapacity struct {
	} `json:"resource_capacity"`
	ResourceReservationPerFeature struct {
	} `json:"resource_reservation_per_feature"`
	ResourceUnreserved struct {
	} `json:"resource_unreserved"`
	ResourceUtilization struct {
	} `json:"resource_utilization"`
	ResourceUtilizationPerFeature struct {
	} `json:"resource_utilization_per_feature"`
	ResourceWidthPerFeature struct {
	} `json:"resource_width_per_feature"`
	Selftest struct {
		Status string `json:"status"`
	} `json:"selftest"`
	SelftestDisable bool `json:"selftest_disable"`
	SoftwareImages  struct {
	} `json:"software_images"`
	State   string `json:"state"`
	Storage struct {
	} `json:"storage"`
	TempSensors  string `json:"temp_sensors"`
	ThermalState string `json:"thermal_state"`
	Type         string `json:"type"`
	UsbStatus    string `json:"usb_status"`
}

Chassis represents the result from the chassis subsystem on v10.09.

type Client

type Client struct {
	// Connection properties.
	Hostname string `json:"hostname"`
	Username string `json:"username"`
	Password string `json:"password"`
	Version  string `json:"version"`
	// Generated after Connect
	Cookie *http.Cookie `json:"cookie"`
	// HTTP transport options.  Note that the VerifyCertificate setting is
	// only used if you do not specify a HTTP transport yourself.
	VerifyCertificate bool            `json:"verify_certificate"`
	Transport         *http.Transport `json:"-"`
}

func Connect

func Connect(c *Client) (*Client, error)

Connect creates connection to given Client object.

func (*Client) GetChassis

func (c *Client) GetChassis(id int) (Chassis, error)

GetChassis returns the chassis information by the given id. The first chassis has id 1.

func (*Client) Logout

func (c *Client) Logout() error

Logout calls the logout endpoint to clear the session.

type Interface

type Interface struct {

	// Connection properties.
	Name             string                 `json:"name"`
	Description      string                 `json:"description"`
	AdminState       string                 `json:"admin"`
	InterfaceDetails map[string]interface{} `json:"details"`
	// contains filtered or unexported fields
}

func (*Interface) Create

func (i *Interface) Create(c *Client) error

Create performs POST to create Interface configuration on the given Client object.

func (*Interface) Delete

func (i *Interface) Delete(c *Client) error

Delete performs PUT to remove/default Interface configuration from the given Client object.

func (*Interface) Get

func (i *Interface) Get(c *Client) error

Get performs GET to retrieve Interface configuration from the given Client object.

func (*Interface) GetStatus

func (i *Interface) GetStatus() bool

GetStatus returns True if Interface exists on Client object or False if not.

func (*Interface) Update

func (i *Interface) Update(c *Client) error

Update performs PATCH to update Interface configuration on the given Client object.

type L2Interface

type L2Interface struct {

	// Connection properties.
	Interface        Interface              `json:"interface"`
	Description      string                 `json:"description"`
	VlanMode         string                 `json:"vlan_mode"`
	VlanIds          []interface{}          `json:"vlan_ids"`
	VlanTag          int                    `json:"vlan_tag"`
	TrunkAllowedAll  bool                   `json:"trunk_allowed_all"`
	NativeVlanTag    bool                   `json:"native_vlan_tag"`
	InterfaceDetails map[string]interface{} `json:"details"`
	// contains filtered or unexported fields
}

func (*L2Interface) Create

func (i *L2Interface) Create(c *Client) error

Create performs PATCH to update L2Interface configuration on the given Client object.

func (*L2Interface) Delete

func (i *L2Interface) Delete(c *Client) error

Delete performs PUT to remove/default L2Interface configuration from the given Client object.

func (*L2Interface) Get

func (i *L2Interface) Get(c *Client) error

Get performs GET to retrieve L2Interface configuration from the given Client object.

func (*L2Interface) GetStatus

func (i *L2Interface) GetStatus() bool

GetStatus returns True if L2Interface exists on Client object or False if not.

func (*L2Interface) Update

func (i *L2Interface) Update(c *Client, use_put bool) error

Update performs PATCH or PUT to update L2Interface configuration on the given Client object.

type RequestError

type RequestError struct {
	StatusCode string

	Err error
}

RequestError is a custom error struct

func (*RequestError) Error

func (r *RequestError) Error() string

Error returns a custom error string

type Vlan

type Vlan struct {

	// Connection properties.
	VlanId      int                    `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	AdminState  string                 `json:"admin_state"`
	VlanDetails map[string]interface{} `json:"details"`
	// contains filtered or unexported fields
}

func (*Vlan) Create

func (v *Vlan) Create(c *Client) error

Create performs POST to create VLAN configuration on the given Client object.

func (*Vlan) Delete

func (v *Vlan) Delete(c *Client) error

Delete performs DELETE to remove VLAN configuration from the given Client object.

func (*Vlan) Get

func (v *Vlan) Get(c *Client) error

Get performs GET to retrieve VLAN configuration for the given Client object.

func (*Vlan) GetStatus

func (v *Vlan) GetStatus() bool

GetStatus returns True if VLAN exists on Client object or False if not.

func (*Vlan) GetURI

func (v *Vlan) GetURI() string

GetURI returns URI of VLAN.

func (*Vlan) Update

func (v *Vlan) Update(c *Client) error

Update performs PATCH to update VLAN configuration on the given Client object.

Jump to

Keyboard shortcuts

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