Skip to content

Commit

Permalink
dcim{,_related-connections}: update to support change from netbox-com…
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Liu committed Aug 2, 2016
1 parent f2becec commit 6097704
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 74 deletions.
125 changes: 91 additions & 34 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,53 @@ func testAggregate(family Family, n int) *Aggregate {
}
}

func testConsolePort(n int) *ConsolePort {
return &ConsolePort{
ID: n,
Device: testDeviceIdentifier(n),
Name: fmt.Sprintf("deviceport %d", n),
CSPort: testConsoleServerPort(n),
ConnectionStatus: true,
}
}

func testConsolePortIdentifier(n int) *ConsolePortIdentifier {
return &ConsolePortIdentifier{
Device: fmt.Sprintf("device %d", n),
Name: fmt.Sprintf("rc console port %d", n),
Port: fmt.Sprintf("port %d", n),
}
}

func testConsoleServerPort(n int) *ConsoleServerPort {
return &ConsoleServerPort{
ID: n,
Device: testDeviceIdentifier(n),
Name: fmt.Sprintf("consoleserverport %d", n),
}
}

func testDevice(n int) *Device {
return &Device{
ID: n,
Name: fmt.Sprintf("device %d", n),
DisplayName: fmt.Sprintf("Device %d", n),
DeviceType: testDeviceTypeIdentifier(n),
DeviceRole: testSimpleIdentifier(n),
Platform: testSimpleIdentifier(n),
Serial: fmt.Sprintf("relatedconnection%d", n),
Rack: testRackIdentifier(n),
Position: n,
Face: n,
ParentDevice: testDeviceIdentifier(n),
Status: true,
PrimaryIP: testIPAddressIdentifier(FamilyIPv4, n),
PrimaryIP4: testIPAddressIdentifier(FamilyIPv4, n),
PrimaryIP6: testIPAddressIdentifier(FamilyIPv6, n),
Comments: "",
}
}

