- Timestamp:
- Sep 14, 2018, 9:18:03 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ddt/ddt
r352 r353 318 318 #------------------------------------------------------------------------------------- 319 319 320 sub control_syntax_cidr { 321 my $cidr = shift; 322 323 return 1 if $cidr !~ m{^(\d+\.){3}\d+/\d+$}; 324 return 1 if not NetAddr::IP->new($cidr); 325 return 0; 326 } 327 328 #------------------------------------------------------------------------------------- 329 320 330 sub control_syntax_comment { 321 331 my $comment = shift; … … 1612 1622 1613 1623 exit_on_error_option($help) 1614 if $sector eq ''1624 if $sector eq '' 1615 1625 or $dns_extension eq '' 1616 1626 or $comment eq ''; … … 1633 1643 }; 1634 1644 $computer_db->{$sector} ||= []; # Create empty sector computer list by default 1645 ipamdb_save("$COMPUTER_YAML", $computer_db); 1646 } 1647 1648 #------------------------------------------------------------------------------- 1649 1650 sub cmd_sector_add_ip { 1651 local @ARGV = @_; 1652 1653 my $help = get_cmd_name(); 1654 my ($sector, $ip_range); 1655 1656 GetOptions( 1657 'sector|s|d=s' => \$sector, 1658 'ip-range|i=s' => \$ip_range, 1659 ); 1660 1661 exit_on_error_option($help) 1662 if $sector eq '' 1663 or $ip_range eq ''; 1664 1665 control_syntax_cidr($ip_range) or die "Error: bad IP range $ip_range syntax (CIDR)\n";; 1666 1667 my $computer_db = ipamdb_load($COMPUTER_YAML); 1668 exists $computer_db->{'dset'}{$sector} or die "Error: sector not exists: $sector\n"; 1669 1670 my $timestamp = time; 1671 $computer_db->{'dset'}{$sector}{'ip-range'} |= []; 1672 LOOP_ON_CIDR: 1673 for my $cidr_current (@{$computer_db->{'dset'}{$sector}{'ip-range'}}) { 1674 next LOOP_ON_CIDR if $cidr_current ne $ip_range; 1675 1676 die "Error: IP range $ip_range already in sector $sector\n"; 1677 } 1678 1679 my $timestamp = time; 1680 push @{$computer_db->{'dset'}{$sector}{'ip-range'}}, $ip_range; 1681 $computer_db->{'dset'}{$sector}{'modify_time'} = $timestamp; 1635 1682 ipamdb_save("$COMPUTER_YAML", $computer_db); 1636 1683 } … … 3129 3176 print "List of options for command: $command\n"; 3130 3177 print " -m : physical MAC address (mandatory). Example: -m 0F:58:AB:2A:22:11\n"; 3178 } 3179 3180 elsif ($command eq 'sector-add-ip') { 3181 print "List of options for command: $command\n"; 3182 print " -s : sector attachment (mandatory)\n"; 3183 print " -i : internet IP range address in CIDR notation (mandatory)\n"; 3131 3184 } 3132 3185 … … 3193 3246 ddt remove-tag [--tag|-t tag] 3194 3247 ddt search-mac [--mac|-m mac] 3248 ddt sector-add-ip [--sector|-s|-d sector] [--ip-range|-i ip_cidr] 3195 3249 ddt show-sector [--no-header|-H] 3196 3250 ddt show … … 3202 3256 COMMANDS 3203 3257 3204 * add-alias : add an alias for a computer (like CNAME for the DNS) 3205 * add-dhcp : add a computer with a fix DHCP IP or in a DHCP pool 3206 * add-float : add a computer with an IP in a DHCP pool 3207 * add-static : add a computer with a static IP 3208 * add-virtual : add a virtual computer with a static IP but a virtual MAC (useful to declare float computer in DNS) 3209 * change-comment : change the computer comment 3210 * change-sector : change the sector attachment for a computer 3211 * change-host : change the computer hostname 3212 * change-ip : change the computer IP address 3213 * change-mac : change the computer physical MAC address 3214 * change-tag : change the list of TAGs associated to a computer 3215 * check-dns : check the DNS table for base IPs 3216 * create-sector : create a new sector 3217 * create-pool : create a new pool for DHCP records 3218 * create-pxe : create a new PXE/BOOTP configuration 3219 * create-tag : create a new TAG 3220 * del-float : remove a computer from a DHCP pool 3221 * del-pc : remove a computer (DHCP or static IP) from the YAML database 3222 * disable-pc : disable a computer (DHCP and/or DNS) (but keep it in the database) 3223 * disable-float : disable a computer from a DHCP pool (but keep it in the database) 3224 * disable-pxe : remove PXE/BOOTP configuration on a computer 3225 * enable-float : enable a previous disable computer (DHCP and/or DNS) 3226 * enable-pc : enable a previous disable computer (DHCP and/or DNS) 3227 * enable-pxe : enable PXE/BOOTP configuration on a computer 3228 * gen-dhcp-file : generate DHCP files for the isc DHCP server 3229 * gen-dns-file : generate DNS files for the bind domain server 3230 * help : this help 3231 * load-database : load the YAML database (be careful) 3232 * remove-pxe : remove a PXE/BOOTP configuration 3233 * remove-tag : remove a TAG 3234 * search-mac : search physical MAC address computer 3235 * show-sector : list all sector group of computer 3236 * show : list all computers 3237 * show-pool : list all pool 3238 * show-pxe : list PXE/BOOTP configuration 3239 * show-tag : list all TAGs 3240 * version : return program version 3258 * add-alias : add an alias for a computer (like CNAME for the DNS) 3259 * add-dhcp : add a computer with a fix DHCP IP or in a DHCP pool 3260 * add-float : add a computer with an IP in a DHCP pool 3261 * add-static : add a computer with a static IP 3262 * add-virtual : add a virtual computer with a static IP but a virtual MAC (useful to declare float computer in DNS) 3263 * change-comment : change the computer comment 3264 * change-sector : change the sector attachment for a computer 3265 * change-host : change the computer hostname 3266 * change-ip : change the computer IP address 3267 * change-mac : change the computer physical MAC address 3268 * change-tag : change the list of TAGs associated to a computer 3269 * check-dns : check the DNS table for base IPs 3270 * create-sector : create a new sector 3271 * create-pool : create a new pool for DHCP records 3272 * create-pxe : create a new PXE/BOOTP configuration 3273 * create-tag : create a new TAG 3274 * del-float : remove a computer from a DHCP pool 3275 * del-pc : remove a computer (DHCP or static IP) from the YAML database 3276 * disable-pc : disable a computer (DHCP and/or DNS) (but keep it in the database) 3277 * disable-float : disable a computer from a DHCP pool (but keep it in the database) 3278 * disable-pxe : remove PXE/BOOTP configuration on a computer 3279 * enable-float : enable a previous disable computer (DHCP and/or DNS) 3280 * enable-pc : enable a previous disable computer (DHCP and/or DNS) 3281 * enable-pxe : enable PXE/BOOTP configuration on a computer 3282 * gen-dhcp-file : generate DHCP files for the isc DHCP server 3283 * gen-dns-file : generate DNS files for the bind domain server 3284 * help : this help 3285 * load-database : load the YAML database (be careful) 3286 * remove-pxe : remove a PXE/BOOTP configuration 3287 * remove-tag : remove a TAG 3288 * search-mac : search physical MAC address computer 3289 * ddt sector-add-ip : add IP range check on a sector 3290 * show-sector : list all sector group of computer 3291 * show : list all computers 3292 * show-pool : list all pool 3293 * show-pxe : list PXE/BOOTP configuration 3294 * show-tag : list all TAGs 3295 * version : return program version 3241 3296 END 3242 3297 return; … … 3287 3342 ddt remove-tag [--tag|-t tag] 3288 3343 ddt search-mac [--mac|-m mac] 3344 ddt sector-add-ip [--sector|-s|-d sector] [--ip-range|-i ip_cidr] 3289 3345 ddt show-sector [--no-header|-H] 3290 3346 ddt show … … 3434 3490 ddt search-mac [--mac|-m mac] 3435 3491 3492 =head2 sector-add-ip 3493 3494 ddt sector-add-ip [--sector|-s|-d sector] [--ip-range|-i ip_cidr] 3495 3436 3496 =head2 show-sector 3437 3497
Note: See TracChangeset
for help on using the changeset viewer.