Hi Sandesh,
> Hello, I tried doing this but it didnt work. Do I need to change flags.py file
What do you exactly mean "it didnt work"?
Did you get any error messages?
FYI, if you want to use flags.py, it can be done as follow.
# Modify the source code.
$ git diff
diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index b9cbad0..c8806d0 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -20,6 +20,7 @@ from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_3
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
+from ryu import cfg
class SimpleSwitch13(app_manager.RyuApp):
@@ -28,6 +29,8 @@ class SimpleSwitch13(app_manager.RyuApp):
def __init__(self, *args, **kwargs):
super(SimpleSwitch13, self).__init__(*args, **kwargs)
self.mac_to_port = {}
+ CONF = cfg.CONF
+ print CONF['test_param_str']
@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev):
diff --git a/ryu/flags.py b/ryu/flags.py
index 225cbbb..9f38dc9 100644
--- a/ryu/flags.py
+++ b/ryu/flags.py
@@ -22,6 +22,9 @@ from ryu import cfg
CONF = cfg.CONF
CONF.register_cli_opts([
+ # TEST
+ cfg.StrOpt('test-param-str', default='default-str',
+ help='the parameter for the cli options test'),
# app/quantum_adapter
cfg.StrOpt('neutron-url', default='http://localhost:9696',
help='URL for connecting to neutron',
# Reinstall Ryu
$ sudo python setup.py install
# Run Ryu App
$ ryu-manager ryu.app.simple_switch_13 --test-param-str 123abc
loading app ryu.app.simple_switch_13
loading app ryu.controller.ofp_handler
instantiating app ryu.app.simple_switch_13 of SimpleSwitch13
123abc
instantiating app ryu.controller.ofp_handler of OFPHandler
...
Thanks
On 2015年03月29日 16:02, Sandesh Shrestha wrote:
> Hello, I tried doing this but it didnt work. Do I need to change flags.py file
>
> Thanks,
> Sandesh Shrestha
>
>
>
>
> Message: 7
> Date: Tue, 24 Mar 2015 10:18:27 +0900
> From: Yusuke Iwase <[email protected] <mailto:[email protected]>>
> Subject: Re: [Ryu-devel] Passing arguments to ryu app
> To: [email protected] <mailto:[email protected]>,
> [email protected] <mailto:[email protected]>
> Message-ID: <[email protected] <mailto:[email protected]>>
> Content-Type: text/plain; charset=UTF-8
>
> Hi Sandesh,
>
> On 2015?03?22? 13:08, Sandesh Shrestha wrote:
>> Dear All,
>>
>> I need to pass arguments to ryu app. How can I do that and how to get that
>> in the app.
>
> How about adding CLI options for your App as follow?
>
>
> $ git diff
> diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
> index b9cbad0..1014c9f 100644
> --- a/ryu/app/simple_switch_13.py
> +++ b/ryu/app/simple_switch_13.py
> @@ -20,6 +20,13 @@ from ryu.controller.handler import set_ev_cls
> from ryu.ofproto import ofproto_v1_3
> from ryu.lib.packet import packet
> from ryu.lib.packet import ethernet
> +from ryu import cfg
> +
> +CONF = cfg.CONF
> +CONF.register_cli_opts([
> + cfg.StrOpt('test-param-str', default='default-str',
> + help='test-param-for-register-cli-opts')
> +])
>
>
> class SimpleSwitch13(app_manager.RyuApp):
> @@ -29,6 +36,9 @@ class SimpleSwitch13(app_manager.RyuApp):
> super(SimpleSwitch13, self).__init__(*args, **kwargs)
> self.mac_to_port = {}
>
> + # Get param
> + print 'test-param-str = %s' % self.CONF.test_param_str
> +
> @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
> def switch_features_handler(self, ev):
> datapath = ev.msg.datapath
> diff --git a/ryu/cmd/manager.py b/ryu/cmd/manager.py
> index 66d59b3..6dca80c 100755
> --- a/ryu/cmd/manager.py
> +++ b/ryu/cmd/manager.py
> @@ -41,6 +41,8 @@ from ryu.app import wsgi
> from ryu.base.app_manager import AppManager
> from ryu.controller import controller
> from ryu.topology import switches
> +# import your app
> +from ryu.app import simple_switch_13
>
>
> CONF = cfg.CONF
> $
> $
> $ sudo python setup.py install
> $
> $ sudo ryu-manager ryu.app.simple_switch_13 --test-param-str abc123
> loading app ryu.app.simple_switch_13
> loading app ryu.controller.ofp_handler
> instantiating app ryu.app.simple_switch_13 of SimpleSwitch13
> test-param-str = abc123
> instantiating app ryu.controller.ofp_handler of OFPHandler
> ...
> $
>
>
> OR,
> You can use Ryu config file (etc/ryu/ryu.conf).
> This way is easy to use, but you need to modify the config file before
> running ryu-manager.
>
>
> Thanks
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel