Skip to content

Commit

Permalink
Merge pull request #12 from Subreptivus/master
Browse files Browse the repository at this point in the history
Added operations for Vlan and Physical Interfaces
  • Loading branch information
sameesin authored Jul 28, 2021
2 parents b6b4ad9 + 7080a53 commit 6aaa5d9
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 36 deletions.
95 changes: 70 additions & 25 deletions ciscoasa/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,41 @@ type interfaceService struct {
*Client
}

// IPAddress represents an IPv4 address.
// SlaTracking represents an SlaTracking Settings.
type SlaTracking struct {
SlaId int `json:"slaId"`
TrackedIP string `json:"trackedIP"`
FrequencyInSeconds int `json:"frequencyInSeconds"`
DataSizeInBytes int `json:"dataSizeInBytes"`
ThresholdInMilliseconds int `json:"thresholdInMilliseconds"`
ToS int `json:"ToS"`
TimeoutInMilliseconds int `json:"timeoutInMilliseconds"`
NumPackets int `json:"numPackets"`
}

// DhcpClient represents an DHCP Settings.
type DhcpClient struct {
SetDefaultRoute bool `json:"setDefaultRoute"`
Metric int `json:"metric"`
PrimaryTrackId int `json:"primaryTrackId"`
TrackingEnabled bool `json:"trackingEnabled"`
SlaTrackingSettings *SlaTracking `json:"slaTrackingSettings"`
}

// Address represents a static IPv4/IPv6 address settings.
type Address struct {
Kind string `json:"kind"`
Value string `json:"value"`
}

// IPAddress represents an IP address settings.
type IPAddress struct {
IP struct {
Kind string `json:"kind"`
Value string `json:"value"`
} `json:"ip"`
NetMask struct {
Kind string `json:"kind"`
Value string `json:"value"`
} `json:"netMask"`
Kind string `json:"kind"`
IP *Address `json:"ip,omitempty"`
NetMask *Address `json:"netMask,omitempty"`
Kind string `json:"kind"`
DhcpOptionUsingMac bool `json:"dhcpOptionUsingMac,omitempty"`
DhcpBroadcast bool `json:"dhcpBroadcast,omitempty"`
DhcpClient *DhcpClient `json:"dhcpClient,omitempty"`
}

// UnmarshalJSON implements json.Unmarshaler interface.
Expand All @@ -56,23 +80,44 @@ func (ip *IPAddress) String() string {
return ip.IP.Value + "/" + bitsize
}

// nDiscoveryPrefix represents an nDiscoveryPrefix list.
type NDiscoveryPrefix struct {
OffLink bool `json:"offLink"`
NoAdvertise bool `json:"noAdvertise"`
PreferredLifetime int `json:"preferredLifetime"`
ValidLifetime int `json:"validLifetime"`
HasDuration bool `json:"hasDuration"`
DefaultPrefix bool `json:"defaultPrefix"`
Kind string `json:"kind"`
}

// Ipv6Address represents an Ipv6Address.
type Ipv6Address struct {
PrefixLength int `json:"prefixLength,omitempty"`
Standby *Address `json:"standby,omitempty"`
Address *Address `json:"address,omitempty"`
// IsEUI64 bool `json:"isEUI64"`
Kind string `json:"kind"`
}

// IPv6Info represents an IPv6 address.
type IPv6Info struct {
Enabled bool `json:"enabled"`
AutoConfig bool `json:"autoConfig"`
EnforceEUI64 bool `json:"enforceEUI64"`
ManagedAddressConfig bool `json:"managedAddressConfig"`
NsInterval int `json:"nsInterval"`
DadAttempts int `json:"dadAttempts"`
NDiscoveryPrefixList []string `json:"nDiscoveryPrefixList"`
OtherStatefulConfig bool `json:"otherStatefulConfig"`
RouterAdvertInterval int `json:"routerAdvertInterval"`
RouterAdvertIntervalUnit string `json:"routerAdvertIntervalUnit"`
RouterAdvertLifetime int `json:"routerAdvertLifetime"`
SuppressRouterAdvert bool `json:"suppressRouterAdvert"`
ReachableTime int `json:"reachableTime"`
Ipv6Addresses []string `json:"ipv6Addresses"`
Kind string `json:"kind"`
Enabled bool `json:"enabled"`
AutoConfig bool `json:"autoConfig"`
EnforceEUI64 bool `json:"enforceEUI64"`
ManagedAddressConfig bool `json:"managedAddressConfig"`
NsInterval int `json:"nsInterval"`
DadAttempts int `json:"dadAttempts"`
NDiscoveryPrefixList []*NDiscoveryPrefix `json:"nDiscoveryPrefixList,omitempty"`
OtherStatefulConfig bool `json:"otherStatefulConfig"`
RouterAdvertInterval int `json:"routerAdvertInterval"`
RouterAdvertIntervalUnit string `json:"routerAdvertIntervalUnit"`
RouterAdvertLifetime int `json:"routerAdvertLifetime"`
SuppressRouterAdvert bool `json:"suppressRouterAdvert"`
ReachableTime int `json:"reachableTime"`
LinkLocalAddress *Ipv6Address `json:"linkLocalAddress,omitempty"`
Ipv6Addresses []*Ipv6Address `json:"ipv6Addresses,omitempty"`
Kind string `json:"kind"`
}

