Changeset 304
- Timestamp:
- Jul 18, 2018, 6:40:31 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r303 r304 1110 1110 my $computer_db = ipamdb_load($COMPUTER_YAML); 1111 1111 1112 if ($ip ne '') { 1112 if ($ip ne '') { # disable by IP 1113 1113 control_syntax_ip($ip); 1114 1114 if ( control_exist_ip($computer_db, $ip) == 1 ) { 1115 print "Error: Unkown IP address: $ip\n"; 1116 exit; 1115 die "Error: Unkown IP address: $ip [FAILED]\n"; 1117 1116 } 1118 1117 … … 1125 1124 1126 1125 my @domainsetdb = @{$computer_db->{$domainset_current}}; 1127 my $cpt_mac = 0; 1128 for my $value (@domainsetdb) { 1129 for my $id (keys %{$value}) { 1130 1131 if ($value->{$id}->{'ip'} eq $ip) { 1132 my $timestamp = time; 1133 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1134 $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1135 print "L'adresse IP: $ip a été désactivée. Valeur du champs enabled: [".$computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1136 ipamdb_save("$COMPUTER_YAML", $computer_db); 1137 exit; 1138 } 1139 $cpt_mac++; 1126 LOOP_ON_COMPUTER: 1127 for my $computer (@domainsetdb) { 1128 my ($mac_address, $attribute) = %{$computer}; 1129 1130 next LOOP_ON_COMPUTER if $attribute->{'ip'} ne $ip; 1131 1132 if ($attribute->{'enabled'} eq 'no') { 1133 print "Info: IP $ip from domain set $domainset_current is already disable [OK]" . 1134 " ... Status: $attribute->{'enabled'}\n"; 1135 exit; 1140 1136 } 1141 } 1142 } 1143 } 1144 else { 1137 1138 my $timestamp = time; 1139 $attribute->{'modify_time'} = $timestamp; 1140 $attribute->{'enabled'} = 'no'; 1141 ipamdb_save("$COMPUTER_YAML", $computer_db); 1142 print "Info: Disabling IP $ip from domain set $domainset_current [OK]" . 1143 " ... Status: $attribute->{'enabled'}\n"; 1144 exit; 1145 } 1146 } 1147 } 1148 else { # disable by Hostname 1145 1149 control_exist_domainset($computer_db, $domainset); 1146 1150 if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) { 1147 die "Error: Unkown host: $hostname, in domain set: $domainset\n"; 1148 } 1149 1150 my $cpt_mac = 0; 1151 for my $value (@{$computer_db->{$domainset}}) { 1152 for my $id (keys %{$value}) { 1153 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) { 1154 my $timestamp = time; 1155 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp; 1156 $computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'no'; 1157 print "La machine $hostname (domaine: $domainset) a été désactivé du DHCP. Valeur du champs enabled: [".$computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n"; 1158 ipamdb_save("$COMPUTER_YAML", $computer_db); 1151 die "Error: Unkown host: $hostname, in domain set: $domainset [FAILED]\n"; 1152 } 1153 1154 LOOP_ON_COMPUTER: 1155 for my $computer (@{$computer_db->{$domainset}}) { 1156 my ($mac_address, $attribute) = %{$computer}; 1157 1158 next LOOP_ON_COMPUTER if $attribute->{'hostname'} ne $hostname; 1159 1160 if ($attribute->{'address_type'} ne 'pool-dhcp') { 1161 1162 if ($attribute->{'enabled'} eq 'no') { 1163 print "Info: Host $hostname from domain set $domainset is already disable [OK]" . 1164 " ... Status: $attribute->{'enabled'}\n"; 1159 1165 exit; 1160 1166 } 1161 1167 1162 if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} eq 'pool-dhcp')) { 1163 print "Désactivation de la machine $hostname sur le domaine $domainset [FAILED]\n"; 1164 print "La machine $hostname fait partie du pool $hostname.\n"; 1165 exit; 1166 } 1167 } 1168 $cpt_mac++; 1169 } 1170 } 1171 #print "Error: Hostname already exist in domain set attachement $domainset: $hostname\n"; 1168 my $timestamp = time; 1169 $attribute->{'modify_time'} = $timestamp; 1170 $attribute->{'enabled'} = 'no'; 1171 ipamdb_save("$COMPUTER_YAML", $computer_db); 1172 print "Info: Disabling host $hostname from domain set $domainset [OK]" . 1173 " ... Status: $attribute->{'enabled'}\n"; 1174 exit; 1175 } 1176 1177 if ($attribute->{'address_type'} eq 'pool-dhcp') { 1178 die "Error: Host $hostname from domain set $domainset inside a pool [FAILED]" . 1179 } 1180 } 1181 } 1172 1182 } 1173 1183 … … 1181 1191 my $cpt_mac; 1182 1192 if ( control_exist_mac($computer_db, $mac) == 1 ) { 1183 print "Error: Unkown physical MAC address: $mac\n"; 1184 exit; 1193 die "Error: Unkown physical MAC address: $mac [FAILED]\n"; 1185 1194 } 1186 1195 … … 1200 1209 1201 1210 if ($attribute->{'ip'} eq $pool) { 1211 if ($attribute->{'enabled'} eq 'no') { 1212 print "Info: Host $mac from pool $pool is already disable [OK]" . 1213 " ... Status: $attribute->{'enabled'}\n"; 1214 exit; 1215 } 1202 1216 my $timestamp = time; 1203 1217 $attribute->{'modify_time'} = $timestamp; 1204 1218 $attribute->{'enabled'} = 'no'; 1205 1219 ipamdb_save("$COMPUTER_YAML", $computer_db); 1206 print " Disabling machine $mac from pool $pool [OK]\n";1207 print "+-> Status:" . $attribute->{'enabled'} . "\n";1220 print "Info: Disabling host $mac from pool $pool [OK]" . 1221 " ... Status: $attribute->{'enabled'}\n"; 1208 1222 exit; 1209 1223 } 1210 1224 else { 1211 print "Computer disable $mac [FAILED]\n"; 1212 print "+-> The computer $mac does not belong to the $pool pool.\n"; 1213 exit; 1225 die "Error: Host disable $mac [FAILED]" . 1226 " ... The host $mac does not belong to the $pool pool.\n"; 1214 1227 } 1215 1228 }
Note: See TracChangeset
for help on using the changeset viewer.