cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4390
Views
10
Helpful
9
Replies

How to query child elements of a class with moquery

O.K.
Level 1
Level 1

Hi everyone,

 

I want to query only the ports that "Oper State: Down" and "Admin State: Up". They are not in the same class for moquery. The first one (Oper State) is listed under the

ethpmPhysIf

module and "Admin State" is listed under

l1PhysIf

how can I join them together with moquery? I've tried the following to get all children of the "l1PhysIf" but it doesn't work with moquery I am getting only attributes.

moquery -d topology/pod-2/node-1234/sys -c l1PhysIf -x query-target=children

When I send a GET req. with REST API I get all children as well, I can't understand why I can't see the children with moquery. any help would be appreciated, Thank you!

 

 

 

1 Accepted Solution

Accepted Solutions

Hi Oguz,

I think you might be getting beyond the limits of moquery

I think the query you want might be:

moquery -c l1PhysIf -x 'rsp-subtree=children rsp-subtree-class=ethpmPhysIf rsp-subtree-filter=ethpm.PhysIf.operSt=="down"' -f 'l1.PhysIf.adminSt=="up"'

...but when I try it I get 

Error: too many values to unpack

so - unless our learned friends @Remi-Astruc , @Sergiu.Daniluk or @Marcel Zehnder can expand, you may have to learn some programming!

In the meantime, this ugly convoluted multiple egrepped output will actually give you a list of port that indeed are:

only the ports that "Oper State: Down" and "Admin State: Up".
moquery -c l1PhysIf -x 'rsp-subtree=children rsp-subtree-class=ethpmPhysIf' -f 'l1.PhysIf.adminSt=="up"' -o json | egrep -B 20 '"operSt": "down"' | egrep '"dn"' 

...at least on my v5.1 APIC. If more attributes are atted later on, you may need to adjust the "-B 20" to a larger number. But better still, use awk or, as I said before, write a program!

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

View solution in original post

9 Replies 9

RedNectar
VIP
VIP

Hi @O.K. ,

I had the same problem. It started a decent discussion on this forum with some helpful suggestions here. In a nutshell, I believe it is a bug, but there are work-arounds.

 

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

Hi @RedNectar ,

 

Thank you for your reply. It helped me a lot. At least I can query the child elements now. But I can't access the child elements attributes using filters. Do you know how can I achieve that? I want to basically access two attributes from two different modules (one of them is child element.) Below is what I wrote and what I expect. Thank you in advance.

 

If I run the following on APIC:

moquery -c l1PhysIf -x 'rsp-subtree=children rsp-subtree-class=ethpmPhysIf' -f 'l1.PhysIf.adminSt=="up"'

I get this:

...
# l1.PhysIf
id                             : eth1/8
adminSt                        : up
autoNeg                        : on
brkoutMap                      : none
bw                             : 0
childAction                    :
delay                          : 1
descr                          : LAN-XXX
dn                             : topology/pod-X/node-XYXY/sys/phys-[eth1/8]
dot1qEtherType                 : 0x8100
ethpmCfgFailedBmp              :
ethpmCfgFailedTs               : 00:00:00:00.000
ethpmCfgState                  : 0
fcotChannelNumber              : Channel32
fecMode                        : inherit
inhBw                          : unspecified
isReflectiveRelayCfgSupported  : Supported
layer                          : Layer2
lcOwn                          : local
linkDebounce                   : 100
linkLog                        : default
mdix                           : auto
medium                         : broadcast
modTs                          : 2021-05-26T09:51:17.840+02:00
mode                           : trunk
monPolDn                       : uni/infra/moninfra-default
mtu                            : 9000
name                           :
pathSDescr                     :
portT                          : leaf
prioFlowCtrl                   : auto
reflectiveRelayEn              : off
rn                             : phys-[eth1/8]
routerMac                      : not-applicable
snmpTrapSt                     : enable
spanMode                       : not-a-span-dest
speed                          : 1G
status                         : modified
switchingSt                    : enabled
trunkLog                       : default
usage                          : epg

# ethpm.PhysIf
  accessVlan         : vlan-XX
  allowedVlans       : XX-YY
  backplaneMac       : AA:AA:AA:AA:AA
  bundleBupId        : 2
  bundleIndex        : unspecified
  cfgAccessVlan      : vlan-XX
  cfgNativeVlan      : vlan-XX
  childAction        :
  currErrIndex       : 4294967299
  diags              : none
  dn                 : topology/pod-X/node-XYXY/sys/phys-[eth1/8]/phys
  encap              : 5
  errDisTimerRunning : no
  errVlanStatusHt    : 0
  errVlans           :
  hwBdId             : 0
  hwResourceId       : 0
  intfT              : phy
  iod                : 12
  lastErrors         : 0
  lastLinkStChg      : 2021-02-14T10:18:14.476+02:00
  media              : 2
  modTs              : never
  monPolDn           : uni/infra/moninfra-default
  nativeVlan         : vlan-XX
  numOfSI            : 0
  operBitset         : 3-4
  operDceMode        : edge
  operDuplex         : full
  operEEERxWkTime    : 0
  operEEEState       : not-applicable
  operEEETxWkTime    : 0
  operErrDisQual     : none
  operFecMode        : disable-fec
  operFlowCtrl       : 0
  operMdix           : auto
  operMode           : trunk
  operModeDetail     : unknown
  operPhyEnSt        : unknown
  operRouterMac      : 00:00:00:00:00:00
  operSpeed          : 1G
  operSt             : up
  operStQual         : none
  operStQualCode     : 0
  operVlans          : XX-YY
  osSum              : failed
  portCfgWaitFlags   : 0
  primaryVlan        : vlan-1
  resetCtr           : 1
  rn                 : phys
  siList             :
  status             :
  txT                : unknown
  usage              : epg
  userCfgdFlags      : 1
  vdcId              : 1
