#
The Basics of Moquery

The Basics of Moquery

 Austin Peacock
Written by Austin Peacock
Published on April 16, 2024, 3:20 p.m.
The Basics of Moquery

Introduction

 Moquery is a powerful tool that you will only find in ACI. For this reason, it can be difficult to find a lot of information about the tool and the process of building new queries. The "mo" in moquery stands for 'managed object', so it is a query of the managed objects in the fabric. It is possible to run moquery on the leaf and spine nodes, but most of the time you are going to be running the queries from the APIC.

Moquery Options

There are several different options that are helpful to use when running moqueries. The two most commonly used are '-c' and '-d'. A '-c' query is a class query, which will return all of the managed objects of that class type. A '-d' query is used when you want to return a single managed object, based on its distinguished name, or 'dn' for short. All managed objects have a unique dn that they can be queried on.

Example of "-c"
moquery -c fvBD
This will query all of the Bridge Domains in the fabric. Note that it will not gather data from other sites, but it would gather data from other pods.

Example of "-d"
moquery -d /uni/tn-Main/ap-Applications/bd-VLAN_10
This will return the managed object for BD VLAN_10, assuming it exists.

Moquery Help

If you get stuck, you can always run moquery -help and look at all the available options.

apic1# moquery --help
usage: Command line cousin to visore [-h] [-i HOST] [-p PORT] [-d DN]
                                     [-c KLASS] [-f FILTER] [-a ATTRS]
                                     [-o OUTPUT] [-u USER]
                                     [-x [OPTIONS [OPTIONS ...]]]

optional arguments:
  -h, --help            show this help message and exit
  -i HOST, --host HOST  Hostname or ip of apic
  -p PORT, --port PORT  REST server port
  -d DN, --dn DN        dn of the mo
  -c KLASS, --klass KLASS
                        comma seperated class names to query
  -f FILTER, --filter FILTER
                        property filter to accept/reject mos
  -a ATTRS, --attrs ATTRS
                        type of attributes to display (config, all)
  -o OUTPUT, --output OUTPUT
                        Display format (block, table, xml, json)
  -u USER, --user USER  User name
  -x [OPTIONS [OPTIONS ...]], --options [OPTIONS [OPTIONS ...]]
                        Extra options to the query

Filtering Results

Other options including filtering the results based on different attributes using the -f option. You can choose any attribute in the object. For example, name, annotation, and childAction are all attributes in the EPG object below:
# fv.AEPg
name                 : Dell_A
annotation           :
childAction          :
configIssues         :
configSt             : applied
descr                :
dn                   : uni/tn-Main/ap-Servers/epg-Dell_A
exceptionTag         :
extMngdBy            :
floodOnEncap         : disabled
fwdCtrl              :
hasMcastSource       : no
isAttrBasedEPg       : no
isSharedSrvMsiteEPg  : no
lcOwn                : local
matchT               : AtleastOne
modTs                : 2024-04-12T18:46:04.888+00:00
monPolDn             : uni/tn-common/monepg-default
nameAlias            :
pcEnfPref            : unenforced
pcTag                : 32770
prefGrMemb           : exclude
prio                 : unspecified
rn                   : epg-Dell_A
scope                : 2588672
shutdown             : no
status               :
triggerSt            : triggerable
txId                 : 2882303761517122100
uid                  : 15374
The filter will need to have the periods in the same place as the object is shown, so # fv.AEPg in this case, and then the attribute itself is case sensitive, and almost always uses camel case notation. (Camel case is a style of writing where compound words or phrases are combined without spaces, and each word starts with a capital letter except the first one)

moquery -c fvAEPg -f 'fv.AEPg.floodOnEncap=="disabled"'

Parent and Child Objects

It is also possible to filter based on the parent or child objects; however, be aware that there is a bug in moquery that causes the query to only return one child. The workaround is to first query the class, and then the dn that you want to search on.

Example: "What EPGs are associated with BD-100?"
moquery -c fvBD -d "uni/tn-Main/BD-100" -x "query-target=children target-subtree-class=fvRtBd"

In Summary

Moquery is a very powerful tool that allows you to quickly gather data without having to comb through the GUI. Make it a habit to use this tool everyday, and soon it will become second nature to query thousands of object at once, and truly wield the power of software defined networking.

Common Examples

Below are some common examples of queries you can quickly copy and paste.

All BDs
moquery -c fvBD 
All EPGs
moquery -c fvAEPg 
All Tenants
moquery -c fvTenant 
All Application Profiles
moquery -c fvAp 
All L3 Subnets (SVIs under BDs)
moquery -c fvSubnet 
All Contracts
moquery -c vzBrCP
All L3Outs
moquery -c l3extOut
All Client Endpoints (this can be quite large)
moquery -c fvCEp

Comments

Please Sign Up or Sign In to post.