// UnmarshalJSON implements json.Unmarshaler interface.
Expand Down
153 changes: 147 additions & 6 deletions ciscoasa/interfaces_physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type PhysicalInterface struct {
InterfaceDesc string `json:"interfaceDesc"`
ChannelGroupID string `json:"channelGroupID"`
ChannelGroupMode string `json:"channelGroupMode"`
Duplex string `json:"duplex"`
Duplex string `json:"duplex,omitempty"`
FlowcontrolOn bool `json:"flowcontrolOn"`
FlowcontrolHigh int `json:"flowcontrolHigh"`
FlowcontrolLow int `json:"flowcontrolLow"`
Expand All @@ -47,12 +47,12 @@ type PhysicalInterface struct {
Name string `json:"name"`
SecurityLevel int `json:"securityLevel"`
Shutdown bool `json:"shutdown"`
Speed string `json:"speed"`
IPAddress *IPAddress `json:"ipAddress"`
Ipv6Info *IPv6Info `json:"ipv6Info"`
Speed string `json:"speed,omitempty"`
IPAddress *IPAddress `json:"ipAddress,omitempty"`
Ipv6Info *IPv6Info `json:"ipv6Info,omitempty"`
Kind string `json:"kind"`
ObjectID string `json:"objectId"`
SelfLink string `json:"selfLink"`
ObjectID string `json:"objectId,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
}

// ListPhysicalInterfaces returns a collection of interfaces.
Expand Down Expand Up @@ -88,3 +88,144 @@ func (s *interfaceService) ListPhysicalInterfaces() (*PhysicalInterfaceCollectio

return result, nil
}

// UpdatePhysicalInterface updates a physical interface
// as there is no way of creating a physical interface.
func (s *interfaceService) UpdatePhysicalInterface(
activeMacAddress string,
forwardTrafficCX bool,
forwardTrafficSFR bool,
hardwareID string,
interfaceDesc string,
ipAddress *IPAddress,
ipv6Info *IPv6Info,
kind string,
managementOnly bool,
mtu int,
name string,
objectID string,
securityLevel int,
shutdown bool,
standByMacAddress string,
) (string, error) {
u := fmt.Sprintf("/api/interfaces/physical/%s", objectID)

duplex := "auto"
speed := "auto"
if kind == "object#TenGigInterface" {
duplex = ""
speed = ""
}

r := &PhysicalInterface{
ActiveMacAddress: activeMacAddress,
ChannelGroupID: "",
ChannelGroupMode: "active",
Duplex: duplex,
FlowcontrolHigh: -1,
FlowcontrolLow: -1,
FlowcontrolOn: false,
FlowcontrolPeriod: -1,
ForwardTrafficCX: forwardTrafficCX,
ForwardTrafficSFR: forwardTrafficSFR,
HardwareID: hardwareID,
InterfaceDesc: interfaceDesc,
IPAddress: ipAddress,
Ipv6Info: ipv6Info,
Kind: kind,
LacpPriority: -1,
ManagementOnly: managementOnly,
Mtu: mtu,
Name: name,
ObjectID: objectID,
SecurityLevel: securityLevel,
Shutdown: shutdown,
Speed: speed,
StandByMacAddress: standByMacAddress,
}

req, err := s.newRequest("PUT", u, r)
if err != nil {
return "", err
}

resp, err := s.do(req, nil)
if err != nil {
return "", err
}

return idFromResponse(resp)
}

// GetPhysicalInterface retrieves a physical interface.
func (s *interfaceService) GetPhysicalInterface(objectID string) (*PhysicalInterface, error) {
u := fmt.Sprintf("/api/interfaces/physical/%s", objectID)

req, err := s.newRequest("GET", u, nil)
if err != nil {
return nil, err
}

r := &PhysicalInterface{}
_, err = s.do(req, r)

return r, err
}

// DeletePhysicalInterface sets values to defaults
// as there is no way of deletion a physical interface.
func (s *interfaceService) DeletePhysicalInterface(
hardwareID string,
kind string,
objectID string,
) error {
u := fmt.Sprintf("/api/interfaces/physical/%s", objectID)

duplex := "auto"
speed := "auto"
if kind == "object#TenGigInterface" {
duplex = ""
speed = ""
}

r := &PhysicalInterface{
ActiveMacAddress: "",
ChannelGroupID: "",
ChannelGroupMode: "active",
Duplex: duplex,
FlowcontrolHigh: -1,
FlowcontrolLow: -1,
FlowcontrolOn: false,
FlowcontrolPeriod: -1,
ForwardTrafficCX: false,
ForwardTrafficSFR: false,
HardwareID: hardwareID,
InterfaceDesc: "",
IPAddress: nil,
Ipv6Info: nil,
Kind: kind,
LacpPriority: -1,
ManagementOnly: false,
Mtu: 1500,
Name: "",
SecurityLevel: -1,
Shutdown: false,
Speed: speed,
StandByMacAddress: "",
}

req, err := s.newRequest("PUT", u, r)
if err != nil {
return err
}

resp, err := s.do(req, nil)
if err != nil {
return err
}

err = checkResponse(resp)

return err

}
Loading

0 comments on commit 6aaa5d9

Please sign in to comment.