diff --git a/client_test.go b/client_test.go index 01502c4770..b80e00a04e 100644 --- a/client_test.go +++ b/client_test.go @@ -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, @@ -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, @@ -273,25 +346,26 @@ 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), } @@ -299,27 +373,10 @@ func testRCPowerPortIdentifier(n int) *RCPowerPortIdentifier { 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)}, } } diff --git a/dcim.go b/dcim.go index 520a5b3138..22fc5858bd 100644 --- a/dcim.go +++ b/dcim.go @@ -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 { diff --git a/dcim_consoleports.go b/dcim_consoleports.go new file mode 100644 index 0000000000..63791c2bce --- /dev/null +++ b/dcim_consoleports.go @@ -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"` +} diff --git a/dcim_devices.go b/dcim_devices.go index 8a25054d48..d7adcd2133 100644 --- a/dcim_devices.go +++ b/dcim_devices.go @@ -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"` diff --git a/dcim_interfaces.go b/dcim_interfaces.go new file mode 100644 index 0000000000..e1758e0f5e --- /dev/null +++ b/dcim_interfaces.go @@ -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"` +} diff --git a/dcim_poweroutlet.go b/dcim_poweroutlet.go new file mode 100644 index 0000000000..e75b708bd5 --- /dev/null +++ b/dcim_poweroutlet.go @@ -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"` +} diff --git a/dcim_powerports.go b/dcim_powerports.go new file mode 100644 index 0000000000..5e606263df --- /dev/null +++ b/dcim_powerports.go @@ -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"` +} diff --git a/dcim_related-connections.go b/dcim_related-connections.go index fcd425d395..1ea16da95f 100644 --- a/dcim_related-connections.go +++ b/dcim_related-connections.go @@ -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"` }