Changeset 307


Ignore:
Timestamp:
Jul 18, 2018, 9:13:46 PM (6 years ago)
Author:
g7moreau
Message:
  • Update some command
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r306 r307  
    192192   my @domainsetdb = @{$computer_db->{$domainset}};
    193193
    194    for my $value (@domainsetdb) {
    195       for my $id (keys %{$value}) {
    196          if ($value->{$id}->{'hostname'} eq $hostname) {
    197             #print "Error: Hostname already exist: $hostname\n";
    198             return 0;
    199             }
    200          }
     194   for my $computer (@domainsetdb) {
     195      my ($mac_address, $attribute) = %{$computer};
     196      return 0 if $attribute->{'hostname'} eq $hostname;
    201197      }
    202198   return 1;
     
    219215
    220216      my @domainsetdb = @{$computer_db->{$domainset_current}};
    221       for my $value (@domainsetdb) {
    222          for my $id (keys %{$value}) {
    223             if ($id eq $mac) {
    224                #print "Error: Physical MAC address already exists: $mac\n";
    225                return 0;
    226                }
    227             }
     217
     218      LOOP_ON_COMPUTER:
     219      for my $computer (@domainsetdb) {
     220         my ($mac_address, $attribute) = %{$computer};
     221         return 0 if $mac_address eq $mac;
    228222         }
    229223      }
     
    428422
    429423   my @domainsetdb = @{$computer_db->{$domainset}};
    430    my $cpt=0;
    431    for my $value (@domainsetdb) {
    432       for my $id (keys %{$value}) {
    433 
    434          if ($value->{$id}->{'hostname'} eq $hostname) {
    435             print  $value->{$id}->{'alias'};
    436             $alias = $alias . ' ' . $value->{$id}->{'alias'};
    437             $computer_db->{$domainset}[$cpt]{$id}{'alias'}        = $alias;
    438             $computer_db->{$domainset}[$cpt]{$id}{'modify_time'}  = time;
    439             ipamdb_save("$COMPUTER_YAML", $computer_db);
    440             print "Update attribute alias [OK]\n";
    441             exit;
    442             }
    443          }
    444       $cpt=$cpt+1;
     424
     425   LOOP_ON_COMPUTER:
     426   for my $computer (@domainsetdb) {
     427      my ($mac_address, $attribute) = %{$computer};
     428
     429      next LOOP_ON_COMPUTER if $attribute->{'hostname'} ne $hostname;
     430
     431      $alias .= ' ' . $attribute->{'alias'};
     432      $attribute->{'alias'}       = $alias;
     433      $attribute->{'modify_time'} = time;
     434      ipamdb_save("$COMPUTER_YAML", $computer_db);
     435      print "Info: Update attribute alias to $alias for host $hostname [OK]\n";
     436      exit;
    445437      }
    446438   }
     
    472464      'alias'        =>  '',
    473465      }};
    474    print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n";
     466   print "Info: Add the host: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset [OK]\n";
    475467
    476468   ipamdb_save("$COMPUTER_YAML", $computer_db);
     
    535527      'comment'      => $comment,
    536528      }};
    537    print "Add the computer in pool MAC: $mac, Domain Set: $domainset, Pool: $pool\n";
     529   print "Info: Add the computer in pool MAC: $mac, Domain Set: $domainset, Pool: $pool [OK]\n";
    538530
    539531   ipamdb_save("$COMPUTER_YAML", $computer_db);
     
    13161308   my $computer_db = ipamdb_load($COMPUTER_YAML);
    13171309
    1318    my $computer_index;
    13191310   if ( control_exist_mac($computer_db, $mac) == 1 ) {
    1320       print "Adresse MAC $mac non trouvée.\n";
    1321       exit;
     1311      die "Error: Unkown physical MAC address: $mac [FAILED]\n";
    13221312      }
    13231313
     
    13311321      my @domainsetdb = @{$computer_db->{$domainset_current}};
    13321322
    1333       $computer_index=0;
    1334       for my $value (@domainsetdb) {
    1335          for my $id (keys %{$value}) {
    1336             if ($id eq $mac) {
    1337                if ($value->{$id}->{'ip'} eq $pool) {
    1338                   my $timestamp = time;
    1339                   $computer_db->{$domainset_current}[$computer_index]->{$id}->{'modify_time'} = $timestamp;
    1340                   $computer_db->{$domainset_current}[$computer_index]->{$id}->{'enabled'} = 'yes';
    1341                   ipamdb_save("$COMPUTER_YAML", $computer_db);
    1342                   print "Réactivation de la machine $mac du pool $pool [OK]\n";
    1343                   exit;
    1344                   }
    1345                else {
    1346                   print "Réactivation de la machine $mac [FAILED]\n";
    1347                   print "La machine $mac n'appartient pas au pool $pool.\n";
    1348                   exit;
    1349                   }
    1350                }
    1351             $computer_index++;
    1352             }
     1323      LOOP_ON_COMPUTER:
     1324      for my $computer (@domainsetdb) {
     1325         my ($mac_address, $attribute) = %{$computer};
     1326         next LOOP_ON_COMPUTER if $mac_address ne $mac;
     1327
     1328         if ($attribute->{'ip'} ne $pool) {
     1329            die "Error: Host enable $mac [FAILED]" .
     1330               " ... The host $mac does not belong to the $pool pool.\n";
     1331            }
     1332
     1333         if ($attribute->{'enabled'} eq 'yes') {
     1334            print "Info: Host $mac from pool $pool is already enable [OK]" .
     1335               " ... Status: $attribute->{'enabled'}\n";
     1336            exit;
     1337            }
     1338
     1339         my $timestamp = time;
     1340         $attribute->{'modify_time'} = $timestamp;
     1341         $attribute->{'enabled'}     = 'yes';
     1342         ipamdb_save("$COMPUTER_YAML", $computer_db);
     1343         print "Info: Enabling host $mac from pool $pool [OK]" .
     1344            " ... Status: $attribute->{'enabled'}\n";
     1345         exit;
    13531346         }
    13541347      }
Note: See TracChangeset for help on using the changeset viewer.