Changeset 2024


Ignore:
Timestamp:
05/05/17 16:12:29 (7 years ago)
Author:
nanardon
Message:

Fix filter in task

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task/Iprecover.pm

    r2020 r2024  
    6161 
    6262    if (my @cfilters = $self->{syncm}->ini->val($self->{name}, 'filter')) { 
     63        $filteredHosts = {}; 
    6364        foreach ($self->{_base}->search_objects('nethost', @cfilters)) { 
    6465            $filteredHosts->{$_} = 1; 
     
    6667    } 
    6768 
    68     my %hosts; 
     69    my $hosts; 
    6970 
    7071    if (my @zones = $self->{syncm}->ini->val($self->{name}, 'netzone')) { 
     72 
     73        $hosts = {}; 
    7174 
    7275        my @filters; 
     
    7982            }; 
    8083 
    81             my @hosts = $oZone->get_attributes('hosts'); 
     84            my @zonehosts = $oZone->get_attributes('hosts'); 
    8285 
    83             push(@filters, [ 'name=' . join('||', @hosts) ]); 
     86            push(@filters, [ 'name=' . join('||', @zonehosts) ]); 
    8487 
    8588            if ($oZone->get_attributes('allow_dyn')) { 
     
    9295            foreach ($self->{_base}->search_objects('nethost', @$filter)) { 
    9396                $filteredHosts && !$filteredHosts->{$_} and next; 
    94                 $hosts{$_} = 1; 
     97                $hosts->{$_} = 1; 
    9598            } 
    9699        } 
     100    } else { 
     101        $hosts = $filteredHosts; 
    97102    } 
    98103 
    99     return %hosts; 
     104    return $hosts; 
    100105} 
    101106 
    102107sub run { 
    103108    my ($self) = @_; 
     109 
     110    $self->{_base}->temp_switch_unexported(sub { 
    104111 
    105112    my $test = $self->{syncm}->ini->val($self->{name}, 'test'); 
     
    108115    my $waitAfterModif = DateTime->now->subtract( days => $modifDelay  )->iso8601; 
    109116 
    110     my %hosts = $self->_filters; 
    111  
     117    my $hosts = $self->_filters; 
    112118 
    113119    my @HostToDisable = $self->{_base}->search_objects('nethost', 'exported=0', 'ip=*', 'date<' . $waitAfterModif); 
    114120 
    115     foreach my $hostname (sort @HostToDisable) { 
    116         $hosts{$hostname} or next; 
     121    foreach my $hostname (@HostToDisable) { 
     122        if ($hosts) { 
     123            $hosts->{$hostname} or next; 
     124        } 
    117125        my $Host = $self->{_base}->get_object('nethost', $hostname) or next; 
    118126        $self->{_base}->log( 
    119             LA_INFO, 
    120             '%sHost %s disable because owner or user is inactive', 
     127            LA_NOTICE, 
     128            '%sRecovering IP for host %s because is disable from a long time', 
    121129            ($test ? '(Test) ' : ''), 
    122130            $hostname, 
     
    128136    $self->{_base}->commit() 
    129137        unless($test); 
     138 
     139    }, 1); 
    130140} 
    131  
    132141 
    1331421; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task/Unusedhosts.pm

    r2015 r2024  
    8181 
    8282    if (my @cfilters = $self->{syncm}->ini->val($self->{name}, 'filter')) { 
     83        $filteredHosts = {}; 
    8384        foreach ($self->{_base}->search_objects('nethost', @cfilters)) { 
    8485            $filteredHosts->{$_} = 1; 
     
    8687    } 
    8788 
    88     my %hosts; 
     89    my $hosts; 
    8990 
    9091    if (my @zones = $self->{syncm}->ini->val($self->{name}, 'netzone')) { 
     92 
     93        $hosts = {}; 
    9194 
    9295        my @filters; 
     
    99102            }; 
    100103 
    101             my @hosts = $oZone->get_attributes('hosts'); 
    102  
    103             push(@filters, [ 'name=' . join('||', @hosts) ]); 
     104            my @zonehosts = $oZone->get_attributes('hosts'); 
     105 
     106            push(@filters, [ 'name=' . join('||', @zonehosts) ]); 
    104107 
    105108            if ($oZone->get_attributes('allow_dyn')) { 
     
    112115            foreach ($self->{_base}->search_objects('nethost', @$filter)) { 
    113116                $filteredHosts && !$filteredHosts->{$_} and next; 
    114                 $hosts{$_} = 1; 
    115             } 
    116         } 
    117     } 
    118  
    119     return %hosts; 
     117                $hosts->{$_} = 1; 
     118            } 
     119        } 
     120    } else { 
     121        $hosts = $filteredHosts; 
     122    } 
     123 
     124    return $hosts; 
    120125} 
    121126 
     
    128133    la_log(LA_DEBUG, "Checking for host to disable using %s method", $mode); 
    129134 
    130     my %hosts = $self->_filters; 
     135    my $hosts = $self->_filters; 
    131136 
    132137    my @HostToDisable; 
     
    171176 
    172177    foreach my $hostname (sort @HostToDisable) { 
    173         $hosts{$hostname} or next; 
     178        if ($hosts) { 
     179            $hosts->{$hostname} or next; 
     180        } 
    174181        my $Host = $self->{_base}->get_object('nethost', $hostname) or next; 
    175182        $self->{_base}->log( 
    176             LA_INFO, 
     183            LA_NOTICE, 
    177184            '%sHost %s disable because owner or user is inactive', 
    178185            ($test ? '(Test) ' : ''), 
     
    195202    la_log(LA_DEBUG, "Checking for host to disable using %s method", $mode); 
    196203 
    197     my %hosts = $self->_filters; 
     204    my $hosts = $self->_filters; 
    198205 
    199206    my @HostToEnable; 
     
    238245 
    239246    foreach my $hostname (sort @HostToEnable) { 
    240         $hosts{$hostname} or next; 
     247        if ($hosts) { 
     248            $hosts->{$hostname} or next; 
     249        } 
    241250        my $Host = $self->{_base}->get_object('nethost', $hostname) or next; 
    242251        $self->{_base}->log( 
Note: See TracChangeset for help on using the changeset viewer.