Event Application Examples - amybuck/SONiC-NAS GitHub Wiki

This information describes how to register and publish events.

Register Events

1. Import the CPS object Python library.

import cps

2. Create a handle to connect to the event service.

handle = cps.event_connect()

3. Register a key with the event service to receive notification when an event is published.

cps.event_register(handle, cps.key_from_name('observed','dell-base-if-cmn/if/interfaces/interface'))
while True:
    # wait for the event
    obj = cps.event_wait(handle)
    print obj

See register-for-events.py to view the Python application example, or see register-for-events.c to view the C application example.

Publish Events

NOTE: The CPS Python API does not support a function to register a callback for published events.

1. Import the CPS and CPS object Python library.

import cps
import cps_utils

2. Create a handle to connect to the event service.

handle = cps.event_connect()

3. Create a CPS object.

obj = cps_utils.CPSObject('dell-base-if-cmn/if/interfaces/interface',qual='observed', data= {"ifindex":23})

4. Publish the object.

cps.event_send(handle, obj.get())

See publish-events.py to view the Python application example, or see publish-events.c to view the C application example.