bb-Ricardo / netbox-sync

Sync objects from VMware or redfish sources to NetBox
MIT License
297 stars 65 forks source link

Dummy interfaces and IP addresses not synced #181

Closed sliddjur closed 2 years ago

sliddjur commented 2 years ago

I have some VyOS VM's that uses the dummy linux type of interfaces. These VMs uses Debian Buster as base OS.

The IP's are exposed on vmware tools, but doing some debugging, I see that they don't have a Device nor a NetworkName property.

I want these IP's to be synced to netbox, as they are used globally. When I do a netbox-sync I don't see the IP's are ever listed in the debug output.

I included a second interface that does work as intended for comparison.

Using PowerCLI tools:

PS> $myVm = Get-VM -name myDummyRouterVM
PS> $myVm.Guest.Nics | select -Property *

...

Connected   : True
Device      : 
IPAddress   : {xxx.xxx.222.248, xxx.xxx.222.249, xxx.xxx.222.250, xxx.xxx.222.251...}
MacAddress  : 76:3e:00:c9:3c:d9
NetworkName : 

Connected   : True
Device      : Network adapter 3
IPAddress   : {172.23.252.1, fe80::250:56ff:febc:5ec}
MacAddress  : 00:50:56:bc:05:ec
NetworkName : dvportgroup-510922

And on the VM, the IP addresses are shown like this

user@myDummyRouter:~$ ip addr show dev dum0 | strip-private
5: dum0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
    link/ether 76:3e:00:c9:3c:d9 brd ff:ff:ff:ff:ff:ff
    inet xxx.xxx.222.248/32 scope global dum0
       valid_lft forever preferred_lft forever
    inet xxx.xxx.222.249/32 scope global dum0
       valid_lft forever preferred_lft forever
    inet xxx.xxx.222.250/32 scope global dum0
       valid_lft forever preferred_lft forever
    inet xxx.xxx.222.251/32 scope global dum0
       valid_lft forever preferred_lft forever
    inet6 fe80::743e:ff:fec9:3cd9/64 scope link 
       valid_lft forever preferred_lft forever

user@myDummyRouter:~$ ip addr show eth2
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:bc:05:ec brd ff:ff:ff:ff:ff:ff
    inet 172.23.252.1/24 brd 172.23.252.255 scope global eth2
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:febc:5ec/64 scope link 
       valid_lft forever preferred_lft forever

Lastly, this is the output from netbox-sync -l DEBUG3, with what I think might be the relevant info.

      (vim.vm.GuestInfo.NicInfo) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         network = <unset>,
         ipAddress = (str) [
            'xxx.xxx.222.248',
            'xxx.xxx.222.249',
            'xxx.xxx.222.250',
            'xxx.xxx.222.251',
            'fe80::743e:ff:fec9:3cd9'
         ],
         macAddress = '76:3e:00:c9:3c:d9',
         connected = true,
         deviceConfigId = -1,
         dnsConfig = <unset>,
         ipConfig = (vim.net.IpConfigInfo) {
            dynamicType = <unset>,
            dynamicProperty = (vmodl.DynamicProperty) [],
            ipAddress = (vim.net.IpConfigInfo.IpAddress) [
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  dynamicProperty = (vmodl.DynamicProperty) [],
                  ipAddress = 'xxx.xxx.222.248',
                  prefixLength = 32,
                  origin = <unset>,
                  state = 'preferred',
                  lifetime = <unset>
               },
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  dynamicProperty = (vmodl.DynamicProperty) [],
                  ipAddress = 'xxx.xxx.222.249',
                  prefixLength = 32,
                  origin = <unset>,
                  state = 'preferred',
                  lifetime = <unset>
               },
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  dynamicProperty = (vmodl.DynamicProperty) [],
                  ipAddress = 'xxx.xxx.222.250',
                  prefixLength = 32,
                  origin = <unset>,
                  state = 'preferred',
                  lifetime = <unset>
               },
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  dynamicProperty = (vmodl.DynamicProperty) [],
                  ipAddress = 'xxx.xxx.222.251',
                  prefixLength = 32,
                  origin = <unset>,
                  state = 'preferred',
                  lifetime = <unset>
               },
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  dynamicProperty = (vmodl.DynamicProperty) [],
                  ipAddress = 'fe80::743e:ff:fec9:3cd9',
                  prefixLength = 64,
                  origin = <unset>,
                  state = 'unknown',
                  lifetime = <unset>
               }
            ],
            dhcp = <unset>,
            autoConfigurationEnabled = <unset>
         },
         netBIOSConfig = <unset>
      },

      (vim.vm.GuestInfo.NicInfo) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         network = '12345-CUST',
         ipAddress = (str) [
            '172.23.252.1',
            'fe80::250:56ff:febc:5ec'
         ],
         macAddress = '00:50:56:bc:05:ec',
         connected = true,
         deviceConfigId = 4002,
         dnsConfig = <unset>,
         ipConfig = (vim.net.IpConfigInfo) {
            dynamicType = <unset>,
            dynamicProperty = (vmodl.DynamicProperty) [],
            ipAddress = (vim.net.IpConfigInfo.IpAddress) [
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  dynamicProperty = (vmodl.DynamicProperty) [],
                  ipAddress = '172.23.252.1',
                  prefixLength = 24,
                  origin = <unset>,
                  state = 'preferred',
                  lifetime = <unset>
               },
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  dynamicProperty = (vmodl.DynamicProperty) [],
                  ipAddress = 'fe80::250:56ff:febc:5ec',
                  prefixLength = 64,
                  origin = <unset>,
                  state = 'unknown',
                  lifetime = <unset>
               }
            ],
            dhcp = <unset>,
            autoConfigurationEnabled = <unset>
         },
         netBIOSConfig = <unset>
      }
   ],
bb-Ricardo commented 2 years ago

Hi,

Good point. Maybe the missing network is the issue here. Will check if I can add these interfaces as well.

bb-Ricardo commented 2 years ago

Hi,

I finally got time and was about adding this info.

The issue here is that there is no interface name exposed. I could make up interface names out of the MC address last few octets.

macAddress = '76:3e:00:c9:3c:d9',

-> "dummy-3cd9"

What do you think?

sliddjur commented 2 years ago

Yes, this sounds like a good idea.

bb-Ricardo commented 2 years ago

Hi,

I just added a ne config option sync_vm_dummy_interfaces to the project. Can you pull the latest development branch and test it out?

Tank you

sliddjur commented 2 years ago

@bb-Ricardo it seems to work - however I noticed some VM's adds an extra interface without an actual IP-address on them.

image

image

bb-Ricardo commented 2 years ago

@sliddjur: That is correct. because these interfaces are populated but have no IP address assigned.

Is there any use for dummy interfaces without IP addresses to be synced?

Otherwise we could just skip these ones.

bb-Ricardo commented 2 years ago

well, I just added it.

sliddjur commented 2 years ago

I think we should skip those interfaces. Thanks for your awesome work! :)

bb-Ricardo commented 2 years ago

did you test the latest "development" commit?

sliddjur commented 2 years ago

Yes - it seems to work as expected.