Previous topic

3.2. How to control basic operations with Java

Next topic

3.4. How to run unittests

This Page

3.3. How to control basic operations with PythonΒΆ

This assumes that you already have an experiment with the MAGI backend running on it. If not, see How to set an experiment with MAGI.

The following code segments are written in python but they can all be written using the Java library as well.

Import some useful items and create a connection to the messaging system.

#!/usr/bin/env python
from magi.messaging import ClientConnection, MAGIMessage, Delivery
import yaml
messaging = ClientConnection("script1", "control.magi.deter", 18808)

Send a method call request to the build in daemon exec agent (Daemon Agent) that starts the wget client agent and has it listen at the dock ‘wget’.

messaging.send(
    MAGIMessage(nodes="u10", docks="daemon", contenttype=MAGIMessage.YAML, data=yaml.safe_dump({
        'version': 1.0,
        'method':'execute',
        'args': {
               'name': 'http_wget',
               'dock': 'wget',
               'args': [],
               'usethread': True
            }
        }
    )),
    api.Delivery.ACKNOWLEDGE)

Now send message to this new agent (Generating HTTP Traffic) that is listening on the ‘wget’ dock and ask it to start running.

messaging.send(
    MAGIMessage(nodes="u10", docks="wget", contenttype=MAGIMessage.YAML, data=yaml.safe_dump( {
        'version': 1.0,
        'method':'startClient',
        'args': {
               'interval': '0.5',
               'servers': ['n1', 'n2']
            }
        }
   )),
   api.Delivery.ACKNOWLEDGE)

After running for some time, ask it to stop running.

messaging.send(
   MAGIMessage(nodes="u10", docks="wget", contenttype=MAGIMessage.YAML, data=yaml.safe_dump({
       'version': 1.0,
       'method':'stopClient',
       'args': {}
       }
   )),
   api.Delivery.ACKNOWLEDGE)