Changeset 311 for trunk/ddt/ddt


Ignore:
Timestamp:
Jul 18, 2018, 10:50:02 PM (6 years ago)
Author:
g7moreau
Message:
  • Update some more command
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r310 r311  
    923923   my $computer_db = ipamdb_load($COMPUTER_YAML);
    924924
    925    control_exist_domainset($computer_db, $domainset)   or exit;
     925   control_exist_domainset($computer_db, $domainset)  or exit;
    926926   control_syntax_mac_address($mac)                   or exit;
    927927   control_syntax_comment($comment)                   or exit;
    928928
    929929   my @domainsetdb = @{$computer_db->{$domainset}};
    930    my $cpt = 0;
    931    for my $value (@domainsetdb) {
    932       for my $id (keys %{$value}) {
    933          if ($id eq $mac) {
    934             my $host = $computer_db->{$domainset}[$cpt]{$mac};
    935             $host->{'comment'}     = $comment;
    936             $host->{'modify_time'} = time;
    937 
    938             ipamdb_save("$COMPUTER_YAML", $computer_db);
    939             exit;
    940             }
    941          }
    942       $cpt++;
    943       }
    944    print "Mise à jour du commentaire de la machine [FAILED]\n";
    945    print "L'adresse MAC: $mac n'existe pas dans le domaine: $domainset.\n";
     930
     931   LOOP_ON_COMPUTER:
     932   for my $computer (@domainsetdb) {
     933      my ($mac_address, $attribute) = %{$computer};
     934
     935      next LOOP_ON_COMPUTER if $mac_address ne $mac;
     936
     937      $attribute->{'modify_time'} = time;
     938      $attribute->{'comment'}     = $comment;
     939      ipamdb_save("$COMPUTER_YAML", $computer_db);
     940      exit;
     941      }
     942   die "Error : Host $attribute->{'hostname'} comment [FAILED]\n" .
     943      " ... No MAC: $mac belongs to the domaine set $domainset.\n";
    946944   }
    947945
     
    983981      my @domainsetdb = @{$computer_db->{$domainset_current}};
    984982      my $computer_index = 0;
    985       for my $value (@domainsetdb) {
    986          for my $id (keys %{$value}) {
    987             if ($id eq $mac) {
    988                my $host = $computer_db->{$domainset_current}[$computer_index]{$mac};
    989                next LOOP_ON_DOMAINSET if $host->{'ip'} ne $ip;
    990 
    991                $host->{'modify_time'} = time;
    992                splice(@{$computer_db->{$domainset_current}}, $computer_index => 1);
    993                push @{$computer_db->{$domainset}}, { $mac => $host };
    994 
    995                ipamdb_save("$COMPUTER_YAML", $computer_db);
    996                exit;
    997                }
    998             }
    999          $computer_index++;
    1000          }
    1001       }
    1002    print "Update of domain set $domainset [FAILED]\n";
    1003    print "L'adresse MAC: $mac ou l'adresse IP: $ip n'existe pas dans la base\n";
     983      LOOP_ON_COMPUTER:
     984      for my $computer (@domainsetdb) {
     985         my ($mac_address, $attribute) = %{$computer};
     986
     987         $computer_index++ and next LOOP_ON_COMPUTER if $mac_address ne $mac;
     988         next LOOP_ON_DOMAINSET if $attribute->{'ip'} ne $ip;
     989
     990         $attribute->{'modify_time'} = time;
     991         splice(@{$computer_db->{$domainset_current}}, $computer_index => 1);
     992         push @{$computer_db->{$domainset}}, { $mac => attribute };
     993
     994         ipamdb_save("$COMPUTER_YAML", $computer_db);
     995         exit;
     996         }
     997      }
     998   die "Error: Update of domain set $domainset [FAILED]\n" .
     999      " ... MAC $mac and IP $ip don't exists in the database\n";
    10041000   }
    10051001
Note: See TracChangeset for help on using the changeset viewer.