Changeset 364 for trunk/ddt


Ignore:
Timestamp:
Sep 17, 2018, 9:13:47 AM (6 years ago)
Author:
g7moreau
Message:
  • Add command change-type (not finish)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r363 r364  
    4747   'change-mac'         => \&cmd_change_mac,
    4848   'change-tag'         => \&cmd_change_tag,
     49   'change-type'        => \&cmd_change_type,
    4950   'check-dns'          => \&cmd_check_dns,
    5051   'create-sector'      => \&cmd_create_sector,
     
    10531054
    10541055   exit_on_error_option($help)
    1055       if $sector  eq ''
     1056      if $sector     eq ''
    10561057      or $tags       eq '';
    10571058   exit_on_error_option($help)
     
    10941095   print "Mise à jour du commentaire de la machine [FAILED]\n";
    10951096   print "L'adresse MAC: $mac n'existe pas dans le domaine: $sector.\n";
     1097   }
     1098
     1099#--------------------------------------------------------------------------------
     1100
     1101sub cmd_change_type {
     1102   local @ARGV = @_;
     1103
     1104   my $help = get_cmd_name();
     1105   my ($hostname, $sector, $type);
     1106
     1107   GetOptions(
     1108      'hostname|h=s'    => \$hostname,
     1109      'sector|s|d=s'    => \$sector,
     1110      'type|t=s'        => \$type,
     1111      );
     1112
     1113   ($hostname, $sector) = split /\./, $hostname, 2 if $hostname =~ m/\./;
     1114
     1115   exit_on_error_option($help)
     1116      if $sector     eq ''
     1117      and $hostname  eq ''
     1118      and $type      eq '';
     1119
     1120   my $computer_db = ipamdb_load($COMPUTER_YAML);
     1121
     1122   if ($type !~ m/^ (dhcp|float|static|virtual) $/xms) {
     1123      die "Error: bad type: $type\n";
     1124      }
     1125
     1126   $type =~ s/^float$/pool-dhcp/;
     1127   # No type virtual actually. See and write exactly type name and their property
     1128
     1129   control_exist_sector($computer_db, $sector) or exit;
     1130
     1131   $mac = get_mac_from_hostname($computer_db, $sector, $hostname, $mac);
     1132   control_syntax_mac_address($mac) or exit;
     1133
     1134   LOOP_ON_COMPUTER:
     1135   for my $computer (@{$computer_db->{$sector}}) {
     1136      my ($mac_address, $attribute) = %{$computer};
     1137
     1138      next LOOP_ON_COMPUTER if $mac_address ne $mac;
     1139
     1140      $attribute->{'address_type'}  = $type;
     1141      $attribute->{'modify_time'}   = time;
     1142
     1143      ipamdb_save("$COMPUTER_YAML", $computer_db);
     1144      exit;
     1145      }
     1146   print "Error: change host $hostname type [FAILED]\n";
    10961147   }
    10971148
     
    31733224      }
    31743225
     3226   elsif ($command eq 'change-type') {
     3227      print "List of options for command: $command\n";
     3228      print " -h : computer hostname (mandatory)\n";
     3229      print " -s : sector attachment (mandatory)\n";
     3230      print " -t : new type). Example: -t static\n";
     3231      }
     3232
    31753233   elsif ($command eq 'load-database') {
    31763234      print "List of options for command: $command\n";
     
    32783336 ddt change-mac [--hostname|-h hostname] [--sector|-s|-d sector] [--ip|-i ip] [--mac|-m mac]
    32793337 ddt change-tag [--hostname|-h hostname] [--sector|-s|-d sector] [--ip|-i ip] [--mac|-m mac] [--tag|-t tag]
     3338 ddt change-type [--hostname|-h hostname] [--sector|-s|-d sector] [--type|-t type]
    32803339 ddt check-dns [--direct] [--reverse]
    32813340 ddt create-sector [--sector|-s|-d sector] [--dns-extension|-e dns_extension] [--comment|-c comment]
     
    33193378 * change-mac        : change the computer physical MAC address
    33203379 * change-tag        : change the list of TAGs associated to a computer
     3380 * change-type       : change the type associated to a computer
    33213381 * check-dns         : check the DNS table for base IPs
    33223382 * create-sector     : create a new sector
     
    33743434 ddt change-mac [--hostname|-h hostname] [--sector|-s|-d sector] [--ip|-i ip] [--mac|-m mac]
    33753435 ddt change-tag [--hostname|-h hostname] [--sector|-s|-d sector] [--ip|-i ip] [--mac|-m mac] [--tag|-t tag]
     3436 ddt change-type [--hostname|-h hostname] [--sector|-s|-d sector] [--type|-t type]
    33763437 ddt check-dns [--direct] [--reverse]
    33773438 ddt create-sector [--sector|-s|-d sector] [--dns-extension|-e dns_extension] [--comment|-c comment]
     
    34623523 ddt change-tag [--hostname|-h hostname] [--sector|-s|-d sector] [--ip|-i ip] [--mac|-m mac] [--tag|-t tag]
    34633524
     3525=head2 change-type
     3526
     3527 ddt change-type [--hostname|-h hostname] [--sector|-s|-d sector] [--type|-t type]
     3528
    34643529=head2 check-dns
    34653530
Note: See TracChangeset for help on using the changeset viewer.