aboutsummaryrefslogtreecommitdiff
path: root/clients/netbox/model.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/netbox/model.go')
-rw-r--r--clients/netbox/model.go73
1 files changed, 72 insertions, 1 deletions
diff --git a/clients/netbox/model.go b/clients/netbox/model.go
index 40c4aa6..be4767d 100644
--- a/clients/netbox/model.go
+++ b/clients/netbox/model.go
@@ -1,6 +1,10 @@
1package netbox 1package netbox
2 2
3import "fmt" 3import (
4 "encoding/json"
5 "fmt"
6 "net"
7)
4 8
5type ApiError struct { 9type ApiError struct {
6 Status int 10 Status int
@@ -85,3 +89,70 @@ type Prefix struct {
85 Tags []*Tag `json:"tags"` 89 Tags []*Tag `json:"tags"`
86 CustomFields map[string]interface{} `json:"custom_fields"` 90 CustomFields map[string]interface{} `json:"custom_fields"`
87} 91}
92
93type ServiceList struct {
94 Count int `json:"count"`
95 Next string `json:"next"`
96 Previous string `json:"previous"`
97 Results []*Service `json:"results"`
98}
99
100type ServiceProtocol struct {
101 Value string `json:"value"`
102 Label string `json:"label"`
103}
104
105type DeviceOrVM struct {
106 ID int `json:"id"`
107 Url string `json:"url"`
108 Name string `json:"name"`
109 Display string `json:"display"`
110}
111
112type ServiceIPAddress struct {
113 ID int `json:"id"`
114 Url string `json:"url"`
115 Display string `json:"display"`
116 Family int `json:"family"`
117 Address net.IP
118 Network *net.IPNet
119}
120
121func (a *ServiceIPAddress) UnmarshalJSON(d []byte) error {
122 type Alias ServiceIPAddress
123 v := &struct {
124 *Alias
125 Address string `json:"address"`
126 }{Alias: (*Alias)(a)}
127
128 if err := json.Unmarshal(d, v); err != nil {
129 return err
130 }
131
132 i, n, err := net.ParseCIDR(v.Address)
133 if err != nil {
134 return err
135 }
136
137 a.Address = i
138 a.Network = n
139
140 return nil
141}
142
143type Service struct {
144 ID int `json:"id" mapstructure:"id"`
145 Url string `json:"url" mapstructure:"url"`
146 Name string `json:"name" mapstructure:"name"`
147 Display string `json:"display" mapstructure:"display"`
148 Device *DeviceOrVM `json:"device" mapstructure:"device"`
149 VirtualMachine *DeviceOrVM `json:"virtual_machine" mapstructure:"virtual_machine"`
150 Ports []int `json:"ports" mapstructure:"ports"`
151 Protocol *ServiceProtocol `json:"protocol" mapstructure:"protocol"`
152 Addresses []*ServiceIPAddress `json:"ipaddresses" mapstructure:"ipaddresses"`
153 Description string `json:"description" mapstructure:"description"`
154 Created string `json:"created" mapstructure:"created"`
155 LastUpdated string `json:"last_updated" mapstructure:"last_updated"`
156 Tags []*Tag `json:"tags" mapstructure:"tags"`
157 CustomFields map[string]interface{} `json:"custom_fields" mapstructure:"custom_fields"`
158}