def add_prefix_from_pool(arg, opts):
    """ Add prefix using from-pool to NIPAP
    """

    args = {}

    # sanity checking
    if 'from-pool' in opts:
        res = Pool.list({ 'name': opts['from-pool'] })
        if len(res) == 0:
            print >> sys.stderr, "No pool named '%s' found." % opts['from-pool']
            sys.exit(1)

        args['from-pool'] = res[0]

    if 'family' not in opts:
        print >> sys.stderr, "ERROR: You have to specify the address family."
        sys.exit(1)

    if opts['family'] == 'ipv4':
        afis = [4]
    elif opts['family'] == 'ipv6':
        afis = [6]
    elif opts['family'] == 'dual-stack':
        afis = [4, 6]
        if 'prefix_length' in opts:
            print >> sys.stderr, "ERROR: 'prefix_length' can not be specified for 'dual-stack' assignment"
            sys.exit(1)
    else:
        print >> sys.stderr, "ERROR: 'family' must be one of: %s" % " ".join(valid_families)
        sys.exit(1)

    if 'prefix_length' in opts:
        args['prefix_length'] = int(opts['prefix_length'])

    for afi in afis:
        p = _prefix_from_opts(opts)

        if opts.get('vrf_rt') is None:
            # if no VRF is specified use the pools implied VRF
            p.vrf = args['from-pool'].vrf
        else:
            # use the specified VRF
            p.vrf = get_vrf(opts.get('vrf_rt'), abort=True)

        # set type to default type of pool unless already set
        if p.type is None:
            if args['from-pool'].default_type is None:
                print >> sys.stderr, "ERROR: Type not specified and no default-type specified for pool: %s" % opts['from-pool']
            p.type = args['from-pool'].default_type

        for avp in opts.get('extra-attribute', []):
            try:
                key, value = avp.split('=', 1)
            except __HOLE__:
                print >> sys.stderr, "ERROR: Incorrect extra-attribute: %s. Accepted form: 'key=value'\n" % avp
                return
            p.avps[key] = value


        args['family'] = afi

        try:
            p.save(args)
        except NipapError as exc:
            print >> sys.stderr, "Could not add prefix to NIPAP: %s" % str(exc)
            sys.exit(1)

        if p.type == 'host':
            print "Host %s added to %s: %s" % (p.display_prefix,
                    vrf_format(p.vrf), p.node or p.description)
        else:
            print "Network %s added to %s: %s" % (p.display_prefix,
                    vrf_format(p.vrf), p.description)

        if opts.get('add-hosts') is not None:
            if p.type != 'assignment':
                print >> sys.stderr, "ERROR: Not possible to add hosts to non-assignment"
                sys.exit(1)

            for host in opts.get('add-hosts').split(','):
                h_opts = {
                        'from-prefix': p.prefix,
                        'vrf_rt': p.vrf.rt,
                        'type': 'host',
                        'node': host
                        }
                add_prefix({}, h_opts, {})
dataset/ETHPy150Open SpriteLink/NIPAP/nipap-cli/nipap_cli/nipap_cli.py/add_prefix_from_pool