From bbdad4a84f01fbd5cfa69dd4a77218222ca519d5 Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Thu, 30 Apr 2026 20:06:16 +0530 Subject: [PATCH 1/2] feat(nautobotOP): Use ID Instead of name when syncing the data --- .../internal/nautobot/dcim/devicetype.go | 33 +++++++++++++------ .../internal/nautobot/dcim/location.go | 33 +++++++++++++------ .../internal/nautobot/dcim/locationtype.go | 33 +++++++++++++------ go/nautobotop/internal/nautobot/dcim/rack.go | 33 +++++++++++++------ .../internal/nautobot/dcim/rackGroup.go | 33 +++++++++++++------ .../internal/nautobot/extras/role.go | 33 +++++++++++++------ .../internal/nautobot/ipam/namespace.go | 33 +++++++++++++------ .../internal/nautobot/ipam/prefix.go | 33 +++++++++++++------ go/nautobotop/internal/nautobot/ipam/rir.go | 33 +++++++++++++------ go/nautobotop/internal/nautobot/ipam/vlan.go | 33 +++++++++++++------ .../internal/nautobot/ipam/vlanGroup.go | 33 +++++++++++++------ .../internal/nautobot/models/cluster.go | 1 + .../internal/nautobot/models/clusterGroup.go | 1 + .../internal/nautobot/models/clusterType.go | 1 + .../internal/nautobot/models/devicetype.go | 1 + .../internal/nautobot/models/location.go | 1 + .../internal/nautobot/models/locationtype.go | 1 + .../internal/nautobot/models/namespace.go | 1 + .../internal/nautobot/models/prefix.go | 1 + .../internal/nautobot/models/rack.go | 1 + .../internal/nautobot/models/rackGroup.go | 1 + go/nautobotop/internal/nautobot/models/rir.go | 1 + .../internal/nautobot/models/role.go | 1 + .../internal/nautobot/models/tenant.go | 1 + .../internal/nautobot/models/tenantGroup.go | 1 + .../internal/nautobot/models/vlan.go | 1 + .../internal/nautobot/models/vlanGroup.go | 1 + .../internal/nautobot/sync/cluster.go | 3 +- .../internal/nautobot/sync/clusterGroup.go | 3 +- .../internal/nautobot/sync/clusterType.go | 3 +- .../internal/nautobot/sync/devicetype.go | 3 +- .../internal/nautobot/sync/helpers.go | 10 ++++++ .../internal/nautobot/sync/location.go | 29 ++++++++++++---- .../internal/nautobot/sync/locationtype.go | 3 +- .../internal/nautobot/sync/namespace.go | 3 +- .../internal/nautobot/sync/prefix.go | 3 +- go/nautobotop/internal/nautobot/sync/rack.go | 3 +- .../internal/nautobot/sync/rackGroup.go | 5 +-- go/nautobotop/internal/nautobot/sync/rir.go | 3 +- go/nautobotop/internal/nautobot/sync/role.go | 3 +- .../internal/nautobot/sync/tenant.go | 3 +- .../internal/nautobot/sync/tenantGroup.go | 3 +- go/nautobotop/internal/nautobot/sync/vlan.go | 3 +- .../internal/nautobot/sync/vlanGroup.go | 12 +++---- .../internal/nautobot/tenancy/tenant.go | 33 +++++++++++++------ .../internal/nautobot/tenancy/tenantGroup.go | 33 +++++++++++++------ .../nautobot/virtualization/cluster.go | 33 +++++++++++++------ .../nautobot/virtualization/clusterGroup.go | 33 +++++++++++++------ .../nautobot/virtualization/clusterType.go | 33 +++++++++++++------ 49 files changed, 451 insertions(+), 188 deletions(-) create mode 100644 go/nautobotop/internal/nautobot/sync/helpers.go diff --git a/go/nautobotop/internal/nautobot/dcim/devicetype.go b/go/nautobotop/internal/nautobot/dcim/devicetype.go index 527e3cd0e..991f3bcdb 100644 --- a/go/nautobotop/internal/nautobot/dcim/devicetype.go +++ b/go/nautobotop/internal/nautobot/dcim/devicetype.go @@ -57,6 +57,29 @@ func (s *DeviceTypeService) GetByName(ctx context.Context, name string) nb.Devic return list.Results[0] } +func (s *DeviceTypeService) GetByID(ctx context.Context, id string) nb.DeviceType { + if id == "" { + return nb.DeviceType{} + } + if deviceType, ok := cache.FindByID(s.client.Cache, "devicetypes", id, func(dt nb.DeviceType) *string { + return dt.Id + }); ok { + return deviceType + } + + list, resp, err := s.client.APIClient.DcimAPI.DcimDeviceTypesList(ctx).Depth(10).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetDeviceTypeByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.DeviceType{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.DeviceType{} + } + + return list.Results[0] +} + func (s *DeviceTypeService) ListAll(ctx context.Context) []nb.DeviceType { ids := s.client.GetChangeObjectIDS(ctx, "dcim.devicetype") list, resp, err := s.client.APIClient.DcimAPI.DcimDeviceTypesList(ctx).Id(ids).Depth(10).Execute() @@ -76,16 +99,6 @@ func (s *DeviceTypeService) ListAll(ctx context.Context) []nb.DeviceType { } func (s *DeviceTypeService) Update(ctx context.Context, id string, req nb.WritableDeviceTypeRequest) (*nb.DeviceType, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateDeviceType", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - deviceType, resp, err := s.client.APIClient.DcimAPI.DcimDeviceTypesUpdate(ctx, id).WritableDeviceTypeRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/dcim/location.go b/go/nautobotop/internal/nautobot/dcim/location.go index 79308cc6a..75c4fb0d8 100644 --- a/go/nautobotop/internal/nautobot/dcim/location.go +++ b/go/nautobotop/internal/nautobot/dcim/location.go @@ -58,6 +58,29 @@ func (s *LocationService) GetByName(ctx context.Context, name string) nb.Locatio return list.Results[0] } +func (s *LocationService) GetByID(ctx context.Context, id string) nb.Location { + if id == "" { + return nb.Location{} + } + if location, ok := cache.FindByID(s.client.Cache, "locations", id, func(l nb.Location) *string { + return l.Id + }); ok { + return location + } + + list, resp, err := s.client.APIClient.DcimAPI.DcimLocationsList(ctx).Depth(10).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetLocationByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.Location{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.Location{} + } + + return list.Results[0] +} + func (s *LocationService) ListAll(ctx context.Context) []nb.Location { ids := s.client.GetChangeObjectIDS(ctx, "dcim.location") list, resp, err := s.client.APIClient.DcimAPI.DcimLocationsList(ctx).Id(ids).Depth(10).Execute() @@ -77,16 +100,6 @@ func (s *LocationService) ListAll(ctx context.Context) []nb.Location { } func (s *LocationService) Update(ctx context.Context, id string, req nb.LocationRequest) (*nb.Location, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateLocation", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - location, resp, err := s.client.APIClient.DcimAPI.DcimLocationsUpdate(ctx, id).LocationRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/dcim/locationtype.go b/go/nautobotop/internal/nautobot/dcim/locationtype.go index 7980fcc51..16c6f3dda 100644 --- a/go/nautobotop/internal/nautobot/dcim/locationtype.go +++ b/go/nautobotop/internal/nautobot/dcim/locationtype.go @@ -57,6 +57,29 @@ func (s *LocationTypeService) GetByName(ctx context.Context, name string) nb.Loc return list.Results[0] } +func (s *LocationTypeService) GetByID(ctx context.Context, id string) nb.LocationType { + if id == "" { + return nb.LocationType{} + } + if locationType, ok := cache.FindByID(s.client.Cache, "locationtypes", id, func(lt nb.LocationType) *string { + return lt.Id + }); ok { + return locationType + } + + list, resp, err := s.client.APIClient.DcimAPI.DcimLocationTypesList(ctx).Depth(10).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetLocationTypeByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.LocationType{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.LocationType{} + } + + return list.Results[0] +} + func (s *LocationTypeService) ListAll(ctx context.Context) []nb.LocationType { ids := s.client.GetChangeObjectIDS(ctx, "dcim.locationtype") list, resp, err := s.client.APIClient.DcimAPI.DcimLocationTypesList(ctx).Id(ids).Depth(10).Execute() @@ -76,16 +99,6 @@ func (s *LocationTypeService) ListAll(ctx context.Context) []nb.LocationType { } func (s *LocationTypeService) Update(ctx context.Context, id string, req nb.LocationTypeRequest) (*nb.LocationType, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateLocationType", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - locationType, resp, err := s.client.APIClient.DcimAPI.DcimLocationTypesUpdate(ctx, id).LocationTypeRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/dcim/rack.go b/go/nautobotop/internal/nautobot/dcim/rack.go index 69f419705..69fa6eb4c 100644 --- a/go/nautobotop/internal/nautobot/dcim/rack.go +++ b/go/nautobotop/internal/nautobot/dcim/rack.go @@ -56,6 +56,29 @@ func (s *RackService) GetByName(ctx context.Context, name string) nb.Rack { return list.Results[0] } +func (s *RackService) GetByID(ctx context.Context, id string) nb.Rack { + if id == "" { + return nb.Rack{} + } + if rack, ok := cache.FindByID(s.client.Cache, "racks", id, func(r nb.Rack) *string { + return r.Id + }); ok { + return rack + } + + list, resp, err := s.client.APIClient.DcimAPI.DcimRacksList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetRackByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.Rack{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.Rack{} + } + + return list.Results[0] +} + func (s *RackService) ListAll(ctx context.Context) []nb.Rack { ids := s.client.GetChangeObjectIDS(ctx, "dcim.rack") list, resp, err := s.client.APIClient.DcimAPI.DcimRacksList(ctx).Id(ids).Depth(2).Execute() @@ -75,16 +98,6 @@ func (s *RackService) ListAll(ctx context.Context) []nb.Rack { } func (s *RackService) Update(ctx context.Context, id string, req nb.WritableRackRequest) (*nb.Rack, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateRack", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - rack, resp, err := s.client.APIClient.DcimAPI.DcimRacksUpdate(ctx, id).WritableRackRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/dcim/rackGroup.go b/go/nautobotop/internal/nautobot/dcim/rackGroup.go index e5080db69..0f04310ec 100644 --- a/go/nautobotop/internal/nautobot/dcim/rackGroup.go +++ b/go/nautobotop/internal/nautobot/dcim/rackGroup.go @@ -57,6 +57,29 @@ func (s *RackGroupService) GetByName(ctx context.Context, name string) nb.RackGr return list.Results[0] } +func (s *RackGroupService) GetByID(ctx context.Context, id string) nb.RackGroup { + if id == "" { + return nb.RackGroup{} + } + if rackGroup, ok := cache.FindByID(s.client.Cache, "rackgroups", id, func(rg nb.RackGroup) *string { + return rg.Id + }); ok { + return rackGroup + } + + list, resp, err := s.client.APIClient.DcimAPI.DcimRackGroupsList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetRackGroupByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.RackGroup{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.RackGroup{} + } + + return list.Results[0] +} + func (s *RackGroupService) ListAll(ctx context.Context) []nb.RackGroup { ids := s.client.GetChangeObjectIDS(ctx, "dcim.rackgroup") list, resp, err := s.client.APIClient.DcimAPI.DcimRackGroupsList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *RackGroupService) ListAll(ctx context.Context) []nb.RackGroup { } func (s *RackGroupService) Update(ctx context.Context, id string, req nb.RackGroupRequest) (*nb.RackGroup, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateRackGroup", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - rackGroup, resp, err := s.client.APIClient.DcimAPI.DcimRackGroupsUpdate(ctx, id).RackGroupRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/extras/role.go b/go/nautobotop/internal/nautobot/extras/role.go index fafc1c91a..32dfebbd6 100644 --- a/go/nautobotop/internal/nautobot/extras/role.go +++ b/go/nautobotop/internal/nautobot/extras/role.go @@ -56,6 +56,29 @@ func (s *RoleService) GetByName(ctx context.Context, name string) nb.Role { return list.Results[0] } +func (s *RoleService) GetByID(ctx context.Context, id string) nb.Role { + if id == "" { + return nb.Role{} + } + if role, ok := cache.FindByID(s.client.Cache, "roles", id, func(r nb.Role) *string { + return r.Id + }); ok { + return role + } + + list, resp, err := s.client.APIClient.ExtrasAPI.ExtrasRolesList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetRoleByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.Role{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.Role{} + } + + return list.Results[0] +} + func (s *RoleService) ListAll(ctx context.Context) []nb.Role { ids := s.client.GetChangeObjectIDS(ctx, "extras.role") list, resp, err := s.client.APIClient.ExtrasAPI.ExtrasRolesList(ctx).Id(ids).Depth(2).Execute() @@ -74,16 +97,6 @@ func (s *RoleService) ListAll(ctx context.Context) []nb.Role { } func (s *RoleService) Update(ctx context.Context, id string, req nb.RoleRequest) (*nb.Role, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateRole", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - role, resp, err := s.client.APIClient.ExtrasAPI.ExtrasRolesUpdate(ctx, id).RoleRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/ipam/namespace.go b/go/nautobotop/internal/nautobot/ipam/namespace.go index 85de53ffd..4e5b170b4 100644 --- a/go/nautobotop/internal/nautobot/ipam/namespace.go +++ b/go/nautobotop/internal/nautobot/ipam/namespace.go @@ -57,6 +57,29 @@ func (s *NamespaceService) GetByName(ctx context.Context, name string) nb.Namesp return list.Results[0] } +func (s *NamespaceService) GetByID(ctx context.Context, id string) nb.Namespace { + if id == "" { + return nb.Namespace{} + } + if ns, ok := cache.FindByID(s.client.Cache, "namespaces", id, func(n nb.Namespace) *string { + return n.Id + }); ok { + return ns + } + + list, resp, err := s.client.APIClient.IpamAPI.IpamNamespacesList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetNamespaceByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.Namespace{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.Namespace{} + } + + return list.Results[0] +} + func (s *NamespaceService) ListAll(ctx context.Context) []nb.Namespace { ids := s.client.GetChangeObjectIDS(ctx, "ipam.namespace") list, resp, err := s.client.APIClient.IpamAPI.IpamNamespacesList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *NamespaceService) ListAll(ctx context.Context) []nb.Namespace { } func (s *NamespaceService) Update(ctx context.Context, id string, req nb.NamespaceRequest) (*nb.Namespace, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateNamespace", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - namespace, resp, err := s.client.APIClient.IpamAPI.IpamNamespacesUpdate(ctx, id).NamespaceRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/ipam/prefix.go b/go/nautobotop/internal/nautobot/ipam/prefix.go index 0c0875a07..74b6ccd73 100644 --- a/go/nautobotop/internal/nautobot/ipam/prefix.go +++ b/go/nautobotop/internal/nautobot/ipam/prefix.go @@ -57,6 +57,29 @@ func (s *PrefixService) GetByPrefix(ctx context.Context, prefix string) nb.Prefi return list.Results[0] } +func (s *PrefixService) GetByID(ctx context.Context, id string) nb.Prefix { + if id == "" { + return nb.Prefix{} + } + if prefix, ok := cache.FindByID(s.client.Cache, "prefixes", id, func(p nb.Prefix) *string { + return p.Id + }); ok { + return prefix + } + + list, resp, err := s.client.APIClient.IpamAPI.IpamPrefixesList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetPrefixByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.Prefix{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.Prefix{} + } + + return list.Results[0] +} + func (s *PrefixService) ListAll(ctx context.Context) []nb.Prefix { ids := s.client.GetChangeObjectIDS(ctx, "ipam.prefix") list, resp, err := s.client.APIClient.IpamAPI.IpamPrefixesList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *PrefixService) ListAll(ctx context.Context) []nb.Prefix { } func (s *PrefixService) Update(ctx context.Context, id string, req nb.WritablePrefixRequest) (*nb.Prefix, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdatePrefix", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - prefix, resp, err := s.client.APIClient.IpamAPI.IpamPrefixesUpdate(ctx, id).WritablePrefixRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/ipam/rir.go b/go/nautobotop/internal/nautobot/ipam/rir.go index aac1814b4..c45f7080f 100644 --- a/go/nautobotop/internal/nautobot/ipam/rir.go +++ b/go/nautobotop/internal/nautobot/ipam/rir.go @@ -56,6 +56,29 @@ func (s *RirService) GetByName(ctx context.Context, name string) nb.RIR { return list.Results[0] } +func (s *RirService) GetByID(ctx context.Context, id string) nb.RIR { + if id == "" { + return nb.RIR{} + } + if rir, ok := cache.FindByID(s.client.Cache, "rirs", id, func(r nb.RIR) *string { + return r.Id + }); ok { + return rir + } + + list, resp, err := s.client.APIClient.IpamAPI.IpamRirsList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetRirByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.RIR{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.RIR{} + } + + return list.Results[0] +} + func (s *RirService) ListAll(ctx context.Context) []nb.RIR { ids := s.client.GetChangeObjectIDS(ctx, "ipam.rir") list, resp, err := s.client.APIClient.IpamAPI.IpamRirsList(ctx).Id(ids).Depth(2).Execute() @@ -74,16 +97,6 @@ func (s *RirService) ListAll(ctx context.Context) []nb.RIR { } func (s *RirService) Update(ctx context.Context, id string, req nb.RIRRequest) (*nb.RIR, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateRir", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - rir, resp, err := s.client.APIClient.IpamAPI.IpamRirsUpdate(ctx, id).RIRRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/ipam/vlan.go b/go/nautobotop/internal/nautobot/ipam/vlan.go index a59288213..fdab616ad 100644 --- a/go/nautobotop/internal/nautobot/ipam/vlan.go +++ b/go/nautobotop/internal/nautobot/ipam/vlan.go @@ -57,6 +57,29 @@ func (s *VlanService) GetByName(ctx context.Context, name string) nb.VLAN { return list.Results[0] } +func (s *VlanService) GetByID(ctx context.Context, id string) nb.VLAN { + if id == "" { + return nb.VLAN{} + } + if vlan, ok := cache.FindByID(s.client.Cache, "vlans", id, func(v nb.VLAN) *string { + return v.Id + }); ok { + return vlan + } + + list, resp, err := s.client.APIClient.IpamAPI.IpamVlansList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetVlanByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.VLAN{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.VLAN{} + } + + return list.Results[0] +} + func (s *VlanService) ListAll(ctx context.Context) []nb.VLAN { ids := s.client.GetChangeObjectIDS(ctx, "ipam.vlan") list, resp, err := s.client.APIClient.IpamAPI.IpamVlansList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *VlanService) ListAll(ctx context.Context) []nb.VLAN { } func (s *VlanService) Update(ctx context.Context, id string, req nb.VLANRequest) (*nb.VLAN, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateVlan", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - vlan, resp, err := s.client.APIClient.IpamAPI.IpamVlansUpdate(ctx, id).VLANRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/ipam/vlanGroup.go b/go/nautobotop/internal/nautobot/ipam/vlanGroup.go index 9022d0dab..873a3360e 100644 --- a/go/nautobotop/internal/nautobot/ipam/vlanGroup.go +++ b/go/nautobotop/internal/nautobot/ipam/vlanGroup.go @@ -57,6 +57,29 @@ func (s *VlanGroupService) GetByName(ctx context.Context, name string) nb.VLANGr return list.Results[0] } +func (s *VlanGroupService) GetByID(ctx context.Context, id string) nb.VLANGroup { + if id == "" { + return nb.VLANGroup{} + } + if vlanGroup, ok := cache.FindByID(s.client.Cache, "vlangroups", id, func(vg nb.VLANGroup) *string { + return vg.Id + }); ok { + return vlanGroup + } + + list, resp, err := s.client.APIClient.IpamAPI.IpamVlanGroupsList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetVlanGroupByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.VLANGroup{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.VLANGroup{} + } + + return list.Results[0] +} + func (s *VlanGroupService) ListAll(ctx context.Context) []nb.VLANGroup { ids := s.client.GetChangeObjectIDS(ctx, "ipam.vlangroup") list, resp, err := s.client.APIClient.IpamAPI.IpamVlanGroupsList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *VlanGroupService) ListAll(ctx context.Context) []nb.VLANGroup { } func (s *VlanGroupService) Update(ctx context.Context, id string, req nb.VLANGroupRequest) (*nb.VLANGroup, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateVlanGroup", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - vlanGroup, resp, err := s.client.APIClient.IpamAPI.IpamVlanGroupsUpdate(ctx, id).VLANGroupRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/models/cluster.go b/go/nautobotop/internal/nautobot/models/cluster.go index 36d0a9d25..bdf3037c3 100644 --- a/go/nautobotop/internal/nautobot/models/cluster.go +++ b/go/nautobotop/internal/nautobot/models/cluster.go @@ -5,6 +5,7 @@ type Clusters struct { } type Cluster struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Comments string `json:"comments" yaml:"comments"` ClusterType string `json:"cluster_type" yaml:"cluster_type"` diff --git a/go/nautobotop/internal/nautobot/models/clusterGroup.go b/go/nautobotop/internal/nautobot/models/clusterGroup.go index fa9832c82..1045fc672 100644 --- a/go/nautobotop/internal/nautobot/models/clusterGroup.go +++ b/go/nautobotop/internal/nautobot/models/clusterGroup.go @@ -5,6 +5,7 @@ type ClusterGroups struct { } type ClusterGroup struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` } diff --git a/go/nautobotop/internal/nautobot/models/clusterType.go b/go/nautobotop/internal/nautobot/models/clusterType.go index dfbd5c309..bb8506138 100644 --- a/go/nautobotop/internal/nautobot/models/clusterType.go +++ b/go/nautobotop/internal/nautobot/models/clusterType.go @@ -5,6 +5,7 @@ type ClusterTypes struct { } type ClusterType struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` } diff --git a/go/nautobotop/internal/nautobot/models/devicetype.go b/go/nautobotop/internal/nautobot/models/devicetype.go index 85c99f537..150aa7486 100644 --- a/go/nautobotop/internal/nautobot/models/devicetype.go +++ b/go/nautobotop/internal/nautobot/models/devicetype.go @@ -5,6 +5,7 @@ type DeviceTypes struct { } type DeviceType struct { + ID string `yaml:"id"` Manufacturer string `yaml:"manufacturer"` PartNumber string `yaml:"part_number"` Model string `yaml:"model"` diff --git a/go/nautobotop/internal/nautobot/models/location.go b/go/nautobotop/internal/nautobot/models/location.go index 92ea38b16..09cbf404c 100644 --- a/go/nautobotop/internal/nautobot/models/location.go +++ b/go/nautobotop/internal/nautobot/models/location.go @@ -5,6 +5,7 @@ type Locations struct { } type Location struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` LocationType string `json:"string" yaml:"location_type"` diff --git a/go/nautobotop/internal/nautobot/models/locationtype.go b/go/nautobotop/internal/nautobot/models/locationtype.go index 96b273261..5d511c31b 100644 --- a/go/nautobotop/internal/nautobot/models/locationtype.go +++ b/go/nautobotop/internal/nautobot/models/locationtype.go @@ -5,6 +5,7 @@ type LocationTypes struct { } type LocationType struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` ContentTypes []string `json:"content_types" yaml:"content_types"` diff --git a/go/nautobotop/internal/nautobot/models/namespace.go b/go/nautobotop/internal/nautobot/models/namespace.go index e473f9ed5..39b5fc922 100644 --- a/go/nautobotop/internal/nautobot/models/namespace.go +++ b/go/nautobotop/internal/nautobot/models/namespace.go @@ -5,6 +5,7 @@ type Namespaces struct { } type Namespace struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` Location string `json:"location" yaml:"location"` diff --git a/go/nautobotop/internal/nautobot/models/prefix.go b/go/nautobotop/internal/nautobot/models/prefix.go index 98158a864..f0791bec0 100644 --- a/go/nautobotop/internal/nautobot/models/prefix.go +++ b/go/nautobotop/internal/nautobot/models/prefix.go @@ -5,6 +5,7 @@ type Prefixes struct { } type Prefix struct { + ID string `json:"id" yaml:"id"` Prefix string `json:"prefix" yaml:"prefix"` Namespace string `json:"namespace" yaml:"namespace"` Type string `json:"type" yaml:"type"` diff --git a/go/nautobotop/internal/nautobot/models/rack.go b/go/nautobotop/internal/nautobot/models/rack.go index a8c66754a..5e290ee28 100644 --- a/go/nautobotop/internal/nautobot/models/rack.go +++ b/go/nautobotop/internal/nautobot/models/rack.go @@ -5,6 +5,7 @@ type Racks struct { } type Rack struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Facility string `json:"facility" yaml:"facility"` Description string `json:"description" yaml:"description"` diff --git a/go/nautobotop/internal/nautobot/models/rackGroup.go b/go/nautobotop/internal/nautobot/models/rackGroup.go index 7bb2d1c20..9f50cd2cd 100644 --- a/go/nautobotop/internal/nautobot/models/rackGroup.go +++ b/go/nautobotop/internal/nautobot/models/rackGroup.go @@ -5,6 +5,7 @@ type RackGroups struct { } type RackGroup struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` Location string `json:"location" yaml:"location"` diff --git a/go/nautobotop/internal/nautobot/models/rir.go b/go/nautobotop/internal/nautobot/models/rir.go index ea56439a9..1ba593d7d 100644 --- a/go/nautobotop/internal/nautobot/models/rir.go +++ b/go/nautobotop/internal/nautobot/models/rir.go @@ -5,6 +5,7 @@ type Rirs struct { } type Rir struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` IsPrivate bool `json:"is_private" yaml:"is_private"` Description string `json:"description" yaml:"description"` diff --git a/go/nautobotop/internal/nautobot/models/role.go b/go/nautobotop/internal/nautobot/models/role.go index f637eaa91..502f9d7fc 100644 --- a/go/nautobotop/internal/nautobot/models/role.go +++ b/go/nautobotop/internal/nautobot/models/role.go @@ -5,6 +5,7 @@ type Roles struct { } type Role struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Color string `json:"color" yaml:"color"` Description string `json:"description" yaml:"description"` diff --git a/go/nautobotop/internal/nautobot/models/tenant.go b/go/nautobotop/internal/nautobot/models/tenant.go index e75fd2176..e6de066bd 100644 --- a/go/nautobotop/internal/nautobot/models/tenant.go +++ b/go/nautobotop/internal/nautobot/models/tenant.go @@ -5,6 +5,7 @@ type Tenants struct { } type Tenant struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` Comments string `json:"comments" yaml:"comments"` diff --git a/go/nautobotop/internal/nautobot/models/tenantGroup.go b/go/nautobotop/internal/nautobot/models/tenantGroup.go index 19e380981..8e1beb714 100644 --- a/go/nautobotop/internal/nautobot/models/tenantGroup.go +++ b/go/nautobotop/internal/nautobot/models/tenantGroup.go @@ -5,6 +5,7 @@ type TenantGroups struct { } type TenantGroup struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` Parent string `json:"parent" yaml:"parent"` diff --git a/go/nautobotop/internal/nautobot/models/vlan.go b/go/nautobotop/internal/nautobot/models/vlan.go index f5e4e6f11..085605343 100644 --- a/go/nautobotop/internal/nautobot/models/vlan.go +++ b/go/nautobotop/internal/nautobot/models/vlan.go @@ -5,6 +5,7 @@ type Vlans struct { } type Vlan struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Vid int `json:"vid" yaml:"vid"` Status string `json:"status" yaml:"status"` diff --git a/go/nautobotop/internal/nautobot/models/vlanGroup.go b/go/nautobotop/internal/nautobot/models/vlanGroup.go index 6a5514bd4..538a9599f 100644 --- a/go/nautobotop/internal/nautobot/models/vlanGroup.go +++ b/go/nautobotop/internal/nautobot/models/vlanGroup.go @@ -5,6 +5,7 @@ type VlanGroups struct { } type VlanGroup struct { + ID string `json:"id" yaml:"id"` Name string `json:"name" yaml:"name"` Location string `json:"location" yaml:"location"` UcvniGroup string `json:"ucvni_group" yaml:"ucvni_group"` diff --git a/go/nautobotop/internal/nautobot/sync/cluster.go b/go/nautobotop/internal/nautobot/sync/cluster.go index e43c5c01d..776c2cacc 100644 --- a/go/nautobotop/internal/nautobot/sync/cluster.go +++ b/go/nautobotop/internal/nautobot/sync/cluster.go @@ -59,7 +59,7 @@ func (s *ClusterSync) SyncAll(ctx context.Context, data map[string]string) error // syncSingleCluster handles the create/update logic for a single cluster and its devices func (s *ClusterSync) syncSingleCluster(ctx context.Context, cluster models.Cluster) error { - existingCluster := s.clusterSvc.GetByName(ctx, cluster.Name) + existingCluster := s.clusterSvc.GetByID(ctx, cluster.ID) // Build cluster type reference (required) clusterTypeRef, err := s.buildClusterTypeReference(ctx, cluster.ClusterType) @@ -68,6 +68,7 @@ func (s *ClusterSync) syncSingleCluster(ctx context.Context, cluster models.Clus } clusterRequest := nb.ClusterRequest{ + Id: optionalID(cluster.ID), Name: cluster.Name, Comments: nb.PtrString(cluster.Comments), ClusterType: clusterTypeRef, diff --git a/go/nautobotop/internal/nautobot/sync/clusterGroup.go b/go/nautobotop/internal/nautobot/sync/clusterGroup.go index b903b0743..7bf0918fa 100644 --- a/go/nautobotop/internal/nautobot/sync/clusterGroup.go +++ b/go/nautobotop/internal/nautobot/sync/clusterGroup.go @@ -50,9 +50,10 @@ func (s *ClusterGroupSync) SyncAll(ctx context.Context, data map[string]string) // syncSingleClusterGroup handles the create/update logic for a single cluster group func (s *ClusterGroupSync) syncSingleClusterGroup(ctx context.Context, clusterGroup models.ClusterGroup) error { - existingClusterGroup := s.clusterGroupSvc.GetByName(ctx, clusterGroup.Name) + existingClusterGroup := s.clusterGroupSvc.GetByID(ctx, clusterGroup.ID) clusterGroupRequest := nb.ClusterGroupRequest{ + Id: optionalID(clusterGroup.ID), Name: clusterGroup.Name, Description: nb.PtrString(clusterGroup.Description), } diff --git a/go/nautobotop/internal/nautobot/sync/clusterType.go b/go/nautobotop/internal/nautobot/sync/clusterType.go index 80112ed1f..7a366ee9f 100644 --- a/go/nautobotop/internal/nautobot/sync/clusterType.go +++ b/go/nautobotop/internal/nautobot/sync/clusterType.go @@ -50,9 +50,10 @@ func (s *ClusterTypeSync) SyncAll(ctx context.Context, data map[string]string) e // syncSingleClusterType handles the create/update logic for a single cluster type func (s *ClusterTypeSync) syncSingleClusterType(ctx context.Context, clusterType models.ClusterType) error { - existingClusterType := s.clusterTypeSvc.GetByName(ctx, clusterType.Name) + existingClusterType := s.clusterTypeSvc.GetByID(ctx, clusterType.ID) clusterTypeRequest := nb.ClusterTypeRequest{ + Id: optionalID(clusterType.ID), Name: clusterType.Name, Description: nb.PtrString(clusterType.Description), } diff --git a/go/nautobotop/internal/nautobot/sync/devicetype.go b/go/nautobotop/internal/nautobot/sync/devicetype.go index c814679b6..21fea41fd 100644 --- a/go/nautobotop/internal/nautobot/sync/devicetype.go +++ b/go/nautobotop/internal/nautobot/sync/devicetype.go @@ -62,8 +62,9 @@ func (s *DeviceTypeSync) SyncAll(ctx context.Context, data map[string]string) er manufacturer = *cm } - deviceType := s.deviceTypeSvc.GetByName(context.Background(), yml.Model) + deviceType := s.deviceTypeSvc.GetByID(ctx, yml.ID) deviceTypeRequest := nb.WritableDeviceTypeRequest{ + Id: optionalID(yml.ID), Model: yml.Model, PartNumber: nb.PtrString(yml.PartNumber), UHeight: nb.PtrInt32(int32(yml.UHeight)), diff --git a/go/nautobotop/internal/nautobot/sync/helpers.go b/go/nautobotop/internal/nautobot/sync/helpers.go new file mode 100644 index 000000000..1123e2595 --- /dev/null +++ b/go/nautobotop/internal/nautobot/sync/helpers.go @@ -0,0 +1,10 @@ +package sync + +import nb "github.com/nautobot/go-nautobot/v3" + +func optionalID(id string) *string { + if id == "" { + return nil + } + return nb.PtrString(id) +} diff --git a/go/nautobotop/internal/nautobot/sync/location.go b/go/nautobotop/internal/nautobot/sync/location.go index 0af84b03c..9f2a019de 100644 --- a/go/nautobotop/internal/nautobot/sync/location.go +++ b/go/nautobotop/internal/nautobot/sync/location.go @@ -70,15 +70,24 @@ func (s *LocationSync) syncLocationRecursive(ctx context.Context, location model // syncSingleLocation handles the create/update logic for a single location func (s *LocationSync) syncSingleLocation(ctx context.Context, location models.Location, parentID *string) (*string, error) { - existingLocation := s.locationSvc.GetByName(ctx, location.Name) + existingLocation := s.locationSvc.GetByID(ctx, location.ID) + locationTypeRef, err := s.buildLocationTypeReference(ctx, location.LocationType) + if err != nil { + return nil, fmt.Errorf("failed to build location type reference for location %s: %w", location.Name, err) + } + statusRef, err := s.buildStatusReference(ctx, location.Status) + if err != nil { + return nil, fmt.Errorf("failed to build status reference for location %s: %w", location.Name, err) + } locationRequest := nb.LocationRequest{ + Id: optionalID(location.ID), Name: location.Name, Description: nb.PtrString(location.Description), Parent: buildParentReference(parentID), - LocationType: s.buildLocationTypeReference(ctx, location.LocationType), - Status: s.buildStatusReference(ctx, location.Status), + LocationType: locationTypeRef, + Status: statusRef, } if existingLocation.Id == nil { @@ -189,12 +198,18 @@ func (s *LocationSync) getParentID(locationType nb.Location) string { } return "" } -func (s *LocationSync) buildStatusReference(ctx context.Context, name string) nb.ApprovalWorkflowStageResponseApprovalWorkflowStage { +func (s *LocationSync) buildStatusReference(ctx context.Context, name string) (nb.ApprovalWorkflowStageResponseApprovalWorkflowStage, error) { locationType := s.statusSvc.GetByName(ctx, name) - return helpers.BuildApprovalWorkflowStageResponseApprovalWorkflowStage(*locationType.Id) + if locationType.Id == nil { + return nb.ApprovalWorkflowStageResponseApprovalWorkflowStage{}, fmt.Errorf("status %q not found in Nautobot", name) + } + return helpers.BuildApprovalWorkflowStageResponseApprovalWorkflowStage(*locationType.Id), nil } -func (s *LocationSync) buildLocationTypeReference(ctx context.Context, name string) nb.ApprovalWorkflowStageResponseApprovalWorkflowStage { +func (s *LocationSync) buildLocationTypeReference(ctx context.Context, name string) (nb.ApprovalWorkflowStageResponseApprovalWorkflowStage, error) { locationType := s.locationTypes.GetByName(ctx, name) - return helpers.BuildApprovalWorkflowStageResponseApprovalWorkflowStage(*locationType.Id) + if locationType.Id == nil { + return nb.ApprovalWorkflowStageResponseApprovalWorkflowStage{}, fmt.Errorf("location type %q not found in Nautobot", name) + } + return helpers.BuildApprovalWorkflowStageResponseApprovalWorkflowStage(*locationType.Id), nil } diff --git a/go/nautobotop/internal/nautobot/sync/locationtype.go b/go/nautobotop/internal/nautobot/sync/locationtype.go index ec531e610..9add5cce4 100644 --- a/go/nautobotop/internal/nautobot/sync/locationtype.go +++ b/go/nautobotop/internal/nautobot/sync/locationtype.go @@ -66,9 +66,10 @@ func (s *LocationTypeSync) syncLocationTypeRecursive(ctx context.Context, locati // syncSingleLocationType handles the create/update logic for a single location type func (s *LocationTypeSync) syncSingleLocationType(ctx context.Context, locationType models.LocationType, parentID *string) (*string, error) { - existingLocationType := s.locationTypeSvc.GetByName(ctx, locationType.Name) + existingLocationType := s.locationTypeSvc.GetByID(ctx, locationType.ID) locationTypeRequest := nb.LocationTypeRequest{ + Id: optionalID(locationType.ID), ContentTypes: locationType.ContentTypes, Name: locationType.Name, Description: nb.PtrString(locationType.Description), diff --git a/go/nautobotop/internal/nautobot/sync/namespace.go b/go/nautobotop/internal/nautobot/sync/namespace.go index bfe116099..889b51977 100644 --- a/go/nautobotop/internal/nautobot/sync/namespace.go +++ b/go/nautobotop/internal/nautobot/sync/namespace.go @@ -56,9 +56,10 @@ func (s *NamespaceSync) SyncAll(ctx context.Context, data map[string]string) err } func (s *NamespaceSync) syncSingleNamespace(ctx context.Context, namespace models.Namespace) error { - existingNamespace := s.namespaceSvc.GetByName(ctx, namespace.Name) + existingNamespace := s.namespaceSvc.GetByID(ctx, namespace.ID) nsRequest := nb.NamespaceRequest{ + Id: optionalID(namespace.ID), Name: namespace.Name, Description: nb.PtrString(namespace.Description), } diff --git a/go/nautobotop/internal/nautobot/sync/prefix.go b/go/nautobotop/internal/nautobot/sync/prefix.go index c9ae606c3..402496cde 100644 --- a/go/nautobotop/internal/nautobot/sync/prefix.go +++ b/go/nautobotop/internal/nautobot/sync/prefix.go @@ -75,7 +75,7 @@ func (s *PrefixSync) SyncAll(ctx context.Context, data map[string]string) error // syncSinglePrefix handles the create/update logic for a single prefix func (s *PrefixSync) syncSinglePrefix(ctx context.Context, prefix models.Prefix) error { - existingPrefix := s.prefixSvc.GetByPrefix(ctx, prefix.Prefix) + existingPrefix := s.prefixSvc.GetByID(ctx, prefix.ID) // Build status reference (required) statusRef, err := s.buildStatusReference(ctx, prefix.Status) @@ -84,6 +84,7 @@ func (s *PrefixSync) syncSinglePrefix(ctx context.Context, prefix models.Prefix) } prefixRequest := nb.WritablePrefixRequest{ + Id: optionalID(prefix.ID), Prefix: prefix.Prefix, Status: statusRef, } diff --git a/go/nautobotop/internal/nautobot/sync/rack.go b/go/nautobotop/internal/nautobot/sync/rack.go index 855a33dfa..36d7850af 100644 --- a/go/nautobotop/internal/nautobot/sync/rack.go +++ b/go/nautobotop/internal/nautobot/sync/rack.go @@ -56,7 +56,7 @@ func (s *RackSync) SyncAll(ctx context.Context, data map[string]string) error { // syncSingleRack handles the create/update logic for a single rack func (s *RackSync) syncSingleRack(ctx context.Context, rack models.Rack) error { - existingRack := s.rackSvc.GetByName(ctx, rack.Name) + existingRack := s.rackSvc.GetByID(ctx, rack.ID) // Build location reference locationRef, err := s.buildLocationReference(ctx, rack.Location) @@ -71,6 +71,7 @@ func (s *RackSync) syncSingleRack(ctx context.Context, rack models.Rack) error { } rackRequest := nb.WritableRackRequest{ + Id: optionalID(rack.ID), Name: rack.Name, Comments: nb.PtrString(rack.Description), Location: locationRef, diff --git a/go/nautobotop/internal/nautobot/sync/rackGroup.go b/go/nautobotop/internal/nautobot/sync/rackGroup.go index e7682ebca..72f9283f1 100644 --- a/go/nautobotop/internal/nautobot/sync/rackGroup.go +++ b/go/nautobotop/internal/nautobot/sync/rackGroup.go @@ -68,9 +68,10 @@ func (s *RackGroupSync) syncRackGroupRecursive(ctx context.Context, rackGroup mo // syncSingleRackGroup handles the create/update logic for a single location func (s *RackGroupSync) syncSingleRackGroup(ctx context.Context, rackGroup models.RackGroup, parentID *string) (*string, error) { - existingRackGroup := s.rackGroupSvc.GetByName(ctx, rackGroup.Name) + existingRackGroup := s.rackGroupSvc.GetByID(ctx, rackGroup.ID) rackGroupRequest := nb.RackGroupRequest{ + Id: optionalID(rackGroup.ID), Name: rackGroup.Name, Description: nb.PtrString(rackGroup.Description), Parent: buildParentReference(parentID), @@ -86,7 +87,7 @@ func (s *RackGroupSync) syncSingleRackGroup(ctx context.Context, rackGroup model } log.Info("rackGroup is unchanged, skipping update", "name", rackGroupRequest.Name) - return rackGroupRequest.Id, nil + return existingRackGroup.Id, nil } // createRackGroup creates a new location in Nautobot diff --git a/go/nautobotop/internal/nautobot/sync/rir.go b/go/nautobotop/internal/nautobot/sync/rir.go index 595452082..5a3d1b346 100644 --- a/go/nautobotop/internal/nautobot/sync/rir.go +++ b/go/nautobotop/internal/nautobot/sync/rir.go @@ -47,9 +47,10 @@ func (s *RirSync) SyncAll(ctx context.Context, data map[string]string) error { } func (s *RirSync) syncSingleRir(ctx context.Context, rir models.Rir) error { - existingRir := s.rirSvc.GetByName(ctx, rir.Name) + existingRir := s.rirSvc.GetByID(ctx, rir.ID) rirRequest := nb.RIRRequest{ + Id: optionalID(rir.ID), Name: rir.Name, IsPrivate: nb.PtrBool(rir.IsPrivate), } diff --git a/go/nautobotop/internal/nautobot/sync/role.go b/go/nautobotop/internal/nautobot/sync/role.go index 7549d0732..a36045c57 100644 --- a/go/nautobotop/internal/nautobot/sync/role.go +++ b/go/nautobotop/internal/nautobot/sync/role.go @@ -47,9 +47,10 @@ func (s *RoleSync) SyncAll(ctx context.Context, data map[string]string) error { } func (s *RoleSync) syncSingleRole(ctx context.Context, role models.Role) error { - existing := s.roleSvc.GetByName(ctx, role.Name) + existing := s.roleSvc.GetByID(ctx, role.ID) roleRequest := nb.RoleRequest{ + Id: optionalID(role.ID), Name: role.Name, ContentTypes: role.ContentTypes, } diff --git a/go/nautobotop/internal/nautobot/sync/tenant.go b/go/nautobotop/internal/nautobot/sync/tenant.go index 864878625..d458a1f68 100644 --- a/go/nautobotop/internal/nautobot/sync/tenant.go +++ b/go/nautobotop/internal/nautobot/sync/tenant.go @@ -52,9 +52,10 @@ func (s *TenantSync) SyncAll(ctx context.Context, data map[string]string) error } func (s *TenantSync) syncSingleTenant(ctx context.Context, tenant models.Tenant) error { - existing := s.tenantSvc.GetByName(ctx, tenant.Name) + existing := s.tenantSvc.GetByID(ctx, tenant.ID) tenantRequest := nb.TenantRequest{ + Id: optionalID(tenant.ID), Name: tenant.Name, } if tenant.Description != "" { diff --git a/go/nautobotop/internal/nautobot/sync/tenantGroup.go b/go/nautobotop/internal/nautobot/sync/tenantGroup.go index e2d064b58..52fc88b31 100644 --- a/go/nautobotop/internal/nautobot/sync/tenantGroup.go +++ b/go/nautobotop/internal/nautobot/sync/tenantGroup.go @@ -47,9 +47,10 @@ func (s *TenantGroupSync) SyncAll(ctx context.Context, data map[string]string) e } func (s *TenantGroupSync) syncSingleTenantGroup(ctx context.Context, tg models.TenantGroup) error { - existing := s.tenantGroupSvc.GetByName(ctx, tg.Name) + existing := s.tenantGroupSvc.GetByID(ctx, tg.ID) tgRequest := nb.TenantGroupRequest{ + Id: optionalID(tg.ID), Name: tg.Name, } if tg.Description != "" { diff --git a/go/nautobotop/internal/nautobot/sync/vlan.go b/go/nautobotop/internal/nautobot/sync/vlan.go index bc32896b2..d8668e6e3 100644 --- a/go/nautobotop/internal/nautobot/sync/vlan.go +++ b/go/nautobotop/internal/nautobot/sync/vlan.go @@ -66,7 +66,7 @@ func (s *VlanSync) SyncAll(ctx context.Context, data map[string]string) error { // syncSingleVlan handles the create/update logic for a single VLAN func (s *VlanSync) syncSingleVlan(ctx context.Context, vlan models.Vlan) error { - existingVlan := s.vlanSvc.GetByName(ctx, vlan.Name) + existingVlan := s.vlanSvc.GetByID(ctx, vlan.ID) // Build status reference (required) statusRef, err := s.buildStatusReference(ctx, vlan.Status) @@ -75,6 +75,7 @@ func (s *VlanSync) syncSingleVlan(ctx context.Context, vlan models.Vlan) error { } vlanRequest := nb.VLANRequest{ + Id: optionalID(vlan.ID), Vid: int32(vlan.Vid), Name: vlan.Name, Status: statusRef, diff --git a/go/nautobotop/internal/nautobot/sync/vlanGroup.go b/go/nautobotop/internal/nautobot/sync/vlanGroup.go index 506458513..ffe5da9c4 100644 --- a/go/nautobotop/internal/nautobot/sync/vlanGroup.go +++ b/go/nautobotop/internal/nautobot/sync/vlanGroup.go @@ -55,23 +55,23 @@ func (s *VlanGroupSync) SyncAll(ctx context.Context, data map[string]string) err // syncSingleVlanGroup handles the create/update logic for a single vlan group func (s *VlanGroupSync) syncSingleVlanGroup(ctx context.Context, vlanGroup models.VlanGroup) error { - existingVlanGroup := s.vlanGroupSvc.GetByName(ctx, vlanGroup.Name) + existingVlanGroup := s.vlanGroupSvc.GetByID(ctx, vlanGroup.ID) vlanGroupRequest := nb.VLANGroupRequest{ + Id: optionalID(vlanGroup.ID), Name: vlanGroup.Name, Location: s.buildLocationReference(ctx, vlanGroup.Location), Range: nb.PtrString(vlanGroup.Range), } - relationships := map[string]nb.ApprovalWorkflowDefinitionRequestRelationshipsValue{ - "ucvnigroup_vlangroup": helpers.BuildRelationshipSource(), - } if vlanGroup.UcvniGroup != "" { if id := s.ucvniGroupSvc.GetByName(ctx, vlanGroup.UcvniGroup).ID; id != "" { - relationships["ucvnigroup_vlangroup"] = helpers.BuildRelationshipSource(id) + relationships := map[string]nb.ApprovalWorkflowDefinitionRequestRelationshipsValue{ + "ucvnigroup_vlangroup": helpers.BuildRelationshipSource(id), + } + vlanGroupRequest.Relationships = &relationships } } - vlanGroupRequest.Relationships = &relationships if existingVlanGroup.Id == nil { return s.createVlanGroup(ctx, vlanGroupRequest) diff --git a/go/nautobotop/internal/nautobot/tenancy/tenant.go b/go/nautobotop/internal/nautobot/tenancy/tenant.go index 36cd66f81..4fe4e8ed2 100644 --- a/go/nautobotop/internal/nautobot/tenancy/tenant.go +++ b/go/nautobotop/internal/nautobot/tenancy/tenant.go @@ -56,6 +56,29 @@ func (s *TenantService) GetByName(ctx context.Context, name string) nb.Tenant { return list.Results[0] } +func (s *TenantService) GetByID(ctx context.Context, id string) nb.Tenant { + if id == "" { + return nb.Tenant{} + } + if tenant, ok := cache.FindByID(s.client.Cache, "tenants", id, func(t nb.Tenant) *string { + return t.Id + }); ok { + return tenant + } + + list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantsList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetTenantByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.Tenant{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.Tenant{} + } + + return list.Results[0] +} + func (s *TenantService) ListAll(ctx context.Context) []nb.Tenant { ids := s.client.GetChangeObjectIDS(ctx, "tenancy.tenant") list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantsList(ctx).Id(ids).Depth(2).Execute() @@ -74,16 +97,6 @@ func (s *TenantService) ListAll(ctx context.Context) []nb.Tenant { } func (s *TenantService) Update(ctx context.Context, id string, req nb.TenantRequest) (*nb.Tenant, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateTenant", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - tenant, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantsUpdate(ctx, id).TenantRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go b/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go index e138a56cf..24f307a77 100644 --- a/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go +++ b/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go @@ -56,6 +56,29 @@ func (s *TenantGroupService) GetByName(ctx context.Context, name string) nb.Tena return list.Results[0] } +func (s *TenantGroupService) GetByID(ctx context.Context, id string) nb.TenantGroup { + if id == "" { + return nb.TenantGroup{} + } + if tg, ok := cache.FindByID(s.client.Cache, "tenantgroups", id, func(t nb.TenantGroup) *string { + return t.Id + }); ok { + return tg + } + + list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantGroupsList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetTenantGroupByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.TenantGroup{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.TenantGroup{} + } + + return list.Results[0] +} + func (s *TenantGroupService) ListAll(ctx context.Context) []nb.TenantGroup { ids := s.client.GetChangeObjectIDS(ctx, "tenancy.tenantgroup") list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantGroupsList(ctx).Id(ids).Depth(2).Execute() @@ -74,16 +97,6 @@ func (s *TenantGroupService) ListAll(ctx context.Context) []nb.TenantGroup { } func (s *TenantGroupService) Update(ctx context.Context, id string, req nb.TenantGroupRequest) (*nb.TenantGroup, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateTenantGroup", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - tg, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantGroupsUpdate(ctx, id).TenantGroupRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/virtualization/cluster.go b/go/nautobotop/internal/nautobot/virtualization/cluster.go index 4fb184623..423b64bd7 100644 --- a/go/nautobotop/internal/nautobot/virtualization/cluster.go +++ b/go/nautobotop/internal/nautobot/virtualization/cluster.go @@ -57,6 +57,29 @@ func (s *ClusterService) GetByName(ctx context.Context, name string) nb.Cluster return list.Results[0] } +func (s *ClusterService) GetByID(ctx context.Context, id string) nb.Cluster { + if id == "" { + return nb.Cluster{} + } + if cluster, ok := cache.FindByID(s.client.Cache, "clusters", id, func(c nb.Cluster) *string { + return c.Id + }); ok { + return cluster + } + + list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClustersList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetClusterByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.Cluster{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.Cluster{} + } + + return list.Results[0] +} + func (s *ClusterService) ListAll(ctx context.Context) []nb.Cluster { ids := s.client.GetChangeObjectIDS(ctx, "virtualization.cluster") list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClustersList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *ClusterService) ListAll(ctx context.Context) []nb.Cluster { } func (s *ClusterService) Update(ctx context.Context, id string, req nb.ClusterRequest) (*nb.Cluster, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateCluster", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - cluster, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClustersUpdate(ctx, id).ClusterRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go b/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go index 99a47686e..0cf541cd9 100644 --- a/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go +++ b/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go @@ -57,6 +57,29 @@ func (s *ClusterGroupService) GetByName(ctx context.Context, name string) nb.Clu return list.Results[0] } +func (s *ClusterGroupService) GetByID(ctx context.Context, id string) nb.ClusterGroup { + if id == "" { + return nb.ClusterGroup{} + } + if clusterGroup, ok := cache.FindByID(s.client.Cache, "clustergroups", id, func(cg nb.ClusterGroup) *string { + return cg.Id + }); ok { + return clusterGroup + } + + list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterGroupsList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetClusterGroupByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.ClusterGroup{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.ClusterGroup{} + } + + return list.Results[0] +} + func (s *ClusterGroupService) ListAll(ctx context.Context) []nb.ClusterGroup { ids := s.client.GetChangeObjectIDS(ctx, "virtualization.clustergroup") list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterGroupsList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *ClusterGroupService) ListAll(ctx context.Context) []nb.ClusterGroup { } func (s *ClusterGroupService) Update(ctx context.Context, id string, req nb.ClusterGroupRequest) (*nb.ClusterGroup, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateClusterGroup", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - clusterGroup, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterGroupsUpdate(ctx, id).ClusterGroupRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) diff --git a/go/nautobotop/internal/nautobot/virtualization/clusterType.go b/go/nautobotop/internal/nautobot/virtualization/clusterType.go index 66bccc5a8..9106c8a96 100644 --- a/go/nautobotop/internal/nautobot/virtualization/clusterType.go +++ b/go/nautobotop/internal/nautobot/virtualization/clusterType.go @@ -57,6 +57,29 @@ func (s *ClusterTypeService) GetByName(ctx context.Context, name string) nb.Clus return list.Results[0] } +func (s *ClusterTypeService) GetByID(ctx context.Context, id string) nb.ClusterType { + if id == "" { + return nb.ClusterType{} + } + if clusterType, ok := cache.FindByID(s.client.Cache, "clustertypes", id, func(ct nb.ClusterType) *string { + return ct.Id + }); ok { + return clusterType + } + + list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterTypesList(ctx).Depth(2).Id([]string{id}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("GetClusterTypeByID", "failed to get", "id", id, "error", err.Error(), "response_body", bodyString) + return nb.ClusterType{} + } + if list == nil || len(list.Results) == 0 || list.Results[0].Id == nil { + return nb.ClusterType{} + } + + return list.Results[0] +} + func (s *ClusterTypeService) ListAll(ctx context.Context) []nb.ClusterType { ids := s.client.GetChangeObjectIDS(ctx, "virtualization.clustertype") list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterTypesList(ctx).Id(ids).Depth(2).Execute() @@ -76,16 +99,6 @@ func (s *ClusterTypeService) ListAll(ctx context.Context) []nb.ClusterType { } func (s *ClusterTypeService) Update(ctx context.Context, id string, req nb.ClusterTypeRequest) (*nb.ClusterType, error) { - owned, err := s.client.IsCreatedByUser(ctx, id) - if err != nil { - s.client.AddReport("UpdateClusterType", "failed to check ownership", "id", id, "error", err.Error()) - return nil, err - } - if !owned { - log.Warn("skipping update, object not created by user", "id", id, "user", s.client.Username) - return nil, nil - } - clusterType, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterTypesUpdate(ctx, id).ClusterTypeRequest(req).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) From 79028d6db044d32f491bcb681578d8416b15a85a Mon Sep 17 00:00:00 2001 From: Abhimanyu Sharma Date: Thu, 30 Apr 2026 20:23:51 +0530 Subject: [PATCH 2/2] fix: remove the use of GetChangeObjectIDS --- .../internal/nautobot/client/graphql.go | 75 +----------------- .../internal/nautobot/dcim/devicetype.go | 3 +- .../internal/nautobot/dcim/location.go | 3 +- .../internal/nautobot/dcim/locationtype.go | 3 +- .../internal/nautobot/dcim/manufacturer.go | 33 +++----- go/nautobotop/internal/nautobot/dcim/rack.go | 3 +- .../internal/nautobot/dcim/rackGroup.go | 3 +- .../nautobot/dcim/templates/console_port.go | 32 +++----- .../nautobot/dcim/templates/interface.go | 30 +++---- .../nautobot/dcim/templates/module_bay.go | 32 +++----- .../nautobot/dcim/templates/power_port.go | 32 +++----- .../internal/nautobot/extras/role.go | 3 +- .../internal/nautobot/helpers/pagination.go | 78 ------------------- .../internal/nautobot/ipam/namespace.go | 3 +- .../internal/nautobot/ipam/prefix.go | 3 +- go/nautobotop/internal/nautobot/ipam/rir.go | 3 +- go/nautobotop/internal/nautobot/ipam/vlan.go | 3 +- .../internal/nautobot/ipam/vlanGroup.go | 3 +- .../internal/nautobot/tenancy/tenant.go | 3 +- .../internal/nautobot/tenancy/tenantGroup.go | 3 +- .../nautobot/virtualization/cluster.go | 3 +- .../nautobot/virtualization/clusterGroup.go | 3 +- .../nautobot/virtualization/clusterType.go | 3 +- 23 files changed, 66 insertions(+), 294 deletions(-) delete mode 100644 go/nautobotop/internal/nautobot/helpers/pagination.go diff --git a/go/nautobotop/internal/nautobot/client/graphql.go b/go/nautobotop/internal/nautobot/client/graphql.go index 871952372..529f0a758 100644 --- a/go/nautobotop/internal/nautobot/client/graphql.go +++ b/go/nautobotop/internal/nautobot/client/graphql.go @@ -3,7 +3,6 @@ package client import ( "context" "io" - "net/http" "k8s.io/apimachinery/pkg/util/json" @@ -15,12 +14,8 @@ type GraphQL struct { } type ObjectChanges struct { - ID string `json:"id"` - UserName string `json:"user_name"` - Action string `json:"action"` - RequestID string `json:"request_id"` - ChangedObjectID string `json:"changed_object_id"` - RelatedObjectID string `json:"related_object_id"` + UserName string `json:"user_name"` + Action string `json:"action"` } type GraphQLData struct { @@ -37,10 +32,8 @@ func (n *NautobotClient) IsCreatedByUser(ctx context.Context, objectID string) ( user_name: $userName action__ic: ["CREATE"] ) { - id user_name action - changed_object_id } }`, Variables: map[string]any{ @@ -74,67 +67,3 @@ func (n *NautobotClient) IsCreatedByUser(ctx context.Context, objectID string) ( } return false, nil } - -func (n *NautobotClient) GetCreateChangeList(ctx context.Context, objectType string) ([]ObjectChanges, *http.Response, error) { - var allObjectChanges []ObjectChanges - var lastResp *http.Response - offset := 0 - limit := 100 - - for { - req := nb.GraphQLAPIRequest{ - Query: ` - query GetObjectChanges($changedObjectType: String, $userName: [String], $action: [String], $limit: Int, $offset: Int) { - object_changes( - changed_object_type: $changedObjectType - user_name: $userName - action: $action - limit: $limit - offset: $offset - ) { - id - user_name - action - request_id - changed_object_id - related_object_id - } - }`, - Variables: map[string]any{ - "changedObjectType": objectType, - "limit": limit, - "offset": offset, - "userName": []string{n.Username}, - "action": []string{"create", "delete"}, - }, - } - - _, resp, err := n.APIClient.GraphqlAPI.GraphqlCreate(ctx). - GraphQLAPIRequest(req). - Execute() - if err != nil { - return allObjectChanges, resp, err - } - - lastResp = resp - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return allObjectChanges, resp, err - } - resp.Body.Close() //nolint:errcheck - - var graphQL GraphQL - if err := json.Unmarshal(bodyBytes, &graphQL); err != nil { - return allObjectChanges, resp, err - } - if len(graphQL.Data.ObjectChanges) == 0 { - break - } - - allObjectChanges = append(allObjectChanges, graphQL.Data.ObjectChanges...) - offset += limit - } - - return allObjectChanges, lastResp, nil -} diff --git a/go/nautobotop/internal/nautobot/dcim/devicetype.go b/go/nautobotop/internal/nautobot/dcim/devicetype.go index 991f3bcdb..25cb64d9d 100644 --- a/go/nautobotop/internal/nautobot/dcim/devicetype.go +++ b/go/nautobotop/internal/nautobot/dcim/devicetype.go @@ -81,8 +81,7 @@ func (s *DeviceTypeService) GetByID(ctx context.Context, id string) nb.DeviceTyp } func (s *DeviceTypeService) ListAll(ctx context.Context) []nb.DeviceType { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.devicetype") - list, resp, err := s.client.APIClient.DcimAPI.DcimDeviceTypesList(ctx).Id(ids).Depth(10).Execute() + list, resp, err := s.client.APIClient.DcimAPI.DcimDeviceTypesList(ctx).Limit(10000).Depth(10).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllDeviceTypes", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/dcim/location.go b/go/nautobotop/internal/nautobot/dcim/location.go index 75c4fb0d8..66a22fecc 100644 --- a/go/nautobotop/internal/nautobot/dcim/location.go +++ b/go/nautobotop/internal/nautobot/dcim/location.go @@ -82,8 +82,7 @@ func (s *LocationService) GetByID(ctx context.Context, id string) nb.Location { } func (s *LocationService) ListAll(ctx context.Context) []nb.Location { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.location") - list, resp, err := s.client.APIClient.DcimAPI.DcimLocationsList(ctx).Id(ids).Depth(10).Execute() + list, resp, err := s.client.APIClient.DcimAPI.DcimLocationsList(ctx).Limit(10000).Depth(10).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllLocations", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/dcim/locationtype.go b/go/nautobotop/internal/nautobot/dcim/locationtype.go index 16c6f3dda..9faa0a524 100644 --- a/go/nautobotop/internal/nautobot/dcim/locationtype.go +++ b/go/nautobotop/internal/nautobot/dcim/locationtype.go @@ -81,8 +81,7 @@ func (s *LocationTypeService) GetByID(ctx context.Context, id string) nb.Locatio } func (s *LocationTypeService) ListAll(ctx context.Context) []nb.LocationType { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.locationtype") - list, resp, err := s.client.APIClient.DcimAPI.DcimLocationTypesList(ctx).Id(ids).Depth(10).Execute() + list, resp, err := s.client.APIClient.DcimAPI.DcimLocationTypesList(ctx).Limit(10000).Depth(10).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllLocationTypes", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/dcim/manufacturer.go b/go/nautobotop/internal/nautobot/dcim/manufacturer.go index 66036fd56..3766fb3b9 100644 --- a/go/nautobotop/internal/nautobot/dcim/manufacturer.go +++ b/go/nautobotop/internal/nautobot/dcim/manufacturer.go @@ -2,7 +2,6 @@ package dcim import ( "context" - "net/http" "github.com/charmbracelet/log" "github.com/rackerlabs/understack/go/nautobotop/internal/nautobot/cache" @@ -23,28 +22,20 @@ func NewManufacturerService(nautobotClient *client.NautobotClient) *Manufacturer } func (s *ManufacturerService) ListAll(ctx context.Context) []nb.Manufacturer { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.manufacturer") - - // Define the API call function for this specific endpoint - apiCall := func(ctx context.Context, batchIds []string) ([]nb.Manufacturer, *http.Response, error) { - list, resp, err := s.client.APIClient.DcimAPI.DcimManufacturersList(ctx).Id(batchIds).Depth(10).Execute() - if err != nil { - return nil, resp, err - } - if list == nil { - return []nb.Manufacturer{}, resp, nil - } - return list.Results, resp, nil + list, resp, err := s.client.APIClient.DcimAPI.DcimManufacturersList(ctx).Limit(10000).Depth(10).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("ListAllManufacturers", "failed to list", "error", err.Error(), "response_body", bodyString) + return []nb.Manufacturer{} + } + if list == nil || len(list.Results) == 0 { + return []nb.Manufacturer{} + } + if list.Results[0].Id == nil { + return []nb.Manufacturer{} } - // Use the helper function for pagination - return helpers.PaginatedListWithIDs( - ctx, - ids, - apiCall, - s.client.AddReport, - "ListAllManufacturers", - ) + return list.Results } func (s *ManufacturerService) GetByName(ctx context.Context, name string) nb.Manufacturer { diff --git a/go/nautobotop/internal/nautobot/dcim/rack.go b/go/nautobotop/internal/nautobot/dcim/rack.go index 69fa6eb4c..086b3a7a8 100644 --- a/go/nautobotop/internal/nautobot/dcim/rack.go +++ b/go/nautobotop/internal/nautobot/dcim/rack.go @@ -80,8 +80,7 @@ func (s *RackService) GetByID(ctx context.Context, id string) nb.Rack { } func (s *RackService) ListAll(ctx context.Context) []nb.Rack { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.rack") - list, resp, err := s.client.APIClient.DcimAPI.DcimRacksList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.DcimAPI.DcimRacksList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllRacks", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/dcim/rackGroup.go b/go/nautobotop/internal/nautobot/dcim/rackGroup.go index 0f04310ec..bc537d4f3 100644 --- a/go/nautobotop/internal/nautobot/dcim/rackGroup.go +++ b/go/nautobotop/internal/nautobot/dcim/rackGroup.go @@ -81,8 +81,7 @@ func (s *RackGroupService) GetByID(ctx context.Context, id string) nb.RackGroup } func (s *RackGroupService) ListAll(ctx context.Context) []nb.RackGroup { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.rackgroup") - list, resp, err := s.client.APIClient.DcimAPI.DcimRackGroupsList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.DcimAPI.DcimRackGroupsList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllRackGroups", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/dcim/templates/console_port.go b/go/nautobotop/internal/nautobot/dcim/templates/console_port.go index 43a15f265..9e54d8bf6 100644 --- a/go/nautobotop/internal/nautobot/dcim/templates/console_port.go +++ b/go/nautobotop/internal/nautobot/dcim/templates/console_port.go @@ -2,7 +2,6 @@ package templates import ( "context" - "net/http" "github.com/rackerlabs/understack/go/nautobotop/internal/nautobot/client" @@ -22,29 +21,16 @@ func NewConsolePortTemplateService(nautobotClient *client.NautobotClient) *Conso } func (s *ConsolePortTemplateService) ListByDeviceType(ctx context.Context, deviceTypeID string) []nb.ConsolePortTemplate { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.consoleporttemplate", deviceTypeID) - - // Define the API call function for this specific endpoint - apiCall := func(ctx context.Context, batchIds []string) ([]nb.ConsolePortTemplate, *http.Response, error) { - list, resp, err := s.client.APIClient.DcimAPI.DcimConsolePortTemplatesList(ctx).Id(batchIds).Depth(2).DeviceType([]string{deviceTypeID}).Execute() - if err != nil { - return nil, resp, err - } - if list == nil { - return []nb.ConsolePortTemplate{}, resp, nil - } - return list.Results, resp, nil + list, resp, err := s.client.APIClient.DcimAPI.DcimConsolePortTemplatesList(ctx).Limit(10000).Depth(2).DeviceType([]string{deviceTypeID}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("ListAllConsolePortTemplateByDeviceType", "failed to list", "device_type_id", deviceTypeID, "error", err.Error(), "response_body", bodyString) + return []nb.ConsolePortTemplate{} } - - // Use the helper function for pagination - return helpers.PaginatedListWithIDs( - ctx, - ids, - apiCall, - s.client.AddReport, - "ListAllConsolePortTemplateByDeviceType", - "device_type_id", deviceTypeID, - ) + if list == nil { + return []nb.ConsolePortTemplate{} + } + return list.Results } func (s *ConsolePortTemplateService) GetByName(ctx context.Context, name, deviceTypeID string) nb.ConsolePortTemplate { diff --git a/go/nautobotop/internal/nautobot/dcim/templates/interface.go b/go/nautobotop/internal/nautobot/dcim/templates/interface.go index 297882974..a324f4df8 100644 --- a/go/nautobotop/internal/nautobot/dcim/templates/interface.go +++ b/go/nautobotop/internal/nautobot/dcim/templates/interface.go @@ -2,7 +2,6 @@ package templates import ( "context" - "net/http" "github.com/rackerlabs/understack/go/nautobotop/internal/nautobot/client" @@ -22,27 +21,16 @@ func NewInterfaceTemplateService(nautobotClient *client.NautobotClient) *Interfa } func (s *InterfaceTemplateService) ListByDeviceType(ctx context.Context, deviceTypeID string) []nb.InterfaceTemplate { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.interfacetemplate", deviceTypeID) - - // Define the API call function for this specific endpoint - apiCall := func(ctx context.Context, batchIds []string) ([]nb.InterfaceTemplate, *http.Response, error) { - list, resp, err := s.client.APIClient.DcimAPI.DcimInterfaceTemplatesList(ctx).Id(batchIds).Depth(2).DeviceType([]string{deviceTypeID}).Execute() - if err != nil { - return nil, resp, err - } - if list == nil { - return []nb.InterfaceTemplate{}, resp, nil - } - return list.Results, resp, nil + list, resp, err := s.client.APIClient.DcimAPI.DcimInterfaceTemplatesList(ctx).Limit(10000).Depth(2).DeviceType([]string{deviceTypeID}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("ListAllInterfaceTemplateByDeviceType", "failed to list", "device_type_id", deviceTypeID, "error", err.Error(), "response_body", bodyString) + return []nb.InterfaceTemplate{} + } + if list == nil { + return []nb.InterfaceTemplate{} } - return helpers.PaginatedListWithIDs( - ctx, - ids, - apiCall, - s.client.AddReport, - "ListAllInterfaceTemplateByDeviceType", - "device_type_id", deviceTypeID, - ) + return list.Results } func (s *InterfaceTemplateService) GetByName(ctx context.Context, name, deviceTypeID string) nb.InterfaceTemplate { diff --git a/go/nautobotop/internal/nautobot/dcim/templates/module_bay.go b/go/nautobotop/internal/nautobot/dcim/templates/module_bay.go index a92165191..fbdafd348 100644 --- a/go/nautobotop/internal/nautobot/dcim/templates/module_bay.go +++ b/go/nautobotop/internal/nautobot/dcim/templates/module_bay.go @@ -2,7 +2,6 @@ package templates import ( "context" - "net/http" "github.com/rackerlabs/understack/go/nautobotop/internal/nautobot/client" @@ -22,29 +21,16 @@ func NewModuleBayTemplateService(nautobotClient *client.NautobotClient) *ModuleB } func (s *ModuleBayTemplateService) ListByDeviceType(ctx context.Context, deviceTypeID string) []nb.ModuleBayTemplate { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.modulebaytemplate", deviceTypeID) - - // Define the API call function for this specific endpoint - apiCall := func(ctx context.Context, batchIds []string) ([]nb.ModuleBayTemplate, *http.Response, error) { - list, resp, err := s.client.APIClient.DcimAPI.DcimModuleBayTemplatesList(ctx).Id(batchIds).Depth(2).DeviceType([]string{deviceTypeID}).Execute() - if err != nil { - return nil, resp, err - } - if list == nil { - return []nb.ModuleBayTemplate{}, resp, nil - } - return list.Results, resp, nil + list, resp, err := s.client.APIClient.DcimAPI.DcimModuleBayTemplatesList(ctx).Limit(10000).Depth(2).DeviceType([]string{deviceTypeID}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("ListAllModuleBayTemplateByDeviceType", "failed to list", "device_type_id", deviceTypeID, "error", err.Error(), "response_body", bodyString) + return []nb.ModuleBayTemplate{} } - - // Use the helper function for pagination - return helpers.PaginatedListWithIDs( - ctx, - ids, - apiCall, - s.client.AddReport, - "ListAllModuleBayTemplateByDeviceType", - "device_type_id", deviceTypeID, - ) + if list == nil { + return []nb.ModuleBayTemplate{} + } + return list.Results } func (s *ModuleBayTemplateService) GetByName(ctx context.Context, name, deviceTypeID string) nb.ModuleBayTemplate { diff --git a/go/nautobotop/internal/nautobot/dcim/templates/power_port.go b/go/nautobotop/internal/nautobot/dcim/templates/power_port.go index 8c7b859c5..c8e5957d9 100644 --- a/go/nautobotop/internal/nautobot/dcim/templates/power_port.go +++ b/go/nautobotop/internal/nautobot/dcim/templates/power_port.go @@ -2,7 +2,6 @@ package templates import ( "context" - "net/http" "github.com/rackerlabs/understack/go/nautobotop/internal/nautobot/client" @@ -22,29 +21,16 @@ func NewPowerPortTemplateService(nautobotClient *client.NautobotClient) *PowerPo } func (s *PowerPortTemplateService) ListByDeviceType(ctx context.Context, deviceTypeID string) []nb.PowerPortTemplate { - ids := s.client.GetChangeObjectIDS(ctx, "dcim.powerporttemplate", deviceTypeID) - - // Define the API call function for this specific endpoint - apiCall := func(ctx context.Context, batchIds []string) ([]nb.PowerPortTemplate, *http.Response, error) { - list, resp, err := s.client.APIClient.DcimAPI.DcimPowerPortTemplatesList(ctx).Id(batchIds).Depth(1).DeviceType([]string{deviceTypeID}).Execute() - if err != nil { - return nil, resp, err - } - if list == nil { - return []nb.PowerPortTemplate{}, resp, nil - } - return list.Results, resp, nil + list, resp, err := s.client.APIClient.DcimAPI.DcimPowerPortTemplatesList(ctx).Limit(10000).Depth(1).DeviceType([]string{deviceTypeID}).Execute() + if err != nil { + bodyString := helpers.ReadResponseBody(resp) + s.client.AddReport("ListAllPowerPortTemplate", "failed to list", "device_type_id", deviceTypeID, "error", err.Error(), "response_body", bodyString) + return []nb.PowerPortTemplate{} } - - // Use the helper function for pagination - return helpers.PaginatedListWithIDs( - ctx, - ids, - apiCall, - s.client.AddReport, - "ListAllPowerPortTemplate", - "device_type_id", deviceTypeID, - ) + if list == nil { + return []nb.PowerPortTemplate{} + } + return list.Results } func (s *PowerPortTemplateService) GetByName(ctx context.Context, name, deviceTypeID string) nb.PowerPortTemplate { diff --git a/go/nautobotop/internal/nautobot/extras/role.go b/go/nautobotop/internal/nautobot/extras/role.go index 32dfebbd6..9e24269d1 100644 --- a/go/nautobotop/internal/nautobot/extras/role.go +++ b/go/nautobotop/internal/nautobot/extras/role.go @@ -80,8 +80,7 @@ func (s *RoleService) GetByID(ctx context.Context, id string) nb.Role { } func (s *RoleService) ListAll(ctx context.Context) []nb.Role { - ids := s.client.GetChangeObjectIDS(ctx, "extras.role") - list, resp, err := s.client.APIClient.ExtrasAPI.ExtrasRolesList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.ExtrasAPI.ExtrasRolesList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllRoles", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/helpers/pagination.go b/go/nautobotop/internal/nautobot/helpers/pagination.go deleted file mode 100644 index 1375f2423..000000000 --- a/go/nautobotop/internal/nautobot/helpers/pagination.go +++ /dev/null @@ -1,78 +0,0 @@ -package helpers - -import ( - "context" - "net/http" - "strconv" - - "github.com/charmbracelet/log" -) - -// PaginatedAPICall represents a function that makes an API call with a batch of IDs -type PaginatedAPICall[T any] func(ctx context.Context, ids []string) ([]T, *http.Response, error) - -// ReportFunc represents a function for reporting errors -type ReportFunc func(key string, line ...string) - -// PaginatedListWithIDs processes a list of IDs in batches and makes paginated API calls -// T: The type of objects being returned (e.g., nb.InterfaceTemplate) -// ids: List of IDs to process -// apiCall: Function that makes the API call with a batch of IDs -// reportFunc: Function to report errors -// operationName: Name of the operation for error reporting -// additionalParams: Additional parameters to include in error reports -func PaginatedListWithIDs[T any]( - ctx context.Context, - ids []string, - apiCall PaginatedAPICall[T], - reportFunc ReportFunc, - operationName string, - additionalParams ...string, -) []T { - if len(ids) == 0 { - log.Info("no IDs found for operation", "operation", operationName) - return []T{} - } - - var allResults []T - pageSize := 20 - - // Process IDs in batches - for i := 0; i < len(ids); i += pageSize { - end := min(i+pageSize, len(ids)) - - batchIds := ids[i:end] - results, resp, err := apiCall(ctx, batchIds) - if err != nil { - bodyString := ReadResponseBody(resp) - batchNum := strconv.Itoa(i/pageSize + 1) - - // Build error report parameters - reportParams := []string{ - "failed to execute paginated API call", - "operation", operationName, - "batch", batchNum, - "error", err.Error(), - "response_body", bodyString, - } - - // Add additional parameters if provided - reportParams = append(reportParams, additionalParams...) - - reportFunc(operationName, reportParams...) - continue // Continue with next batch instead of returning empty - } - - if len(results) > 0 { - allResults = append(allResults, results...) - } - } - - if len(allResults) == 0 { - log.Info("no results found", "operation", operationName) - return []T{} - } - - log.Info("retrieved paginated results", "operation", operationName, "count", len(allResults)) - return allResults -} diff --git a/go/nautobotop/internal/nautobot/ipam/namespace.go b/go/nautobotop/internal/nautobot/ipam/namespace.go index 4e5b170b4..4f5d92e8a 100644 --- a/go/nautobotop/internal/nautobot/ipam/namespace.go +++ b/go/nautobotop/internal/nautobot/ipam/namespace.go @@ -81,8 +81,7 @@ func (s *NamespaceService) GetByID(ctx context.Context, id string) nb.Namespace } func (s *NamespaceService) ListAll(ctx context.Context) []nb.Namespace { - ids := s.client.GetChangeObjectIDS(ctx, "ipam.namespace") - list, resp, err := s.client.APIClient.IpamAPI.IpamNamespacesList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.IpamAPI.IpamNamespacesList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllNamespaces", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/ipam/prefix.go b/go/nautobotop/internal/nautobot/ipam/prefix.go index 74b6ccd73..2991951ec 100644 --- a/go/nautobotop/internal/nautobot/ipam/prefix.go +++ b/go/nautobotop/internal/nautobot/ipam/prefix.go @@ -81,8 +81,7 @@ func (s *PrefixService) GetByID(ctx context.Context, id string) nb.Prefix { } func (s *PrefixService) ListAll(ctx context.Context) []nb.Prefix { - ids := s.client.GetChangeObjectIDS(ctx, "ipam.prefix") - list, resp, err := s.client.APIClient.IpamAPI.IpamPrefixesList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.IpamAPI.IpamPrefixesList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllPrefixes", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/ipam/rir.go b/go/nautobotop/internal/nautobot/ipam/rir.go index c45f7080f..6b0222e39 100644 --- a/go/nautobotop/internal/nautobot/ipam/rir.go +++ b/go/nautobotop/internal/nautobot/ipam/rir.go @@ -80,8 +80,7 @@ func (s *RirService) GetByID(ctx context.Context, id string) nb.RIR { } func (s *RirService) ListAll(ctx context.Context) []nb.RIR { - ids := s.client.GetChangeObjectIDS(ctx, "ipam.rir") - list, resp, err := s.client.APIClient.IpamAPI.IpamRirsList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.IpamAPI.IpamRirsList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllRirs", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/ipam/vlan.go b/go/nautobotop/internal/nautobot/ipam/vlan.go index fdab616ad..10ddb57f1 100644 --- a/go/nautobotop/internal/nautobot/ipam/vlan.go +++ b/go/nautobotop/internal/nautobot/ipam/vlan.go @@ -81,8 +81,7 @@ func (s *VlanService) GetByID(ctx context.Context, id string) nb.VLAN { } func (s *VlanService) ListAll(ctx context.Context) []nb.VLAN { - ids := s.client.GetChangeObjectIDS(ctx, "ipam.vlan") - list, resp, err := s.client.APIClient.IpamAPI.IpamVlansList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.IpamAPI.IpamVlansList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllVlans", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/ipam/vlanGroup.go b/go/nautobotop/internal/nautobot/ipam/vlanGroup.go index 873a3360e..9ba5aa145 100644 --- a/go/nautobotop/internal/nautobot/ipam/vlanGroup.go +++ b/go/nautobotop/internal/nautobot/ipam/vlanGroup.go @@ -81,8 +81,7 @@ func (s *VlanGroupService) GetByID(ctx context.Context, id string) nb.VLANGroup } func (s *VlanGroupService) ListAll(ctx context.Context) []nb.VLANGroup { - ids := s.client.GetChangeObjectIDS(ctx, "ipam.vlangroup") - list, resp, err := s.client.APIClient.IpamAPI.IpamVlanGroupsList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.IpamAPI.IpamVlanGroupsList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllVlanGroups", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/tenancy/tenant.go b/go/nautobotop/internal/nautobot/tenancy/tenant.go index 4fe4e8ed2..8cec9bed2 100644 --- a/go/nautobotop/internal/nautobot/tenancy/tenant.go +++ b/go/nautobotop/internal/nautobot/tenancy/tenant.go @@ -80,8 +80,7 @@ func (s *TenantService) GetByID(ctx context.Context, id string) nb.Tenant { } func (s *TenantService) ListAll(ctx context.Context) []nb.Tenant { - ids := s.client.GetChangeObjectIDS(ctx, "tenancy.tenant") - list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantsList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantsList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllTenants", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go b/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go index 24f307a77..371015545 100644 --- a/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go +++ b/go/nautobotop/internal/nautobot/tenancy/tenantGroup.go @@ -80,8 +80,7 @@ func (s *TenantGroupService) GetByID(ctx context.Context, id string) nb.TenantGr } func (s *TenantGroupService) ListAll(ctx context.Context) []nb.TenantGroup { - ids := s.client.GetChangeObjectIDS(ctx, "tenancy.tenantgroup") - list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantGroupsList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.TenancyAPI.TenancyTenantGroupsList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllTenantGroups", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/virtualization/cluster.go b/go/nautobotop/internal/nautobot/virtualization/cluster.go index 423b64bd7..6a0293cb5 100644 --- a/go/nautobotop/internal/nautobot/virtualization/cluster.go +++ b/go/nautobotop/internal/nautobot/virtualization/cluster.go @@ -81,8 +81,7 @@ func (s *ClusterService) GetByID(ctx context.Context, id string) nb.Cluster { } func (s *ClusterService) ListAll(ctx context.Context) []nb.Cluster { - ids := s.client.GetChangeObjectIDS(ctx, "virtualization.cluster") - list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClustersList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClustersList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllClusters", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go b/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go index 0cf541cd9..54e3a20b6 100644 --- a/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go +++ b/go/nautobotop/internal/nautobot/virtualization/clusterGroup.go @@ -81,8 +81,7 @@ func (s *ClusterGroupService) GetByID(ctx context.Context, id string) nb.Cluster } func (s *ClusterGroupService) ListAll(ctx context.Context) []nb.ClusterGroup { - ids := s.client.GetChangeObjectIDS(ctx, "virtualization.clustergroup") - list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterGroupsList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterGroupsList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllClusterGroups", "failed to list", "error", err.Error(), "response_body", bodyString) diff --git a/go/nautobotop/internal/nautobot/virtualization/clusterType.go b/go/nautobotop/internal/nautobot/virtualization/clusterType.go index 9106c8a96..658795ca7 100644 --- a/go/nautobotop/internal/nautobot/virtualization/clusterType.go +++ b/go/nautobotop/internal/nautobot/virtualization/clusterType.go @@ -81,8 +81,7 @@ func (s *ClusterTypeService) GetByID(ctx context.Context, id string) nb.ClusterT } func (s *ClusterTypeService) ListAll(ctx context.Context) []nb.ClusterType { - ids := s.client.GetChangeObjectIDS(ctx, "virtualization.clustertype") - list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterTypesList(ctx).Id(ids).Depth(2).Execute() + list, resp, err := s.client.APIClient.VirtualizationAPI.VirtualizationClusterTypesList(ctx).Limit(10000).Depth(2).Execute() if err != nil { bodyString := helpers.ReadResponseBody(resp) s.client.AddReport("ListAllClusterTypes", "failed to list", "error", err.Error(), "response_body", bodyString)