...

What I want to achieve here is to check two attributes and list them only if the conditions inside the filter are met. For this I have the following but it is not working instead gives back "No Mos found"

 

moquery -c l1PhysIf -x 'rsp-subtree=children rsp-subtree-class=ethpmPhysIf' -f 'l1.PhysIf.adminSt=="up" and ethpm.PhysIf.operSt=="down"'

I will be glad if you can help.

 

Have a nice day.
Oguz

Hi Oguz,

I think you might be getting beyond the limits of moquery

I think the query you want might be:

moquery -c l1PhysIf -x 'rsp-subtree=children rsp-subtree-class=ethpmPhysIf rsp-subtree-filter=ethpm.PhysIf.operSt=="down"' -f 'l1.PhysIf.adminSt=="up"'

...but when I try it I get 

Error: too many values to unpack

so - unless our learned friends @Remi-Astruc , @Sergiu.Daniluk or @Marcel Zehnder can expand, you may have to learn some programming!

In the meantime, this ugly convoluted multiple egrepped output will actually give you a list of port that indeed are:

only the ports that "Oper State: Down" and "Admin State: Up".
moquery -c l1PhysIf -x 'rsp-subtree=children rsp-subtree-class=ethpmPhysIf' -f 'l1.PhysIf.adminSt=="up"' -o json | egrep -B 20 '"operSt": "down"' | egrep '"dn"' 

...at least on my v5.1 APIC. If more attributes are atted later on, you may need to adjust the "-B 20" to a larger number. But better still, use awk or, as I said before, write a program!

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

Hi guys

I agree, I think you can't filter on parent attributes and child attributes at the same time. Neither via moquery nor with a direct REST-call.

I recommend query all l1PhysIf-MOs with admitSt==up and use a python script to collect all l1PysIf-MOs where the ethpmPhysIf-Child's operSt==down.

Marcel

Hello @RedNectar ,

 

I agree, this is ugly but it works : ) Thank you.


In the meantime, this ugly convoluted multiple egrepped output will actually give you a list of port that indeed are:

only the ports that "Oper State: Down" and "Admin State: Up".
moquery -c l1PhysIf -x 'rsp-subtree=children rsp-subtree-class=ethpmPhysIf' -f 'l1.PhysIf.adminSt=="up"' -o json | egrep -B 20 '"operSt": "down"' | egrep '"dn"' 

 


I am going to write an Ansible playbook to get what I want, I think it is much better that way...

 

Kind Regards,

Oguz

Oh yes - Ansible would be a much better approach. Post back here when you get it worked out and mark your own answer as correct (to help others)

Good luck!

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

ecsnnsls
Level 1
Level 1

Let me know if this works for you,

for OUTPUT in $(moquery -c l1PhysIf -x 'query-target-filter=eq(l1PhysIf.adminSt,"up")' | grep -o "topology/pod-1/node-[0-9]..*/sys/phys-\[eth[0-9]/[0-9]*\]")
do
moquery -c ethpmPhysIf -x 'query-target-filter=and(eq(ethpmPhysIf.dn,"'"$OUTPUT"'/phys"),eq(ethpmPhysIf.operSt,"down"))' | egrep 'dn'
done

This will return the interfaces that are admin "UP" and operational "DOWN". You can execute this directly on the APIC.

Hi @ecsnnsls ,

Although it missed all the FEX interfaces on my system*, I can confirm that your solution produces the same output, albeit much slower.

HOWEVER - your solution is much more elegant because it doesn't rely on positional values which could change at any time.

Pity it is so slow... possibly gets back to - "need to write some code"


*To allow the FEX interfaces you'd need to allow 3 digits for interface number and an extra "/" character - change 

[eth[0-9]/[0-9]*

to

[eth[0-9\/]*/[0-9]*

 

RedNectar aka Chris Welsh.
Forum Tips: 1. Paste images inline - don't attach. 2. Always mark helpful and correct answers, it helps others find what they need.

Hi @RedNectar ,

Yep, you are right, it is painfully slow and the best way is to create a customized script.

Good call on the fex. I missed it since I don't have a fex in my env.

Thanks again.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Save 25% on Day-2 Operations Add-On License