Provide an API endpoint to enable ASN object assignments #8771

Closed
opened 2025-12-29 20:41:01 +01:00 by adam · 2 comments
Owner

Originally created by @richardjohnallsopp on GitHub (Oct 24, 2023).

NetBox version

v3.6.2

Feature type

Change to existing functionality

Proposed functionality

It could be something I'm missing, but I don't see a way to assign an ASN object to a site like you can with contact objects.

Use case

We're in the process of migrating from v2.11.11 to v3.6.2 and there are several changes to the way data is handled. We're writing some scripts to handle these changes like pulling contacts from our current version and creating + assigning them on our updated stage version. We don't see a way to handle ASN objects programatically using the API and Pynetbox.

For example with contacts we were able to do this:

import pynetbox

nb_prod = pynetbox.api(url='https://netbox.prod, token='')
nb_dev = pynetbox.api(url='https://netbox.stage', token='')

# fetch all site objects
nb_site_list = nb_prod.dcim.sites.all()

def assigning_site_contacts(data,api):

  for site in data:
    if site.contact_name != "":
      assigning_contacts = api.tenancy.contact_assignments.create(
          content_type = "dcim.site",
          object_id = site.id,
          contact = {'name': site.contact_name},
          role = {'name': 'Site Contact'},
      )
    print("assigning contacts: " + str(assigning_contacts))

assigning_site_contacts(nb_site_list,nb_dev)

Could we add something like this for ASN objects?

Database changes

No response

External dependencies

No response

Originally created by @richardjohnallsopp on GitHub (Oct 24, 2023). ### NetBox version v3.6.2 ### Feature type Change to existing functionality ### Proposed functionality It could be something I'm missing, but I don't see a way to assign an ASN object to a site like you can with contact objects. ### Use case We're in the process of migrating from v2.11.11 to v3.6.2 and there are several changes to the way data is handled. We're writing some scripts to handle these changes like pulling contacts from our current version and creating + assigning them on our updated stage version. We don't see a way to handle ASN objects programatically using the API and Pynetbox. For example with contacts we were able to do this: ``` import pynetbox nb_prod = pynetbox.api(url='https://netbox.prod, token='') nb_dev = pynetbox.api(url='https://netbox.stage', token='') # fetch all site objects nb_site_list = nb_prod.dcim.sites.all() def assigning_site_contacts(data,api): for site in data: if site.contact_name != "": assigning_contacts = api.tenancy.contact_assignments.create( content_type = "dcim.site", object_id = site.id, contact = {'name': site.contact_name}, role = {'name': 'Site Contact'}, ) print("assigning contacts: " + str(assigning_contacts)) assigning_site_contacts(nb_site_list,nb_dev) ``` Could we add something like this for ASN objects? ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 20:41:01 +01:00
adam closed this issue 2025-12-29 20:41:01 +01:00
Author
Owner

@siemhermans commented on GitHub (Oct 25, 2023):

We have a similar usecase where we want to assign ASNs to dcim.device objects. We run a spine-leaf datacenter fabric where each switch has its own ASN. Currently we use the description field to 'assign' an ASN to a device and query the description in our automation tooling: https://netbox.internal/api/ipam/asns/?description=$DEVICE_NAME

This works, but the downside is that a namechange of a device would require a change on the ASN-object descrption as well.

@siemhermans commented on GitHub (Oct 25, 2023): We have a similar usecase where we want to assign ASNs to dcim.device objects. We run a spine-leaf datacenter fabric where each switch has its own ASN. Currently we use the description field to 'assign' an ASN to a device and query the description in our automation tooling: https://netbox.internal/api/ipam/asns/?description=$DEVICE_NAME This works, but the downside is that a namechange of a device would require a change on the ASN-object descrption as well.
Author
Owner

@stavr666 commented on GitHub (Oct 25, 2023):

This works, but the downside is that a namechange of a device would require a change on the ASN-object descrption as well.

You can use custom field with "device" objects.

@stavr666 commented on GitHub (Oct 25, 2023): > This works, but the downside is that a namechange of a device would require a change on the ASN-object descrption as well. You can use custom field with "device" objects.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8771