Changeset 353 for trunk


Ignore:
Timestamp:
Sep 14, 2018, 9:18:03 AM (6 years ago)
Author:
g7moreau
Message:
  • Add IP range on sector
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r352 r353  
    318318#-------------------------------------------------------------------------------------
    319319
     320sub 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
    320330sub control_syntax_comment {
    321331   my $comment = shift;
     
    16121622
    16131623   exit_on_error_option($help)
    1614       if $sector     eq ''
     1624      if $sector        eq ''
    16151625      or $dns_extension eq ''
    16161626      or $comment       eq '';
     
    16331643      };
    16341644   $computer_db->{$sector} ||= []; # Create empty sector computer list by default
     1645   ipamdb_save("$COMPUTER_YAML", $computer_db);
     1646   }
     1647
     1648#-------------------------------------------------------------------------------
     1649
     1650sub 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;
    16351682   ipamdb_save("$COMPUTER_YAML", $computer_db);
    16361683   }
     
    31293176      print "List of options for command: $command\n";
    31303177      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";
    31313184      }
    31323185
     
    31933246 ddt remove-tag [--tag|-t tag]
    31943247 ddt search-mac [--mac|-m mac]
     3248 ddt sector-add-ip [--sector|-s|-d sector] [--ip-range|-i ip_cidr]
    31953249 ddt show-sector [--no-header|-H]
    31963250 ddt show
     
    32023256COMMANDS
    32033257
    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
    32413296END
    32423297   return;
     
    32873342 ddt remove-tag [--tag|-t tag]
    32883343 ddt search-mac [--mac|-m mac]
     3344 ddt sector-add-ip [--sector|-s|-d sector] [--ip-range|-i ip_cidr]
    32893345 ddt show-sector [--no-header|-H]
    32903346 ddt show
     
    34343490 ddt search-mac [--mac|-m mac]
    34353491
     3492=head2 sector-add-ip
     3493
     3494 ddt sector-add-ip [--sector|-s|-d sector] [--ip-range|-i ip_cidr]
     3495
    34363496=head2 show-sector
    34373497
Note: See TracChangeset for help on using the changeset viewer.