-
Notifications
You must be signed in to change notification settings - Fork 35
YANG object modeling
This information describes how the OPX package uses YANG data models to define the contents of objects used to configure and retrieve information from the system using the CPS object library APIs.
A YANG model consists of types (typedef
, groupings, and enums), containers (container
, list
, choice
, and case
), and properties (leaf
and leaf-list
). Each property in the YANG container is an object attribute. List containers nested in a YANG model are treated as multiple instances of embedded attributes. CPS also supports defining a separate CPS object from each nested container.
Using YANG-modeled data, the CPS object library YANG parser generates:
- C/C++ header file containing:
- YANG model name
-
typedefs
extracted from the model - Enumerations found in the model
- Enumeration of any YANG container or properties (
leaf
,leaf-list
,container
,list
, and so on) found in the model
- A Python C extension library containing CPS object metadata and YANG name-to-CPS object library ID mapping information
In a C/C++ application, include the generated C header to use the object key and attribute identifiers to create or delete objects and set values for each attribute. In a Python application, use the YANG module, and object and attribute names directly. The CPS object library Python engine automatically uses the extension library to derive the corresponding identifiers for these names.
Python values present in the top-level dictionary:
Value | Description |
---|---|
data | Python dictionary containing the actual values of an object. Each element in the dictionary is a key-value pair, where the key is an attribute name and the value is a byte array or another dictionary. Depending on the object, the data dictionary may contain other dictionaries and a CPS key_data attribute that contains the instance keys for the object. |
key | String that indicates the CPS key as a string or an alias |
operation | Indicates whether an object is related to a set, delete, create, or action transaction (used when events are received). |
Common commands used to manage CPS API objects are included.
Retrieve and view the contents of a CPS API object.
cps_get_oid.py [-h] [-mod module] [-d]
[-qua {target,observed,proposed,realtime,registration,running,startup}]
[-attr ATTR] [-db]
module [additional [additional ...]]
-
module
— object's name and optional qualifier; for example, cps/node-group of if/interfaces/interface (a qualifier can optionally be placed at the beginning) -
additional
— field can contain a series of object attributes in the form of attr=value combinations -
-h,--help
— (Optional) displays this help message and exit -
mod module
— (Optional) alternate way to specify the module name -
-d
— (Optional) print some additional details about the objects parsed and sent to the backend -
-qua {target,observed,proposed,realtime,registration,running,startup}
— (Optional) object's qualifier -
attr ATTR
— (Optional) object attributes in the form of attr=value -
db
— (Optional) attempt to use the database directly to satisfy the request instead of the normally registered object
cps_get_oid.py observed/base-pas/entity entity-type=1 slot=1
============base-pas/entity==========
base-pas/entity/platform-name =
base-pas/entity/hw-version = A00
base-pas/entity/present = 1
base-pas/entity/service-code = 226 457 410 55
base-pas/entity/insertion-timestamp = 1522692340
base-pas/entity/product-name = CN0T9FNW2829845L0006
base-pas/entity/oper-status = 1
base-pas/entity/vendor-name =
base-pas/entity/slot = 1
base-pas/entity/entity-type = 1
base-pas/entity/name = PSU Tray-1
base-pas/entity/service-tag = AEIOU##
base-pas/entity/part-number = 0T9FNW
base-pas/entity/slot = 1
base-pas/entity/fault-type = 1
base-pas/entity/entity-type = 1
base-pas/entity/ppid = CN0T9FNW2829845L0006
base-pas/entity/insertion-cnt = 1
base-pas/entity/admin-status = 1
------------------------------------------------
cps_get_oid.py -qua observed base-pas/entity entity-type=1 slot=1
Perform a CPS commit operation taking the object specified on the command line.
cps_set_oid.py [-h] [-mod module] [-d]
[-qua {target,observed,proposed,realtime,registration,running,startup}]
[-attr ATTR] [-db] -oper {delete,create,set,action}
[-commit-event]
module [additional [additional ...]]
-
module
— object's name and optional qualifier; for example, cps/node-group or if/interfaces/interface (a qualifier can optionally be placed at the beginning) -
additional
— field can contain a series of object attributes in the form of attr=value combinations -
-h,--help
— (Optional) displays this help message and exit -
-mod module
— (Optional) alternate way to specify the module name -
-d
— (Optional) print some additional details about the objects parsed and sent to the backend -
-qua {target,observed,proposed,realtime,registration,running,startup}
— (Optional) object's qualifier -
attr ATTR
— (Optional) object attributes in the form of attr=value -
-db
— (Optional) attempt to use the database directly to satisfy the request instead of the normally registered object -
-oper {delete,create,set,action}
— (Optional) operations types; only used in CPS commit operations -
-commit-event
— (Optional) flag will try to force the default state of the auto-commit event to true; only used in CPS commit operations
cps_set_oid.py -oper create base-pas/led entity-type=3 slot=1 name=Beacon on=1
Success
Key: 1.28.1835214.1835062.1835063.1835064.
base-pas/led/slot = 1
base-pas/led/on = 1
cps/object-group/return-code = 0
base-pas/led/entity-type = 3
base-pas/led/name = Beacon
cps_set_oid.py –oper create target/base-pas/led entity-type=3 slot=1 name=Beacon on=1
The object dictionary APIs access metadata for each YANG model. The dictionary contains these items for each YANG class or attribute:
- Static key of the element (including the elements hierarchy)
- Type of element
- Information associated with the element
- Model type — attribute, attribute-list, or object
- Unique attribute identifier
NOTE: You can access the CPS dictionary in both C/C++ and Python.
© 2019 OpenSwitch project. All information is contributed to and made available by OPX under the Creative Commons Attribution 4.0 International License (available at http://creativecommons.org/licenses/by/4.0/).
- Home
- System overview
- Software releases
- Hardware support
- FAQs
- Install
- Build
- Configure
- Develop
- Administer
- Troubleshoot
- Software compatibility
- Contribute
- DevOps
- Join