I did some attempts and find one solution, but it is inefficient.  I would
appreciate if anyone can help me with a easier approach.

The key part is how to find the instantiated instance by
app_manager.RYUapp, one way I find is to use locals()['self'] to find the
object and refer to a variable. Later I can use this variable to
send/receive events. The code as follows:

RESTAPIobj = None  #Create a global variable to track the instantiated
object

class RestStatsApi(app_manager.RyuApp):
    _CONTEXTS = {
        'dpset': dpset.DPSet,
        'wsgi': WSGIApplication
    }

    def __init__(self, *args, **kwargs):
        super(RestStatsApi, self).__init__(*args, **kwargs)

        #details emitted

        global RESTAPIobj
        RESTAPIobj = locals()['self']

Since the object is found and assigned, now I can use it to send events
under any class (e.g. ControlBase here).

class StatsController(ControllerBase):
    def get_dpids(self, req, **_kwargs):
        dps = self.dpset.dps.keys()
        body = json.dumps(dps)

        #build ryu events and send to ryu_app1.py observer#
        ev = custom_event.RequestEvent()
        ev.src = None
        ev.dst = 'ryu_app1_class'
        ev.sync = True
        ev.reply_q = None
        global RESTAPIobj
        RESTAPIobj.send_request(ev)

        return (Response(content_type='application/json', body=body))

This approach works for me so far but it is cumbersome and looks weird. Can
anyone let me know if there is a simple version?

Thanks.

Weiyang

On Fri, Mar 11, 2016 at 6:24 PM, Weiyang Mo <[email protected]> wrote:

> Hi All,
>
> I use the ofctl_rest.py to use the service. I get stuck in that how can I
> send out events to other modules.'
>
> For example, suppose when I visit /stats/switches to get a list of
> switches, I want to send some events to another running RYU module (assume
> ryu_app1.py) before generate a web HTTPResponse.
>
> class StatsController(ControllerBase):
>     def __init__(self, req, link, data, **config):
>         super(StatsController, self).__init__(req, link, data, **config)
>         self.dpset = data['dpset']
>         self.waiters = data['waiters']
>
>     #### Get the list of all switches
>     def get_dpids(self, req, **_kwargs):
>         dps = self.dpset.dps.keys()
>         body = json.dumps(dps)
>
>         --build ryu events and send to ryu_app1.py observer--
>
>        return (Response(content_type='application/json', body=body))
>
> I have no problem to build custom events but I have no clues on how to
> send it out. The example uses  self.send_request(ev), but that requires the
> class inherits from RYUapp.manager  and do not work in this case.
>
> Any suggestions?
>
> Thanks.
>
> Weiyang
>
>
> ------------------------------------------------------------------------------
> Transform Data into Opportunity.
> Accelerate data analysis in your applications with
> Intel Data Analytics Acceleration Library.
> Click to learn more.
> http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to