func testDeviceIdentifier(n int) *DeviceIdentifier {
return &DeviceIdentifier{
ID: n,
Expand All @@ -188,6 +235,32 @@ func testDeviceTypeIdentifier(n int) *DeviceTypeIdentifier {
}
}

func testInterface(n int) *Interface {
return &Interface{
ID: n,
Name: fmt.Sprintf("interface %d", n),
FormFactor: fmt.Sprintf("form factor %d", n),
MacAddress: fmt.Sprintf("f4:9d:82:9e:34:c%d", n),
MgmtOnly: true,
Description: fmt.Sprintf("Description %d", n),
IsConnected: true,
ConnectedInterface: testInterfaceDetail(n),
}
}

func testInterfaceDetail(n int) *InterfaceDetail {
return &InterfaceDetail{
ID: n,
Device: testDeviceIdentifier(n),
Name: fmt.Sprintf("interfacedetail %d", n),
FormFactor: fmt.Sprintf("form factor %d", n),
MacAddress: fmt.Sprintf("f4:9d:82:9e:34:c%d", n),
MgmtOnly: true,
Description: fmt.Sprintf("Description %d", n),
IsConnected: true,
}
}

func testInterfaceIdentifier(n int) *InterfaceIdentifier {
return &InterfaceIdentifier{
ID: n,
Expand Down Expand Up @@ -273,53 +346,37 @@ func testRackIdentifier(n int) *RackIdentifier {
}
}

func testRCConsolePortIdentifier(n int) *RCConsolePortIdentifier {
return &RCConsolePortIdentifier{
ConsoleServer: fmt.Sprintf("console server %d", n),
Name: fmt.Sprintf("rc console port %d", n),
Port: fmt.Sprintf("port %d", n),
func testPowerOutlet(n int) *PowerOutletIdentifier {
return &PowerOutletIdentifier{
ID: n,
Device: testDeviceIdentifier(n),
Name: fmt.Sprintf("poweroutlet %d", n),
}
}

func testRCInterfaceIdentifier(n int) *RCInterfaceIdentifier {
return &RCInterfaceIdentifier{
Device: fmt.Sprintf("device %d", n),
Interface: fmt.Sprintf("interface %d", n),
Name: fmt.Sprintf("rc interface %d", n),
func testPowerPort(n int) *PowerPort {
return &PowerPort{
ID: n,
Name: fmt.Sprintf("powerport %d", n),
PowerOutlet: testPowerOutlet(n),
ConnectionStatus: true,
}
}

func testRCPowerPortIdentifier(n int) *RCPowerPortIdentifier {
return &RCPowerPortIdentifier{
PDU: fmt.Sprintf("pdu %d", n),
func testPowerPortIdentifier(n int) *PowerPortIdentifier {
return &PowerPortIdentifier{
Device: fmt.Sprintf("device %d", n),
Name: fmt.Sprintf("rc power port %d", n),
Outlet: fmt.Sprintf("outlet %d", n),
}
}

func testRelatedConnection(n int) *RelatedConnection {
return &RelatedConnection{
Device: &Device{
ID: n,
Name: fmt.Sprintf("device %d", n),
DisplayName: fmt.Sprintf("Device %d", n),
DeviceType: testDeviceTypeIdentifier(n),
DeviceRole: testSimpleIdentifier(n),
Platform: testSimpleIdentifier(n),
Serial: fmt.Sprintf("relatedconnection%d", n),
Rack: testRackIdentifier(n),
Position: n,
Face: n,
ParentDevice: testDeviceIdentifier(n),
Status: true,
PrimaryIP: testIPAddressIdentifier(FamilyIPv4, n),
PrimaryIP4: testIPAddressIdentifier(FamilyIPv4, n),
PrimaryIP6: testIPAddressIdentifier(FamilyIPv6, n),
Comments: "",
},
ConsolePorts: []*RCConsolePortIdentifier{testRCConsolePortIdentifier(n)},
Interfaces: []*RCInterfaceIdentifier{testRCInterfaceIdentifier(n)},
PowerPorts: []*RCPowerPortIdentifier{testRCPowerPortIdentifier(n)},
Device: testDevice(n),
ConsolePorts: []*ConsolePort{testConsolePort(n)},
Interfaces: []*Interface{testInterface(n)},
PowerPorts: []*PowerPort{testPowerPort(n)},
}
}

Expand Down
21 changes: 0 additions & 21 deletions dcim.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ type DCIMService struct {
c *Client
}

// An InterfaceIdentifier is a reduced version of an Interface, returned as a
// nested object in some top-level objects. It contains information which can
// be used in subsequent API calls to identify and retrieve a full Interface.
//
// At this time, the Interface type is not implemented.
type InterfaceIdentifier struct {
ID int `json:"id"`
Device *DeviceIdentifier `json:"device"`
Name string `json:"name"`
}

// A DeviceIdentifier is a reduced version of a Device, returned as a nested
// object in some top-level objects. It contains information which can
// be used in subsequent API calls to identify and retrieve a full Device.
//
// At this time, the Device type is not implemented.
type DeviceIdentifier struct {
ID int `json:"id"`
Name string `json:"name"`
}

// SimpleIdentifier represents a simple object that consists of only an ID,
// name, and slug.
type SimpleIdentifier struct {
Expand Down
31 changes: 31 additions & 0 deletions dcim_consoleports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2016 The go-netbox Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package netbox

// ConsolePort represents a console port object.
type ConsolePort struct {
ID int `json:"id"`
Device *DeviceIdentifier `json:"device"`
Name string `json:"name"`
CSPort *ConsoleServerPort `json:"cs_port"`
ConnectionStatus bool `json:"connection_status"`
}

// ConsoleServerPort represents a console server port object.
type ConsoleServerPort struct {
ID int `json:"id"`
Device *DeviceIdentifier `json:"device"`
Name string `json:"name"`
}
8 changes: 8 additions & 0 deletions dcim_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ type Device struct {
Comments string `json:"comments"`
}

// A DeviceIdentifier is a reduced version of a Device, returned as a nested
// object in some top-level objects. It contains information which can
// be used in subsequent API calls to identify and retrieve a full Device.
type DeviceIdentifier struct {
ID int `json:"id"`
Name string `json:"name"`
}

// A DeviceTypeIdentifier indicates the device type of a network device.
type DeviceTypeIdentifier struct {
ID int `json:"id"`
Expand Down
48 changes: 48 additions & 0 deletions dcim_interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2016 The go-netbox Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package netbox

// Interface represents an interface object.
type Interface struct {
ID int `json:"id"`
Name string `json:"name"`
FormFactor string `json:"form_factor"`
MacAddress string `json:"mac_address"`
MgmtOnly bool `json:"mgmt_only"`
Description string `json:"description"`
IsConnected bool `json:"is_connected"`
ConnectedInterface *InterfaceDetail `json:"connected_interface"`
}

// InterfaceDetail represents an interface-detail object.
type InterfaceDetail struct {
ID int `json:"id"`
Device *DeviceIdentifier `json:"device"`
Name string `json:"name"`
FormFactor string `json:"form_factor"`
MacAddress string `json:"mac_address"`
MgmtOnly bool `json:"mgmt_only"`
Description string `json:"description"`
IsConnected bool `json:"is_connected"`
}

// An InterfaceIdentifier is a reduced version of an Interface, returned as a
// nested object in some top-level objects. It contains information which can
// be used in subsequent API calls to identify and retrieve a full Interface.
type InterfaceIdentifier struct {
ID int `json:"id"`
Device *DeviceIdentifier `json:"device"`
Name string `json:"name"`
}
22 changes: 22 additions & 0 deletions dcim_poweroutlet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 The go-netbox Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package netbox

// PowerOutletIdentifier represents a reduced version of a power outlet object.
type PowerOutletIdentifier struct {
ID int `json:"id"`
Device *DeviceIdentifier `json:"device"`
Name string `json:"name"`
}
23 changes: 23 additions & 0 deletions dcim_powerports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2016 The go-netbox Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package netbox

// PowerPort represents a power port object.
type PowerPort struct {
ID int `json:"id"`
Name string `json:"name"`
PowerOutlet *PowerOutletIdentifier `json:"power_outlet"`
ConnectionStatus bool `json:"connection_status"`
}
31 changes: 12 additions & 19 deletions dcim_related-connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@ import (
// RelatedConnection represents components that have a related peer-device and
// peer-interface.
type RelatedConnection struct {
Device *Device `json:"device"`
ConsolePorts []*RCConsolePortIdentifier `json:"console-ports"`
Interfaces []*RCInterfaceIdentifier `json:"interfaces"`
PowerPorts []*RCPowerPortIdentifier `json:"power-ports"`
Device *Device `json:"device"`
ConsolePorts []*ConsolePort `json:"console-ports"`
Interfaces []*Interface `json:"interfaces"`
PowerPorts []*PowerPort `json:"power-ports"`
}

// RCConsolePortIdentifier represents a reduced version of a console port.
type RCConsolePortIdentifier struct {
ConsoleServer string `json:"console-server"`
Name string `json:"name"`
Port string `json:"port"`
}

// RCInterfaceIdentifier represents a reduced version of a device interface.
type RCInterfaceIdentifier struct {
Device string `json:"device"`
Interface string `json:"interface"`
Name string `json:"name"`
// ConsolePortIdentifier represents a reduced version of a console port.
type ConsolePortIdentifier struct {
Device string `json:"device"`
Name string `json:"name"`
Port string `json:"port"`
}

// RCPowerPortIdentifier represents a reduced version of a single power port.
type RCPowerPortIdentifier struct {
PDU string `json:"pdu"`
// PowerPortIdentifier represents a reduced version of a single power port.
type PowerPortIdentifier struct {
Device string `json:"device"`
Name string `json:"name"`
Outlet string `json:"outlet"`
}
Expand Down

0 comments on commit 6097704

Please sign in to comment.