- Timestamp:
- Aug 28, 2018, 2:55:44 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r331 r332 273 273 } 274 274 275 print {*STDERR} "Error: Bad MAC syntax: $mac\n";275 print {*STDERR} "Error: bad MAC syntax: $mac\n"; 276 276 return 0; 277 277 } … … 289 289 290 290 if ( scalar(@ip_split) != 4 ) { 291 print {*STDERR} "Error: Bad IP syntax: $ip\n";291 print {*STDERR} "Error: bad IP syntax: $ip\n"; 292 292 return 0; 293 293 } … … 302 302 303 303 if ($comment !~ m{^20\d\d-\d\d-\d\d\s}) { 304 print {*STDERR} " Syntax Error: No date like 2014-01-10 at the beginning: $comment\n";304 print {*STDERR} "Error: no date like 2014-01-10 at the beginning: $comment\n"; 305 305 return 0; 306 306 } 307 307 308 308 if ($comment !~ m{\(\w+\)$}) { 309 print {*STDERR} " Syntax Error: No (SERVICE) at the end: $comment\n";309 print {*STDERR} "Error: no (SERVICE) at the end: $comment\n"; 310 310 return 0; 311 311 } 312 312 313 313 if ($comment =~ m{\s\s}) { 314 print {*STDERR} " Syntax Error: Double space: $comment\n";314 print {*STDERR} "Error: double space: $comment\n"; 315 315 return 0; 316 316 } … … 419 419 420 420 control_exist_domainset($computer_db, $domainset) or exit; 421 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";421 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: host already exist in domain set $domainset: $hostname\n"; 422 422 423 423 my @domainsetdb = @{$computer_db->{$domainset}}; … … 447 447 $mac = normalize_mac_address($mac); 448 448 $comment = normalize_comment($comment); 449 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";449 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: host already exist in domain set $domainset: $hostname\n"; 450 450 control_syntax_mac_address($mac) or exit; 451 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n";451 control_exist_mac($computer_db, $mac) or die "Error: physical MAC address already exists: $mac\n"; 452 452 control_syntax_ip($ip) or exit; 453 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement$domainset: $ip\n";453 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set $domainset: $ip\n"; 454 454 control_syntax_comment($comment) or exit; 455 455 my $timestamp = time; … … 464 464 'alias' => '', 465 465 }}; 466 print "Info: Add the host: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset [OK]\n";466 print "Info: Add the host: $hostname, IP: $ip, MAC: $mac, domain set: $domainset [OK]\n"; 467 467 468 468 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 482 482 $comment = normalize_comment($comment); 483 483 control_exist_domainset($computer_db, $domainset) or exit; 484 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";484 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: host already exist in domain set $domainset: $hostname\n"; 485 485 control_syntax_mac_address($mac) or exit; 486 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n";486 control_exist_mac($computer_db, $mac) or die "Error: physical MAC address already exists: $mac\n"; 487 487 control_syntax_ip($ip) or exit; 488 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement$domainset: $ip.\n";488 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set $domainset: $ip.\n"; 489 489 control_syntax_comment($comment) or exit; 490 490 … … 499 499 'alias' => '', 500 500 }}; 501 print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n";501 print "Add the computer: $hostname, IP: $ip, MAC: $mac, domain set: $domainset\n"; 502 502 503 503 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 515 515 control_exist_domainset($computer_db, $domainset) or exit; 516 516 control_syntax_mac_address($mac) or exit; 517 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n";518 control_exist_pool($computer_db, $pool) or die "Error: The pool doesn't exists: $pool\n";517 control_exist_mac($computer_db, $mac) or die "Error: physical MAC address already exists: $mac\n"; 518 control_exist_pool($computer_db, $pool) or die "Error: the pool doesn't exists: $pool\n"; 519 519 control_syntax_comment($comment) or exit; 520 520 push @{$computer_db->{$domainset}}, { $mac => { … … 527 527 'comment' => $comment, 528 528 }}; 529 print "Info: Add the computer in pool MAC: $mac, Domain Set: $domainset, Pool: $pool [OK]\n";529 print "Info: Add the computer in pool MAC: $mac, domain set: $domainset, Pool: $pool [OK]\n"; 530 530 531 531 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 669 669 670 670 control_exist_domainset($computer_db, $domainset) or exit; 671 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";671 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: host already exist in domain set $domainset: $hostname\n"; 672 672 control_syntax_ip($ip) or exit; 673 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement$domainset: $ip.\n";673 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set $domainset: $ip.\n"; 674 674 control_syntax_comment($comment) or exit; 675 675 676 676 my $mac = join ':', 'FF', 'FF', map({sprintf("%02X", $_)} split(/\./, $ip)); 677 677 control_syntax_mac_address($mac) or exit; 678 control_exist_mac($computer_db, $mac) or die "Error: Virtual Physical MAC address already exists: $mac\n";678 control_exist_mac($computer_db, $mac) or die "Error: virtual physical MAC address already exists: $mac\n"; 679 679 680 680 push @{$computer_db->{$domainset}}, { $mac => { … … 687 687 'comment' => $comment, 688 688 }}; 689 print "Add the virtual computer: $hostname, IP: $ip, Domain Set: $domainset\n";689 print "Add the virtual computer: $hostname, IP: $ip, domain set: $domainset\n"; 690 690 691 691 ipamdb_save("$COMPUTER_YAML", $computer_db); … … 711 711 control_exist_domainset($computer_db, $domainset) or exit; 712 712 control_syntax_mac_address($mac) or exit; 713 control_exist_mac($computer_db, $mac) or die "Error: Physical MAC address already exists: $mac\n";713 control_exist_mac($computer_db, $mac) or die "Error: physical MAC address already exists: $mac\n"; 714 714 if ($ip ne '') { 715 715 control_syntax_ip($ip) or exit; 716 716 if ( control_exist_ip($computer_db, $ip) == 1 ) { 717 print "Error: Unkown IP address: $ip\n";717 print "Error: unkown IP address: $ip\n"; 718 718 exit; 719 719 } 720 720 my @domainsetdb = @{$computer_db->{$domainset}}; 721 my $computer_index = 0;722 721 LOOP_ON_COMPUTER: 723 722 for my $computer (@domainsetdb) { 724 723 my ($mac_address, $attribute) = %{$computer}; 725 726 $computer_index++, next LOOP_ON_COMPUTER if $attribute->{'ip'} ne $ip; 724 die "Error: physical MAC address $mac already exists in domain set $domainset\n" if $mac_address eq $mac; 725 726 next LOOP_ON_COMPUTER if $attribute->{'ip'} ne $ip; 727 727 728 728 $attribute->{'modify_time'} = time; 729 $computer_db->{$domainset}[$computer_index] = { $mac => $attribute }; 729 $computer->{$mac} = $attribut; # add new mac 730 delete $computer->{$mac_address}; # remove old mac 731 730 732 ipamdb_save("$COMPUTER_YAML", $computer_db); 731 print "Info: Update host $hostname MAC: $mac IP: $ip[OK]\n";733 print "Info: Update host $hostname, domain set $domainset, MAC $mac, IP $attribute->{'ip'} [OK]\n"; 732 734 exit; 733 735 } … … 735 737 elsif ($hostname ne '') { 736 738 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 737 die "Error: Unkown host: $hostname, in domain set: $domainset\n";739 die "Error: unkown Host: $hostname, in Domain Set: $domainset\n"; 738 740 } 739 741 my @domainsetdb = @{$computer_db->{$domainset}}; 740 my $computer_index = 0;741 742 LOOP_ON_COMPUTER: 742 743 for my $computer (@domainsetdb) { 743 744 my ($mac_address, $attribute) = %{$computer}; 744 745 $computer_index++, next LOOP_ON_COMPUTER if $attribute->{'hostname'} ne $hostname; 745 die "Error: physical MAC address $mac already exists in domain set $domainset\n" if $mac_address eq $mac; 746 747 next LOOP_ON_COMPUTER if $attribute->{'hostname'} ne $hostname; 746 748 747 749 $attribute->{'modify_time'} = time; 748 $computer_db->{$domainset}[$computer_index] = { $mac => $attribute }; 750 $computer->{$mac} = $attribut; # add new mac 751 delete $computer->{$mac_address}; # remove old mac 752 749 753 ipamdb_save("$COMPUTER_YAML", $computer_db); 750 print "Info: Update HOST: $hostname DOMAINSET: $domainset MAC: $mac IP:$attribute->{'ip'} [OK]\n";754 print "Info: Update host $hostname, domain set $domainset, MAC $mac, IP $attribute->{'ip'} [OK]\n"; 751 755 exit; 752 756 } … … 766 770 control_exist_domainset($computer_db, $domainset) or exit; 767 771 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 768 die "Error: Unkown host: $hostname, in domain set: $domainset\n";772 die "Error: unkown host: $hostname, in domain set: $domainset\n"; 769 773 } 770 774 control_syntax_ip($ip) or exit; 771 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement$domainset: $ip\n";775 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set $domainset: $ip\n"; 772 776 773 777 my @domainsetdb = @{$computer_db->{$domainset}}; … … 780 784 781 785 if ($attribute->{'address_type'} eq 'pool-dhcp') { 782 die "Error: Host $hostname from domain set $domainset belongs to a a pool [FAILED]" .786 die "Error: host $hostname from domain set $domainset belongs to a a pool [FAILED]" . 783 787 " ... use 'del-float' command before"; 784 788 } … … 804 808 control_syntax_ip($ip) or exit; 805 809 if ( control_exist_ip($computer_db, $ip) == 1 ) { 806 die "Error: Unkown IP address: $ip\n";807 } 808 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";810 die "Error: unkown IP address: $ip\n"; 811 } 812 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: host already exist in domain set $domainset: $hostname\n"; 809 813 810 814 my @domainsetdb = @{$computer_db->{$domainset}}; … … 823 827 } 824 828 825 die "Error: Failed to update hostname $hostname [FAILED]\n" .829 die "Error: failed to update hostname $hostname [FAILED]\n" . 826 830 " ... no IP $ip belongs to the domain set $domainset\n"; 827 831 } … … 996 1000 } 997 1001 } 998 die "Error: Update of domain set $domainset [FAILED]\n" .1002 die "Error: update of domain set $domainset [FAILED]\n" . 999 1003 " ... MAC $mac and IP $ip don't exists in the database\n"; 1000 1004 } … … 1031 1035 1032 1036 if ($tags !~ m/^ (?:\w+,)* \w+ $/xms) { 1033 die "Error: Bad format for tags (comma separated list): $tags\n";1037 die "Error: bad format for tags (comma separated list): $tags\n"; 1034 1038 } 1035 1039 … … 1078 1082 control_syntax_ip($ip); 1079 1083 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1080 die "Error: Unkown IP address: $ip [FAILED]\n";1084 die "Error: unkown IP address: $ip [FAILED]\n"; 1081 1085 } 1082 1086 … … 1114 1118 control_exist_domainset($computer_db, $domainset); 1115 1119 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1116 die "Error: Unkown host: $hostname, in domain set: $domainset [FAILED]\n";1120 die "Error: unkown host: $hostname, in domain set: $domainset [FAILED]\n"; 1117 1121 } 1118 1122 … … 1124 1128 1125 1129 if ($attribute->{'address_type'} eq 'pool-dhcp') { 1126 die "Error: Host $hostname from domain set $domainset belongs to a a pool [FAILED]" .1130 die "Error: host $hostname from domain set $domainset belongs to a a pool [FAILED]" . 1127 1131 " ... use 'disable-float' command instead"; 1128 1132 } … … 1154 1158 my $computer_index; 1155 1159 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1156 die "Error: Unkown physical MAC address: $mac [FAILED]\n";1160 die "Error: unkown physical MAC address: $mac [FAILED]\n"; 1157 1161 } 1158 1162 … … 1186 1190 } 1187 1191 else { 1188 die "Error: Host disable $mac [FAILED]" .1192 die "Error: host disable $mac [FAILED]" . 1189 1193 " ... The host $mac does not belong to the $pool pool.\n"; 1190 1194 } … … 1207 1211 control_syntax_ip($ip); 1208 1212 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1209 print "Error: Unkown IP address: $ip\n";1213 print "Error: unkown IP address: $ip\n"; 1210 1214 exit; 1211 1215 } … … 1244 1248 else { # enable by Hostname 1245 1249 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1246 die "Error: Unkown host: $hostname, in domain set: $domainset\n";1250 die "Error: unkown host: $hostname, in domain set: $domainset\n"; 1247 1251 } 1248 1252 … … 1253 1257 1254 1258 if ($attribute->{'address_type'} eq 'pool-dhcp') { 1255 die "Error: Host $hostname from domain set $domainset belongs to a a pool [FAILED]" .1259 die "Error: host $hostname from domain set $domainset belongs to a a pool [FAILED]" . 1256 1260 " ... use 'enable-float' command instead"; 1257 1261 } … … 1282 1286 1283 1287 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1284 die "Error: Unkown physical MAC address: $mac [FAILED]\n";1288 die "Error: unkown physical MAC address: $mac [FAILED]\n"; 1285 1289 } 1286 1290 … … 1300 1304 1301 1305 if ($attribute->{'ip'} ne $pool) { 1302 die "Error: Host enable $mac [FAILED]" .1306 die "Error: host enable $mac [FAILED]" . 1303 1307 " ... The host $mac does not belong to the $pool pool.\n"; 1304 1308 } … … 1433 1437 if ($ip ne '') { # delete by IP 1434 1438 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1435 die "Error: Unkown IP address: $ip\n";1439 die "Error: unkown IP address: $ip\n"; 1436 1440 } 1437 1441 … … 1452 1456 else { 1453 1457 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1454 die "Error: Unkown host: $hostname, in domain set: $domainset\n";1458 die "Error: unkown host: $hostname, in domain set: $domainset\n"; 1455 1459 } 1456 1460 … … 1464 1468 1465 1469 if ($attribute->{'address_type'} eq 'pool-dhcp') { 1466 die "Error: Host remove $hostname from the domain set $domainset [FAILED]" .1470 die "Error: host remove $hostname from the domain set $domainset [FAILED]" . 1467 1471 " ... The host $hostname belongs to a DHCP pool.\n"; 1468 1472 } … … 1508 1512 1509 1513 if ($attribute->{'ip'} ne $pool) { 1510 die "Error: Host remove $mac [FAILED]" .1514 die "Error: host remove $mac [FAILED]" . 1511 1515 " ... The host $mac does not belong to the $pool pool.\n"; 1512 1516 } … … 1594 1598 1595 1599 $computer_db->{'dset'} ||= {}; 1596 die "Error: Domain Set already exists: $domainset\n" if exists $computer_db->{'dset'}{$domainset};1600 die "Error: domain set already exists: $domainset\n" if exists $computer_db->{'dset'}{$domainset}; 1597 1601 1598 1602 control_syntax_comment($comment) or exit; … … 1605 1609 'modify_time' => $timestamp, 1606 1610 }; 1607 $computer_db->{$domainset} ||= []; # Create empty Domain Set computer list by default1611 $computer_db->{$domainset} ||= []; # Create empty domain set computer list by default 1608 1612 ipamdb_save("$COMPUTER_YAML", $computer_db); 1609 1613 } … … 1642 1646 1643 1647 if ($computer_db->{'pool'}) { 1644 die "Error: Pool already exists: $pool\n" if exists $computer_db->{'pool'}{$pool};1648 die "Error: pool already exists: $pool\n" if exists $computer_db->{'pool'}{$pool}; 1645 1649 } 1646 1650 … … 1657 1661 for (my $cpt = $first; $cpt <= $last; $cpt++) { 1658 1662 my $ip_loc = "$ip1.$ip2.$ip3.$cpt"; 1659 control_syntax_ip($ip_loc) or die "Error: Bad IP syntax: $ip_loc\n";1663 control_syntax_ip($ip_loc) or die "Error: bad IP syntax: $ip_loc\n"; 1660 1664 control_exist_ip($computer_db, $ip_loc) or die "Error: IP address already exists: $ip_loc\n"; 1661 1665 push @ip_list, $ip_loc; … … 1739 1743 die "Error: PXE config already exists: $pxe_config\n" if exists $computer_db->{'pxe'}{$pxe_config}; 1740 1744 1741 control_syntax_ip($ip_next_server) or die "Error: Bad IP syntax: $ip_next_server\n";1745 control_syntax_ip($ip_next_server) or die "Error: bad IP syntax: $ip_next_server\n"; 1742 1746 control_syntax_comment($comment) or exit; 1743 1747 … … 1855 1859 control_syntax_ip($ip); 1856 1860 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1857 die "Error: Unkown IP address: $ip\n";1861 die "Error: unkown IP address: $ip\n"; 1858 1862 } 1859 1863 … … 1872 1876 $computer_db->{$domainset_current}[$computer_index]->{$id}->{'modify_time'} = $timestamp; 1873 1877 $computer_db->{$domainset_current}[$computer_index]->{$id}->{'pxe_config'} = $pxe_config; 1874 print "IP Address: $ip, PXE enabled in config: $pxe_config\n";1878 print "IP address: $ip, PXE enabled in config: $pxe_config\n"; 1875 1879 ipamdb_save("$COMPUTER_YAML", $computer_db); 1876 1880 exit; … … 1883 1887 else { 1884 1888 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1885 die "Error: Unkown host: $hostname, in domain set: $domainset\n";1889 die "Error: unkown host: $hostname, in domain set: $domainset\n"; 1886 1890 } 1887 1891 … … 1934 1938 control_syntax_ip($ip); 1935 1939 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1936 die "Error: Unkown IP address: $ip\n";1940 die "Error: unkown IP address: $ip\n"; 1937 1941 } 1938 1942 … … 1955 1959 delete $attribute->{'pxe_config'}; 1956 1960 ipamdb_save("$COMPUTER_YAML", $computer_db); 1957 print "Info: IP Address: $ip, PXE disable from config: $pxe_config [OK]\n";1961 print "Info: IP address: $ip, PXE disable from config: $pxe_config [OK]\n"; 1958 1962 exit; 1959 1963 } … … 1962 1966 else { 1963 1967 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1964 die "Error: Unkown host: $hostname, in domain set: $domainset\n";1968 die "Error: unkown host: $hostname, in domain set: $domainset\n"; 1965 1969 } 1966 1970 … … 1972 1976 1973 1977 if ($attribute->{'address_type'} eq 'pool-dhcp') { 1974 die "Error . Host $hostname ($domainset) in a pool. No PXE possible [FAILED]\n";1978 die "Error: host $hostname ($domainset) in a pool. No PXE possible [FAILED]\n"; 1975 1979 } 1976 1980 … … 2016 2020 2017 2021 if ($tag !~ m/^ \w+ $/xms) { 2018 die "Error: Bad format for TAG (alphanumeric string): $tag\n";2022 die "Error: bad format for TAG (alphanumeric string): $tag\n"; 2019 2023 } 2020 2024 … … 2065 2069 if (exists $attribute->{'tag'}) { 2066 2070 my $hostname = $attribute->{'hostname'}; 2067 die "Error: Computer still use this TAG: $hostname.$domainset_current $mac_address\n" if $tag eq $attribute->{'tag'};2071 die "Error: computer still use this TAG: $hostname.$domainset_current $mac_address\n" if $tag eq $attribute->{'tag'}; 2068 2072 } 2069 2073 } … … 2710 2714 2711 2715 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 0 ) { 2712 print "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";2716 print "Error: host already exist in domain set $domainset: $hostname\n"; 2713 2717 next; 2714 2718 } 2715 2719 control_syntax_mac_address($mac) or next; 2716 2720 if ( control_exist_mac($computer_db, $mac) == 0) { 2717 print "Error: Physical MAC address already exists: $mac\n";2721 print "Error: physical MAC address already exists: $mac\n"; 2718 2722 next; 2719 2723 } … … 2770 2774 control_syntax_mac_address($mac) or next; 2771 2775 if (control_exist_mac($computer_db, $mac) == 0) { 2772 print "Error: Physical MAC address already exists: $mac\n";2776 print "Error: physical MAC address already exists: $mac\n"; 2773 2777 next; 2774 2778 } … … 2776 2780 #--- cette partie teste si le pool existe. 2777 2781 if (not exists $computer_db->{'pool'}{$pool}) { 2778 print "Error: Create pool with create_pool command before load database: $pool\n";2782 print "Error: create pool with create_pool command before load database: $pool\n"; 2779 2783 exit; 2780 2784 } … … 2793 2797 else { 2794 2798 print "Ajout de la machine $mac [FAILED]\n"; 2795 print "Error: The pool doesn't exists: $pool, for the domain: $domainset\n";2799 print "Error: the pool doesn't exists: $pool, for the domain: $domainset\n"; 2796 2800 } 2797 2801 } … … 2850 2854 my $date = sprintf '%04i-%02i-%02i-%02i-%02i-%02i', $year, $mon, $mday, $hour, $min, $sec; 2851 2855 2852 copy($COMPUTER_YAML, "$FOLDER_BACKUP/$COMPUTER_BASENAME-$date.conf") or die "Error: Database copy backup failed: $!\n";2856 copy($COMPUTER_YAML, "$FOLDER_BACKUP/$COMPUTER_BASENAME-$date.conf") or die "Error: database copy backup failed: $!\n"; 2853 2857 } 2854 2858
Note: See TracChangeset
for help on using the changeset viewer.