Look at the way register_deprecated() works in the nicira plugin to get an idea of how to implement this somewhat sanely
Basically, the only reason you want to parse these files directly is to get the list of [NEXUS_SWITCH:<ip>] sections
Once you've got the list of IPs, you can do e.g.
nexus_opts = [
cfg.StrOpt('username'),
...
]
def _read_nexus_switch_config(conf, ip, nexus_dict):
group_name = 'nexus_switch:' + ip conf.register_opts(nexus_opts, group=group_name)
for key, value in conf[group_name].items(): nexus_dict[(ip, key)] = value
def _read_nexus_config(conf):
multi_parser = cfg.MultiConfigParser()
read_ok = multi_parser.read(conf.config_file)
if len(read_ok) != len(conf.config_file):
raise cfg.Error("Some config files were not parsed properly")
nexus_dict = {}
for parsed_file in multi_parser.parsed:
for section in parsed_file.keys():
if not section.lower().startswith("nexus_switch:"): continue
Look at the way register_ deprecated( ) works in the nicira plugin to get an idea of how to implement this somewhat sanely
Basically, the only reason you want to parse these files directly is to get the list of [NEXUS_SWITCH:<ip>] sections
Once you've got the list of IPs, you can do e.g.
nexus_opts = [ StrOpt( 'username' ),
cfg.
...
]
def _read_nexus_ switch_ config( conf, ip, nexus_dict):
conf.register_ opts(nexus_ opts, group=group_name) name].items( ):
nexus_ dict[(ip, key)] = value
group_name = 'nexus_switch:' + ip
for key, value in conf[group_
def _read_nexus_ config( conf): Parser( ) read(conf. config_ file) config_ file):
multi_parser = cfg.MultiConfig
read_ok = multi_parser.
if len(read_ok) != len(conf.
raise cfg.Error("Some config files were not parsed properly")
nexus_dict = {}
for parsed_file in multi_parser. parsed: lower() .startswith( "nexus_ switch: "):
continue
for section in parsed_file.keys():
if not section.
ip = section.split(':', 1)[1]