ryu

2017/01/16

SDN ryu

学习

oslo_config

  • 有下面的例子:app.conf app.py
app.conf

# this is comments

# group
[network]
# BoolOpt
enable = True
# IPOpt
ip     = '127.0.0.1'
# PortOpt
port   = 8080
# HostnameOp
host   = www.tyr.gift

[user]
# ListOpt
userlist = ['user1', 'user2', 'user3']
# DictOpt
paradict = {'name': 'jason', 'sex': 'male', 'age':23}
# StrOpt
description = hello,world
# FloatOpt
pi = 3.14
# IntOpt
num = 3

from oslo_config import cfg

network_optgroup = cfg.OptGroup(name='network', title='network settings')
user_optgroup = cfg.OptGroup(name='user', title='user settings')

network_opts = [
            cfg.BoolOpt('enable', default=False, help='enable or not'),
            cfg.IPOpt('ip', default='127.0.0.1', help='listen ip address'),
            cfg.PortOpt('port', default=8080, help='listen port'),
            cfg.HostnameOpt('host', default='tyr.gift', help='listen hostname')
        
]

user_opts = [
            cfg.ListOpt('userlist', default=[], help='user list'),
            cfg.DictOpt('paradict', default={}, help='para dict'),
            cfg.StrOpt('description', default='', help='user description'),
            cfg.FloatOpt('pi', default=0.0, help='pi'),
            cfg.IntOpt('num', default=0, help='num')

        
]
cli_opts = [
        cfg.MultiStrOpt('app',positional=True,
            default=[],
            help='please input app name'),
        cfg.ListOpt('app_list',
            default=[],
            help='Print app-list.')
        
]

CONF = cfg.CONF
CONF.register_group(network_optgroup)
CONF.register_opts(network_opts, network_optgroup)
CONF.register_cli_opts(network_opts, network_optgroup)

CONF.register_group(user_optgroup)
CONF.register_opts(user_opts, user_optgroup)
CONF.register_cli_opts(user_opts, user_optgroup)
CONF.register_cli_opts(cli_opts)
if __name__ == '__main__':
    CONF(default_config_files=['app.conf'])
    print CONF.network.enable
    print CONF.network.ip
    print CONF.network.port
    print CONF.network.host
    print CONF.user.userlist
    print CONF.user.paradict
    print CONF.user.description
    print CONF.user.pi
    print CONF.user.num
    #print CONF.app
    #print ('%s' % CONF.app-list)
    print("conf.app_lists is %s ,CONF.app is %s " % (CONF.app_list,CONF.app))

打印调用栈

    import traceback
    ....
    traceback.print_stack()

资料

ryu

ryu-simple

ryu-info

ryu 装饰介绍

附件

Post Directory