Ignore:
Timestamp:
04/11/16 17:52:49 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Refine and regularize name for allocation type in RPC argument hash
Update rpc_allocateBlock for new VRF status and tweak the missing-data

flags. See #54.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/ipdb-rpc.cgi

    r668 r837  
    44# $Id$
    55###
    6 # Copyright (C) 2013 Kris Deugau <kdeugau@deepnet.cx>
     6# Copyright (C) 2013,2014,2016 Kris Deugau <kdeugau@deepnet.cx>
    77
    88use strict;
     
    148148  my $argref = shift;
    149149
    150   die "Block/IP is required\n" if !$argref->{block};
     150  if (!$argref->{block}) {
     151    $argref->{block} = $argref->{cidr} if $argref->{cidr};
     152    die "Block/IP is required\n" if !$argref->{block};
     153  }
    151154
    152155  # Alloctype check.
    153   chomp $argref->{alloctype};
    154 
    155   die "Invalid allocation type\n" if (!grep /$argref->{alloctype}/, keys %disp_alloctypes);
     156  chomp $argref->{type};
     157
     158  die "Invalid allocation type\n" if (!grep /$argref->{type}/, keys %disp_alloctypes);
    156159
    157160  # Arguably not quite correct, as the custID won't be checked for
    158161  # validity if there's a default on the type.
    159   if ($def_custids{$argref->{alloctype}} eq '') {
     162  if ($def_custids{$argref->{type}} eq '') {
    160163    # Types without a default custID must have one passed in
    161164    die "Customer ID is required\n" if !$argref->{custid};
     
    167170    # Types that have a default will use it unless one is specified.
    168171    if ((!$argref->{custid}) || ($argref->{custid} ne 'STAFF')) {
    169       $argref->{custid} = $def_custids{$argref->{alloctype}};
     172      $argref->{custid} = $def_custids{$argref->{type}};
    170173    }
    171174  }
     
    214217  # Not required for update, delete
    215218  die "City is required\n" if !$args{city};
    216   die "Block/pool to allocate from is required\n" if !$args{alloc_from};
    217 
    218   # Desc, notes, circid, privdata, node, and vrf are all optional and handled in allocateBlock()
    219   my ($code,$msg) = allocateBlock($ip_dbh, $args{block}, $args{alloc_from},
    220         $args{custid}, $args{alloctype}, $args{city}, $args{desc}, $args{notes},
    221         $args{circid}, $args{privdata}, $args{node}, $args{vrf});
     219  die "Customer ID is required\n" if !$args{custid};
     220  die "Allocation type is required\n" if !$args{type};
     221
     222  if ($args{type} =~ /^.i$/) {
     223    die "Pool ID or VRF to allocate from is required\n" if !$args{parent} && !$args{vrf};
     224  } else {
     225    die "Free block to allocate from is required\n" if !$args{fbid};
     226  }
     227
     228  my ($code,$msg) = allocateBlock($ip_dbh, %args);
    222229
    223230  if ($code eq 'OK' || $code eq 'WARN') {
    224     if ($args{alloctype} =~ /^.i$/) {
     231    if ($args{type} =~ /^.i$/) {
    225232      $msg =~ s|/32||;
    226       mailNotify($ip_dbh, "a$args{alloctype}", "ADDED: $disp_alloctypes{$args{alloctype}} allocation",
    227         "$disp_alloctypes{$args{alloctype}} $msg allocated to customer $args{custid}\n".
     233      mailNotify($ip_dbh, "a$args{type}", "ADDED: $disp_alloctypes{$args{type}} allocation",
     234        "$disp_alloctypes{$args{type}} $msg allocated to customer $args{custid}\n".
    228235        "Description: $args{desc}\n\nAllocated by: $args{rpcsystem}/$args{rpcuser}\n");
    229236    } else {
    230237      my $netblock = new NetAddr::IP $args{block};
    231       mailNotify($ip_dbh, "a$args{alloctype}", "ADDED: $disp_alloctypes{$args{alloctype}} allocation",
    232         "$disp_alloctypes{$args{alloctype}} $args{block} allocated to customer $args{custid}\n".
     238      mailNotify($ip_dbh, "a$args{type}", "ADDED: $disp_alloctypes{$args{type}} allocation",
     239        "$disp_alloctypes{$args{type}} $args{block} allocated to customer $args{custid}\n".
    233240        "Description: $args{desc}\n\nAllocated by: $args{rpcsystem}/$args{rpcuser}\n");
    234241    }
    235242    syslog "notice", "$args{rpcsystem}/$args{rpcuser} allocated '$args{block}' to '$args{custid}' as ".
    236         "'$args{alloctype}' ($msg)";
     243        "'$args{type}' ($msg)";
    237244  } else {
    238245    syslog "err", "Allocation of '$args{block}' to '$args{custid}' as ".
    239         "'$args{alloctype}' by $args{rpcsystem}/$args{rpcuser} failed: '$msg'";
     246        "'$args{type}' by $args{rpcsystem}/$args{rpcuser} failed: '$msg'";
    240247    die "$msg\n";
    241248  }
Note: See TracChangeset for help on using the changeset viewer.