Add a lag to an interface via pynetbox

290 views
Skip to first unread message

Erwan

unread,
Oct 17, 2019, 12:36:29 PM10/17/19
to NetBox
Hello,


Is it possible to add a lag on an existing interface via pynetbox ?

I did some tests but I can not do it...

Here is the information I retrieve / use:

Device:
command:
        sesrv=nb.dcim.devices.get(name=srsrv)
result:
        "v3bj33-cas01"

Dictionnary Device
I create a dictionnary to store all information about my device:
Command:
        dict_sesrv = {
            'name':sesrv.name,
            'id':sesrv.id,
        }
result:
{'name': 'v3bj33-cas01', 'id': 648}

Interface (to add LAG):
command:
        get_sint = nb.dcim.interfaces.get(
            device_id=sesrv.id,
            name=srint,
         )

result:
        "ETH1/14"

LACP (lag) information:
Command:
        get_po = nb.dcim.interfaces.get(
            device_id=sesrv.id,
            name=po,
        )
result:
        "Po700"

Dictionnary lag:
I create a dictionnary for lag informations:
        test={
            'id':get_po.id,
            'device':dict_sesrv,
        }


For me, I have all the information required to add my lag (already existing) on my interface
I admit I do not know if I should perform a create or update.
I tried to create but it is not working.

This is the second trial:
            test = nb.dcim.interfaces.create(
                device=dict_sesrv,    
                id=get_sint.id,
                name=get_sint.name,
                lag=test,
            )

result:
          {"non_field_errors":["The fields device, name must make a unique set."]}

So do you have an idea?

Thx

Brian Candler

unread,
Oct 17, 2019, 2:43:12 PM10/17/19
to NetBox
On Thursday, 17 October 2019 17:36:29 UTC+1, Erwan wrote:
Is it possible to add a lag on an existing interface via pynetbox ?


You mean, make an existing interface become a member of a LAG?

Do it the same as you would in the web interface: on the physical interface, set its "lag" attribute to point to the LAG you want to be a member of.  That would be an "update" operation, not a "create" operation.

Erwan

unread,
Oct 17, 2019, 4:32:55 PM10/17/19
to NetBox
Ok thank you for your answer.

So I tested "update" in my python script:

            new=get_dint.update(
            lag=test,
            )

But I have a new problem:

Traceback (most recent call last):
  File "Intrefaces_IN_PO_create csv.py", line 57, in <module>
    lag=test,
TypeError: update() got an unexpected keyword argument 'lag'

Brian Candler

unread,
Oct 18, 2019, 5:51:14 AM10/18/19
to NetBox
Documentation for pynetbox is very sparse, but look here for an example:

It will be something like:

myint = nb.dcim.interfaces.get(...)
myint.lag = foo
myint.save()

Reply all
Reply to author
Forward
0 new messages