Changeset 238
- Timestamp:
- Jun 22, 2018, 10:30:05 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r237 r238 21 21 use strict; 22 22 #use warnings; 23 use version; our $VERSION = version->declare('0.9. 5');23 use version; our $VERSION = version->declare('0.9.6'); 24 24 25 25 use Getopt::Long qw(GetOptions); … … 99 99 mkdir $FOLDER_GEN_DNS, 0755 if not -d $FOLDER_GEN_DNS; 100 100 101 touch $COMPUTER_YAML if not -e $COMPUTER_YAML;102 103 my $COMPUTER_DB = ipamdb_load($COMPUTER_YAML);104 105 101 if (defined $cmd_db{$command}) { 106 102 $cmd_db{$command}->(@ARGV); … … 130 126 131 127 sub ipamdb_load { 132 my $database_file = shift; 133 134 my $computer_db = YAML::Syck::LoadFile($database_file); 128 my $database_yaml = shift; 129 130 touch $database_yaml if not -e $database_yaml; 131 my $computer_db = YAML::Syck::LoadFile($database_yaml); 135 132 136 133 # add database version if not exist … … 146 143 147 144 sub ipamdb_save { 148 my ($database_ file, $computer_db) = @_;149 150 my $dirdb = $database_ file;145 my ($database_yaml, $computer_db) = @_; 146 147 my $dirdb = $database_yaml; 151 148 $dirdb =~ s{ / [^/]* $}{}xms; 152 149 mkdir "$dirdb", 0755 unless -d "$dirdb"; 153 YAML::Syck::DumpFile($database_ file, $computer_db);150 YAML::Syck::DumpFile($database_yaml, $computer_db); 154 151 155 152 return $computer_db; … … 161 158 162 159 sub control_exist_pool { 163 my ($ COMPUTER_DB, $pool) = @_;164 165 return exists $ COMPUTER_DB->{'pool'}{$pool} ? 1 : 0;160 my ($computer_db, $pool) = @_; 161 162 return exists $computer_db->{'pool'}{$pool} ? 1 : 0; 166 163 } 167 164 … … 172 169 173 170 sub control_exist_domainset { 174 my ($ COMPUTER_DB, $domainset) = @_;175 176 return 1 if exists $ COMPUTER_DB->{$domainset};171 my ($computer_db, $domainset) = @_; 172 173 return 1 if exists $computer_db->{$domainset}; 177 174 178 175 print {*STDERR} "Error: domain set $domainset not found\n"; … … 186 183 187 184 sub control_exist_hostname { 188 my ($ COMPUTER_DB, $domainset, $hostname) = @_;189 190 if ($ COMPUTER_DB->{$domainset} eq '') {185 my ($computer_db, $domainset, $hostname) = @_; 186 187 if ($computer_db->{$domainset} eq '') { 191 188 return 1; 192 189 } 193 190 194 my @domainsetdb = @{$ COMPUTER_DB->{$domainset}};191 my @domainsetdb = @{$computer_db->{$domainset}}; 195 192 196 193 for my $value (@domainsetdb) { … … 211 208 212 209 sub control_exist_mac { 213 my ($ COMPUTER_DB, $mac) = @_;214 215 for my $domainset_current (keys %{$ COMPUTER_DB}) {210 my ($computer_db, $mac) = @_; 211 212 for my $domainset_current (keys %{$computer_db}) { 216 213 next if $domainset_current eq 'dset'; 217 214 next if $domainset_current eq 'pool'; … … 220 217 next if $domainset_current eq 'version'; 221 218 222 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};219 my @domainsetdb = @{$computer_db->{$domainset_current}}; 223 220 for my $value (@domainsetdb) { 224 221 for my $id (keys %{$value}) { … … 239 236 240 237 sub control_exist_ip { 241 my ($ COMPUTER_DB, $ip) = @_;242 243 for my $domainset_current (keys %{$ COMPUTER_DB}) {238 my ($computer_db, $ip) = @_; 239 240 for my $domainset_current (keys %{$computer_db}) { 244 241 next if $domainset_current eq 'dset'; 245 242 next if $domainset_current eq 'pool'; … … 248 245 next if $domainset_current eq 'version'; 249 246 250 for my $value (@{$ COMPUTER_DB->{$domainset_current}}) {247 for my $value (@{$computer_db->{$domainset_current}}) { 251 248 for my $id (keys %{$value}) { 252 249 #print "Erreur: cette adresse IP $ip existe déjà\n"; … … 256 253 } 257 254 258 for my $current_pool (keys %{$ COMPUTER_DB->{'pool'}}) {255 for my $current_pool (keys %{$computer_db->{'pool'}}) { 259 256 #--- Cette partie pour tester les ip des pools est bonne ne plus la changer ---# 260 my @T_pool_ip = @{ $ COMPUTER_DB->{'pool'}{$current_pool}{'ip'}};257 my @T_pool_ip = @{ $computer_db->{'pool'}{$current_pool}{'ip'}}; 261 258 262 259 for my $pool_ip (@T_pool_ip) { … … 365 362 366 363 sub get_mac_from_hostname { 367 my ($ domainset, $hostname, $mac) = @_;364 my ($computer_db, $domainset, $hostname, $mac) = @_; 368 365 369 366 return $mac if $mac ne ''; … … 371 368 372 369 LOOP_ON_COMPUTER: 373 for my $computer (@{$ COMPUTER_DB->{$domainset}}) {370 for my $computer (@{$computer_db->{$domainset}}) { 374 371 my ($mac_address, $attribute) = %{$computer}; 375 372 … … 383 380 384 381 sub get_mac_from_ip { 385 my ($ domainset, $ip, $mac) = @_;382 my ($computer_db, $domainset, $ip, $mac) = @_; 386 383 387 384 return $mac if $mac ne ''; … … 389 386 390 387 LOOP_ON_COMPUTER: 391 for my $computer (@{$ COMPUTER_DB->{$domainset}}) {388 for my $computer (@{$computer_db->{$domainset}}) { 392 389 my ($mac_address, $attribute) = %{$computer}; 393 390 … … 402 399 403 400 sub get_computer_from_mac { 404 my ($ domainset, $mac) = @_;401 my ($computer_db, $domainset, $mac) = @_; 405 402 406 403 LOOP_ON_COMPUTER: 407 for my $computer (@{$ COMPUTER_DB->{$domainset}}) {404 for my $computer (@{$computer_db->{$domainset}}) { 408 405 my ($mac_address, $attribute) = %{$computer}; 409 406 … … 424 421 425 422 sub add_alias { 426 my ($ hostname, $domainset, $alias) = @_;427 428 control_exist_domainset($ COMPUTER_DB, $domainset) or exit;429 control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";430 431 my @domainsetdb = @{$ COMPUTER_DB->{$domainset}};423 my ($computer_db, $hostname, $domainset, $alias) = @_; 424 425 control_exist_domainset($computer_db, $domainset) or exit; 426 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 427 428 my @domainsetdb = @{$computer_db->{$domainset}}; 432 429 my $cpt=0; 433 430 for my $value (@domainsetdb) { … … 437 434 print $value->{$id}->{'alias'}; 438 435 $alias = $alias . ' ' . $value->{$id}->{'alias'}; 439 $ COMPUTER_DB->{$domainset}[$cpt]{$id}{'alias'} = $alias;440 $ COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time;441 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);436 $computer_db->{$domainset}[$cpt]{$id}{'alias'} = $alias; 437 $computer_db->{$domainset}[$cpt]{$id}{'modify_time'} = time; 438 ipamdb_save("$COMPUTER_YAML", $computer_db); 442 439 print "Update attribute alias [OK]\n"; 443 440 exit; … … 453 450 454 451 sub add_static { 455 my ($ hostname, $domainset, $ip, $mac, $comment) = @_;452 my ($computer_db, $hostname, $domainset, $ip, $mac, $comment) = @_; 456 453 457 454 $mac = normalize_mac_address($mac); 458 455 $comment = normalize_comment($comment); 459 control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";456 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 460 457 control_syntax_mac_address($mac) or exit; 461 control_exist_mac($ COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n";458 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 462 459 control_syntax_ip($ip) or exit; 463 control_exist_ip($ COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n";460 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n"; 464 461 control_syntax_comment($comment) or exit; 465 462 my $timestamp = time; 466 push @{$ COMPUTER_DB->{$domainset}}, { $mac => {463 push @{$computer_db->{$domainset}}, { $mac => { 467 464 'hostname' => $hostname, 468 465 'ip' => $ip, … … 476 473 print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n"; 477 474 478 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);475 ipamdb_save("$COMPUTER_YAML", $computer_db); 479 476 } 480 477 … … 486 483 487 484 sub add_dhcp { 488 my ($ hostname, $domainset, $ip, $mac, $comment) = @_;485 my ($computer_db, $hostname, $domainset, $ip, $mac, $comment) = @_; 489 486 490 487 my $timestamp = time; 491 488 $mac = normalize_mac_address($mac); 492 489 $comment = normalize_comment($comment); 493 control_exist_domainset($ COMPUTER_DB, $domainset) or exit;494 control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";490 control_exist_domainset($computer_db, $domainset) or exit; 491 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 495 492 control_syntax_mac_address($mac) or exit; 496 control_exist_mac($ COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n";493 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 497 494 control_syntax_ip($ip) or exit; 498 control_exist_ip($ COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n";495 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n"; 499 496 control_syntax_comment($comment) or exit; 500 497 501 push @{$ COMPUTER_DB->{$domainset}}, { $mac => {498 push @{$computer_db->{$domainset}}, { $mac => { 502 499 'hostname' => $hostname, 503 500 'ip' => $ip, … … 511 508 print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n"; 512 509 513 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);510 ipamdb_save("$COMPUTER_YAML", $computer_db); 514 511 } 515 512 … … 518 515 519 516 sub add_float { 520 my ($ pool, $domainset, $mac, $comment) = @_;517 my ($computer_db, $pool, $domainset, $mac, $comment) = @_; 521 518 522 519 my $timestamp = time; 523 520 $mac = normalize_mac_address($mac); 524 521 $comment = normalize_comment($comment); 525 control_exist_domainset($ COMPUTER_DB, $domainset) or exit;522 control_exist_domainset($computer_db, $domainset) or exit; 526 523 control_syntax_mac_address($mac) or exit; 527 control_exist_mac($ COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n";528 control_exist_pool($ COMPUTER_DB, $pool) or die "Error: The pool doesn't exists: $pool\n";524 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 525 control_exist_pool($computer_db, $pool) or die "Error: The pool doesn't exists: $pool\n"; 529 526 control_syntax_comment($comment) or exit; 530 push @{$ COMPUTER_DB->{$domainset}}, { $mac => {527 push @{$computer_db->{$domainset}}, { $mac => { 531 528 'hostname' => $pool, 532 529 'ip' => $pool, … … 539 536 print "Add the computer in pool MAC: $mac, Domain Set: $domainset, Pool: $pool\n"; 540 537 541 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);538 ipamdb_save("$COMPUTER_YAML", $computer_db); 542 539 } 543 540 … … 564 561 or $alias eq ''; 565 562 566 add_alias($hostname, $domainset, $alias); 563 my $computer_db = ipamdb_load($COMPUTER_YAML); 564 add_alias($computer_db, $hostname, $domainset, $alias); 567 565 } 568 566 … … 591 589 or $comment eq ''; 592 590 593 add_dhcp($hostname, $domainset, $ip, $mac, $comment); 591 my $computer_db = ipamdb_load($COMPUTER_YAML); 592 add_dhcp($computer_db, $hostname, $domainset, $ip, $mac, $comment); 594 593 } 595 594 … … 616 615 or $comment eq ''; 617 616 618 add_float($pool, $domainset, $mac, $comment); 617 my $computer_db = ipamdb_load($COMPUTER_YAML); 618 add_float($computer_db, $pool, $domainset, $mac, $comment); 619 619 } 620 620 … … 643 643 or $comment eq ''; 644 644 645 add_static($hostname, $domainset, $ip, $mac, $comment); 645 my $computer_db = ipamdb_load($COMPUTER_YAML); 646 add_static($computer_db, $hostname, $domainset, $ip, $mac, $comment); 646 647 } 647 648 … … 669 670 or $comment eq ''; 670 671 672 my $computer_db = ipamdb_load($COMPUTER_YAML); 673 671 674 $comment = normalize_comment($comment); 672 675 my $timestamp = time; 673 676 674 control_exist_domainset($ COMPUTER_DB, $domainset) or exit;675 control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";677 control_exist_domainset($computer_db, $domainset) or exit; 678 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 676 679 control_syntax_ip($ip) or exit; 677 control_exist_ip($ COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n";680 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n"; 678 681 control_syntax_comment($comment) or exit; 679 682 680 683 my $mac = join ':', 'FF', 'FF', map({sprintf("%02X", $_)} split(/\./, $ip)); 681 684 control_syntax_mac_address($mac) or exit; 682 control_exist_mac($ COMPUTER_DB, $mac) or die "Error: Virtual Physical MAC address already exists: $mac\n";683 684 push @{$ COMPUTER_DB->{$domainset}}, { $mac => {685 control_exist_mac($computer_db, $mac) or die "Error: Virtual Physical MAC address already exists: $mac\n"; 686 687 push @{$computer_db->{$domainset}}, { $mac => { 685 688 'hostname' => $hostname, 686 689 'ip' => $ip, … … 693 696 print "Add the virtual computer: $hostname, IP: $ip, Domain Set: $domainset\n"; 694 697 695 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);698 ipamdb_save("$COMPUTER_YAML", $computer_db); 696 699 } 697 700 … … 710 713 my ($hostname, $domainset, $ip, $mac) = @_; 711 714 715 my $computer_db = ipamdb_load($COMPUTER_YAML); 716 712 717 $mac = normalize_mac_address($mac); 713 control_exist_domainset($ COMPUTER_DB, $domainset) or exit;718 control_exist_domainset($computer_db, $domainset) or exit; 714 719 control_syntax_mac_address($mac) or exit; 715 control_exist_mac($ COMPUTER_DB, $mac) or die "Error: Physical MAC address already exists: $mac\n";720 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n"; 716 721 if ($ip ne '') { 717 722 control_syntax_ip($ip) or exit; 718 if ( control_exist_ip($ COMPUTER_DB, $ip) == 1 ) {723 if ( control_exist_ip($computer_db, $ip) == 1 ) { 719 724 print "Error: Unkown IP address: $ip\n"; 720 725 exit; 721 726 } 722 my @domainsetdb = @{$ COMPUTER_DB->{$domainset}};727 my @domainsetdb = @{$computer_db->{$domainset}}; 723 728 my $cpt = 0; 724 729 for my $value (@domainsetdb) { … … 727 732 my $host = $value->{$id}; 728 733 $host->{'modify_time'} = time; 729 $ COMPUTER_DB->{$domainset}->[$cpt] = { $mac => $host };730 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);734 $computer_db->{$domainset}->[$cpt] = { $mac => $host }; 735 ipamdb_save("$COMPUTER_YAML", $computer_db); 731 736 print "Update [OK]\n"; 732 737 print "Hostname: $host->{'hostname'}\n"; … … 742 747 } 743 748 elsif ($hostname ne '') { 744 if ( control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) == 1 ) {749 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 745 750 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 746 751 } 747 my @domainsetdb = @{$ COMPUTER_DB->{$domainset}};752 my @domainsetdb = @{$computer_db->{$domainset}}; 748 753 my $cpt = 0; 749 754 for my $value (@domainsetdb) { … … 752 757 my $host = $value->{$id}; 753 758 $host->{'modify_time'} = time; 754 $ COMPUTER_DB->{$domainset}->[$cpt] = { $mac => $host };755 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);759 $computer_db->{$domainset}->[$cpt] = { $mac => $host }; 760 ipamdb_save("$COMPUTER_YAML", $computer_db); 756 761 print "Update [OK]\n"; 757 762 print "Hostname: $host->{'hostname'}\n"; … … 774 779 my ($hostname, $domainset, $ip) = @_; 775 780 776 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 777 if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) { 781 my $computer_db = ipamdb_load($COMPUTER_YAML); 782 783 control_exist_domainset($computer_db, $domainset) or exit; 784 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 778 785 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 779 786 } 780 787 control_syntax_ip($ip) or exit; 781 control_exist_ip($ COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n";782 my @domainsetdb = @{$ COMPUTER_DB->{$domainset}};788 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n"; 789 my @domainsetdb = @{$computer_db->{$domainset}}; 783 790 my $cpt = 0; 784 791 for my $value (@domainsetdb) { … … 790 797 ) 791 798 ) { 792 $ COMPUTER_DB->{$domainset}[$cpt]{$id}{'ip'} = $ip;793 $ COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time;794 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);799 $computer_db->{$domainset}[$cpt]{$id}{'ip'} = $ip; 800 $computer_db->{$domainset}[$cpt]{$id}{'modify_time'} = time; 801 ipamdb_save("$COMPUTER_YAML", $computer_db); 795 802 print "Update [OK]\n"; 796 803 print "Hostname: $hostname\n"; … … 819 826 my ($hostname, $domainset, $ip) = @_; 820 827 821 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 828 my $computer_db = ipamdb_load($COMPUTER_YAML); 829 830 control_exist_domainset($computer_db, $domainset) or exit; 822 831 control_syntax_ip($ip) or exit; 823 if ( control_exist_ip($ COMPUTER_DB, $ip) == 1 ) {832 if ( control_exist_ip($computer_db, $ip) == 1 ) { 824 833 print "Error: Unkown IP address: $ip\n"; 825 834 exit; 826 835 } 827 control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";828 829 my @domainsetdb = @{$ COMPUTER_DB->{$domainset}};836 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 837 838 my @domainsetdb = @{$computer_db->{$domainset}}; 830 839 my $cpt = 0; 831 840 for my $value (@domainsetdb) { 832 841 for my $id (keys %{$value}) { 833 842 if ($value->{$id}->{'ip'} eq $ip) { 834 $ COMPUTER_DB->{$domainset}[$cpt]{$id}{'hostname'} = $hostname;835 $ COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time;836 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);843 $computer_db->{$domainset}[$cpt]{$id}{'hostname'} = $hostname; 844 $computer_db->{$domainset}[$cpt]{$id}{'modify_time'} = time; 845 ipamdb_save("$COMPUTER_YAML", $computer_db); 837 846 print "Update [OK]\n"; 838 847 print "Hostname: $hostname\n"; … … 942 951 $comment = normalize_comment($comment); 943 952 944 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 953 my $computer_db = ipamdb_load($COMPUTER_YAML); 954 955 control_exist_domainset($computer_db, $domainset) or exit; 945 956 control_syntax_mac_address($mac) or exit; 946 957 control_syntax_comment($comment) or exit; 947 958 948 my @domainsetdb = @{$ COMPUTER_DB->{$domainset}};959 my @domainsetdb = @{$computer_db->{$domainset}}; 949 960 my $cpt = 0; 950 961 for my $value (@domainsetdb) { 951 962 for my $id (keys %{$value}) { 952 963 if ($id eq $mac) { 953 my $host = $ COMPUTER_DB->{$domainset}[$cpt]{$mac};964 my $host = $computer_db->{$domainset}[$cpt]{$mac}; 954 965 $host->{'comment'} = $comment; 955 966 $host->{'modify_time'} = time; 956 967 957 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);968 ipamdb_save("$COMPUTER_YAML", $computer_db); 958 969 exit; 959 970 } … … 986 997 $mac = normalize_mac_address($mac); 987 998 988 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 999 my $computer_db = ipamdb_load($COMPUTER_YAML); 1000 1001 control_exist_domainset($computer_db, $domainset) or exit; 989 1002 control_syntax_ip($ip) or exit; 990 1003 control_syntax_mac_address($mac) or exit; 991 1004 992 1005 LOOP_ON_DOMAINSET: 993 for my $domainset_current (keys %{$ COMPUTER_DB}) {1006 for my $domainset_current (keys %{$computer_db}) { 994 1007 next if $domainset_current eq 'dset'; 995 1008 next if $domainset_current eq 'pool'; … … 998 1011 next if $domainset_current eq 'version'; 999 1012 1000 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};1013 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1001 1014 my $cpt_mac = 0; 1002 1015 for my $value (@domainsetdb) { 1003 1016 for my $id (keys %{$value}) { 1004 1017 if ($id eq $mac) { 1005 my $host = $ COMPUTER_DB->{$domainset_current}[$cpt_mac]{$mac};1018 my $host = $computer_db->{$domainset_current}[$cpt_mac]{$mac}; 1006 1019 next LOOP_ON_DOMAINSET if $host->{'ip'} ne $ip; 1007 1020 1008 1021 $host->{'modify_time'} = time; 1009 splice(@{$ COMPUTER_DB->{$domainset_current}}, $cpt_mac => 1);1010 push @{$ COMPUTER_DB->{$domainset}}, { $mac => $host };1011 1012 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1022 splice(@{$computer_db->{$domainset_current}}, $cpt_mac => 1); 1023 push @{$computer_db->{$domainset}}, { $mac => $host }; 1024 1025 ipamdb_save("$COMPUTER_YAML", $computer_db); 1013 1026 exit; 1014 1027 } … … 1049 1062 $mac = normalize_mac_address($mac); 1050 1063 1064 my $computer_db = ipamdb_load($COMPUTER_YAML); 1065 1051 1066 if ($tags !~ m/^ (?:\w+,)* \w+ $/xms) { 1052 1067 die "Error: Bad format for tags (comma separated list): $tags\n"; … … 1055 1070 for my $tag (split/,/, $tags) { 1056 1071 next if $tag eq 'universal'; 1057 die "Error: TAG doesn't exist in the database. Create it before with create_tag: $tag\n" if not exists $ COMPUTER_DB->{'tag'}{$tag};1058 } 1059 1060 control_exist_domainset($ COMPUTER_DB, $domainset) or exit;1061 1062 $mac = get_mac_from_ip($ domainset, $ip, $mac) if $ip ne '';1063 $mac = get_mac_from_hostname($ domainset, $hostname, $mac) if $hostname ne '';1072 die "Error: TAG doesn't exist in the database. Create it before with create_tag: $tag\n" if not exists $computer_db->{'tag'}{$tag}; 1073 } 1074 1075 control_exist_domainset($computer_db, $domainset) or exit; 1076 1077 $mac = get_mac_from_ip($computer_db, $domainset, $ip, $mac) if $ip ne ''; 1078 $mac = get_mac_from_hostname($computer_db, $domainset, $hostname, $mac) if $hostname ne ''; 1064 1079 control_syntax_mac_address($mac) or exit; 1065 1080 1066 1081 LOOP_ON_COMPUTER: 1067 for my $computer (@{$ COMPUTER_DB->{$domainset}}) {1082 for my $computer (@{$computer_db->{$domainset}}) { 1068 1083 my ($mac_address, $attribute) = %{$computer}; 1069 1084 … … 1074 1089 1075 1090 delete $attribute->{'tag'} if $tags eq 'universal'; 1076 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1091 ipamdb_save("$COMPUTER_YAML", $computer_db); 1077 1092 exit; 1078 1093 } … … 1092 1107 my ($hostname, $domainset, $ip) = @_; 1093 1108 1109 my $computer_db = ipamdb_load($COMPUTER_YAML); 1110 1094 1111 if ($ip ne '') { 1095 1112 control_syntax_ip($ip); 1096 if ( control_exist_ip($ COMPUTER_DB, $ip) == 1 ) {1113 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1097 1114 print "Error: Unkown IP address: $ip\n"; 1098 1115 exit; 1099 1116 } 1100 1117 1101 for my $domainset_current (keys %{$ COMPUTER_DB}) {1118 for my $domainset_current (keys %{$computer_db}) { 1102 1119 next if $domainset_current eq 'dset'; 1103 1120 next if $domainset_current eq 'pool'; … … 1106 1123 next if $domainset_current eq 'version'; 1107 1124 1108 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};1125 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1109 1126 my $cpt_mac = 0; 1110 1127 for my $value (@domainsetdb) { … … 1113 1130 if ($value->{$id}->{'ip'} eq $ip) { 1114 1131 my $timestamp = time; 1115 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1116 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no';1117 print "L'adresse IP: $ip a été désactivée. Valeur du champs enabled: [".$ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n";1118 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1132 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1133 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1134 print "L'adresse IP: $ip a été désactivée. Valeur du champs enabled: [".$computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1135 ipamdb_save("$COMPUTER_YAML", $computer_db); 1119 1136 exit; 1120 1137 } … … 1125 1142 } 1126 1143 else { 1127 control_exist_domainset($ COMPUTER_DB, $domainset);1128 if ( control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) == 1 ) {1144 control_exist_domainset($computer_db, $domainset); 1145 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1129 1146 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1130 1147 } 1131 1148 1132 1149 my $cpt_mac = 0; 1133 for my $value (@{$ COMPUTER_DB->{$domainset}}) {1150 for my $value (@{$computer_db->{$domainset}}) { 1134 1151 for my $id (keys %{$value}) { 1135 1152 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1136 1153 my $timestamp = time; 1137 $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1138 $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'no';1139 print "La machine $hostname (domaine: $domainset) a été désactivé du DHCP. Valeur du champs enabled: [".$ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n";1140 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1154 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1155 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1156 print "La machine $hostname (domaine: $domainset) a été désactivé du DHCP. Valeur du champs enabled: [".$computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1157 ipamdb_save("$COMPUTER_YAML", $computer_db); 1141 1158 exit; 1142 1159 } … … 1159 1176 my ($pool, $mac) = @_; 1160 1177 1178 my $computer_db = ipamdb_load($COMPUTER_YAML); 1179 1161 1180 my $cpt_mac; 1162 if ( control_exist_mac($ COMPUTER_DB, $mac) == 1 ) {1181 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1163 1182 print "Error: Unkown physical MAC address: $mac\n"; 1164 1183 exit; 1165 1184 } 1166 1185 1167 for my $domainset_current (keys %{$ COMPUTER_DB}) {1186 for my $domainset_current (keys %{$computer_db}) { 1168 1187 next if $domainset_current eq 'dset'; 1169 1188 next if $domainset_current eq 'pool'; … … 1172 1191 next if $domainset_current eq 'version'; 1173 1192 1174 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};1193 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1175 1194 1176 1195 $cpt_mac=0; … … 1179 1198 if ($id eq $mac) { 1180 1199 if ($value->{$id}->{'ip'} eq $pool) { 1181 #splice(@{$ COMPUTER_DB->($domainset_current)} , $cpt_mac => 1);1200 #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1); 1182 1201 my $timestamp = time; 1183 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1184 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no';1185 print $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."\n";1186 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1202 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1203 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1204 print $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."\n"; 1205 ipamdb_save("$COMPUTER_YAML", $computer_db); 1187 1206 print "Désactivation de la machine $mac du pool $pool [OK]\n"; 1188 1207 exit; … … 1207 1226 my ($hostname, $domainset, $ip) = @_; 1208 1227 1209 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 1228 my $computer_db = ipamdb_load($COMPUTER_YAML); 1229 1230 control_exist_domainset($computer_db, $domainset) or exit; 1210 1231 if ($ip ne '') { 1211 1232 control_syntax_ip($ip); 1212 if ( control_exist_ip($ COMPUTER_DB, $ip) == 1 ) {1233 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1213 1234 print "Error: Unkown IP address: $ip\n"; 1214 1235 exit; 1215 1236 } 1216 1237 1217 for my $domainset_current (keys %{$ COMPUTER_DB}) {1238 for my $domainset_current (keys %{$computer_db}) { 1218 1239 next if $domainset_current eq 'dset'; 1219 1240 next if $domainset_current eq 'pool'; … … 1222 1243 next if $domainset_current eq 'version'; 1223 1244 1224 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};1245 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1225 1246 my $cpt_mac=0; 1226 1247 for my $value (@domainsetdb) { … … 1228 1249 if ($value->{$id}->{'ip'} eq $ip) { 1229 1250 my $timestamp = time; 1230 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1231 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes';1232 print "L'adresse IP: $ip a été réactivée. Valeur du champs enabled: [".$ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n";1233 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1251 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1252 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes'; 1253 print "L'adresse IP: $ip a été réactivée. Valeur du champs enabled: [".$computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1254 ipamdb_save("$COMPUTER_YAML", $computer_db); 1234 1255 exit; 1235 1256 } … … 1240 1261 } 1241 1262 else { 1242 if ( control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) == 1 ) {1263 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1243 1264 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1244 1265 } 1245 1266 1246 1267 my $cpt_mac=0; 1247 for my $value (@{$ COMPUTER_DB->{$domainset}}) {1268 for my $value (@{$computer_db->{$domainset}}) { 1248 1269 for my $id (keys %{$value}) { 1249 1270 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1250 1271 my $timestamp = time; 1251 $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1252 $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'yes';1253 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";1254 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1272 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1273 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'yes'; 1274 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"; 1275 ipamdb_save("$COMPUTER_YAML", $computer_db); 1255 1276 exit; 1256 1277 } … … 1273 1294 my ($pool, $mac) = @_; 1274 1295 1296 my $computer_db = ipamdb_load($COMPUTER_YAML); 1297 1275 1298 my $cpt_mac; 1276 if ( control_exist_mac($ COMPUTER_DB, $mac) == 1 ) {1299 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1277 1300 print "Adresse MAC $mac non trouvée.\n"; 1278 1301 exit; 1279 1302 } 1280 1303 1281 for my $domainset_current (keys %{$ COMPUTER_DB}) {1304 for my $domainset_current (keys %{$computer_db}) { 1282 1305 next if $domainset_current eq 'dset'; 1283 1306 next if $domainset_current eq 'pool'; … … 1286 1309 next if $domainset_current eq 'version'; 1287 1310 1288 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};1311 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1289 1312 1290 1313 $cpt_mac=0; … … 1293 1316 if ($id eq $mac) { 1294 1317 if ($value->{$id}->{'ip'} eq $pool) { 1295 #splice(@{$ COMPUTER_DB->($domainset_current)} , $cpt_mac => 1);1318 #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1); 1296 1319 my $timestamp = time; 1297 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1298 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes';1299 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1320 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1321 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes'; 1322 ipamdb_save("$COMPUTER_YAML", $computer_db); 1300 1323 print "Réactivation de la machine $mac du pool $pool [OK]\n"; 1301 1324 exit; … … 1418 1441 my ($hostname, $domainset, $ip) = @_; 1419 1442 1420 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 1443 my $computer_db = ipamdb_load($COMPUTER_YAML); 1444 1445 control_exist_domainset($computer_db, $domainset) or exit; 1421 1446 if ($ip ne '') { 1422 if ( control_exist_ip($ COMPUTER_DB, $ip) == 1 ) {1447 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1423 1448 die "Error: Unkown IP address: $ip\n"; 1424 1449 } 1425 1450 my $cpt_mac=0; 1426 for my $value (@{$ COMPUTER_DB->{$domainset}}) {1451 for my $value (@{$computer_db->{$domainset}}) { 1427 1452 for my $id (keys %{$value}) { 1428 1453 if ($value->{$id}->{'ip'} eq $ip) { 1429 1454 my $timestamp = time; 1430 splice(@{$ COMPUTER_DB->{$domainset}}, $cpt_mac => 1);1455 splice(@{$computer_db->{$domainset}}, $cpt_mac => 1); 1431 1456 print "La machine $ip a été supprimer du domaine $domainset\n"; 1432 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1457 ipamdb_save("$COMPUTER_YAML", $computer_db); 1433 1458 exit; 1434 1459 } … … 1439 1464 } 1440 1465 else { 1441 if ( control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) == 1 ) {1466 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1442 1467 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1443 1468 } 1444 1469 my $cpt_mac=0; 1445 for my $value (@{$ COMPUTER_DB->{$domainset}}) {1470 for my $value (@{$computer_db->{$domainset}}) { 1446 1471 for my $id (keys %{$value}) { 1447 1472 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1448 1473 my $timestamp = time; 1449 splice(@{$ COMPUTER_DB->{$domainset}}, $cpt_mac => 1);1474 splice(@{$computer_db->{$domainset}}, $cpt_mac => 1); 1450 1475 print "La machine $hostname a été supprimer du domaine $domainset\n"; 1451 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1476 ipamdb_save("$COMPUTER_YAML", $computer_db); 1452 1477 exit; 1453 1478 } … … 1472 1497 my ($pool, $mac) = @_; 1473 1498 1499 my $computer_db = ipamdb_load($COMPUTER_YAML); 1500 1474 1501 my $cpt_mac; 1475 if ( control_exist_mac($ COMPUTER_DB, $mac) == 1 ) {1502 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1476 1503 print "Adresse MAC $mac non trouvée.\n"; 1477 1504 exit; 1478 1505 } 1479 1506 1480 for my $domainset_current (keys %{$ COMPUTER_DB}) {1507 for my $domainset_current (keys %{$computer_db}) { 1481 1508 next if $domainset_current eq 'dset'; 1482 1509 next if $domainset_current eq 'pool'; … … 1485 1512 next if $domainset_current eq 'version'; 1486 1513 1487 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};1514 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1488 1515 1489 1516 $cpt_mac=0; … … 1493 1520 if ($id eq $mac) { 1494 1521 if ($value->{$id}->{'ip'} eq $pool) { 1495 #splice(@{$ COMPUTER_DB->($domainset_current)} , $cpt_mac => 1);1496 splice(@{$ COMPUTER_DB->{$domainset_current}}, $cpt_mac => 1);1497 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1522 #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1); 1523 splice(@{$computer_db->{$domainset_current}}, $cpt_mac => 1); 1524 ipamdb_save("$COMPUTER_YAML", $computer_db); 1498 1525 print "Suppression de la machine $mac du pool $pool [OK]\n"; 1499 1526 exit; … … 1581 1608 $comment = normalize_comment($comment); 1582 1609 1583 $COMPUTER_DB->{'dset'} ||= {}; 1584 die "Error: Domain Set already exists: $domainset\n" if exists $COMPUTER_DB->{'dset'}{$domainset}; 1610 my $computer_db = ipamdb_load($COMPUTER_YAML); 1611 1612 $computer_db->{'dset'} ||= {}; 1613 die "Error: Domain Set already exists: $domainset\n" if exists $computer_db->{'dset'}{$domainset}; 1585 1614 1586 1615 control_syntax_comment($comment) or exit; 1587 1616 1588 1617 my $timestamp = time; 1589 $ COMPUTER_DB->{'dset'}{$domainset} = {1618 $computer_db->{'dset'}{$domainset} = { 1590 1619 'dns_extension' => $dns_extension, 1591 1620 'comment' => $comment, … … 1593 1622 'modify_time' => $timestamp, 1594 1623 }; 1595 $ COMPUTER_DB->{$domainset} ||= []; # Create empty Domain Set computer list by default1596 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1624 $computer_db->{$domainset} ||= []; # Create empty Domain Set computer list by default 1625 ipamdb_save("$COMPUTER_YAML", $computer_db); 1597 1626 } 1598 1627 … … 1627 1656 or $ipaddress_pool eq ''; 1628 1657 1629 if ($COMPUTER_DB->{'pool'}) { 1630 die "Error: Pool already exists: $pool\n" if exists $COMPUTER_DB->{'pool'}{$pool}; 1658 my $computer_db = ipamdb_load($COMPUTER_YAML); 1659 1660 if ($computer_db->{'pool'}) { 1661 die "Error: Pool already exists: $pool\n" if exists $computer_db->{'pool'}{$pool}; 1631 1662 } 1632 1663 1633 1664 #--- control if the domain's pool exist ---# 1634 control_exist_domainset($ COMPUTER_DB, $domainset) or exit;1665 control_exist_domainset($computer_db, $domainset) or exit; 1635 1666 1636 1667 my @ip_list = (); … … 1644 1675 my $ip_loc = "$ip1.$ip2.$ip3.$cpt"; 1645 1676 control_syntax_ip($ip_loc) or die "Error: Bad IP syntax: $ip_loc\n"; 1646 control_exist_ip($ COMPUTER_DB, $ip_loc) or die "Error: IP address already exists: $ip_loc\n";1677 control_exist_ip($computer_db, $ip_loc) or die "Error: IP address already exists: $ip_loc\n"; 1647 1678 push @ip_list, $ip_loc; 1648 1679 } … … 1650 1681 else { 1651 1682 control_syntax_ip($ip) or next; 1652 if ( control_exist_ip($ COMPUTER_DB, $ip) == 0 ) {1683 if ( control_exist_ip($computer_db, $ip) == 0 ) { 1653 1684 print "L'adresse IP $ip existe déjà\n"; 1654 1685 next; … … 1660 1691 1661 1692 my $timestamp = time; 1662 $ COMPUTER_DB->{'pool'}{$pool} = {1693 $computer_db->{'pool'}{$pool} = { 1663 1694 'ip' => [@ip_list], 1664 1695 'enabled' => 'yes', … … 1668 1699 'domain' => $domainset, 1669 1700 }; 1670 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1701 ipamdb_save("$COMPUTER_YAML", $computer_db); 1671 1702 } 1672 1703 … … 1682 1713 ); 1683 1714 1715 my $computer_db = ipamdb_load($COMPUTER_YAML); 1716 1684 1717 printf "%-17s %-17s %s\n", 'Pool', 'File', 'DNS-Domain' if not $no_header; 1685 1718 LOOP_ON_PXE: 1686 for my $pool ( keys %{$ COMPUTER_DB->{'pool'}} ) {1719 for my $pool ( keys %{$computer_db->{'pool'}} ) { 1687 1720 1688 1721 printf "%-17s %-17s %s\n", 1689 1722 $pool, 1690 $ COMPUTER_DB->{'pool'}{$pool}{'file'},1691 $ COMPUTER_DB->{'pool'}{$pool}{'domain'},1723 $computer_db->{'pool'}{$pool}{'file'}, 1724 $computer_db->{'pool'}{$pool}{'domain'}, 1692 1725 } 1693 1726 } … … 1716 1749 or $comment eq ''; 1717 1750 1751 my $computer_db = ipamdb_load($COMPUTER_YAML); 1752 1718 1753 $comment = normalize_comment($comment); 1719 1754 1720 $ COMPUTER_DB->{'pxe'} ||= {};1721 die "Error: PXE config already exists: $pxe_config\n" if exists $ COMPUTER_DB->{'pxe'}{$pxe_config};1755 $computer_db->{'pxe'} ||= {}; 1756 die "Error: PXE config already exists: $pxe_config\n" if exists $computer_db->{'pxe'}{$pxe_config}; 1722 1757 1723 1758 control_syntax_ip($ip_next_server) or die "Error: Bad IP syntax: $ip_next_server\n"; … … 1725 1760 1726 1761 my $timestamp = time; 1727 $ COMPUTER_DB->{'pxe'}{$pxe_config} = {1762 $computer_db->{'pxe'}{$pxe_config} = { 1728 1763 'ip_next_server' => $ip_next_server, 1729 1764 'filename' => $filename, … … 1732 1767 'modify_time' => $timestamp, 1733 1768 }; 1734 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1769 ipamdb_save("$COMPUTER_YAML", $computer_db); 1735 1770 } 1736 1771 … … 1750 1785 if $pxe_config eq ''; 1751 1786 1752 $COMPUTER_DB->{'pxe'} ||= {}; 1753 die "Error: PXE config does not exist: $pxe_config\n" if not exists $COMPUTER_DB->{'pxe'}{$pxe_config}; 1787 my $computer_db = ipamdb_load($COMPUTER_YAML); 1788 1789 $computer_db->{'pxe'} ||= {}; 1790 die "Error: PXE config does not exist: $pxe_config\n" if not exists $computer_db->{'pxe'}{$pxe_config}; 1754 1791 1755 1792 # Test if some computer use this config 1756 1793 LOOP_ON_DOMAIN: 1757 for my $domainset_current (keys %{$ COMPUTER_DB}) {1794 for my $domainset_current (keys %{$computer_db}) { 1758 1795 next if $domainset_current eq 'dset'; 1759 1796 next if $domainset_current eq 'pool'; … … 1763 1800 1764 1801 LOOP_ON_COMPUTER: 1765 for my $computer (@{$ COMPUTER_DB->{$domainset_current}}) {1802 for my $computer (@{$computer_db->{$domainset_current}}) { 1766 1803 my ($mac_address, $attribute) = %{$computer}; 1767 1804 … … 1773 1810 } 1774 1811 1775 delete $ COMPUTER_DB->{'pxe'}{$pxe_config};1776 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1812 delete $computer_db->{'pxe'}{$pxe_config}; 1813 ipamdb_save("$COMPUTER_YAML", $computer_db); 1777 1814 } 1778 1815 … … 1788 1825 ); 1789 1826 1827 my $computer_db = ipamdb_load($COMPUTER_YAML); 1828 1790 1829 printf "%-12s %-13s %-30s %s\n", 'PXE-Config', 'Next-Server', 'Filename', 'Comment' if not $no_header; 1791 1830 LOOP_ON_PXE: 1792 for my $pxe_config ( keys %{$ COMPUTER_DB->{'pxe'}} ) {1793 my $ip_next_server = $ COMPUTER_DB->{'pxe'}{$pxe_config}{'ip_next_server'};1794 my $filename = $ COMPUTER_DB->{'pxe'}{$pxe_config}{'filename'};1795 my $comment = $ COMPUTER_DB->{'pxe'}{$pxe_config}{'comment'};1831 for my $pxe_config ( keys %{$computer_db->{'pxe'}} ) { 1832 my $ip_next_server = $computer_db->{'pxe'}{$pxe_config}{'ip_next_server'}; 1833 my $filename = $computer_db->{'pxe'}{$pxe_config}{'filename'}; 1834 my $comment = $computer_db->{'pxe'}{$pxe_config}{'comment'}; 1796 1835 1797 1836 printf "%-12s %-13s %-30s %s\n", $pxe_config, $ip_next_server, $filename, $comment; … … 1825 1864 and $ip ne ''; 1826 1865 1827 die "Error: PXE config not exists: $pxe_config\n" if not exists $COMPUTER_DB->{'pxe'}{$pxe_config}; 1828 1829 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 1866 my $computer_db = ipamdb_load($COMPUTER_YAML); 1867 1868 die "Error: PXE config not exists: $pxe_config\n" if not exists $computer_db->{'pxe'}{$pxe_config}; 1869 1870 control_exist_domainset($computer_db, $domainset) or exit; 1830 1871 if ($ip ne '') { 1831 1872 control_syntax_ip($ip); 1832 if ( control_exist_ip($ COMPUTER_DB, $ip) == 1 ) {1873 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1833 1874 die "Error: Unkown IP address: $ip\n"; 1834 1875 } 1835 1876 1836 for my $domainset_current (keys %{$ COMPUTER_DB}) {1877 for my $domainset_current (keys %{$computer_db}) { 1837 1878 next if $domainset_current eq 'dset'; 1838 1879 next if $domainset_current eq 'pool'; … … 1842 1883 1843 1884 my $cpt_mac = 0; 1844 for my $computer (@{$ COMPUTER_DB->{$domainset_current}}) {1885 for my $computer (@{$computer_db->{$domainset_current}}) { 1845 1886 for my $id (keys %{$computer}) { 1846 1887 if ($computer->{$id}->{'ip'} eq $ip) { 1847 1888 my $timestamp = time; 1848 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1849 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'} = $pxe_config;1889 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1890 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'} = $pxe_config; 1850 1891 print "IP Address: $ip, PXE enabled in config: $pxe_config\n"; 1851 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1892 ipamdb_save("$COMPUTER_YAML", $computer_db); 1852 1893 exit; 1853 1894 } … … 1858 1899 } 1859 1900 else { 1860 if ( control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) == 1 ) {1901 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1861 1902 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1862 1903 } 1863 1904 1864 1905 my $cpt_mac = 0; 1865 for my $value (@{$ COMPUTER_DB->{$domainset}}) {1906 for my $value (@{$computer_db->{$domainset}}) { 1866 1907 for my $id (keys %{$value}) { 1867 1908 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1868 1909 my $timestamp = time; 1869 $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1870 $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'} = $pxe_config;1910 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1911 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'} = $pxe_config; 1871 1912 print "Host $hostname ($domainset), PXE enabled in config: $pxe_config\n"; 1872 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1913 ipamdb_save("$COMPUTER_YAML", $computer_db); 1873 1914 exit; 1874 1915 } … … 1907 1948 and $ip ne ''; 1908 1949 1909 control_exist_domainset($COMPUTER_DB, $domainset) or exit; 1950 my $computer_db = ipamdb_load($COMPUTER_YAML); 1951 1952 control_exist_domainset($computer_db, $domainset) or exit; 1910 1953 if ($ip ne '') { 1911 1954 control_syntax_ip($ip); 1912 if ( control_exist_ip($ COMPUTER_DB, $ip) == 1 ) {1955 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1913 1956 die "Error: Unkown IP address: $ip\n"; 1914 1957 } 1915 1958 1916 for my $domainset_current (keys %{$ COMPUTER_DB}) {1959 for my $domainset_current (keys %{$computer_db}) { 1917 1960 next if $domainset_current eq 'dset'; 1918 1961 next if $domainset_current eq 'pool'; … … 1922 1965 1923 1966 my $cpt_mac = 0; 1924 for my $computer (@{$ COMPUTER_DB->{$domainset_current}}) {1967 for my $computer (@{$computer_db->{$domainset_current}}) { 1925 1968 for my $id (keys %{$computer}) { 1926 1969 if ($computer->{$id}->{'ip'} eq $ip) { 1927 next if not exists $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};1928 1929 my $pxe_config = $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};1970 next if not exists $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}; 1971 1972 my $pxe_config = $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}; 1930 1973 my $timestamp = time; 1931 $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1932 delete $ COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};1974 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1975 delete $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}; 1933 1976 print "IP Address: $ip, PXE disable from config: $pxe_config\n"; 1934 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);1977 ipamdb_save("$COMPUTER_YAML", $computer_db); 1935 1978 exit; 1936 1979 } … … 1941 1984 } 1942 1985 else { 1943 if ( control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) == 1 ) {1986 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1944 1987 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1945 1988 } 1946 1989 1947 1990 my $cpt_mac = 0; 1948 for my $value (@{$ COMPUTER_DB->{$domainset}}) {1991 for my $value (@{$computer_db->{$domainset}}) { 1949 1992 for my $id (keys %{$value}) { 1950 1993 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1951 1994 next if not exists $value->{$id}->{'pxe_config'}; 1952 1995 1953 my $pxe_config = $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'};1996 my $pxe_config = $computer_db->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'}; 1954 1997 my $timestamp = time; 1955 $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;1956 delete $ COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'};1998 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1999 delete $computer_db->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'}; 1957 2000 print "Host $hostname ($domainset), PXE disable from config: $pxe_config\n"; 1958 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);2001 ipamdb_save("$COMPUTER_YAML", $computer_db); 1959 2002 exit; 1960 2003 } … … 1988 2031 or $comment eq ''; 1989 2032 2033 my $computer_db = ipamdb_load($COMPUTER_YAML); 2034 1990 2035 $comment = normalize_comment($comment); 1991 2036 1992 $ COMPUTER_DB->{'tag'} ||= {};1993 die "Error: TAG already exists: $tag\n" if exists $ COMPUTER_DB->{'tag'}{$tag};2037 $computer_db->{'tag'} ||= {}; 2038 die "Error: TAG already exists: $tag\n" if exists $computer_db->{'tag'}{$tag}; 1994 2039 1995 2040 die "Error: TAG 'universal' is intrinsic. It's not possible to create it.\n" if $tag eq 'universal'; … … 2002 2047 2003 2048 my $timestamp = time; 2004 $ COMPUTER_DB->{'tag'}{$tag} = {2049 $computer_db->{'tag'}{$tag} = { 2005 2050 'comment' => $comment, 2006 2051 'create_time' => $timestamp, 2007 2052 'modify_time' => $timestamp, 2008 2053 }; 2009 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);2054 ipamdb_save("$COMPUTER_YAML", $computer_db); 2010 2055 } 2011 2056 … … 2025 2070 if $tag eq ''; 2026 2071 2027 $COMPUTER_DB->{'tag'} ||= {}; 2028 die "Error: TAG does not exist: $tag\n" if not exists $COMPUTER_DB->{'tag'}{$tag}; 2072 my $computer_db = ipamdb_load($COMPUTER_YAML); 2073 2074 $computer_db->{'tag'} ||= {}; 2075 die "Error: TAG does not exist: $tag\n" if not exists $computer_db->{'tag'}{$tag}; 2029 2076 2030 2077 # Test if some computer use this config 2031 2078 LOOP_ON_DOMAIN: 2032 for my $domainset_current (keys %{$ COMPUTER_DB}) {2079 for my $domainset_current (keys %{$computer_db}) { 2033 2080 next if $domainset_current eq 'dset'; 2034 2081 next if $domainset_current eq 'pool'; … … 2038 2085 2039 2086 LOOP_ON_COMPUTER: 2040 for my $computer (@{$ COMPUTER_DB->{$domainset_current}}) {2087 for my $computer (@{$computer_db->{$domainset_current}}) { 2041 2088 my ($mac_address, $attribute) = %{$computer}; 2042 2089 … … 2048 2095 } 2049 2096 2050 delete $ COMPUTER_DB->{'tag'}{$tag};2051 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);2097 delete $computer_db->{'tag'}{$tag}; 2098 ipamdb_save("$COMPUTER_YAML", $computer_db); 2052 2099 } 2053 2100 … … 2063 2110 ); 2064 2111 2112 my $computer_db = ipamdb_load($COMPUTER_YAML); 2113 2065 2114 printf "%-12s %s\n", 'TAG', 'Comment' if not $no_header; 2066 2115 LOOP_ON_TAG: 2067 for my $tag ( keys %{$ COMPUTER_DB->{'tag'}} ) {2068 my $comment = $ COMPUTER_DB->{'tag'}{$tag}{'comment'};2116 for my $tag ( keys %{$computer_db->{'tag'}} ) { 2117 my $comment = $computer_db->{'tag'}{$tag}{'comment'}; 2069 2118 2070 2119 printf "%-12s %s\n", $tag, $comment; … … 2079 2128 my $flag_change; 2080 2129 2130 my $computer_db = ipamdb_load($COMPUTER_YAML); 2131 2081 2132 LOOP_ON_DOMAIN: 2082 for my $domainset_current (keys %{$ COMPUTER_DB}) {2133 for my $domainset_current (keys %{$computer_db}) { 2083 2134 next if $domainset_current eq 'dset'; 2084 2135 next if $domainset_current eq 'pool'; … … 2087 2138 next if $domainset_current eq 'version'; 2088 2139 2089 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};2140 my @domainsetdb = @{$computer_db->{$domainset_current}}; 2090 2141 2091 2142 LOOP_ON_COMPUTER: … … 2111 2162 print "# FLAG :$flag_change\n"; 2112 2163 2113 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB) if $flag_change;2164 ipamdb_save("$COMPUTER_YAML", $computer_db) if $flag_change; 2114 2165 } 2115 2166 … … 2118 2169 sub cmd_show_domainset { 2119 2170 2171 my $computer_db = ipamdb_load($COMPUTER_YAML); 2172 2120 2173 LOOP_ON_DOMAIN: 2121 for my $domainset_current (keys %{$ COMPUTER_DB}) {2174 for my $domainset_current (keys %{$computer_db}) { 2122 2175 next if $domainset_current eq 'dset'; 2123 2176 next if $domainset_current eq 'pool'; … … 2147 2200 $mac = normalize_mac_address($mac); 2148 2201 2202 my $computer_db = ipamdb_load($COMPUTER_YAML); 2203 2149 2204 control_syntax_mac_address($mac) or exit; 2150 2205 2151 2206 LOOP_ON_DOMAIN: 2152 for my $domainset_current (keys %{$ COMPUTER_DB}) {2207 for my $domainset_current (keys %{$computer_db}) { 2153 2208 next if $domainset_current eq 'dset'; 2154 2209 next if $domainset_current eq 'pool'; … … 2157 2212 next if $domainset_current eq 'version'; 2158 2213 2159 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};2214 my @domainsetdb = @{$computer_db->{$domainset_current}}; 2160 2215 2161 2216 LOOP_ON_COMPUTER: … … 2200 2255 my %ipdb = (); 2201 2256 2257 my $computer_db = ipamdb_load($COMPUTER_YAML); 2258 2202 2259 LOOP_ON_DOMAIN: 2203 for my $domainset_current (keys %{$ COMPUTER_DB}) {2260 for my $domainset_current (keys %{$computer_db}) { 2204 2261 next if $domainset_current eq 'dset'; 2205 2262 next if $domainset_current eq 'pool'; … … 2217 2274 'Date', 2218 2275 'Comment'; 2219 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};2276 my @domainsetdb = @{$computer_db->{$domainset_current}}; 2220 2277 2221 2278 LOOP_ON_COMPUTER: … … 2303 2360 backup_database(); 2304 2361 2362 my $computer_db = ipamdb_load($COMPUTER_YAML); 2363 2305 2364 my %file_pool; 2306 2365 2307 for my $domainset_current (keys %{$ COMPUTER_DB}) {2366 for my $domainset_current (keys %{$computer_db}) { 2308 2367 next if $domainset_current eq 'dset'; 2309 2368 next if $domainset_current eq 'pool'; … … 2313 2372 2314 2373 open FILE_VLAN, '>', "$FOLDER_GEN_DHCP/$domainset_current"; 2315 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};2374 my @domainsetdb = @{$computer_db->{$domainset_current}}; 2316 2375 for my $value (@domainsetdb) { 2317 2376 ALL_MAC_ADDRESS: … … 2338 2397 if (exists $value->{$mac_addres}{'pxe_config'}) { 2339 2398 my $pxe_config = $value->{$mac_addres}{'pxe_config'}; 2340 my $ip_next_server = $ COMPUTER_DB->{'pxe'}{$pxe_config}{'ip_next_server'};2341 my $filename = $ COMPUTER_DB->{'pxe'}{$pxe_config}{'filename'};2399 my $ip_next_server = $computer_db->{'pxe'}{$pxe_config}{'ip_next_server'}; 2400 my $filename = $computer_db->{'pxe'}{$pxe_config}{'filename'}; 2342 2401 $buffer .= " next-server $ip_next_server;\n"; 2343 2402 $buffer .= " filename \"$filename\";\n"; … … 2364 2423 elsif ($address_type eq 'pool-dhcp') { 2365 2424 #--- Génère les fichiers pool dhcp ---# 2366 for my $current_pool (keys %{$ COMPUTER_DB->{'pool'}}) {2425 for my $current_pool (keys %{$computer_db->{'pool'}}) { 2367 2426 next if $current_pool ne $ip; 2368 2427 … … 2379 2438 } 2380 2439 2381 my $current_pool_file_name = $ COMPUTER_DB->{'pool'}{$current_pool}{'file'};2440 my $current_pool_file_name = $computer_db->{'pool'}{$current_pool}{'file'}; 2382 2441 2383 2442 $file_pool{$current_pool_file_name} ||= []; … … 2409 2468 my $pool_domain; 2410 2469 2411 for my $domainset_current (keys %{$COMPUTER_DB}) { 2470 my $computer_db = ipamdb_load($COMPUTER_YAML); 2471 2472 for my $domainset_current (keys %{$computer_db}) { 2412 2473 next if $domainset_current eq 'dset'; 2413 2474 next if $domainset_current eq 'pool'; … … 2418 2479 if ($domainset_current eq 'pool') { 2419 2480 #next; 2420 for my $value (@{$ COMPUTER_DB->{$domainset_current}}) {2481 for my $value (@{$computer_db->{$domainset_current}}) { 2421 2482 for my $pool_name (keys %{$value}) { 2422 2483 $pool_domain = $value->{$pool_name}->{'domain'}."\n"; … … 2443 2504 open ( FILE_FORWARD_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.fwd"); 2444 2505 open ( FILE_REVERSE_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.rev"); 2445 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};2506 my @domainsetdb = @{$computer_db->{$domainset_current}}; 2446 2507 for my $value (@domainsetdb) { 2447 2508 for my $id (keys %{$value}) { … … 2457 2518 2458 2519 my $dns_domain = $domainset_current; 2459 if (exists $ COMPUTER_DB->{'dset'}{$domainset_current}) {2460 $dns_domain = $ COMPUTER_DB->{'dset'}{$domainset_current}{'dns_extension'};2520 if (exists $computer_db->{'dset'}{$domainset_current}) { 2521 $dns_domain = $computer_db->{'dset'}{$domainset_current}{'dns_extension'}; 2461 2522 } 2462 2523 my @T_split = split(/\./ , $ip); … … 2505 2566 2506 2567 sub cmd_check_dns { 2568 my $computer_db = ipamdb_load($COMPUTER_YAML); 2507 2569 2508 2570 LOOP_ON_DOMAIN: 2509 for my $domainset_current (keys %{$ COMPUTER_DB}) {2571 for my $domainset_current (keys %{$computer_db}) { 2510 2572 next if $domainset_current eq 'dset'; 2511 2573 next if $domainset_current eq 'pool'; … … 2514 2576 next if $domainset_current eq 'version'; 2515 2577 2516 my @domainsetdb = @{$ COMPUTER_DB->{$domainset_current}};2578 my @domainsetdb = @{$computer_db->{$domainset_current}}; 2517 2579 2518 2580 LOOP_ON_COMPUTER: … … 2552 2614 my ($hostname_fq, $ip) = ($1, $2); 2553 2615 control_syntax_ip($ip) or next LOOP_ON_IP; 2554 if (control_exist_ip($ COMPUTER_DB, $ip) == 1) {2616 if (control_exist_ip($computer_db, $ip) == 1) { 2555 2617 printf "Unkown IP: %015s / %s\n", $ip, $hostname_fq; 2556 2618 next LOOP_ON_IP; … … 2568 2630 sub load_data_dhcp { 2569 2631 my ($domainset, $input_file) = @_; 2632 2633 my $computer_db = ipamdb_load($COMPUTER_YAML); 2570 2634 2571 2635 my @T_mac; … … 2615 2679 $cpt = 0; 2616 2680 2617 if ( control_exist_hostname($ COMPUTER_DB, $domainset, $hostname) == 0 ) {2681 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 0 ) { 2618 2682 print "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 2619 2683 next; 2620 2684 } 2621 2685 control_syntax_mac_address($mac) or next; 2622 if ( control_exist_mac($ COMPUTER_DB, $mac) == 0) {2686 if ( control_exist_mac($computer_db, $mac) == 0) { 2623 2687 print "Error: Physical MAC address already exists: $mac\n"; 2624 2688 next; … … 2626 2690 2627 2691 control_syntax_ip($ip) or next; 2628 if ( control_exist_ip($ COMPUTER_DB, $ip) == 0 ) {2692 if ( control_exist_ip($computer_db, $ip) == 0 ) { 2629 2693 print "Error: IP address already exists: $ip\n"; 2630 2694 next; 2631 2695 } 2632 2696 my $timestamp = time; 2633 push @{$ COMPUTER_DB->{$domainset}}, { $mac => {2697 push @{$computer_db->{$domainset}}, { $mac => { 2634 2698 'hostname' => $hostname, 2635 2699 'ip' => $ip, … … 2657 2721 close(FILE); 2658 2722 2723 my $computer_db = ipamdb_load($COMPUTER_YAML); 2724 2659 2725 for my $ligne (@buffer) { 2660 2726 #-- … … 2673 2739 my $mac = $T_mac[1].":".$T_mac[2].":".$T_mac[3].":".$T_mac[4].":".$T_mac[5].":".$T_mac[6]; 2674 2740 control_syntax_mac_address($mac) or next; 2675 if (control_exist_mac($ COMPUTER_DB, $mac) == 0) {2741 if (control_exist_mac($computer_db, $mac) == 0) { 2676 2742 print "Error: Physical MAC address already exists: $mac\n"; 2677 2743 next; … … 2679 2745 2680 2746 #--- cette partie teste si le pool existe. 2681 if (not exists $ COMPUTER_DB->{'pool'}{$pool}) {2747 if (not exists $computer_db->{'pool'}{$pool}) { 2682 2748 print "Error: Create pool with create_pool command before load database: $pool\n"; 2683 2749 exit; 2684 2750 } 2685 2751 2686 if ($ COMPUTER_DB->{'pool'}{'domain'} eq $domainset) {2752 if ($computer_db->{'pool'}{'domain'} eq $domainset) { 2687 2753 my $timestamp = time; 2688 push @{$ COMPUTER_DB->{$domainset}}, { $mac => {2754 push @{$computer_db->{$domainset}}, { $mac => { 2689 2755 'hostname' => $pool, 2690 2756 'ip' => $pool, … … 2708 2774 my ($domainset, $input_file, $type_file) = @_; 2709 2775 2710 #$COMPUTER_DB 2776 my $computer_db = ipamdb_load($COMPUTER_YAML); 2777 2778 #$computer_db 2711 2779 if ($type_file eq 'dhcp') { 2712 2780 load_data_dhcp($domainset, $input_file); … … 2717 2785 } 2718 2786 2719 ipamdb_save("$COMPUTER_YAML", $ COMPUTER_DB);2787 ipamdb_save("$COMPUTER_YAML", $computer_db); 2720 2788 } 2721 2789
Note: See TracChangeset
for help on using the changeset viewer.