- Timestamp:
- Jul 18, 2018, 10:23:11 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r307 r308 719 719 } 720 720 my @domainsetdb = @{$computer_db->{$domainset}}; 721 my $cpt = 0; 722 for my $value (@domainsetdb) { 723 for my $id (keys %{$value}) { 724 if ($value->{$id}->{'ip'} eq $ip) { 725 my $host = $value->{$id}; 726 $host->{'modify_time'} = time; 727 $computer_db->{$domainset}->[$cpt] = { $mac => $host }; 728 ipamdb_save("$COMPUTER_YAML", $computer_db); 729 print "Update [OK]\n"; 730 print "Hostname: $host->{'hostname'}\n"; 731 print "MAC: $mac\n"; 732 print "IP: $host->{'ip'}\n"; 733 exit; 734 } 735 $cpt++; 736 } 737 } 738 #print "Mise à jour de l'adresse MAC [FAILED]\n"; 739 #print "l'adresse IP n'existe pas sur le domaine $domainset\n"; 721 my $computer_index = 0; 722 LOOP_ON_COMPUTER: 723 for my $computer (@domainsetdb) { 724 my ($mac_address, $attribute) = %{$computer}; 725 726 $computer_index++ and next LOOP_ON_COMPUTER if $attribute->{'ip'} ne $ip; 727 728 $attribute->{'modify_time'} = time; 729 $computer_db->{$domainset}[$computer_index] = { $mac => $attribute }; 730 ipamdb_save("$COMPUTER_YAML", $computer_db); 731 print "Info: Update host $host->{'hostname'} MAC: $mac IP: $host->{'ip'} [OK]\n"; 732 exit; 733 } 740 734 } 741 735 elsif ($hostname ne '') { … … 744 738 } 745 739 my @domainsetdb = @{$computer_db->{$domainset}}; 746 my $cpt = 0; 747 for my $value (@domainsetdb) { 748 for my $id (keys %{$value}) { 749 if ($value->{$id}->{'hostname'} eq $hostname) { 750 my $host = $value->{$id}; 751 $host->{'modify_time'} = time; 752 $computer_db->{$domainset}->[$cpt] = { $mac => $host }; 753 ipamdb_save("$COMPUTER_YAML", $computer_db); 754 print "Update [OK]\n"; 755 print "Hostname: $host->{'hostname'}\n"; 756 print "MAC: $mac\n"; 757 print "IP: $host->{'ip'}\n"; 758 exit; 759 } 760 } 761 $cpt++; 740 my $computer_index = 0; 741 LOOP_ON_COMPUTER: 742 for my $computer (@domainsetdb) { 743 my ($mac_address, $attribute) = %{$computer}; 744 745 $computer_index++ and next LOOP_ON_COMPUTER if $attribute->{'hostname'} ne $hostname; 746 747 $attribute->{'modify_time'} = time; 748 $computer_db->{$domainset}[$computer_index] = { $mac => $attribute }; 749 ipamdb_save("$COMPUTER_YAML", $computer_db); 750 print "Info: Update host $host->{'hostname'} MAC: $mac IP: $host->{'ip'} [OK]\n"; 751 exit; 762 752 } 763 753 } … … 780 770 control_syntax_ip($ip) or exit; 781 771 control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n"; 772 782 773 my @domainsetdb = @{$computer_db->{$domainset}}; 783 my $cpt = 0; 784 for my $value (@domainsetdb) { 785 for my $id (keys %{$value}) { 786 if (($value->{$id}->{'hostname'} eq $hostname) 787 and ( 788 ($value->{$id}->{'address_type'} eq 'dhcp') 789 or ($value->{$id}->{'address_type'} eq 'static') 790 ) 791 ) { 792 $computer_db->{$domainset}[$cpt]{$id}{'ip'} = $ip; 793 $computer_db->{$domainset}[$cpt]{$id}{'modify_time'} = time; 794 ipamdb_save("$COMPUTER_YAML", $computer_db); 795 print "Update [OK]\n"; 796 print "Hostname: $hostname\n"; 797 print "MAC: $id\n"; 798 print "IP: $ip\n"; 799 exit; 800 } 801 else { 802 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} eq 'pool-dhcp')) { 803 print "Modification de l'adresse IP [FAILED]\n"; 804 print "La machine $hostname sur le domain set $domainset fait partie du pool DHCP ".$value->{$id}->{'ip'}."\n"; 805 print "Veuillez la supprimer du pool et la recréer avec l'adresse IP que vous souhaitez.\n"; 806 exit; 807 } 808 } 809 } 810 $cpt++; 774 775 LOOP_ON_COMPUTER: 776 for my $computer (@domainsetdb) { 777 my ($mac_address, $attribute) = %{$computer}; 778 779 next LOOP_ON_COMPUTER if $attribute->{'hostname'} ne $hostname); 780 781 if ($attribute->{'address_type'} eq 'pool-dhcp') { 782 die "Error: Host $hostname from domain set $domainset belongs to a a pool [FAILED]" . 783 " ... use 'del-float' command before"; 784 } 785 786 $attribute->{'modify_time'} = time; 787 $attribute->{'ip'} = $ip; 788 ipamdb_save("$COMPUTER_YAML", $computer_db); 789 print "Info: Update host $host->{'hostname'} MAC: $mac IP: $host->{'ip'} [OK]\n"; 790 exit; 811 791 } 812 792 } … … 824 804 control_syntax_ip($ip) or exit; 825 805 if ( control_exist_ip($computer_db, $ip) == 1 ) { 826 print "Error: Unkown IP address: $ip\n"; 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"; 809 810 my @domainsetdb = @{$computer_db->{$domainset}}; 811 812 LOOP_ON_COMPUTER: 813 for my $computer (@domainsetdb) { 814 my ($mac_address, $attribute) = %{$computer}; 815 816 next LOOP_ON_COMPUTER if $attribute->{'ip'} ne $ip; 817 818 $attribute->{'modify_time'} = time; 819 $attribute->{'hostname'} = $hostname; 820 ipamdb_save("$COMPUTER_YAML", $computer_db); 821 print "Info: Update host $host->{'hostname'} MAC: $mac IP: $host->{'ip'} [OK]\n"; 827 822 exit; 828 823 } 829 control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 830 831 my @domainsetdb = @{$computer_db->{$domainset}}; 832 my $cpt = 0; 833 for my $value (@domainsetdb) { 834 for my $id (keys %{$value}) { 835 if ($value->{$id}->{'ip'} eq $ip) { 836 $computer_db->{$domainset}[$cpt]{$id}{'hostname'} = $hostname; 837 $computer_db->{$domainset}[$cpt]{$id}{'modify_time'} = time; 838 ipamdb_save("$COMPUTER_YAML", $computer_db); 839 print "Update [OK]\n"; 840 print "Hostname: $hostname\n"; 841 print "MAC: $id\n"; 842 print "IP: $ip\n"; 843 exit; 844 } 845 } 846 $cpt++; 847 } 848 print "Error: Failed to update computer hostname\n"; 849 print "L'adresse IP: $ip n'existe pas dans le domaine: $domainset.\n"; 824 825 die "Error: Failed to update hostname $hostname [FAILED]\n" . 826 " ... no IP $ip belongs to the domain set $domainset\n"; 850 827 } 851 828
Note: See TracChangeset
for help on using the changeset viewer.