View Only


This community is currently under full moderation, meaning  all posts will be reviewed before appearing in the community. Please expect a brief delay—there is no need to post multiple times. If your post is rejected, you'll receive an email outlining the reason(s). We've implemented full moderation to control spam. Thank you for your patience and participation.

  • 1.  Using PyEz to configure interface results in error: bad element: interface

    Posted 11-02-2020 23:40


    I've just begun my road to victory with python and pyez. So there might be some basic failure in my understanding on what and how this should be working.

    First out, I deployed set vlans config, no issue at all, works just fine.

    Then I've added "set interface ge-0/0/5.<XXX> vlan-id <XXX>. This just wont load. If I run it manually on the cli it works fine. 

    Here is my code snippet!


    a_device = Device(host=my_host, gather_facts=Falseuser=usrname, password=usrpasswd)
      cfg = Config(a_device)
      if set_cmds:
        for cmd in set_cmds:
          print("Debug... " + cmd)
          #cfg.load(cmd, format="set", merge=True) <-- This doesnt work.
          #Adding the cfg static, to rule out everything else.
          cfg.load("set interface ge-0/0/5 unit 122 vlan-id 122", format="set", merge=True) <-- it breaks here!
          print("Did it pass?")
          #if it passed, can i do cfg.load with more set-lines?
          #cfg.load("set interface ge-0/0/5 unit 11 vlan-id 11", format="set", merge=True)
    I can see that the commands in my "set_cmds" list is just fine if i print them. Also the set vlan works with the "set_cmds" list. So thats not the problem.
    It says "bad element" when trying to set the interface:
    Traceback (most recent call last):
    File "", line 150, in <module>
    jnpr_vlanarg_ssh_keys(host, buildvlancfg())
    File "", line 91, in jnpr_vlanarg_ssh_keys
    cfg.load("set interface ge-0/0/5 unit 122 vlan-id 122", format="set", merge=True)
    File "/usr/lib/python3.8/site-packages/jnpr/junos/utils/", line 579, in load
    return try_load(rpc_contents, rpc_xattrs, ignore_warning=ignore_warning)
    File "/usr/lib/python3.8/site-packages/jnpr/junos/utils/", line 496, in try_load
    raise ConfigLoadError(cmd=err.cmd, rsp=err.rsp, errs=err.errs)
    jnpr.junos.exception.ConfigLoadError: ConfigLoadError(severity: error, bad_element: interface, message: error: syntax error)
    Any ideas why?
    I've tried to find out in the docs but cant see a clear reason on this matter.
    Thanks in advance for any input!

  • 2.  Re: Using PyEz to configure interface results in error: bad element: interface
    Best Answer

    Posted 11-03-2020 00:34



    Just use the correct CLI command (as you do not have autocompletion when using the scripts) and it will work.


    Your case:   "set interface ge-0/0/5.<XXX> vlan-id <XXX>."

    Correct:  "set interfaces ge-0/0/5.<XXX> vlan-id <XXX>.






    Accept as Solution = cool !
    Accept as Solution+Kudo = You are a Star !


  • 3.  Re: Using PyEz to configure interface results in error: bad element: interface

    Posted 11-04-2020 00:35

    oh god, your right, i didnt see that one, a #### typo!!


    Changes on device:

    [edit interfaces ge-0/0/5]
    + unit 122 {
    + vlan-id 122;
    + }

    Diff exists, push to device? y/n y
    Pushing configuration to device


    Thanks a lot, i was looking at all other kind of things as the source of this issue 🙂

    Now i might be able to get the first version running of my script to simplify deployment of new networks.

    optional arguments:
    -h, --help show this help message and exit
    --vid VID Enter: a numeric vlanid
    --vname VNAME Enter: DMZ<id> or LAN<id>
    --vdesc VDESC Enter: SystemX_LAN
    --devfile DEVFILE Enter: mydevicelistfile.txt (,ip1,ip2), overrides devicelist
    --devlist DEVLIST Enter:,ip1,ip2
    --fwprod FWPROD Enter interface address:
    --fwdev FWDEV Enter interface address: