Changeset 895


Ignore:
Timestamp:
11/18/16 14:00:54 (8 years ago)
Author:
Kris Deugau
Message:

/trunk

Commit update to allocate.pl utility for allocateBlock() API change
waaaay back in r554

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/allocate.pl

    r517 r895  
    4545# Hokay, now we can start to handle the allocation.
    4646
    47 my ($cidr, $type, $custid, $city, $desc, $alloc_from);
     47my ($cidr, $type, $vrf, $custid, $city, $desc) = @ARGV;
     48my ($fbid, $fbparent);
    4849# Check ARGV.  We need some information to determine what to allocate.
    49 if (!$ARGV[1]) {
     50if (!defined($vrf)) {
    5051  # Usage message
    51   print "Usage:  allocate.pl [IP/subnet] [Type] [CustID] [City] [\"Description\"]\n".
     52  print "Usage:  allocate.pl <IP/subnet> <Type> <VRF> [CustID] [City] [\"Description\"]\n".
     53        "       IP/subnet, Type, and VRF are required\n".
    5254        "       Further information can be entered via the web interface\n";
    5355  exit;
    5456} else {
    55   $cidr = new NetAddr::IP "$ARGV[0]";
    56   $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr'");
    57   $sth->execute;
    58   my @data = $sth->fetchrow_array;
    59 # User deserves errors if user can't be bothered to find the free block first.
    60   die "Can't allocate from outside a free block!!\n"
    61         if !$data[0];
    62   $alloc_from = new NetAddr::IP $data[0];
    63   $sth->finish;
    64   $type = $ARGV[1];
    65   if (!$ARGV[4]) {
     57
     58  $cidr = new NetAddr::IP $cidr;
     59  ($fbid,$fbparent) = $ip_dbh->selectrow_array(
     60        "SELECT id,parent_id FROM freeblocks WHERE cidr >>= ? AND vrf = ?", undef, "$cidr", $vrf)
     61        or die "Couldn't find a free block to match '$cidr' in $vrf\n";
     62  if (!$desc) {
    6663    # Default desc
    6764    $desc = "DEFAULT: $disp_alloctypes{$type}";
    68   } else {
    69     $desc = $ARGV[4];
    7065  }
    71   if (!$ARGV[3]) {
    72     # Default city
    73     $sth = $ip_dbh->prepare("select city from routed where cidr >>='$cidr'");
    74     $sth->execute;
    75     my @data = $sth->fetchrow_array;
    76     $city = $data[0];
    77     $sth->finish;
    78   } else {
    79     $city = $ARGV[3];
     66  if (!$city) {
     67    # Default city taken from parent allocation
     68    ($city) = $ip_dbh->selectrow_array("SELECT city FROM allocations WHERE id = ?", undef, $fbparent);
    8069  }
    81   if (!$ARGV[2]) {
    82     # Default custid - make it REAL obvious.
    83     $custid = "FIXME";
    84   } else {
    85     $custid = $ARGV[2];
     70  if (!$custid) {
     71    # See if the type has a default custID....
     72    $custid = $ip_dbh->selectrow_array("SELECT def_custid FROM alloctypes WHERE type = ?", undef, $type);
     73    # ... and if not, make it REAL obvious this needs to be fixed.
     74    $custid = "FIXME" if !$custid;
    8675  }
    8776}
     
    8978print "Allocating $cidr as $type to $custid in $city: '$desc'\n";
    9079
    91 my ($code,$msg) = allocateBlock($ip_dbh, $cidr, $alloc_from, $custid, $type, $city,
    92         $desc, '', '');
     80my %insert_args = (
     81        cidr            => "$cidr",
     82        fbid            => $fbid,
     83        parent          => $fbparent,
     84        custid          => $custid,
     85        type            => $type,
     86        city            => $city,
     87        desc            => $desc,
     88        vrf             => $vrf,
     89        user            => $authuser,
     90);
     91
     92my ($code,$msg) = allocateBlock($ip_dbh, %insert_args);
    9393
    9494if ($code eq 'OK') {
Note: See TracChangeset for help on using the changeset viewer.