- Timestamp:
- Jul 18, 2018, 8:37:58 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r305 r306 246 246 next if $domainset_current eq 'version'; 247 247 248 for my $value (@{$computer_db->{$domainset_current}}) {249 for my $id (keys %{$value}) {250 #print "Erreur: cette adresse IP $ip existe déjà\n";251 return 0 if $value->{$id}{'ip'} eq $ip;252 }248 LOOP_ON_COMPUTER: 249 for my $computer (@{$computer_db->{$domainset_current}}) { 250 my ($mac_address, $attribute) = %{$computer}; 251 #print "Erreur: cette adresse IP $ip existe déjà\n"; 252 return 0 if $attribute->{'ip'} eq $ip; 253 253 } 254 254 } 255 255 256 256 for my $current_pool (keys %{$computer_db->{'pool'}}) { 257 258 my @T_pool_ip = @{ 257 #--- Cette partie pour tester les ip des pools est bonne ne plus la changer ---# 258 my @T_pool_ip = @{$computer_db->{'pool'}{$current_pool}{'ip'}}; 259 259 260 260 for my $pool_ip (@T_pool_ip) { … … 1013 1013 1014 1014 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1015 my $c pt_mac= 0;1015 my $computer_index = 0; 1016 1016 for my $value (@domainsetdb) { 1017 1017 for my $id (keys %{$value}) { 1018 1018 if ($id eq $mac) { 1019 my $host = $computer_db->{$domainset_current}[$c pt_mac]{$mac};1019 my $host = $computer_db->{$domainset_current}[$computer_index]{$mac}; 1020 1020 next LOOP_ON_DOMAINSET if $host->{'ip'} ne $ip; 1021 1021 1022 1022 $host->{'modify_time'} = time; 1023 splice(@{$computer_db->{$domainset_current}}, $c pt_mac=> 1);1023 splice(@{$computer_db->{$domainset_current}}, $computer_index => 1); 1024 1024 push @{$computer_db->{$domainset}}, { $mac => $host }; 1025 1025 … … 1028 1028 } 1029 1029 } 1030 $c pt_mac++;1030 $computer_index++; 1031 1031 } 1032 1032 } … … 1187 1187 my $computer_db = ipamdb_load($COMPUTER_YAML); 1188 1188 1189 my $c pt_mac;1189 my $computer_index; 1190 1190 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1191 1191 die "Error: Unkown physical MAC address: $mac [FAILED]\n"; … … 1238 1238 1239 1239 control_exist_domainset($computer_db, $domainset) or exit; 1240 if ($ip ne '') { 1240 1241 if ($ip ne '') { # enable by IP 1241 1242 control_syntax_ip($ip); 1242 1243 if ( control_exist_ip($computer_db, $ip) == 1 ) { … … 1253 1254 1254 1255 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1255 my $cpt_mac=0; 1256 for my $value (@domainsetdb) {1257 for my $id (keys %{$value}) {1258 if ($value->{$id}->{'ip'} eq $ip) {1259 my $timestamp = time;1260 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1261 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes';1262 print " L'adresse IP: $ip a été réactivée. Valeur du champs enabled: [".$computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n";1263 ipamdb_save("$COMPUTER_YAML", $computer_db);1256 1257 LOOP_ON_COMPUTER: 1258 for my $computer (@domainsetdb) { 1259 my ($mac_address, $attribute) = %{$computer}; 1260 if ($attribute->{'ip'} eq $ip) { 1261 1262 if ($attribute->{'enabled'} eq 'yes') { 1263 print "Info: IP $ip belongs to domain set $domainset is already enable [OK]" . 1264 " ... Status: $attribute->{'enabled'}\n"; 1264 1265 exit; 1265 1266 } 1266 $cpt_mac=$cpt_mac+1; 1267 1268 my $timestamp = time; 1269 $attribute->{'modify_time'} = $timestamp; 1270 $attribute->{'enabled'} = 'yes'; 1271 ipamdb_save("$COMPUTER_YAML", $computer_db); 1272 print "Info: IP $ip is now enable [OK]" . 1273 " ... Status: $attribute->{'enabled'}\n"; 1274 exit; 1267 1275 } 1268 1276 } 1269 1277 } 1270 1278 } 1271 else { 1279 else { # enable by Hostname 1272 1280 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1273 1281 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1274 1282 } 1275 1283 1276 my $cpt_mac=0; 1277 for my $value (@{$computer_db->{$domainset}}) { 1278 for my $id (keys %{$value}) { 1279 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1280 my $timestamp = time; 1281 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1282 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'yes'; 1283 print "La machine $hostname (domaine: $domainset) a été réactivée du DHCP. Valeur du champs enabled: [".$computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1284 ipamdb_save("$COMPUTER_YAML", $computer_db); 1285 exit; 1286 } 1287 1288 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} eq 'pool-dhcp')) { 1289 print "Réactivation de la machine $hostname sur le domaine $domainset [FAILED]\n"; 1290 print "La machine $hostname fait partie du pool $hostname.\n"; 1291 exit; 1292 } 1293 } 1294 $cpt_mac++; 1295 } 1296 } 1297 #print "La machine $hostname n'existe pas sur le domaineset: $domainset\n"; 1284 LOOP_ON_COMPUTER: 1285 for my $computer (@{$computer_db->{$domainset}}) { 1286 my ($mac_address, $attribute) = %{$computer}; 1287 next LOOP_ON_COMPUTER if $attribute->{'hostname'} ne $hostname; 1288 1289 if ($attribute->{'address_type'} eq 'pool-dhcp') { 1290 die "Error: Host $hostname from domain set $domainset belongs to a a pool [FAILED]" . 1291 " ... use 'enable-float' command instead"; 1292 } 1293 1294 if ($attribute->{'enabled'} eq 'yes') { 1295 print "Info: Host $hostname belongs to domain set $domainset is already enable [OK]" . 1296 " ... Status: $attribute->{'enabled'}\n"; 1297 exit; 1298 } 1299 1300 my $timestamp = time; 1301 $attribute->{'modify_time'} = $timestamp; 1302 $attribute->{'enabled'} = 'yes'; 1303 ipamdb_save("$COMPUTER_YAML", $computer_db); 1304 print "Info: Host $hostname is now enable [OK]" . 1305 " ... Status: $attribute->{'enabled'}\n"; 1306 exit; 1307 } 1308 } 1298 1309 } 1299 1310 … … 1305 1316 my $computer_db = ipamdb_load($COMPUTER_YAML); 1306 1317 1307 my $c pt_mac;1318 my $computer_index; 1308 1319 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1309 1320 print "Adresse MAC $mac non trouvée.\n"; … … 1320 1331 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1321 1332 1322 $c pt_mac=0;1333 $computer_index=0; 1323 1334 for my $value (@domainsetdb) { 1324 1335 for my $id (keys %{$value}) { 1325 1336 if ($id eq $mac) { 1326 1337 if ($value->{$id}->{'ip'} eq $pool) { 1327 #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1);1328 1338 my $timestamp = time; 1329 $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'modify_time'} = $timestamp;1330 $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'enabled'} = 'yes';1339 $computer_db->{$domainset_current}[$computer_index]->{$id}->{'modify_time'} = $timestamp; 1340 $computer_db->{$domainset_current}[$computer_index]->{$id}->{'enabled'} = 'yes'; 1331 1341 ipamdb_save("$COMPUTER_YAML", $computer_db); 1332 1342 print "Réactivation de la machine $mac du pool $pool [OK]\n"; … … 1339 1349 } 1340 1350 } 1341 $c pt_mac++;1351 $computer_index++; 1342 1352 } 1343 1353 } … … 1459 1469 die "Error: Unkown IP address: $ip\n"; 1460 1470 } 1461 my $c pt_mac=0;1471 my $computer_index=0; 1462 1472 for my $value (@{$computer_db->{$domainset}}) { 1463 1473 for my $id (keys %{$value}) { 1464 1474 if ($value->{$id}->{'ip'} eq $ip) { 1465 1475 my $timestamp = time; 1466 splice(@{$computer_db->{$domainset}}, $c pt_mac=> 1);1476 splice(@{$computer_db->{$domainset}}, $computer_index => 1); 1467 1477 print "La machine $ip a été supprimer du domaine $domainset\n"; 1468 1478 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 1470 1480 } 1471 1481 } 1472 $c pt_mac++;1482 $computer_index++; 1473 1483 } 1474 1484 #print "La machine $ip n'existe pas sur le domaine $domainset.\n"; … … 1478 1488 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1479 1489 } 1480 my $c pt_mac=0;1490 my $computer_index=0; 1481 1491 for my $value (@{$computer_db->{$domainset}}) { 1482 1492 for my $id (keys %{$value}) { 1483 1493 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1484 1494 my $timestamp = time; 1485 splice(@{$computer_db->{$domainset}}, $c pt_mac=> 1);1495 splice(@{$computer_db->{$domainset}}, $computer_index => 1); 1486 1496 print "La machine $hostname a été supprimer du domaine $domainset\n"; 1487 1497 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 1495 1505 } 1496 1506 } 1497 $c pt_mac++;1507 $computer_index++; 1498 1508 } 1499 1509 #print "La machine $hostname n'existe pas sur le domaine $domainset.\n"; … … 1510 1520 my $computer_db = ipamdb_load($COMPUTER_YAML); 1511 1521 1512 my $cpt_mac;1513 1522 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1514 1523 print "Adresse MAC $mac non trouvée.\n"; … … 1525 1534 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1526 1535 1527 $cpt_mac=0; 1528 for my $value (@domainsetdb) { 1529 for my $id (keys %{$value}) { 1530 1531 if ($id eq $mac) { 1532 if ($value->{$id}->{'ip'} eq $pool) { 1533 #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1); 1534 splice(@{$computer_db->{$domainset_current}}, $cpt_mac => 1); 1535 ipamdb_save("$COMPUTER_YAML", $computer_db); 1536 print "Suppression de la machine $mac du pool $pool [OK]\n"; 1537 exit; 1538 } 1539 else { 1540 print "Suppression de la machine $mac [FAILED]\n"; 1541 print "La machine $mac n'appartient pas au pool $pool.\n"; 1542 exit; 1543 } 1544 } 1545 $cpt_mac++; 1546 } 1536 my $computer_index = 0; 1537 1538 LOOP_ON_COMPUTER: 1539 for my $computer (@domainsetdb) { 1540 my ($mac_address, $attribute) = %{$computer}; 1541 1542 $computer_index++ and next LOOP_ON_COMPUTER if $mac_address ne $mac; 1543 1544 if ($attribute->{'ip'} ne $pool) { 1545 die "Error: Host remove $mac [FAILED]" . 1546 " ... The host $mac does not belong to the $pool pool.\n"; 1547 } 1548 1549 splice(@{$computer_db->{$domainset_current}}, $computer_index => 1); 1550 ipamdb_save("$COMPUTER_YAML", $computer_db); 1551 print "Info: remove host $mac from the pool $pool [OK]\n"; 1552 exit; 1547 1553 } 1548 1554 } … … 1894 1900 next if $domainset_current eq 'version'; 1895 1901 1896 my $c pt_mac= 0;1902 my $computer_index = 0; 1897 1903 for my $computer (@{$computer_db->{$domainset_current}}) { 1898 1904 for my $id (keys %{$computer}) { 1899 1905 if ($computer->{$id}->{'ip'} eq $ip) { 1900 1906 my $timestamp = time; 1901 $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'modify_time'} = $timestamp;1902 $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'pxe_config'} = $pxe_config;1907 $computer_db->{$domainset_current}[$computer_index]->{$id}->{'modify_time'} = $timestamp; 1908 $computer_db->{$domainset_current}[$computer_index]->{$id}->{'pxe_config'} = $pxe_config; 1903 1909 print "IP Address: $ip, PXE enabled in config: $pxe_config\n"; 1904 1910 ipamdb_save("$COMPUTER_YAML", $computer_db); 1905 1911 exit; 1906 1912 } 1907 $c pt_mac++;1913 $computer_index++; 1908 1914 } 1909 1915 } … … 1915 1921 } 1916 1922 1917 my $c pt_mac= 0;1923 my $computer_index = 0; 1918 1924 for my $value (@{$computer_db->{$domainset}}) { 1919 1925 for my $id (keys %{$value}) { 1920 1926 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1921 1927 my $timestamp = time; 1922 $computer_db->{$domainset}[$c pt_mac]->{$id}->{'modify_time'} = $timestamp;1923 $computer_db->{$domainset}[$c pt_mac]->{$id}->{'pxe_config'} = $pxe_config;1928 $computer_db->{$domainset}[$computer_index]->{$id}->{'modify_time'} = $timestamp; 1929 $computer_db->{$domainset}[$computer_index]->{$id}->{'pxe_config'} = $pxe_config; 1924 1930 print "Host $hostname ($domainset), PXE enabled in config: $pxe_config\n"; 1925 1931 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 1931 1937 } 1932 1938 } 1933 $c pt_mac++;1939 $computer_index++; 1934 1940 } 1935 1941 } … … 1976 1982 next if $domainset_current eq 'version'; 1977 1983 1978 my $c pt_mac= 0;1984 my $computer_index = 0; 1979 1985 for my $computer (@{$computer_db->{$domainset_current}}) { 1980 1986 for my $id (keys %{$computer}) { 1981 1987 if ($computer->{$id}->{'ip'} eq $ip) { 1982 next if not exists $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'pxe_config'};1983 1984 my $pxe_config = $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'pxe_config'};1988 next if not exists $computer_db->{$domainset_current}[$computer_index]->{$id}->{'pxe_config'}; 1989 1990 my $pxe_config = $computer_db->{$domainset_current}[$computer_index]->{$id}->{'pxe_config'}; 1985 1991 my $timestamp = time; 1986 $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'modify_time'} = $timestamp;1987 delete $computer_db->{$domainset_current}[$c pt_mac]->{$id}->{'pxe_config'};1992 $computer_db->{$domainset_current}[$computer_index]->{$id}->{'modify_time'} = $timestamp; 1993 delete $computer_db->{$domainset_current}[$computer_index]->{$id}->{'pxe_config'}; 1988 1994 print "IP Address: $ip, PXE disable from config: $pxe_config\n"; 1989 1995 ipamdb_save("$COMPUTER_YAML", $computer_db); 1990 1996 exit; 1991 1997 } 1992 $c pt_mac++;1998 $computer_index++; 1993 1999 } 1994 2000 } … … 2000 2006 } 2001 2007 2002 my $c pt_mac= 0;2008 my $computer_index = 0; 2003 2009 for my $value (@{$computer_db->{$domainset}}) { 2004 2010 for my $id (keys %{$value}) { … … 2006 2012 next if not exists $value->{$id}->{'pxe_config'}; 2007 2013 2008 my $pxe_config = $computer_db->{$domainset}[$c pt_mac]->{$id}->{'pxe_config'};2014 my $pxe_config = $computer_db->{$domainset}[$computer_index]->{$id}->{'pxe_config'}; 2009 2015 my $timestamp = time; 2010 $computer_db->{$domainset}[$c pt_mac]->{$id}->{'modify_time'} = $timestamp;2011 delete $computer_db->{$domainset}[$c pt_mac]->{$id}->{'pxe_config'};2016 $computer_db->{$domainset}[$computer_index]->{$id}->{'modify_time'} = $timestamp; 2017 delete $computer_db->{$domainset}[$computer_index]->{$id}->{'pxe_config'}; 2012 2018 print "Host $hostname ($domainset), PXE disable from config: $pxe_config\n"; 2013 2019 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 2019 2025 } 2020 2026 } 2021 $c pt_mac++;2027 $computer_index++; 2022 2028 } 2023 2029 }
Note: See TracChangeset
for help on using the changeset viewer.