Skip to content

Event application examples

Amy Buck edited this page Nov 28, 2018 · 7 revisions

This information contains event application examples, including verification.

  • opx-alm-service contains an example of a Python application that registers for events (see opx-alm-service).

  • cps_api_events_unittest.cpp contains an example of a C++ application that registers for events (see cps_api_events_unittest.cpp).

  • cps_send_event.py contains an example of publishing events in Python (see cps_send_event.py).

  • cps_api_events_unittest.cpp contains an example of publishing events in C++ (see cps_api_events_unittest.cpp).

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 CPS 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.

Clone this wiki locally