Changeset 333 for trunk/ddt


Ignore:
Timestamp:
Aug 28, 2018, 3:07:40 PM (6 years ago)
Author:
g7moreau
Message:
  • Rewrite enable_pxe
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r332 r333  
    11331133
    11341134         if ($attribute->{'enabled'} eq 'no') {
    1135             print "Info: Host $hostname from domain set $domainset is already disable [OK]" .
     1135            print "Info: host $hostname from domain set $domainset is already disable [OK]" .
    11361136               " ... Status: $attribute->{'enabled'}\n";
    11371137            exit;
     
    11561156   my $computer_db = ipamdb_load($COMPUTER_YAML);
    11571157
    1158    my $computer_index;
    11591158   if ( control_exist_mac($computer_db, $mac) == 1 ) {
    11601159      die "Error: unkown physical MAC address: $mac [FAILED]\n";
     
    11771176         if ($attribute->{'ip'} eq $pool) {
    11781177            if ($attribute->{'enabled'} eq 'no') {
    1179                print "Info: Host $mac from pool $pool is already disable [OK]" .
     1178               print "Info: host $mac from pool $pool is already disable [OK]" .
    11801179                  " ... Status: $attribute->{'enabled'}\n";
    11811180               exit;
     
    11851184            $attribute->{'enabled'}     = 'no';
    11861185            ipamdb_save("$COMPUTER_YAML", $computer_db);
    1187             print "Info: Disabling host $mac from pool $pool [OK]" .
     1186            print "Info: disabling host $mac from pool $pool [OK]" .
    11881187               " ... Status: $attribute->{'enabled'}\n";
    11891188            exit;
     
    12621261
    12631262         if ($attribute->{'enabled'} eq 'yes') {
    1264             print "Info: Host $hostname belongs to domain set $domainset is already enable [OK]" .
     1263            print "Info: host $hostname belongs to domain set $domainset is already enable [OK]" .
    12651264               " ... Status: $attribute->{'enabled'}\n";
    12661265            exit;
     
    12711270         $attribute->{'enabled'}     = 'yes';
    12721271         ipamdb_save("$COMPUTER_YAML", $computer_db);
    1273          print "Info: Host $hostname is now enable [OK]" .
     1272         print "Info: host $hostname is now enable [OK]" .
    12741273            " ... Status: $attribute->{'enabled'}\n";
    12751274         exit;
     
    13091308
    13101309         if ($attribute->{'enabled'} eq 'yes') {
    1311             print "Info: Host $mac from pool $pool is already enable [OK]" .
     1310            print "Info: host $mac from pool $pool is already enable [OK]" .
    13121311               " ... Status: $attribute->{'enabled'}\n";
    13131312            exit;
     
    14501449         splice(@{$computer_db->{$domainset}}, $computer_index => 1);
    14511450         ipamdb_save("$COMPUTER_YAML", $computer_db);
    1452          print "Info: Host $ip has been removed from the domain set $domainset [OK]\n";
     1451         print "Info: host $ip has been removed from the domain set $domainset [OK]\n";
    14531452         exit;
    14541453         }
     
    14741473         splice(@{$computer_db->{$domainset}}, $computer_index => 1);
    14751474         ipamdb_save("$COMPUTER_YAML", $computer_db);
    1476          print "Info: Host $hostname has been removed from the domain set $domainset [OK]\n";
     1475         print "Info: host $hostname has been removed from the domain set $domainset [OK]\n";
    14771476         exit;
    14781477         }
     
    18691868         next if $domainset_current eq 'version';
    18701869
    1871          my $computer_index = 0;
     1870         LOOP_ON_COMPUTER:
    18721871         for my $computer (@{$computer_db->{$domainset_current}}) {
    1873             for my $id (keys %{$computer}) {
    1874                if ($computer->{$id}->{'ip'} eq $ip) {
    1875                   my $timestamp = time;
    1876                   $computer_db->{$domainset_current}[$computer_index]->{$id}->{'modify_time'} = $timestamp;
    1877                   $computer_db->{$domainset_current}[$computer_index]->{$id}->{'pxe_config'}  = $pxe_config;
    1878                   print "IP address: $ip, PXE enabled in config: $pxe_config\n";
    1879                   ipamdb_save("$COMPUTER_YAML", $computer_db);
    1880                   exit;
    1881                   }
    1882                $computer_index++;
    1883                }
     1872            my ($mac_address, $attribute) = %{$computer};
     1873            next LOOP_ON_COMPUTER if $attribute->{'ip'} ne $ip;
     1874
     1875            $attribute->{'modify_time'} = time;
     1876            $attribute->{'pxe_config'}  = $pxe_config;
     1877            ipamdb_save("$COMPUTER_YAML", $computer_db);
     1878            print "Info: host $attribute->{'hostname'} ($domainset_current), IP $ip, PXE enabled: $pxe_config\n";
     1879            exit;
    18841880            }
    18851881         }
     
    19021898         $attribute->{'pxe_config'}  = $pxe_config;
    19031899         ipamdb_save("$COMPUTER_YAML", $computer_db);
    1904          print "Info: Host $hostname ($domainset), PXE enabled in config: $pxe_config [OK]\n";
     1900         print "Info: host $hostname ($domainset), IP $attribute->{'ip'}, PXE enabled: $pxe_config [OK]\n";
    19051901         exit;
    19061902         }
     
    19851981         delete $attribute->{'pxe_config'};
    19861982         ipamdb_save("$COMPUTER_YAML", $computer_db);
    1987          print "Info: Host $hostname ($domainset), PXE disable from config: $pxe_config [OK]\n";
     1983         print "Info: host $hostname ($domainset), PXE disable from config: $pxe_config [OK]\n";
    19881984         exit;
    19891985         }
Note: See TracChangeset for help on using the changeset viewer.