def add_prefix(arg, opts, shell_opts):
<EOL>if '<STR_LIT>' not in opts and '<STR_LIT>' not in opts and '<STR_LIT>' not in opts:<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if len([opt for opt in opts if opt in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']]) > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if '<STR_LIT>' in opts:<EOL><INDENT>return add_prefix_from_pool(arg, opts)<EOL><DEDENT>args = {}<EOL>p = _prefix_from_opts(opts)<EOL>p.vrf = get_vrf(opts.get('<STR_LIT>'), abort=True)<EOL>for avp in opts.get('<STR_LIT>', []):<EOL><INDENT>try:<EOL><INDENT>key, value = avp.split('<STR_LIT:=>', <NUM_LIT:1>)<EOL><DEDENT>except ValueError:<EOL><INDENT>print("<STR_LIT>" % avp, file=sys.stderr)<EOL>return<EOL><DEDENT>p.avps[key] = value<EOL><DEDENT>if '<STR_LIT>' in opts:<EOL><INDENT>args['<STR_LIT>'] = [ opts['<STR_LIT>'], ]<EOL><DEDENT>if '<STR_LIT>' in opts:<EOL><INDENT>args['<STR_LIT>'] = int(opts['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in opts:<EOL><INDENT>if opts['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>family = <NUM_LIT:4><EOL><DEDENT>elif opts['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>family = <NUM_LIT:6><EOL><DEDENT>elif opts['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>args['<STR_LIT>'] = family<EOL><DEDENT>vrf_id = <NUM_LIT:0><EOL>if p.vrf:<EOL><INDENT>vrf_id = p.vrf.id<EOL><DEDENT>if '<STR_LIT>' in args:<EOL><INDENT>parent_prefix = args['<STR_LIT>'][<NUM_LIT:0>]<EOL>parent_op = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if len(opts.get('<STR_LIT>').split("<STR_LIT:/>")) == <NUM_LIT:2>:<EOL><INDENT>ip = IPy.IP(opts.get('<STR_LIT>').split("<STR_LIT:/>")[<NUM_LIT:0>])<EOL>plen = int(opts.get('<STR_LIT>').split("<STR_LIT:/>")[<NUM_LIT:1>])<EOL>if ip.version() == <NUM_LIT:4> and plen == <NUM_LIT:32> or ip.version() == <NUM_LIT:6> and plen == <NUM_LIT>:<EOL><INDENT>parent_prefix = str(ip)<EOL>parent_op = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>parent_prefix = str(IPy.IP(opts.get('<STR_LIT>'), make_net=True))<EOL>parent_op = '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>parent_prefix = opts.get('<STR_LIT>')<EOL>parent_op = '<STR_LIT>'<EOL><DEDENT><DEDENT>auto_type_query = {<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>'      : '<STR_LIT>',<EOL>'<STR_LIT>'  : parent_op,<EOL>'<STR_LIT>'      : parent_prefix<EOL>},<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>'      : '<STR_LIT>',<EOL>'<STR_LIT>'  : '<STR_LIT>',<EOL>'<STR_LIT>'      : vrf_id<EOL>}<EOL>}<EOL>res = Prefix.search(auto_type_query, { })<EOL>if len(res['<STR_LIT:result>']) == <NUM_LIT:0>:<EOL><INDENT>if p.type is None:<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>parent = res['<STR_LIT:result>'][-<NUM_LIT:1>]<EOL>if parent.type == '<STR_LIT>':<EOL><INDENT>if p.type is None:<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL><DEDENT>elif p.type == '<STR_LIT:host>':<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>" % p.type, file=sys.stderr)<EOL><DEDENT>p.type = '<STR_LIT:host>'<EOL>if '<STR_LIT>' in opts:<EOL><INDENT>if parent.family == <NUM_LIT:4>:<EOL><INDENT>p.prefix = p.prefix.split('<STR_LIT:/>')[<NUM_LIT:0>] + '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>p.prefix = p.prefix.split('<STR_LIT:/>')[<NUM_LIT:0>] + '<STR_LIT>'<EOL><DEDENT><DEDENT>elif '<STR_LIT>' in opts:<EOL><INDENT>if parent.family == <NUM_LIT:4>:<EOL><INDENT>args['<STR_LIT>'] = <NUM_LIT:32><EOL><DEDENT>else:<EOL><INDENT>args['<STR_LIT>'] = <NUM_LIT><EOL><DEDENT><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>p.save(args)<EOL><DEDENT>except NipapError as exc:<EOL><INDENT>print("<STR_LIT>" % str(exc), file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if p.type == '<STR_LIT:host>':<EOL><INDENT>print("<STR_LIT>" % (p.display_prefix,<EOL>vrf_format(p.vrf), p.node or p.description))<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>" % (p.display_prefix,<EOL>vrf_format(p.vrf), p.description))<EOL><DEDENT>if opts.get('<STR_LIT>') is not None:<EOL><INDENT>if p.type != '<STR_LIT>':<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>for host in opts.get('<STR_LIT>').split('<STR_LIT:U+002C>'):<EOL><INDENT>h_opts = {<EOL>'<STR_LIT>': p.prefix,<EOL>'<STR_LIT>': p.vrf.rt,<EOL>'<STR_LIT:type>': '<STR_LIT:host>',<EOL>'<STR_LIT>': host<EOL>}<EOL>add_prefix({}, h_opts, {})<EOL><DEDENT><DEDENT>
Add prefix to NIPAP