netbox-community / devicetype-library

A collection of community-sourced DeviceType definitions for import to NetBox
Creative Commons Zero v1.0 Universal
884 stars 876 forks source link

DeviceType structure varies from that of go-netbox? #1884

Closed jacobsalmela closed 7 months ago

jacobsalmela commented 7 months ago

If I try to use go-netbox to import any of the devicetypes defined here, it cannot unmarshal them

For example, on a dell switch, manufacturer: Dell is a string, but in go-netbox, the manufacturer is a NestedManufacturer, not a simple string.

yaml: unmarshal errors:
  line 2: cannot unmarshal !!str `Dell` into netbox.NestedManufacturer
exit status 1

Which is correct?

Here is some sample code where I see the issue:

package main

import (
    "bytes"
    "fmt"
    "os"

    "github.com/netbox-community/go-netbox/v3"
    "gopkg.in/yaml.v3"
)

type MyType struct {
    netbox.DeviceType `yaml:",inline"`
    Custom            MyCustomThing `yaml:"my-custom-thing"`
}

type MyCustomThing string

func main() {
    // load yaml file
    f, err := os.ReadFile("../devicetype-library/device-types/Dell/PowerSwitch-S4048-ON.yaml")
    if err != nil {
        fmt.Printf("%+v\n", err)
        os.Exit(1)
    }
    r := bytes.NewReader(f)
    decoder := yaml.NewDecoder(r)
    mytype := MyType{}
    err = decoder.Decode(&mytype)
    if err != nil {
        fmt.Printf("%+v\n", err)
        os.Exit(1)
    }
    fmt.Printf("%+v\n", mytype.Manufacturer)
}
jacobsalmela commented 7 months ago

This seems more go-netbox related: https://github.com/netbox-community/go-netbox/issues/168