junos-eznc VLANs

817 views
Skip to first unread message

gtrx...@gmail.com

unread,
Mar 28, 2015, 2:27:39 AM3/28/15
to junos-p...@googlegroups.com
I am trying to get the basic VLAN information from a device using:

from jnpr.junos import Device
from jnpr.junos.op.vlan import VlanTable

dev=Device(host='10.0.0.10',user='foobar',passwd='foobar',port=830)
dev.open(gather_facts=False)

myVlans=VlanTable(dev)
myVlans.get()

Out[15]: VlanTable:10.0.0.10: 0 items


This always returns 0 items on any switch I have tested, this includes EX2200, EX3200, EX4200, EX4500, and QFX5100 running various version of Junos (below is the normal "show vlans" CLI output from a QFX5100 13.2X51-D25.2 currently being tested), am I missing something?

show vlans
VL0001 {
    vlan-id 1;
}
VL0002 {
    vlan-id 2;
}
VL0003 {
    vlan-id 3;
}
VL0004 {
    vlan-id 4;
}
VL0005 {
    vlan-id 5;
}
VL0006 {
    vlan-id 6;
}

Running the similar commands for EthPortTable, RouteTable, etc... all return the proper information, it just seems that the VLAN information is not being populated.

Python:         2.7.6
junos-eznc:     1.1.2

NitinKumar

unread,
Mar 29, 2015, 4:10:44 AM3/29/15
to gtrx...@gmail.com, junos-p...@googlegroups.com
If your cli output show something like below:

ex4300-c> show vlans | display xml         
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/xx0/junos">
    <l2ng-l2ald-vlan-instance-information xmlns="http://xml.juniper.net/junos/xxx0/junos-l2al" junos:style="brief">
        <l2ng-l2ald-vlan-instance-group>
            <l2ng-l2rtb-brief-summary/>
            <l2ng-l2rtb-name>default-switch</l2ng-l2rtb-name>
            <l2ng-l2rtb-vlan-name>Blue</l2ng-l2rtb-vlan-name>
            <l2ng-l2rtb-vlan-tag>520</l2ng-l2rtb-vlan-tag>
            <l2ng-l2rtb-vlan-member>
                <l2ng-l2rtb-vlan-member-interface>ge-0/0/1.0*</l2ng-l2rtb-vlan-member-interface>
            </l2ng-l2rtb-vlan-member>
    -------
    -------

Try by replacing the content of vlan.yml file with

---
VlanTable:
rpc: get-vlan-information
key: l2ng-l2rtb-vlan-name
item: l2ng-l2ald-vlan-instance-group
view: VlanView

VlanView:
fields:
name: l2ng-l2rtb-vlan-name
tag: l2ng-l2rtb-vlan-tag
members: .//l2ng-l2rtb-vlan-member-interface
I have tested this and it should work for you too.

Thanks
Nitin Kr

--
You received this message because you are subscribed to the Google Groups "Junos Python EZ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to junos-python-...@googlegroups.com.
Visit this group at http://groups.google.com/group/junos-python-ez.
To view this discussion on the web visit https://groups.google.com/d/msgid/junos-python-ez/645fa3c0-8ebc-42b1-af4b-e06d7292fcb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gtrx...@gmail.com

unread,
Mar 29, 2015, 5:42:40 AM3/29/15
to junos-p...@googlegroups.com, gtrx...@gmail.com, nit...@juniper.net
I will give that a try as soon as I have a chance later today, thank you.

GTRX Core

unread,
Mar 29, 2015, 11:44:28 PM3/29/15
to junos-p...@googlegroups.com, GTRX Core, nit...@juniper.net
I gave your modifications a shot and it worked like a charm on the QFX5100, I have not yet had a chance to try it out on other devices (EX, MX, or SRX) but will do so as soon as I am able.  The follow-up question I have, I am relatively new to the junos-eznc, is this a bug in the version I have (I have no tested any older version of the module) or is this something that would be specific to how I am choosing to retrieve this information?

<BEGIN>
In [1]: from jnpr.junos import Device

In [3]: dev=Device(host='10.0.0.10',user='foobar',passw='foobar',port=830)

In [4]: dev.probe()
Out[4]: True

In [5]: dev.open(gather_facts=False)
Out[5]: Device(10.0.0.10)

In [6]: from jnpr.junos.op.vlan import VlanTable

In [7]: vlans=VlanTable(dev)

In [8]: vlans.get()
Out[8]: VlanTable:10.0.0.10: 11 items

In [9]: for vlan in vlans:
    print vlan.name
   ....:    
VL0001
VL0002
VL0003
VL0004
VL0005
VL0006
VL0007
VL0008
VL0009
VL0010
VL0011
</END>

Duc Nguyen

unread,
Apr 13, 2015, 12:12:47 PM4/13/15
to junos-p...@googlegroups.com, gtrx...@gmail.com, nit...@juniper.net
I have seen a similar issue on the EX3200.

