opsmill / infrahub

Infrahub - A new approach to Infrastructure Management
https://opsmill.com/
GNU Affero General Public License v3.0
148 stars 7 forks source link

feature: Be able to change MacAddress output #3687

Closed BeArchiTek closed 1 day ago

BeArchiTek commented 2 weeks ago

Component

API Server / GraphQL

Describe the Feature Request

As a user i would like to get different Mac Address format, the same way we are providing different output for IPHost / IPNetwork.

Describe the Use Case

If would like to force the "virtual" mac-address in a EVPN fabric. Base on the manufacturer (juniper or cisco) I would like to get the mac address in a different format

Additional Information

https://pypi.org/project/hwaddress/ or https://github.com/netaddr/netaddr/blob/master/netaddr/strategy/__init__.py

ogenstad commented 2 weeks ago

Do you have a name for the different formats? I don't know if there are any established names for this?

gmazoyer commented 2 weeks ago

We could probably follow the way Ansible names those formats.

BeArchiTek commented 2 weeks ago

The EUI-48 is an identifier that is formed by concatenating the 24-bit OUI with a 24-bit extension identifier that is assigned by the organization that purchased the OUI – the resulting identifier is generally represented as a set of octets separated by dashes (hexadecimal notation) or colons (bit-reversed notation) as in FF-FF-FF-FF-FF-FF or FF:FF:FF:FF:FF:FF, as a string of 6 bytes as in {FF,FF,FF,FF,FF,FF}, or as a base 16 number as in FFFFFFFFFFFF16

So something like :

ogenstad commented 2 weeks ago

Any thoughts about what the default format would be and also if we use upper or lowercase or if it's different depending on the format?

We should aim for accepting all variations as input and converting it into a standard format that's saved to the DB.

Not sure if it would be desirable to be able to select the default display format through Infrahub Config or if we should just choose a default one.

BeArchiTek commented 2 weeks ago

FF:FF:FF:FF:FF:FF

Should be the default and we accept the different methods

wvandeun commented 2 weeks ago

Some Cisco products also use the format "0011.434A.B862" not sure if there's an name for it though. If I remember it correctly then there's also some Aruba products that don't use a separator at all "0011434AB862"

The NTC netutils library also has some functions for this: https://github.com/networktocode/netutils/blob/develop/netutils/mac.py

gmazoyer commented 4 days ago

Played a bit with the MAC address things, don't mind the naming, would it be enough to get started with?

{
  TestWidget {
    count
    edges {
      node {
        name {
          value
        }
        mac_address {
          value
          bare
          cisco
          unix
          pgsql
          eui48
          ei
          binary
        }
      }
    }
  }
}

Resulting in:

{
  "data": {
    "TestWidget": {
      "count": 1,
      "edges": [
        {
          "node": {
            "name": {
              "value": "Test"
            },
            "mac_address": {
              "value": "36BE63D416C0",
              "bare": "36BE63D416C0",
              "cisco": "36be.63d4.16c0",
              "unix": "36:be:63:d4:16:c0",
              "pgsql": "36be63:d416c0",
              "eui48": "36-BE-63-D4-16-C0",
              "ei": "D4-16-C0",
              "binary": "0b1101101011111001100011110101000001011011000000"
            }
          }
        }
      ]
    }
  }
}
ogenstad commented 4 days ago

I know you said don't mind the naming. But :) I'm not sure I like that we include names such as "cisco" here. It could be that some Cisco products use different formats or that other vendors also use this "cisco" format. I'd rather document examples within the GraphQL schema and let users figure out what one suites them best. Other than that I think it looks good.