package unipede import ( "fmt" "net/http" "net/url" ) type ( UpDeviceVlans struct { Count int `json:"count" bson:"count"` Errors []Error `json:"errors" bson:"errors"` Items []UpDeviceVlan `json:"items" bson:"items"` Links map[string]Links `json:"links" bson:"links"` } UpDeviceVlan struct { Created string `json:"created" bson:"created"` Id int `json:"id" bson:"id"` Name string `json:"name" bson:"name"` Protocol string `json:"protocol" bson:"protocol"` Root string `json:"root" bson:"root"` Status string `json:"status" bson:"status"` UpDeviceId int `json:"up_device_id" bson:"up_device_id"` Updated string `json:"updated" bson:"updated"` Vlan int `json:"vlan" bson:"vlan"` } DeviceVlanPortViews struct { Count int `json:"count" bson:"count"` Errors []Error `json:"errors" bson:"errors"` Items []DeviceVlanPortView `json:"items" bson:"items"` Links map[string]Links `json:"links" bson:"links"` } DeviceVlanPortView struct { AccessVlan int `json:"access_vlan" bson:"access_vlan"` Admin string `json:"admin" bson:"admin"` Bia int `json:"bia" bson:"bia"` ConfiguredDuplex string `json:"configured_duplex" bson:"configured_duplex"` ConfiguredSpeed string `json:"configured_speed" bson:"configured_speed"` CoreAccount int `json:"core_account" bson:"core_account"` CoreDevice int `json:"core_device" bson:"core_device"` Cost int `json:"cost" bson:"cost"` Description string `json:"description" bson:"description"` Direction string `json:"direction" bson:"direction"` Duplex string `json:"duplex" bson:"duplex"` EEE bool `json:"eee" bson:"eee"` FeAggregatedTo int `json:"fe_aggregated_to" bson:"fe_aggregated_to"` FeInterface int `json:"fe_interface" bson:"fe_interface"` FePort int `json:"fe_port" bson:"fe_port"` HasConnector bool `json:"has_connector" bson:"has_connector"` Interface string `json:"interface" bson:"interface"` Link string `json:"link" bson:"link"` LocalHostname string `json:"local_hostname" bson:"local_hostname"` LocalInterface string `json:"local_interface" bson:"local_interface"` Mode string `json:"mode" bson:"mode"` Name string `json:"name" bson:"name"` NativeVlan int `json:"native_vlan" bson:"native_vlan"` PortID int `json:"port_id" bson:"port_id"` PortSecurity bool `json:"port_security" bson:"port_security"` PortType string `json:"port_type" bson:"port_type"` PortFast bool `json:"portfast" bson:"portfast"` PortFastTrunk bool `json:"portfast_trunk" bson:"portfast_trunk"` Priority int `json:"priority" bson:"priority"` RemoteDeviceID int `json:"remote_device_id" bson:"remote_device_id"` RemoteHostname string `json:"remote_hostname" bson:"remote_hostname"` RemoteInterface string `json:"remote_interface" bson:"remote_interface"` Root string `json:"root" bson:"root"` Shutdown bool `json:"shutdown" bson:"shutdown"` Speed string `json:"speed" bson:"speed"` Trunking bool `json:"trunking" bson:"trunking"` Type string `json:"type" bson:"type"` UpDeviceID int `json:"up_device_id" bson:"up_device_id"` UpDeviceVlanCreated string `json:"up_device_vlan_created" bson:"up_device_vlan_created"` UpDeviceVlanID int `json:"up_device_vlan_id" bson:"up_device_vlan_id"` UpDeviceVlanPortCreated string `json:"up_device_vlan_port_created" bson:"up_device_vlan_port_created"` UpDeviceVlanPortID int `json:"up_device_vlan_port_id" bson:"up_device_vlan_port_id"` UpDeviceVlanPortRole string `json:"up_device_vlan_port_role" bson:"up_device_vlan_port_role"` UpDeviceVlanPortStatus string `json:"up_device_vlan_port_status" bson:"up_device_vlan_port_status"` UpDeviceVlanPortUpdated string `json:"up_device_vlan_port_updated" bson:"up_device_vlan_port_updated"` UpDeviceVlanProtocol string `json:"up_device_vlan_protocol" bson:"up_device_vlan_protocol"` UpDeviceVlanStatus string `json:"up_device_vlan_status" bson:"up_device_vlan_status"` UpDeviceVlanUpdated string `json:"up_device_vlan_updated" bson:"up_device_vlan_updated"` UpInterfaceAssignmentCreated string `json:"up_interface_assignment_created" bson:"up_interface_assignment_created"` UpInterfaceAssignmentID int `json:"up_interface_assignment_id" bson:"up_interface_assignment_id"` UpInterfaceAssignmentUpdated string `json:"up_interface_assignment_updated" bson:"up_interface_assignment_updated"` UpInterfaceConfigCreated string `json:"up_interface_config_created" bson:"up_interface_config_created"` UpInterfaceConfigID int `json:"up_interface_config_id" bson:"up_interface_config_id"` UpInterfaceConfigUpdated string `json:"up_interface_config_updated" bson:"up_interface_config_updated"` UpInterfaceCreated string `json:"up_interface_created" bson:"up_interface_created"` UpInterfaceID int `json:"up_interface_id" bson:"up_interface_id"` UpInterfaceUpdated string `json:"up_interface_updated" bson:"up_interface_updated"` UpNeighborCreated string `json:"up_neighbor_created" bson:"up_neighbor_created"` UpNeighborID int `json:"up_neighbor_id" bson:"up_neighbor_id"` UpNeighborProtocol string `json:"up_neighbor_protocol" bson:"up_neighbor_protocol"` UpNeighborUpdated string `json:"up_neighbor_updated" bson:"up_neighbor_updated"` Vlan int `json:"vlan" bson:"vlan"` Vlans []int `json:"vlans" bson:"vlans"` } // VlanRoot defines the specific type we would have returned from the helper function // to get root bridge information in the DeviceVlanWithRoot method. VlanRoot struct { Vlan int `json:"vlan" bson:"vlan"` Device struct { Hostname string `json:"hostname" bson:"hostname"` } `json:"device" bson:"device"` } ) func (u *Client) UpDeviceVlans(switchName string, refresh *int, options ...*UnipedeOptions) (*UpDeviceVlans, error) { o := processOptions(refresh, nil, options...) req, err := u.newRequest(unipedeURL+"devices/"+switchName+"/UpDeviceVlan::Vlan", http.MethodGet, o, nil) if err != nil { return nil, err } swconf := new(UpDeviceVlans) _, err = u.do(req, o, swconf) return swconf, err } func (u *Client) DeviceVlanPortView(params url.Values, switchName string, refresh *int, options ...*UnipedeOptions) (DeviceVlanPortViews, error) { ret := new(DeviceVlanPortViews) o := processOptions(refresh, ¶ms, options...) req, err := u.newRequest(unipedeURL+"devices/"+switchName+"/device_vlan_port_view", http.MethodGet, o, nil) if err != nil { return *ret, err } _, err = u.do(req, o, ret) return *ret, err } // DeviceVlanWithRoot will return all the devices associated with a vlan id and a common root mac-address. This // is used to determine the root-bridge for a given vlan. func (u *Client) DeviceVlanWithRoot(vlanID int, root string, refresh *int) ([]VlanRoot, error) { o := processOptions(refresh, &url.Values{ "with": []string{"device"}, "filter": []string{fmt.Sprintf("vlan:=%d,root:=%s", vlanID, root)}, "columns": []string{"vlan,device.hostname"}, }) type resp struct { Count int `json:"count" bson:"count"` Data []VlanRoot `json:"data" bson:"data"` } req, err := u.newRequest(unipedeURL+"property/device_vlan", http.MethodGet, o, nil) if err != nil { return nil, err } retVal := new(resp) _, err = u.do(req, o, retVal) return retVal.Data, err }