I think because there is now key definition by default in vlan.yml (I reported this issue in #371).

Regards,

Kurt Bales

unread,
Apr 13, 2015, 6:59:47 PM4/13/15
to Duc Nguyen, junos-p...@googlegroups.com, gtrx...@gmail.com, nit...@juniper.net
Without looking to closely at this, it's probably due to the YAML file being rewritten the Legacy (original EX) switching model, and the models you are using use the new Junos L2NG switching model where some of the underlying XML structures have changed to make Junos more extensible.

Current EX4300 and QFX5100 code will be the new format, but previous EX4200 and 3200s remain in the Legacy model.

Regards,

Kurt Bales
@networkjanitor JNCIE-ENT #368



Jose Padilla

unread,
May 5, 2015, 9:20:06 PM5/5/15
to junos-p...@googlegroups.com, td...@duc-project.com, nit...@juniper.net, gtrx...@gmail.com
Hello guys,

I am having the same trouble with the VLAN yml file, but I do not know what to modify. I am connecting to an EX4200. I am new to PyEZ and I am trying to learn python to use it for automation. Everytime I try to retrieve the vlan table it tells me there is 0 items. If you guys could help would be wonderful.
This is the yaml file:

---

VlanTable:

  rpc: get-vlan-information

  item: vlan

  view: VlanView


VlanView:

  fields:

    instance: vlan-instance

    name: vlan-name

    created: vlan-create-time

    status: vlan-status

    owner: vlan-owner

    tag: vlan-tag

    members: .//vlan-member-interface

And this is part of the config of the EX4200

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.3R3/junos">

    <vlan-information junos:style="terse">

        <vlan-terse/>

        <vlan>

            <vlan-instance>0</vlan-instance>

            <vlan-name>BC-Concourse</vlan-name>

            <vlan-create-time>Thu Jun 13 21:02:38 2013

            </vlan-create-time>

            <vlan-status>Enabled</vlan-status>

            <vlan-owner>static</vlan-owner>

            <vlan-tag>183</vlan-tag>

            <vlan-tag-string>183</vlan-tag-string>

            <vlan-index>2</vlan-index>

            <vlan-protocol-port>Port Mode</vlan-protocol-port>

            <vlan-members-count>1</vlan-members-count>

            <vlan-members-upcount>1</vlan-members-upcount>

            <vlan-detail>

                <vlan-member-list>

                    <vlan-member>

                        <vlan-member-interface>ae0.0*</vlan-member-interface>

                    </vlan-member>

                </vlan-member-list>

            </vlan-detail>

        </vlan>

NitinKumar

unread,
May 6, 2015, 2:54:35 AM5/6/15
to Jose Padilla, junos-p...@googlegroups.com, td...@duc-project.com, gtrx...@gmail.com
Hi Jose,

You need to use below yaml 
VlanTable:
rpc: get-vlan-information
item: vlan
  key: vlan-name
  view: VlanView

VlanView:
fields:
instance: vlan-instance
name: vlan-name
created: vlan-create-time
status: vlan-status
owner: vlan-owner
tag: vlan-tag

Reason to add key here is defined at: 
If table-item uses this <name> tag, then you do not need to define a specific key, name is the default.

In your case its not <name> but <vlan-name>, hence we need to provide this optional parameter too. 

Hope that helps!! 

Thanks
Nitin Kr
Message has been deleted

Jose Padilla

unread,
Jun 2, 2015, 1:18:24 PM6/2/15
to junos-p...@googlegroups.com
Hello Nitin,

Thank you for your reply. I didn't have a chance to test this out until today and it still didn't work. I keep getting the same results. I am using junos-eznc 1.2.0 dev.

YAML:
---
VlanTable:
  rpc: get-vlan-information
  item: vlan-information
  key: vlan-name
  view: VlanView

VlanView:
  fields:
    instance: vlan-instance
    name: vlan-name
    created: vlan-create-time
    status: vlan-status
    owner: vlan-owner
    tag: vlan-tag

Results:
>>> dev.open()
Device(10.0.255.203)
>>> from jnpr.junos.op.vlan import VlanTable
>>> vlan=VlanTable(dev)
>>> vlan.get()
VlanTable:10.0.255.203: 0 items

Nitin Kumar

unread,
Jun 3, 2015, 6:51:58 AM6/3/15
to Jose Padilla, junos-p...@googlegroups.com
Hello Jose,
In your case vlan is the item that need to be iterable with respect to the View. Do change you yaml accordingly (marked in yellow).
from jnpr.junos import Device
from jnpr.junos.factory.factory_loader import FactoryLoader
import yaml

YamlTable =
"""
---
VlanTable:
rpc: get-vlan-information
item: vlan
  key: vlan-name
view: VlanView

VlanView:
fields:
instance: vlan-instance
name: vlan-name
created: vlan-create-time
status: vlan-status
owner: vlan-owner
tag: vlan-tag
"""
globals().update(FactoryLoader().load(yaml.load(YamlTable)))
dev = Device(
host=xxxx', user=xxx', password=xxx')
dev.open()

vlans = VlanTable(dev).get()
for vlan in vlans:
print 'instance: ', vlan.instance
print 'name: ', vlan.name
print 'created: ', vlan.name
print 'status: ', vlan.status
print 'owner: ', vlan.owner
print 'tag: ', vlan.tag
Print

Output:

instance:  0
name:  BC-Concourse
created:  BC-Concourse
status:  Enabled
owner:  static
tag:  0

instance:  0
name:  blue
created:  blue
status:  Enabled
owner:  static
tag:  1

——
———

Hope this helps!!

Thanks
Nitin Kr

--
You received this message because you are subscribed to the Google Groups "Junos Python EZ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to junos-python-...@googlegroups.com.
Visit this group at http://groups.google.com/group/junos-python-ez.

Jose Padilla

unread,
Jun 3, 2015, 11:58:04 AM6/3/15
to junos-p...@googlegroups.com, nit...@juniper.net
Thank you Nitin,

I was able to make it work yesterday. I forgot to post again with my results, but you are right my item needed to be vlan. This is how my yaml looks like now

---
VlanTable:
  rpc: get-vlan-information
  args:
    terse: True
  item: vlan
  key: vlan-name
  view: VlanView

VlanView:
  fields:
    instance: vlan-instance
    name: vlan-name
    created: vlan-create-time
    status: vlan-status
    owner: vlan-owner
    tag: vlan-tag
Reply all
Reply to author
Forward
0 new messages