[freeside-commits] freeside/FS/FS AccessRight.pm, 1.27, 1.28 addr_block.pm, 1.7, 1.8 router.pm, 1.3, 1.4 svc_broadband.pm, 1.14, 1.15

Jeff Finucane,420,, jeff at wavetail.420.am
Sat Jun 28 12:25:25 PDT 2008


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv20117/FS/FS

Modified Files:
	AccessRight.pm addr_block.pm router.pm svc_broadband.pm 
Log Message:
agent virtualize address blocks and routers

Index: AccessRight.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/AccessRight.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- AccessRight.pm	17 Jun 2008 03:35:38 -0000	1.27
+++ AccessRight.pm	28 Jun 2008 19:25:23 -0000	1.28
@@ -238,6 +238,9 @@
     'Edit billing events',
     { rightname=>'Edit global billing events', global=>1 },
   
+    { rightname=>'Engineering configuration' },
+    { rightname=>'Engineering global configuration', global=>1 },
+
     { rightname=>'Configuration', global=>1 }, #most of the rest of the configuraiton is not agent-virtualized
   ],
   

Index: addr_block.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/addr_block.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- addr_block.pm	16 Mar 2008 05:13:13 -0000	1.7
+++ addr_block.pm	28 Jun 2008 19:25:23 -0000	1.8
@@ -7,6 +7,7 @@
 use FS::svc_broadband;
 use FS::Conf;
 use NetAddr::IP;
+use Carp qw( carp );
 
 @ISA = qw( FS::Record );
 
@@ -47,6 +48,8 @@
 
 =item ip_netmask - the netmask of the block, expressed as an integer.
 
+=item agentnum - optional agent number (see L<FS::agent>)
+
 =back
 
 =head1 METHODS
@@ -84,6 +87,28 @@
 Replaces OLD_RECORD with this one in the database.  If there is an error,
 returns the error, otherwise returns false.
 
+At present it's not possible to reallocate a block to a different router 
+except by deallocating it first, which requires that none of its addresses 
+be assigned.  This is probably as it should be.
+
+sub replace_check {
+  my ( $new, $old ) = ( shift, shift );
+
+  unless($new->routernum == $old->routernum) {
+    my @svc = $self->svc_broadband;
+    if (@svc) {
+      return 'Block has assigned addresses: '.
+             join ', ', map {$_->ip_addr} @svc;
+    }
+
+    return 'Block is already allocated'
+      if($new->routernum && $old->routernum);
+
+  }
+
+  '';
+}
+
 =item check
 
 Checks all fields to make sure this is a valid record.  If there is an error,
@@ -99,6 +124,7 @@
     $self->ut_number('routernum')
     || $self->ut_ip('ip_gateway')
     || $self->ut_number('ip_netmask')
+    || $self->ut_agentnum_acl('agentnum', 'Engineering global configuration')
   ;
   return $error if $error;
 
@@ -202,7 +228,7 @@
 
 }
 
-=item allocate
+=item allocate -- deprecated
 
 Allocates this address block to a router.  Takes an FS::router object 
 as an argument.
@@ -215,25 +241,18 @@
 
 sub allocate {
   my ($self, $router) = @_;
-
-  return 'Block is already allocated'
-    if($self->router);
+  carp "deallocate deprecated -- use replace";
 
   return 'Block must be allocated to a router'
     unless(ref $router eq 'FS::router');
 
-  my @svc = $self->svc_broadband;
-  if (@svc) {
-    return 'Block has assigned addresses: '. join ', ', map {$_->ip_addr} @svc;
-  }
-
   my $new = new FS::addr_block {$self->hash};
   $new->routernum($router->routernum);
   return $new->replace($self);
 
 }
 
-=item deallocate
+=item deallocate -- deprecated
 
 Deallocates the block (i.e. sets the routernum to 0).  If any addresses in the 
 block are assigned to services, it fails.
@@ -241,13 +260,9 @@
 =cut
 
 sub deallocate {
+  carp "deallocate deprecated -- use replace";
   my $self = shift;
 
-  my @svc = $self->svc_broadband;
-  if (@svc) {
-    return 'Block has assigned addresses: '. join ', ', map {$_->ip_addr} @svc;
-  }
-
   my $new = new FS::addr_block {$self->hash};
   $new->routernum(0);
   return $new->replace($self);
@@ -328,6 +343,29 @@
 
 To be implemented.
 
+=item agent
+
+Returns the agent (see L<FS::agent>) for this address block, if one exists.
+
+=cut
+
+sub agent {
+  qsearchs('agent', { 'agentnum' => shift->agentnum } );
+}
+
+=item label
+
+Returns text including the router name, gateway ip, and netmask for this
+block.
+
+=cut
+
+sub label {
+  my $self = shift;
+  my $router = $self->router;
+  ($router ? $router->routername : '(unallocated)'). ':'. $self->NetAddr;
+}
+
 =back
 
 =head1 BUGS

Index: svc_broadband.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_broadband.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- svc_broadband.pm	16 Mar 2008 05:13:13 -0000	1.14
+++ svc_broadband.pm	28 Jun 2008 19:25:23 -0000	1.15
@@ -220,6 +220,24 @@
   if($self->speed_up < 0) { return 'speed_up must be positive'; }
   if($self->speed_down < 0) { return 'speed_down must be positive'; }
 
+  my $cust_svc = $self->svcnum
+                 ? qsearchs('cust_svc', { 'svcnum' => $self->svcnum } )
+                 : '';
+  my $cust_pkg;
+  if ($cust_svc) {
+    $cust_pkg = $cust_svc->cust_pkg;
+  }else{
+    $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $self->pkgnum } );
+    return "Invalid pkgnum" unless $cust_pkg;
+  }
+    
+  if ($cust_pkg) {
+    my $addr_agentnum = $self->addr_block->agentnum;
+    if ($addr_agentnum && $addr_agentnum != $cust_pkg->cust_main->agentnum) {
+      return "Address block does not service this customer";
+    }
+  }
+
   if (not($self->ip_addr) or $self->ip_addr eq '0.0.0.0') {
     my $next_addr = $self->addr_block->next_free_addr;
     if ($next_addr) {
@@ -290,6 +308,9 @@
 
 The business with sb_field has been 'fixed', in a manner of speaking.
 
+allowed_routers isn't agent virtualized because part_svc isn't agent
+virtualized
+
 =head1 SEE ALSO
 
 FS::svc_Common, FS::Record, FS::addr_block,

Index: router.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/router.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- router.pm	26 Nov 2004 09:39:52 -0000	1.3
+++ router.pm	28 Jun 2008 19:25:23 -0000	1.4
@@ -5,7 +5,7 @@
 use FS::Record qw( qsearchs qsearch );
 use FS::addr_block;
 
- at ISA = qw( FS::Record );
+ at ISA = qw( FS::Record FS::m2m_Common );
 
 =head1 NAME
 
@@ -82,7 +82,9 @@
 
   my $error =
     $self->ut_numbern('routernum')
-    || $self->ut_text('routername');
+    || $self->ut_text('routername')
+    || $self->ut_agentnum_acl('agentnum', 'Engineering global configuration')
+  ;
   return $error if $error;
 
   $self->SUPER::check;
@@ -125,6 +127,16 @@
       $self->part_svc_router;
 }
 
+=item agent
+
+Returns the agent associated with this router, if any.
+
+=cut
+
+sub agent {
+  qsearchs('agent', { 'agentnum' => shift->agentnum });
+}
+
 =back
 
 =head1 BUGS



More information about the freeside-commits mailing list