/
device.go
347 lines (317 loc) · 12.6 KB
/
device.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// Code generated by entc, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent/dialect/sql"
"github.com/mrzack99s/netcoco/ent/device"
"github.com/mrzack99s/netcoco/ent/deviceplatform"
"github.com/mrzack99s/netcoco/ent/devicetype"
)
// Device is the model entity for the Device schema.
type Device struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// DeviceName holds the value of the "device_name" field.
DeviceName string `json:"device_name,omitempty"`
// DeviceHostname holds the value of the "device_hostname" field.
DeviceHostname string `json:"device_hostname,omitempty"`
// DeviceUsername holds the value of the "device_username" field.
DeviceUsername string `json:"device_username,omitempty"`
// DevicePassword holds the value of the "device_password" field.
DevicePassword string `json:"device_password,omitempty"`
// DeviceSecret holds the value of the "device_secret" field.
DeviceSecret string `json:"device_secret,omitempty"`
// DeviceSSHPort holds the value of the "device_ssh_port" field.
DeviceSSHPort int `json:"device_ssh_port,omitempty"`
// DeviceCommitConfig holds the value of the "device_commit_config" field.
DeviceCommitConfig bool `json:"device_commit_config,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the DeviceQuery when eager-loading is set.
Edges DeviceEdges `json:"edges"`
device_platform_platforms *int
device_type_types *int
}
// DeviceEdges holds the relations/edges for other nodes in the graph.
type DeviceEdges struct {
// InType holds the value of the in_type edge.
InType *DeviceType `json:"in_type,omitempty"`
// InPlatform holds the value of the in_platform edge.
InPlatform *DevicePlatform `json:"in_platform,omitempty"`
// Interfaces holds the value of the interfaces edge.
Interfaces []*NetInterface `json:"interfaces,omitempty"`
// IPStaticRouting holds the value of the ip_static_routing edge.
IPStaticRouting []*IPStaticRoutingTable `json:"ip_static_routing,omitempty"`
// PoInterfaces holds the value of the po_interfaces edge.
PoInterfaces []*PortChannelInterface `json:"po_interfaces,omitempty"`
// HaveIPAddresses holds the value of the have_ip_addresses edge.
HaveIPAddresses []*IPAddress `json:"have_ip_addresses,omitempty"`
// InTopology holds the value of the in_topology edge.
InTopology []*NetTopologyDeviceMap `json:"in_topology,omitempty"`
// StoreVlans holds the value of the store_vlans edge.
StoreVlans []*Vlan `json:"store_vlans,omitempty"`
// DeletedVlans holds the value of the deleted_vlans edge.
DeletedVlans []*DeletedVlanLog `json:"deleted_vlans,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [9]bool
}
// InTypeOrErr returns the InType value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e DeviceEdges) InTypeOrErr() (*DeviceType, error) {
if e.loadedTypes[0] {
if e.InType == nil {
// The edge in_type was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: devicetype.Label}
}
return e.InType, nil
}
return nil, &NotLoadedError{edge: "in_type"}
}
// InPlatformOrErr returns the InPlatform value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e DeviceEdges) InPlatformOrErr() (*DevicePlatform, error) {
if e.loadedTypes[1] {
if e.InPlatform == nil {
// The edge in_platform was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: deviceplatform.Label}
}
return e.InPlatform, nil
}
return nil, &NotLoadedError{edge: "in_platform"}
}
// InterfacesOrErr returns the Interfaces value or an error if the edge
// was not loaded in eager-loading.
func (e DeviceEdges) InterfacesOrErr() ([]*NetInterface, error) {
if e.loadedTypes[2] {
return e.Interfaces, nil
}
return nil, &NotLoadedError{edge: "interfaces"}
}
// IPStaticRoutingOrErr returns the IPStaticRouting value or an error if the edge
// was not loaded in eager-loading.
func (e DeviceEdges) IPStaticRoutingOrErr() ([]*IPStaticRoutingTable, error) {
if e.loadedTypes[3] {
return e.IPStaticRouting, nil
}
return nil, &NotLoadedError{edge: "ip_static_routing"}
}
// PoInterfacesOrErr returns the PoInterfaces value or an error if the edge
// was not loaded in eager-loading.
func (e DeviceEdges) PoInterfacesOrErr() ([]*PortChannelInterface, error) {
if e.loadedTypes[4] {
return e.PoInterfaces, nil
}
return nil, &NotLoadedError{edge: "po_interfaces"}
}
// HaveIPAddressesOrErr returns the HaveIPAddresses value or an error if the edge
// was not loaded in eager-loading.
func (e DeviceEdges) HaveIPAddressesOrErr() ([]*IPAddress, error) {
if e.loadedTypes[5] {
return e.HaveIPAddresses, nil
}
return nil, &NotLoadedError{edge: "have_ip_addresses"}
}
// InTopologyOrErr returns the InTopology value or an error if the edge
// was not loaded in eager-loading.
func (e DeviceEdges) InTopologyOrErr() ([]*NetTopologyDeviceMap, error) {
if e.loadedTypes[6] {
return e.InTopology, nil
}
return nil, &NotLoadedError{edge: "in_topology"}
}
// StoreVlansOrErr returns the StoreVlans value or an error if the edge
// was not loaded in eager-loading.
func (e DeviceEdges) StoreVlansOrErr() ([]*Vlan, error) {
if e.loadedTypes[7] {
return e.StoreVlans, nil
}
return nil, &NotLoadedError{edge: "store_vlans"}
}
// DeletedVlansOrErr returns the DeletedVlans value or an error if the edge
// was not loaded in eager-loading.
func (e DeviceEdges) DeletedVlansOrErr() ([]*DeletedVlanLog, error) {
if e.loadedTypes[8] {
return e.DeletedVlans, nil
}
return nil, &NotLoadedError{edge: "deleted_vlans"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Device) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case device.FieldDeviceCommitConfig:
values[i] = new(sql.NullBool)
case device.FieldID, device.FieldDeviceSSHPort:
values[i] = new(sql.NullInt64)
case device.FieldDeviceName, device.FieldDeviceHostname, device.FieldDeviceUsername, device.FieldDevicePassword, device.FieldDeviceSecret:
values[i] = new(sql.NullString)
case device.ForeignKeys[0]: // device_platform_platforms
values[i] = new(sql.NullInt64)
case device.ForeignKeys[1]: // device_type_types
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type Device", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Device fields.
func (d *Device) assignValues(columns []string, values []interface{}) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case device.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
d.ID = int(value.Int64)
case device.FieldDeviceName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field device_name", values[i])
} else if value.Valid {
d.DeviceName = value.String
}
case device.FieldDeviceHostname:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field device_hostname", values[i])
} else if value.Valid {
d.DeviceHostname = value.String
}
case device.FieldDeviceUsername:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field device_username", values[i])
} else if value.Valid {
d.DeviceUsername = value.String
}
case device.FieldDevicePassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field device_password", values[i])
} else if value.Valid {
d.DevicePassword = value.String
}
case device.FieldDeviceSecret:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field device_secret", values[i])
} else if value.Valid {
d.DeviceSecret = value.String
}
case device.FieldDeviceSSHPort:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field device_ssh_port", values[i])
} else if value.Valid {
d.DeviceSSHPort = int(value.Int64)
}
case device.FieldDeviceCommitConfig:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field device_commit_config", values[i])
} else if value.Valid {
d.DeviceCommitConfig = value.Bool
}
case device.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field device_platform_platforms", value)
} else if value.Valid {
d.device_platform_platforms = new(int)
*d.device_platform_platforms = int(value.Int64)
}
case device.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field device_type_types", value)
} else if value.Valid {
d.device_type_types = new(int)
*d.device_type_types = int(value.Int64)
}
}
}
return nil
}
// QueryInType queries the "in_type" edge of the Device entity.
func (d *Device) QueryInType() *DeviceTypeQuery {
return (&DeviceClient{config: d.config}).QueryInType(d)
}
// QueryInPlatform queries the "in_platform" edge of the Device entity.
func (d *Device) QueryInPlatform() *DevicePlatformQuery {
return (&DeviceClient{config: d.config}).QueryInPlatform(d)
}
// QueryInterfaces queries the "interfaces" edge of the Device entity.
func (d *Device) QueryInterfaces() *NetInterfaceQuery {
return (&DeviceClient{config: d.config}).QueryInterfaces(d)
}
// QueryIPStaticRouting queries the "ip_static_routing" edge of the Device entity.
func (d *Device) QueryIPStaticRouting() *IPStaticRoutingTableQuery {
return (&DeviceClient{config: d.config}).QueryIPStaticRouting(d)
}
// QueryPoInterfaces queries the "po_interfaces" edge of the Device entity.
func (d *Device) QueryPoInterfaces() *PortChannelInterfaceQuery {
return (&DeviceClient{config: d.config}).QueryPoInterfaces(d)
}
// QueryHaveIPAddresses queries the "have_ip_addresses" edge of the Device entity.
func (d *Device) QueryHaveIPAddresses() *IPAddressQuery {
return (&DeviceClient{config: d.config}).QueryHaveIPAddresses(d)
}
// QueryInTopology queries the "in_topology" edge of the Device entity.
func (d *Device) QueryInTopology() *NetTopologyDeviceMapQuery {
return (&DeviceClient{config: d.config}).QueryInTopology(d)
}
// QueryStoreVlans queries the "store_vlans" edge of the Device entity.
func (d *Device) QueryStoreVlans() *VlanQuery {
return (&DeviceClient{config: d.config}).QueryStoreVlans(d)
}
// QueryDeletedVlans queries the "deleted_vlans" edge of the Device entity.
func (d *Device) QueryDeletedVlans() *DeletedVlanLogQuery {
return (&DeviceClient{config: d.config}).QueryDeletedVlans(d)
}
// Update returns a builder for updating this Device.
// Note that you need to call Device.Unwrap() before calling this method if this Device
// was returned from a transaction, and the transaction was committed or rolled back.
func (d *Device) Update() *DeviceUpdateOne {
return (&DeviceClient{config: d.config}).UpdateOne(d)
}
// Unwrap unwraps the Device entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (d *Device) Unwrap() *Device {
tx, ok := d.config.driver.(*txDriver)
if !ok {
panic("ent: Device is not a transactional entity")
}
d.config.driver = tx.drv
return d
}
// String implements the fmt.Stringer.
func (d *Device) String() string {
var builder strings.Builder
builder.WriteString("Device(")
builder.WriteString(fmt.Sprintf("id=%v", d.ID))
builder.WriteString(", device_name=")
builder.WriteString(d.DeviceName)
builder.WriteString(", device_hostname=")
builder.WriteString(d.DeviceHostname)
builder.WriteString(", device_username=")
builder.WriteString(d.DeviceUsername)
builder.WriteString(", device_password=")
builder.WriteString(d.DevicePassword)
builder.WriteString(", device_secret=")
builder.WriteString(d.DeviceSecret)
builder.WriteString(", device_ssh_port=")
builder.WriteString(fmt.Sprintf("%v", d.DeviceSSHPort))
builder.WriteString(", device_commit_config=")
builder.WriteString(fmt.Sprintf("%v", d.DeviceCommitConfig))
builder.WriteByte(')')
return builder.String()
}
// Devices is a parsable slice of Device.
type Devices []*Device
func (d Devices) config(cfg config) {
for _i := range d {
d[_i].config = cfg
}
}