Changeset 668 for trunk/cgi-bin


Ignore:
Timestamp:
12/31/14 11:39:14 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Stub out all core IPDB subs for RPC. Fill in a few quick global-retrieval
subs. See #40.

File:
1 edited

Legend:

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

    r661 r668  
    4646
    4747my $methods = {
    48 #       'ipdb.getCityList'      => \&rpc_getCityList,
     48        # Internal core IPDB subs;  no value in exposing them since the DB handle can't be used by the caller
     49        #'ipdb._rpc'
     50        # This one could be exposed, but the globals aren't automatically
     51        # inherited by the caller anyway, and we call it just above locally.
     52        #'ipdb.initIPDBGlobals'
     53        #'ipdb.connectDB'
     54        #'ipdb.finish'
     55        #'ipdb.checkDBSanity'
     56        'ipdb.addMaster'        =>      \&rpc_addMaster,
     57        'ipdb.touchMaster'      =>      \&rpc_touchMaster,
     58        'ipdb.listSummary'      =>      \&rpc_listSummary,
     59        'ipdb.listSubs' =>      \&rpc_listSubs,
     60        'ipdb.listContainers'   =>      \&rpc_listContainers,
     61        'ipdb.listAllocations'  =>      \&rpc_listAllocations,
     62        'ipdb.listFree' =>      \&rpc_listFree,
     63        'ipdb.listPool' =>      \&rpc_listPool,
     64        'ipdb.getMasterList'    =>      \&rpc_getMasterList,
     65        'ipdb.getTypeList'      =>      \&rpc_getTypeList,
     66        'ipdb.getPoolSelect'    =>      \&rpc_getPoolSelect,
     67        'ipdb.findAllocateFrom' =>      \&rpc_findAllocateFrom,
     68        'ipdb.ipParent' =>      \&rpc_ipParent,
     69        'ipdb.subParent'        =>      \&rpc_subParent,
     70        'ipdb.blockParent'      =>      \&rpc_blockParent,
     71        'ipdb.getRoutedCity'    =>      \&rpc_getRoutedCity,
     72        'ipdb.allocateBlock'    =>      \&rpc_allocateBlock,
     73        # another internal sub;  mainly a sub to make allocateBlock() a lot smaller
     74        #'ipdb.initPool'        =>      \&rpc_initPool
     75        'ipdb.updateBlock'      =>      \&rpc_updateBlock,
     76        'ipdb.deleteBlock'      =>      \&rpc_deleteBlock,
     77        'ipdb.getBlockData'     =>      \&rpc_getBlockData,
     78        'ipdb.getBlockRDNS'     =>      \&rpc_getBlockRDNS,
     79        'ipdb.getNodeList'      =>      \&rpc_getNodeList,
     80        'ipdb.getNodeName'      =>      \&rpc_getNodeName,
     81        'ipdb.getNodeInfo'      =>      \&rpc_getNodeInfo,
     82        'ipdb.mailNotify'       =>      \&rpc_mailNotify,
     83
     84# Subs not part of the core IPDB
     85        'ipdb.getDispAlloctypes'        => \&rpc_getDispAlloctypes,
     86        'ipdb.getListAlloctypes'        => \&rpc_getListAlloctypes,
     87        'ipdb.getDefCustIDs'    => \&rpc_getDefCustIDs,
     88        'ipdb.getCityList'      => \&rpc_getCityList,
    4989        'ipdb.getAvailableStatics'      => \&rpc_getAvailableStatics,
    50         'ipdb.allocateBlock'    =>      \&rpc_allocateBlock,
    5190};
    5291
     
    138177##
    139178
     179# Core IPDB subs
    140180# Prefixed with rpc_ to not conflict with subs in IPDB.pm
    141181
    142 sub rpc_getCityList {
    143   my %args = @_;
    144 
    145   _commoncheck(\%args, 'n');
    146 }
    147 
    148 # Get a list of available static IPs of the given type
    149 sub rpc_getAvailableStatics {
    150   my %args = @_;
    151 
    152   _commoncheck(\%args, 'n');
    153 
    154   my ($base,undef) = split //, $args{type};
    155   $base .= "_";
    156   my @params = ($base);
    157 
    158   # IPDB 2.7
    159   my $sql = "SELECT 0 AS id,poolips.ip,0 AS parent_id,pool ".
    160   "FROM poolips JOIN allocations ON poolips.pool=allocations.cidr WHERE poolips.type LIKE ?";
    161 
    162   $sql .= " AND allocations.city=?" if $base ne 'd_';
    163   push @params, $args{city} if $base ne 'd_';
    164 
    165   $sql .= " AND poolips.available='y'";
    166 
    167   my $ret = $ip_dbh->selectall_arrayref($sql, { Slice => {} }, (@params) );
    168   # IPDB 3.0
    169   #my $ret = $ipdb->getIPList(arg arg arg);
    170   die $ip_dbh->errstr if !$ret;
    171   return $ret;
    172 } # rpc_getAvailableStatics()
     182# These are deep internals and don't make much sense to expose, since RPC
     183# by definition does not access the backing DB directly.
     184#sub _rpc {}
     185#sub initIPDBGlobals {}
     186#sub connectDB {}
     187#sub finish {}
     188#sub checkDBSanity {}
     189
     190sub rpc_addMaster {}
     191sub rpc_touchMaster {}
     192sub rpc_listSummary {}
     193sub rpc_listSubs {}
     194sub rpc_listContainers {}
     195sub rpc_listAllocations {}
     196sub rpc_listFree {}
     197sub rpc_listPool {}
     198sub rpc_getMasterList {}
     199sub rpc_getTypeList {}
     200sub rpc_getPoolSelect {}
     201sub rpc_findAllocateFrom {}
     202sub rpc_ipParent {}
     203sub rpc_subParent {}
     204sub rpc_blockParent {}
     205sub rpc_getRoutedCity {}
    173206
    174207sub rpc_allocateBlock {
     
    209242  return $msg;
    210243} # rpc_allocateBlock()
     244
     245# another internal sub;  mainly a sub to make allocateBlock() a lot smaller
     246#sub rpc_initPool {}
     247sub rpc_updateBlock {}
     248sub rpc_deleteBlock {}
     249sub rpc_getBlockData {}
     250sub rpc_getBlockRDNS {}
     251sub rpc_getNodeList {}
     252sub rpc_getNodeName {}
     253sub rpc_getNodeInfo {}
     254sub rpc_mailNotify {}
     255
     256
     257##
     258## Subs not part of the core IPDB
     259##
     260
     261# Subs to send back IPDB globals
     262
     263#our %disp_alloctypes;
     264sub rpc_getDispAlloctypes {
     265  my %args = @_;
     266  _commoncheck(\%args, 'n');
     267  return \%disp_alloctypes;
     268}
     269
     270#our %list_alloctypes;
     271sub rpc_getListAlloctypes {
     272  my %args = @_;
     273  _commoncheck(\%args, 'n');
     274  return \%list_alloctypes;
     275}
     276
     277#our %def_custids;
     278sub rpc_getDefCustIDs {
     279  my %args = @_;
     280  _commoncheck(\%args, 'n');
     281  return \%def_custids;
     282}
     283
     284#our @citylist;
     285sub rpc_getCityList {
     286  my %args = @_;
     287  _commoncheck(\%args, 'n');
     288  return \@citylist;
     289}
     290
     291#our @poplist;
     292sub rpc_getPOPList {
     293  my %args = @_;
     294  _commoncheck(\%args, 'n');
     295  return \@poplist;
     296}
     297
     298# not sure how useful it is to expose this on RPC
     299#our %IPDBacl;
     300sub rpc_getIPDBacl {
     301  my %args = @_;
     302  _commoncheck(\%args, 'n');
     303  return \%IPDBacl;
     304}
     305
     306# Operations not provided directly by the core IPDB
     307
     308# Get a list of available static IPs of the given type
     309# Not a core IPDB sub since there's little use for this format.
     310sub rpc_getAvailableStatics {
     311  my %args = @_;
     312
     313  _commoncheck(\%args, 'n');
     314
     315  my ($base,undef) = split //, $args{type};
     316  $base .= "_";
     317  my @params = ($base);
     318
     319  my $sql = "SELECT poolips.id,poolips.ip,poolips.parent_id,poolips.pool ".
     320        "FROM poolips JOIN allocations ON poolips.parent_id=allocations.id WHERE poolips.type LIKE ?";
     321  if ($base ne 'd_' && $args{city}) {
     322    $sql .= " AND allocations.city=?";
     323    push @params, $args{city};
     324  }
     325  $sql .= " AND poolips.available='y'";
     326
     327  my $ret = $ip_dbh->selectall_arrayref($sql, { Slice => {} }, (@params) );
     328  die $ip_dbh->errstr if !$ret;
     329
     330  return $ret;
     331} # rpc_getAvailableStatics()
Note: See TracChangeset for help on using the changeset viewer.