Index: /trunk/ddt/ddt
===================================================================
--- /trunk/ddt/ddt	(revision 237)
+++ /trunk/ddt/ddt	(revision 238)
@@ -21,5 +21,5 @@
 use strict;
 #use warnings;
-use version; our $VERSION = version->declare('0.9.5');
+use version; our $VERSION = version->declare('0.9.6');
 
 use Getopt::Long qw(GetOptions);
@@ -99,8 +99,4 @@
 mkdir $FOLDER_GEN_DNS, 0755  if not -d $FOLDER_GEN_DNS;
 
-touch $COMPUTER_YAML if not -e $COMPUTER_YAML;
-
-my $COMPUTER_DB = ipamdb_load($COMPUTER_YAML);
-
 if (defined $cmd_db{$command}) {
    $cmd_db{$command}->(@ARGV);
@@ -130,7 +126,8 @@
 
 sub ipamdb_load {
-   my $database_file = shift;
-
-   my $computer_db = YAML::Syck::LoadFile($database_file);
+   my $database_yaml = shift;
+
+   touch $database_yaml if not -e $database_yaml;
+   my $computer_db = YAML::Syck::LoadFile($database_yaml);
 
    # add database version if not exist
@@ -146,10 +143,10 @@
 
 sub ipamdb_save {
-   my ($database_file, $computer_db) = @_;
-
-   my $dirdb = $database_file;
+   my ($database_yaml, $computer_db) = @_;
+
+   my $dirdb = $database_yaml;
       $dirdb =~ s{ / [^/]* $}{}xms;
    mkdir "$dirdb", 0755 unless -d "$dirdb";
-   YAML::Syck::DumpFile($database_file, $computer_db);
+   YAML::Syck::DumpFile($database_yaml, $computer_db);
 
    return $computer_db;
@@ -161,7 +158,7 @@
 
 sub control_exist_pool {
-   my ($COMPUTER_DB, $pool) = @_;
-
-   return exists $COMPUTER_DB->{'pool'}{$pool} ? 1 : 0;
+   my ($computer_db, $pool) = @_;
+
+   return exists $computer_db->{'pool'}{$pool} ? 1 : 0;
    }
 
@@ -172,7 +169,7 @@
 
 sub control_exist_domainset {
-   my ($COMPUTER_DB, $domainset) = @_;
-
-   return 1 if exists $COMPUTER_DB->{$domainset};
+   my ($computer_db, $domainset) = @_;
+
+   return 1 if exists $computer_db->{$domainset};
 
    print {*STDERR} "Error: domain set $domainset not found\n";
@@ -186,11 +183,11 @@
 
 sub control_exist_hostname {
-   my ($COMPUTER_DB, $domainset, $hostname) = @_;
-
-   if ($COMPUTER_DB->{$domainset} eq '') {
+   my ($computer_db, $domainset, $hostname) = @_;
+
+   if ($computer_db->{$domainset} eq '') {
       return 1;
       }
 
-   my @domainsetdb = @{$COMPUTER_DB->{$domainset}};
+   my @domainsetdb = @{$computer_db->{$domainset}};
 
    for my $value (@domainsetdb) {
@@ -211,7 +208,7 @@
 
 sub control_exist_mac {
-   my ($COMPUTER_DB, $mac) = @_;
-
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   my ($computer_db, $mac) = @_;
+
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -220,5 +217,5 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
       for my $value (@domainsetdb) {
          for my $id (keys %{$value}) {
@@ -239,7 +236,7 @@
 
 sub control_exist_ip {
-   my ($COMPUTER_DB, $ip) = @_;
-
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   my ($computer_db, $ip) = @_;
+
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -248,5 +245,5 @@
       next if $domainset_current eq 'version';
 
-      for my $value (@{$COMPUTER_DB->{$domainset_current}}) {
+      for my $value (@{$computer_db->{$domainset_current}}) {
          for my $id (keys %{$value}) {
             #print "Erreur: cette adresse IP $ip existe déjà\n";
@@ -256,7 +253,7 @@
       }
 
-   for my $current_pool (keys %{$COMPUTER_DB->{'pool'}}) {
+   for my $current_pool (keys %{$computer_db->{'pool'}}) {
          #--- Cette partie pour tester les ip des pools est bonne ne plus la changer ---#
-      my @T_pool_ip = @{ $COMPUTER_DB->{'pool'}{$current_pool}{'ip'}};
+      my @T_pool_ip = @{ $computer_db->{'pool'}{$current_pool}{'ip'}};
 
       for my $pool_ip (@T_pool_ip) {
@@ -365,5 +362,5 @@
 
 sub get_mac_from_hostname {
-   my ($domainset, $hostname, $mac) = @_;
+   my ($computer_db, $domainset, $hostname, $mac) = @_;
 
    return $mac if $mac ne '';
@@ -371,5 +368,5 @@
 
    LOOP_ON_COMPUTER:
-   for my $computer (@{$COMPUTER_DB->{$domainset}}) {
+   for my $computer (@{$computer_db->{$domainset}}) {
       my ($mac_address, $attribute) = %{$computer};
 
@@ -383,5 +380,5 @@
 
 sub get_mac_from_ip {
-   my ($domainset, $ip, $mac) = @_;
+   my ($computer_db, $domainset, $ip, $mac) = @_;
 
    return $mac if $mac ne '';
@@ -389,5 +386,5 @@
 
    LOOP_ON_COMPUTER:
-   for my $computer (@{$COMPUTER_DB->{$domainset}}) {
+   for my $computer (@{$computer_db->{$domainset}}) {
       my ($mac_address, $attribute) = %{$computer};
 
@@ -402,8 +399,8 @@
 
 sub get_computer_from_mac {
-   my ($domainset, $mac) = @_;
+   my ($computer_db, $domainset, $mac) = @_;
 
    LOOP_ON_COMPUTER:
-   for my $computer (@{$COMPUTER_DB->{$domainset}}) {
+   for my $computer (@{$computer_db->{$domainset}}) {
       my ($mac_address, $attribute) = %{$computer};
 
@@ -424,10 +421,10 @@
 
 sub add_alias {
-   my ($hostname, $domainset, $alias) = @_;
-
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
-   control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
-
-   my @domainsetdb = @{$COMPUTER_DB->{$domainset}};
+   my ($computer_db, $hostname, $domainset, $alias) = @_;
+
+   control_exist_domainset($computer_db, $domainset) or exit;
+   control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
+
+   my @domainsetdb = @{$computer_db->{$domainset}};
    my $cpt=0;
    for my $value (@domainsetdb) {
@@ -437,7 +434,7 @@
             print  $value->{$id}->{'alias'};
             $alias = $alias . ' ' . $value->{$id}->{'alias'};
-            $COMPUTER_DB->{$domainset}[$cpt]{$id}{'alias'}        = $alias;
-            $COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'}  = time;
-            ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+            $computer_db->{$domainset}[$cpt]{$id}{'alias'}        = $alias;
+            $computer_db->{$domainset}[$cpt]{$id}{'modify_time'}  = time;
+            ipamdb_save("$COMPUTER_YAML", $computer_db);
             print "Update attribute alias [OK]\n";
             exit;
@@ -453,16 +450,16 @@
 
 sub add_static {
-   my ($hostname, $domainset, $ip, $mac, $comment) = @_;
+   my ($computer_db, $hostname, $domainset, $ip, $mac, $comment) = @_;
 
    $mac = normalize_mac_address($mac);
    $comment = normalize_comment($comment);
-   control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
+   control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
    control_syntax_mac_address($mac)                   or exit;
-   control_exist_mac($COMPUTER_DB, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
+   control_exist_mac($computer_db, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
    control_syntax_ip($ip)                             or exit;
-   control_exist_ip($COMPUTER_DB, $ip)                or die "Error: IP address already exist in domain set attachement $domainset: $ip\n";
+   control_exist_ip($computer_db, $ip)                or die "Error: IP address already exist in domain set attachement $domainset: $ip\n";
    control_syntax_comment($comment)                   or exit;
    my $timestamp = time;
-   push @{$COMPUTER_DB->{$domainset}}, { $mac => {
+   push @{$computer_db->{$domainset}}, { $mac => {
       'hostname'     => $hostname,
       'ip'           => $ip,
@@ -476,5 +473,5 @@
    print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n";
 
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -486,18 +483,18 @@
 
 sub add_dhcp {
-   my ($hostname, $domainset, $ip, $mac, $comment) = @_;
+   my ($computer_db, $hostname, $domainset, $ip, $mac, $comment) = @_;
 
    my $timestamp = time;
    $mac = normalize_mac_address($mac);
    $comment = normalize_comment($comment);
-   control_exist_domainset($COMPUTER_DB, $domainset)  or exit;
-   control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
+   control_exist_domainset($computer_db, $domainset)  or exit;
+   control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
    control_syntax_mac_address($mac)                   or exit;
-   control_exist_mac($COMPUTER_DB, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
+   control_exist_mac($computer_db, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
    control_syntax_ip($ip)                             or exit;
-   control_exist_ip($COMPUTER_DB, $ip)                or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n";
+   control_exist_ip($computer_db, $ip)                or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n";
    control_syntax_comment($comment)                   or exit;
 
-   push @{$COMPUTER_DB->{$domainset}}, { $mac => {
+   push @{$computer_db->{$domainset}}, { $mac => {
       'hostname'     => $hostname,
       'ip'           => $ip,
@@ -511,5 +508,5 @@
    print "Add the computer: $hostname, IP: $ip, MAC: $mac, Domain Set: $domainset\n";
 
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -518,15 +515,15 @@
 
 sub add_float {
-   my ($pool, $domainset, $mac, $comment) = @_;
+   my ($computer_db, $pool, $domainset, $mac, $comment) = @_;
 
    my $timestamp = time;
    $mac = normalize_mac_address($mac);
    $comment = normalize_comment($comment);
-   control_exist_domainset($COMPUTER_DB, $domainset)  or exit;
+   control_exist_domainset($computer_db, $domainset)  or exit;
    control_syntax_mac_address($mac)                   or exit;
-   control_exist_mac($COMPUTER_DB, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
-   control_exist_pool($COMPUTER_DB, $pool)            or die "Error: The pool doesn't exists: $pool\n";
+   control_exist_mac($computer_db, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
+   control_exist_pool($computer_db, $pool)            or die "Error: The pool doesn't exists: $pool\n";
    control_syntax_comment($comment)                   or exit;
-   push @{$COMPUTER_DB->{$domainset}}, { $mac => {
+   push @{$computer_db->{$domainset}}, { $mac => {
       'hostname'     => $pool,
       'ip'           => $pool,
@@ -539,5 +536,5 @@
    print "Add the computer in pool MAC: $mac, Domain Set: $domainset, Pool: $pool\n";
 
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -564,5 +561,6 @@
       or $alias      eq '';
 
-   add_alias($hostname, $domainset, $alias);
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+   add_alias($computer_db, $hostname, $domainset, $alias);
    }
 
@@ -591,5 +589,6 @@
       or $comment    eq '';
 
-   add_dhcp($hostname, $domainset, $ip, $mac, $comment);
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+   add_dhcp($computer_db, $hostname, $domainset, $ip, $mac, $comment);
    }
 
@@ -616,5 +615,6 @@
       or $comment    eq '';
 
-   add_float($pool, $domainset, $mac, $comment);
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+   add_float($computer_db, $pool, $domainset, $mac, $comment);
    }
 
@@ -643,5 +643,6 @@
       or $comment    eq '';
 
-   add_static($hostname, $domainset, $ip, $mac, $comment);
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+   add_static($computer_db, $hostname, $domainset, $ip, $mac, $comment);
    }
 
@@ -669,18 +670,20 @@
       or $comment    eq '';
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    $comment = normalize_comment($comment);
    my $timestamp = time;
 
-   control_exist_domainset($COMPUTER_DB, $domainset)           or exit;
-   control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
+   control_exist_domainset($computer_db, $domainset)           or exit;
+   control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
    control_syntax_ip($ip)                                      or exit;
-   control_exist_ip($COMPUTER_DB, $ip)                         or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n";
+   control_exist_ip($computer_db, $ip)                         or die "Error: IP address already exist in domain set attachement $domainset: $ip.\n";
    control_syntax_comment($comment)                            or exit;
 
    my $mac = join ':', 'FF', 'FF', map({sprintf("%02X", $_)} split(/\./, $ip));
    control_syntax_mac_address($mac)             or exit;
-   control_exist_mac($COMPUTER_DB, $mac)         or die "Error: Virtual Physical MAC address already exists: $mac\n";
-
-   push @{$COMPUTER_DB->{$domainset}}, { $mac => {
+   control_exist_mac($computer_db, $mac)         or die "Error: Virtual Physical MAC address already exists: $mac\n";
+
+   push @{$computer_db->{$domainset}}, { $mac => {
       'hostname'     => $hostname,
       'ip'           => $ip,
@@ -693,5 +696,5 @@
    print "Add the virtual computer: $hostname, IP: $ip, Domain Set: $domainset\n";
 
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -710,15 +713,17 @@
    my ($hostname, $domainset, $ip, $mac) = @_;
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    $mac = normalize_mac_address($mac);
-   control_exist_domainset($COMPUTER_DB, $domainset)  or exit;
+   control_exist_domainset($computer_db, $domainset)  or exit;
    control_syntax_mac_address($mac)                   or exit;
-   control_exist_mac($COMPUTER_DB, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
+   control_exist_mac($computer_db, $mac)              or die "Error: Physical MAC address already exists: $mac\n";
    if ($ip ne '') {
       control_syntax_ip($ip) or exit;
-      if ( control_exist_ip($COMPUTER_DB, $ip) == 1 ) {
+      if ( control_exist_ip($computer_db, $ip) == 1 ) {
          print "Error: Unkown IP address: $ip\n";
          exit;
          }
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset}};
+      my @domainsetdb = @{$computer_db->{$domainset}};
       my $cpt = 0;
       for my $value (@domainsetdb) {
@@ -727,6 +732,6 @@
                my $host = $value->{$id};
                $host->{'modify_time'} = time;
-               $COMPUTER_DB->{$domainset}->[$cpt] = { $mac => $host };
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               $computer_db->{$domainset}->[$cpt] = { $mac => $host };
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                print "Update [OK]\n";
                print "Hostname: $host->{'hostname'}\n";
@@ -742,8 +747,8 @@
       }
    elsif ($hostname ne '') {
-      if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) {
+      if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) {
          die "Error: Unkown host: $hostname, in domain set: $domainset\n";
          }
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset}};
+      my @domainsetdb = @{$computer_db->{$domainset}};
       my $cpt = 0;
       for my $value (@domainsetdb) {
@@ -752,6 +757,6 @@
                my $host = $value->{$id};
                $host->{'modify_time'} = time;
-               $COMPUTER_DB->{$domainset}->[$cpt] = { $mac => $host };
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               $computer_db->{$domainset}->[$cpt] = { $mac => $host };
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                print "Update [OK]\n";
                print "Hostname: $host->{'hostname'}\n";
@@ -774,11 +779,13 @@
    my ($hostname, $domainset, $ip) = @_;
 
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
-   if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) {
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   control_exist_domainset($computer_db, $domainset) or exit;
+   if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) {
       die "Error: Unkown host: $hostname, in domain set: $domainset\n";
       }
    control_syntax_ip($ip) or exit;
-   control_exist_ip($COMPUTER_DB, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n";
-   my @domainsetdb = @{$COMPUTER_DB->{$domainset}};
+   control_exist_ip($computer_db, $ip) or die "Error: IP address already exist in domain set attachement $domainset: $ip\n";
+   my @domainsetdb = @{$computer_db->{$domainset}};
    my $cpt = 0;
    for my $value (@domainsetdb) {
@@ -790,7 +797,7 @@
                   )
                ) {
-            $COMPUTER_DB->{$domainset}[$cpt]{$id}{'ip'} = $ip;
-            $COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time;
-            ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+            $computer_db->{$domainset}[$cpt]{$id}{'ip'} = $ip;
+            $computer_db->{$domainset}[$cpt]{$id}{'modify_time'} = time;
+            ipamdb_save("$COMPUTER_YAML", $computer_db);
             print "Update [OK]\n";
             print "Hostname: $hostname\n";
@@ -819,20 +826,22 @@
    my ($hostname, $domainset, $ip) = @_;
 
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   control_exist_domainset($computer_db, $domainset) or exit;
    control_syntax_ip($ip)   or exit;
-   if ( control_exist_ip($COMPUTER_DB, $ip) == 1 ) {
+   if ( control_exist_ip($computer_db, $ip) == 1 ) {
       print "Error: Unkown IP address: $ip\n";
       exit;
       }
-   control_exist_hostname($COMPUTER_DB, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
-
-   my @domainsetdb = @{$COMPUTER_DB->{$domainset}};
+   control_exist_hostname($computer_db, $domainset, $hostname) or die "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
+
+   my @domainsetdb = @{$computer_db->{$domainset}};
    my $cpt = 0;
    for my $value (@domainsetdb) {
       for my $id (keys %{$value}) {
          if ($value->{$id}->{'ip'} eq $ip) {
-            $COMPUTER_DB->{$domainset}[$cpt]{$id}{'hostname'} = $hostname;
-            $COMPUTER_DB->{$domainset}[$cpt]{$id}{'modify_time'} = time;
-            ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+            $computer_db->{$domainset}[$cpt]{$id}{'hostname'} = $hostname;
+            $computer_db->{$domainset}[$cpt]{$id}{'modify_time'} = time;
+            ipamdb_save("$COMPUTER_YAML", $computer_db);
             print "Update [OK]\n";
             print "Hostname: $hostname\n";
@@ -942,18 +951,20 @@
    $comment = normalize_comment($comment);
 
-   control_exist_domainset($COMPUTER_DB, $domainset)   or exit;
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   control_exist_domainset($computer_db, $domainset)   or exit;
    control_syntax_mac_address($mac)                   or exit;
    control_syntax_comment($comment)                   or exit;
 
-   my @domainsetdb = @{$COMPUTER_DB->{$domainset}};
+   my @domainsetdb = @{$computer_db->{$domainset}};
    my $cpt = 0;
    for my $value (@domainsetdb) {
       for my $id (keys %{$value}) {
          if ($id eq $mac) {
-            my $host = $COMPUTER_DB->{$domainset}[$cpt]{$mac};
+            my $host = $computer_db->{$domainset}[$cpt]{$mac};
             $host->{'comment'}     = $comment;
             $host->{'modify_time'} = time;
 
-            ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+            ipamdb_save("$COMPUTER_YAML", $computer_db);
             exit;
             }
@@ -986,10 +997,12 @@
    $mac = normalize_mac_address($mac);
 
-   control_exist_domainset($COMPUTER_DB, $domainset)   or exit;
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   control_exist_domainset($computer_db, $domainset)   or exit;
    control_syntax_ip($ip)                             or exit;
    control_syntax_mac_address($mac)                   or exit;
 
    LOOP_ON_DOMAINSET:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -998,17 +1011,17 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
       my $cpt_mac = 0;
       for my $value (@domainsetdb) {
          for my $id (keys %{$value}) {
             if ($id eq $mac) {
-               my $host = $COMPUTER_DB->{$domainset_current}[$cpt_mac]{$mac};
+               my $host = $computer_db->{$domainset_current}[$cpt_mac]{$mac};
                next LOOP_ON_DOMAINSET if $host->{'ip'} ne $ip;
 
                $host->{'modify_time'} = time;
-               splice(@{$COMPUTER_DB->{$domainset_current}}, $cpt_mac => 1);
-               push @{$COMPUTER_DB->{$domainset}}, { $mac => $host };
-
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               splice(@{$computer_db->{$domainset_current}}, $cpt_mac => 1);
+               push @{$computer_db->{$domainset}}, { $mac => $host };
+
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                exit;
                }
@@ -1049,4 +1062,6 @@
    $mac = normalize_mac_address($mac);
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    if ($tags !~ m/^ (?:\w+,)* \w+ $/xms) {
       die "Error: Bad format for tags (comma separated list): $tags\n";
@@ -1055,15 +1070,15 @@
    for my $tag (split/,/, $tags) {
       next if $tag eq 'universal';
-      die "Error: TAG doesn't exist in the database. Create it before with create_tag: $tag\n" if not exists $COMPUTER_DB->{'tag'}{$tag};
-      }
-
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
-
-   $mac = get_mac_from_ip($domainset, $ip, $mac)             if $ip ne '';
-   $mac = get_mac_from_hostname($domainset, $hostname, $mac) if $hostname ne '';
+      die "Error: TAG doesn't exist in the database. Create it before with create_tag: $tag\n" if not exists $computer_db->{'tag'}{$tag};
+      }
+
+   control_exist_domainset($computer_db, $domainset) or exit;
+
+   $mac = get_mac_from_ip($computer_db, $domainset, $ip, $mac)             if $ip ne '';
+   $mac = get_mac_from_hostname($computer_db, $domainset, $hostname, $mac) if $hostname ne '';
    control_syntax_mac_address($mac) or exit;
 
    LOOP_ON_COMPUTER:
-   for my $computer (@{$COMPUTER_DB->{$domainset}}) {
+   for my $computer (@{$computer_db->{$domainset}}) {
       my ($mac_address, $attribute) = %{$computer};
 
@@ -1074,5 +1089,5 @@
 
       delete $attribute->{'tag'} if $tags eq 'universal';
-      ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+      ipamdb_save("$COMPUTER_YAML", $computer_db);
       exit;
       }
@@ -1092,12 +1107,14 @@
    my ($hostname, $domainset, $ip) = @_;
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    if ($ip ne '') {
       control_syntax_ip($ip);
-      if ( control_exist_ip($COMPUTER_DB, $ip) == 1 ) {
+      if ( control_exist_ip($computer_db, $ip) == 1 ) {
          print "Error: Unkown IP address: $ip\n";
          exit;
          }
 
-      for my $domainset_current (keys %{$COMPUTER_DB}) {
+      for my $domainset_current (keys %{$computer_db}) {
          next if $domainset_current eq 'dset';
          next if $domainset_current eq 'pool';
@@ -1106,5 +1123,5 @@
          next if $domainset_current eq 'version';
 
-         my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+         my @domainsetdb = @{$computer_db->{$domainset_current}};
          my $cpt_mac = 0;
          for my $value (@domainsetdb) {
@@ -1113,8 +1130,8 @@
                if ($value->{$id}->{'ip'} eq $ip) {
                   my $timestamp = time;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no';
-                  print "L'adresse IP: $ip a été désactivée. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n";
-                  ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no';
+                  print "L'adresse IP: $ip a été désactivée. Valeur du champs enabled: [".$computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n";
+                  ipamdb_save("$COMPUTER_YAML", $computer_db);
                   exit;
                   }
@@ -1125,18 +1142,18 @@
       }
    else {
-      control_exist_domainset($COMPUTER_DB, $domainset);
-      if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) {
+      control_exist_domainset($computer_db, $domainset);
+      if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) {
          die "Error: Unkown host: $hostname, in domain set: $domainset\n";
          }
 
       my $cpt_mac = 0;
-      for my $value (@{$COMPUTER_DB->{$domainset}}) {
+      for my $value (@{$computer_db->{$domainset}}) {
          for my $id (keys %{$value}) {
             if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) {
                my $timestamp = time;
-               $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-               $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'no';
-               print "La machine $hostname (domaine: $domainset) a été désactivé du DHCP. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n";
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+               $computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'no';
+               print "La machine $hostname (domaine: $domainset) a été désactivé du DHCP. Valeur du champs enabled: [".$computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n";
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                exit;
                }
@@ -1159,11 +1176,13 @@
    my ($pool, $mac) = @_;
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    my $cpt_mac;
-   if ( control_exist_mac($COMPUTER_DB, $mac) == 1 ) {
+   if ( control_exist_mac($computer_db, $mac) == 1 ) {
       print "Error: Unkown physical MAC address: $mac\n";
       exit;
       }
 
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -1172,5 +1191,5 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
 
       $cpt_mac=0;
@@ -1179,10 +1198,10 @@
             if ($id eq $mac) {
                if ($value->{$id}->{'ip'} eq $pool) {
-                  #splice(@{$COMPUTER_DB->($domainset_current)} , $cpt_mac => 1);
+                  #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1);
                   my $timestamp = time;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no';
-                  print  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."\n";
-                  ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'no';
+                  print  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."\n";
+                  ipamdb_save("$COMPUTER_YAML", $computer_db);
                   print "Désactivation de la machine $mac du pool $pool [OK]\n";
                   exit;
@@ -1207,13 +1226,15 @@
    my ($hostname, $domainset, $ip) = @_;
 
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   control_exist_domainset($computer_db, $domainset) or exit;
    if ($ip ne '') {
       control_syntax_ip($ip);
-      if ( control_exist_ip($COMPUTER_DB, $ip) == 1 ) {
+      if ( control_exist_ip($computer_db, $ip) == 1 ) {
          print "Error: Unkown IP address: $ip\n";
          exit;
          }
 
-      for my $domainset_current (keys %{$COMPUTER_DB}) {
+      for my $domainset_current (keys %{$computer_db}) {
          next if $domainset_current eq 'dset';
          next if $domainset_current eq 'pool';
@@ -1222,5 +1243,5 @@
          next if $domainset_current eq 'version';
 
-         my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+         my @domainsetdb = @{$computer_db->{$domainset_current}};
          my $cpt_mac=0;
          for my $value (@domainsetdb) {
@@ -1228,8 +1249,8 @@
                if ($value->{$id}->{'ip'} eq $ip) {
                   my $timestamp = time;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes';
-                  print "L'adresse IP: $ip a été réactivée. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n";
-                  ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes';
+                  print "L'adresse IP: $ip a été réactivée. Valeur du champs enabled: [".$computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'}."]\n";
+                  ipamdb_save("$COMPUTER_YAML", $computer_db);
                   exit;
                   }
@@ -1240,17 +1261,17 @@
       }
    else {
-      if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) {
+      if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) {
          die "Error: Unkown host: $hostname, in domain set: $domainset\n";
          }
 
       my $cpt_mac=0;
-      for my $value (@{$COMPUTER_DB->{$domainset}}) {
+      for my $value (@{$computer_db->{$domainset}}) {
          for my $id (keys %{$value}) {
             if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) {
                my $timestamp = time;
-               $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-               $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'yes';
-               print "La machine $hostname (domaine: $domainset) a été réactivée du DHCP. Valeur du champs enabled: [".$COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n";
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+               $computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'} = 'yes';
+               print "La machine $hostname (domaine: $domainset) a été réactivée du DHCP. Valeur du champs enabled: [".$computer_db->{$domainset}[$cpt_mac]->{$id}->{'enabled'}."]\n";
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                exit;
                }
@@ -1273,11 +1294,13 @@
    my ($pool, $mac) = @_;
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    my $cpt_mac;
-   if ( control_exist_mac($COMPUTER_DB, $mac) == 1 ) {
+   if ( control_exist_mac($computer_db, $mac) == 1 ) {
       print "Adresse MAC $mac non trouvée.\n";
       exit;
       }
 
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -1286,5 +1309,5 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
 
       $cpt_mac=0;
@@ -1293,9 +1316,9 @@
             if ($id eq $mac) {
                if ($value->{$id}->{'ip'} eq $pool) {
-                  #splice(@{$COMPUTER_DB->($domainset_current)} , $cpt_mac => 1);
+                  #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1);
                   my $timestamp = time;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes';
-                  ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'enabled'} = 'yes';
+                  ipamdb_save("$COMPUTER_YAML", $computer_db);
                   print "Réactivation de la machine $mac du pool $pool [OK]\n";
                   exit;
@@ -1418,17 +1441,19 @@
    my ($hostname, $domainset, $ip) = @_;
 
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   control_exist_domainset($computer_db, $domainset) or exit;
    if ($ip ne '') {
-      if ( control_exist_ip($COMPUTER_DB, $ip) == 1 ) {
+      if ( control_exist_ip($computer_db, $ip) == 1 ) {
          die "Error: Unkown IP address: $ip\n";
          }
       my $cpt_mac=0;
-      for my $value (@{$COMPUTER_DB->{$domainset}}) {
+      for my $value (@{$computer_db->{$domainset}}) {
          for my $id (keys %{$value}) {
             if ($value->{$id}->{'ip'} eq $ip) {
                my $timestamp = time;
-               splice(@{$COMPUTER_DB->{$domainset}}, $cpt_mac => 1);
+               splice(@{$computer_db->{$domainset}}, $cpt_mac => 1);
                print "La machine $ip a été supprimer du domaine $domainset\n";
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                exit;
                }
@@ -1439,15 +1464,15 @@
       }
    else {
-      if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) {
+      if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) {
          die "Error: Unkown host: $hostname, in domain set: $domainset\n";
          }
       my $cpt_mac=0;
-      for my $value (@{$COMPUTER_DB->{$domainset}}) {
+      for my $value (@{$computer_db->{$domainset}}) {
          for my $id (keys %{$value}) {
             if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) {
                my $timestamp = time;
-               splice(@{$COMPUTER_DB->{$domainset}}, $cpt_mac => 1);
+               splice(@{$computer_db->{$domainset}}, $cpt_mac => 1);
                print "La machine $hostname a été supprimer du domaine $domainset\n";
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                exit;
                }
@@ -1472,11 +1497,13 @@
    my ($pool, $mac) = @_;
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    my $cpt_mac;
-   if ( control_exist_mac($COMPUTER_DB, $mac) == 1 ) {
+   if ( control_exist_mac($computer_db, $mac) == 1 ) {
       print "Adresse MAC $mac non trouvée.\n";
       exit;
       }
 
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -1485,5 +1512,5 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
 
       $cpt_mac=0;
@@ -1493,7 +1520,7 @@
             if ($id eq $mac) {
                if ($value->{$id}->{'ip'} eq $pool) {
-                  #splice(@{$COMPUTER_DB->($domainset_current)} , $cpt_mac => 1);
-                  splice(@{$COMPUTER_DB->{$domainset_current}}, $cpt_mac => 1);
-                  ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+                  #splice(@{$computer_db->($domainset_current)} , $cpt_mac => 1);
+                  splice(@{$computer_db->{$domainset_current}}, $cpt_mac => 1);
+                  ipamdb_save("$COMPUTER_YAML", $computer_db);
                   print "Suppression de la machine $mac du pool $pool [OK]\n";
                   exit;
@@ -1581,11 +1608,13 @@
    $comment = normalize_comment($comment);
 
-   $COMPUTER_DB->{'dset'} ||= {};
-   die "Error: Domain Set already exists: $domainset\n" if exists $COMPUTER_DB->{'dset'}{$domainset};
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   $computer_db->{'dset'} ||= {};
+   die "Error: Domain Set already exists: $domainset\n" if exists $computer_db->{'dset'}{$domainset};
 
    control_syntax_comment($comment)    or exit;
 
    my $timestamp = time;
-   $COMPUTER_DB->{'dset'}{$domainset} = {
+   $computer_db->{'dset'}{$domainset} = {
       'dns_extension'   => $dns_extension,
       'comment'         => $comment,
@@ -1593,6 +1622,6 @@
       'modify_time'     => $timestamp,
       };
-   $COMPUTER_DB->{$domainset} ||= []; # Create empty Domain Set computer list by default
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   $computer_db->{$domainset} ||= []; # Create empty Domain Set computer list by default
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -1627,10 +1656,12 @@
       or $ipaddress_pool   eq '';
 
-   if ($COMPUTER_DB->{'pool'}) {
-      die "Error: Pool already exists: $pool\n" if exists $COMPUTER_DB->{'pool'}{$pool};
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   if ($computer_db->{'pool'}) {
+      die "Error: Pool already exists: $pool\n" if exists $computer_db->{'pool'}{$pool};
       }
 
    #--- control if the domain's pool exist ---#
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
+   control_exist_domainset($computer_db, $domainset) or exit;
 
    my @ip_list = ();
@@ -1644,5 +1675,5 @@
                my $ip_loc = "$ip1.$ip2.$ip3.$cpt";
                control_syntax_ip($ip_loc) or die "Error: Bad IP syntax: $ip_loc\n";
-               control_exist_ip($COMPUTER_DB, $ip_loc) or die "Error: IP address already exists: $ip_loc\n";
+               control_exist_ip($computer_db, $ip_loc) or die "Error: IP address already exists: $ip_loc\n";
                push @ip_list, $ip_loc;
                }
@@ -1650,5 +1681,5 @@
          else {
             control_syntax_ip($ip) or next;
-            if ( control_exist_ip($COMPUTER_DB, $ip) == 0 ) {
+            if ( control_exist_ip($computer_db, $ip) == 0 ) {
                print "L'adresse IP $ip existe déjà\n";
                next;
@@ -1660,5 +1691,5 @@
 
    my $timestamp = time;
-   $COMPUTER_DB->{'pool'}{$pool} = {
+   $computer_db->{'pool'}{$pool} = {
       'ip'          => [@ip_list],
       'enabled'     => 'yes',
@@ -1668,5 +1699,5 @@
       'domain'      => $domainset,
       };
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -1682,12 +1713,14 @@
       );
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    printf "%-17s %-17s %s\n", 'Pool', 'File', 'DNS-Domain' if not $no_header;
    LOOP_ON_PXE:
-   for my $pool ( keys %{$COMPUTER_DB->{'pool'}} ) {
+   for my $pool ( keys %{$computer_db->{'pool'}} ) {
 
       printf "%-17s %-17s %s\n",
          $pool,
-         $COMPUTER_DB->{'pool'}{$pool}{'file'},
-         $COMPUTER_DB->{'pool'}{$pool}{'domain'},
+         $computer_db->{'pool'}{$pool}{'file'},
+         $computer_db->{'pool'}{$pool}{'domain'},
       }
    }
@@ -1716,8 +1749,10 @@
       or $comment          eq '';
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    $comment = normalize_comment($comment);
 
-   $COMPUTER_DB->{'pxe'} ||= {};
-   die "Error: PXE config already exists: $pxe_config\n" if exists $COMPUTER_DB->{'pxe'}{$pxe_config};
+   $computer_db->{'pxe'} ||= {};
+   die "Error: PXE config already exists: $pxe_config\n" if exists $computer_db->{'pxe'}{$pxe_config};
 
    control_syntax_ip($ip_next_server)  or die "Error: Bad IP syntax: $ip_next_server\n";
@@ -1725,5 +1760,5 @@
 
    my $timestamp = time;
-   $COMPUTER_DB->{'pxe'}{$pxe_config} = {
+   $computer_db->{'pxe'}{$pxe_config} = {
       'ip_next_server'  => $ip_next_server,
       'filename'        => $filename,
@@ -1732,5 +1767,5 @@
       'modify_time'     => $timestamp,
       };
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -1750,10 +1785,12 @@
       if $pxe_config eq '';
 
-   $COMPUTER_DB->{'pxe'} ||= {};
-   die "Error: PXE config does not exist: $pxe_config\n" if not exists $COMPUTER_DB->{'pxe'}{$pxe_config};
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   $computer_db->{'pxe'} ||= {};
+   die "Error: PXE config does not exist: $pxe_config\n" if not exists $computer_db->{'pxe'}{$pxe_config};
 
    # Test if some computer use this config
    LOOP_ON_DOMAIN:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -1763,5 +1800,5 @@
 
       LOOP_ON_COMPUTER:
-      for my $computer (@{$COMPUTER_DB->{$domainset_current}}) {
+      for my $computer (@{$computer_db->{$domainset_current}}) {
          my ($mac_address, $attribute) = %{$computer};
 
@@ -1773,6 +1810,6 @@
       }
 
-   delete $COMPUTER_DB->{'pxe'}{$pxe_config};
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   delete $computer_db->{'pxe'}{$pxe_config};
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -1788,10 +1825,12 @@
       );
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    printf "%-12s %-13s %-30s %s\n", 'PXE-Config', 'Next-Server', 'Filename', 'Comment' if not $no_header;
    LOOP_ON_PXE:
-   for my $pxe_config ( keys %{$COMPUTER_DB->{'pxe'}} ) {
-      my $ip_next_server = $COMPUTER_DB->{'pxe'}{$pxe_config}{'ip_next_server'};
-      my $filename       = $COMPUTER_DB->{'pxe'}{$pxe_config}{'filename'};
-      my $comment        = $COMPUTER_DB->{'pxe'}{$pxe_config}{'comment'};
+   for my $pxe_config ( keys %{$computer_db->{'pxe'}} ) {
+      my $ip_next_server = $computer_db->{'pxe'}{$pxe_config}{'ip_next_server'};
+      my $filename       = $computer_db->{'pxe'}{$pxe_config}{'filename'};
+      my $comment        = $computer_db->{'pxe'}{$pxe_config}{'comment'};
 
       printf "%-12s %-13s %-30s %s\n", $pxe_config, $ip_next_server, $filename, $comment;
@@ -1825,14 +1864,16 @@
       and $ip        ne '';
 
-   die "Error: PXE config not exists: $pxe_config\n" if not exists $COMPUTER_DB->{'pxe'}{$pxe_config};
-
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   die "Error: PXE config not exists: $pxe_config\n" if not exists $computer_db->{'pxe'}{$pxe_config};
+
+   control_exist_domainset($computer_db, $domainset) or exit;
    if ($ip ne '') {
       control_syntax_ip($ip);
-      if ( control_exist_ip($COMPUTER_DB, $ip) == 1 ) {
+      if ( control_exist_ip($computer_db, $ip) == 1 ) {
          die "Error: Unkown IP address: $ip\n";
          }
 
-      for my $domainset_current (keys %{$COMPUTER_DB}) {
+      for my $domainset_current (keys %{$computer_db}) {
          next if $domainset_current eq 'dset';
          next if $domainset_current eq 'pool';
@@ -1842,12 +1883,12 @@
 
          my $cpt_mac = 0;
-         for my $computer (@{$COMPUTER_DB->{$domainset_current}}) {
+         for my $computer (@{$computer_db->{$domainset_current}}) {
             for my $id (keys %{$computer}) {
                if ($computer->{$id}->{'ip'} eq $ip) {
                   my $timestamp = time;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}  = $pxe_config;
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'}  = $pxe_config;
                   print "IP Address: $ip, PXE enabled in config: $pxe_config\n";
-                  ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+                  ipamdb_save("$COMPUTER_YAML", $computer_db);
                   exit;
                   }
@@ -1858,17 +1899,17 @@
       }
    else {
-      if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) {
+      if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) {
          die "Error: Unkown host: $hostname, in domain set: $domainset\n";
          }
 
       my $cpt_mac = 0;
-      for my $value (@{$COMPUTER_DB->{$domainset}}) {
+      for my $value (@{$computer_db->{$domainset}}) {
          for my $id (keys %{$value}) {
             if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) {
                my $timestamp = time;
-               $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-               $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'}  = $pxe_config;
+               $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+               $computer_db->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'}  = $pxe_config;
                print "Host $hostname ($domainset), PXE enabled in config: $pxe_config\n";
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                exit;
                }
@@ -1907,12 +1948,14 @@
       and $ip        ne '';
 
-   control_exist_domainset($COMPUTER_DB, $domainset) or exit;
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   control_exist_domainset($computer_db, $domainset) or exit;
    if ($ip ne '') {
       control_syntax_ip($ip);
-      if ( control_exist_ip($COMPUTER_DB, $ip) == 1 ) {
+      if ( control_exist_ip($computer_db, $ip) == 1 ) {
          die "Error: Unkown IP address: $ip\n";
          }
 
-      for my $domainset_current (keys %{$COMPUTER_DB}) {
+      for my $domainset_current (keys %{$computer_db}) {
          next if $domainset_current eq 'dset';
          next if $domainset_current eq 'pool';
@@ -1922,15 +1965,15 @@
 
          my $cpt_mac = 0;
-         for my $computer (@{$COMPUTER_DB->{$domainset_current}}) {
+         for my $computer (@{$computer_db->{$domainset_current}}) {
             for my $id (keys %{$computer}) {
                if ($computer->{$id}->{'ip'} eq $ip) {
-                  next if not exists $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};
-
-                  my $pxe_config = $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};
+                  next if not exists $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};
+
+                  my $pxe_config = $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};
                   my $timestamp  = time;
-                  $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-                  delete $COMPUTER_DB->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};
+                  $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+                  delete $computer_db->{$domainset_current}[$cpt_mac]->{$id}->{'pxe_config'};
                   print "IP Address: $ip, PXE disable from config: $pxe_config\n";
-                  ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+                  ipamdb_save("$COMPUTER_YAML", $computer_db);
                   exit;
                   }
@@ -1941,20 +1984,20 @@
       }
    else {
-      if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 1 ) {
+      if ( control_exist_hostname($computer_db, $domainset, $hostname) == 1 ) {
          die "Error: Unkown host: $hostname, in domain set: $domainset\n";
          }
 
       my $cpt_mac = 0;
-      for my $value (@{$COMPUTER_DB->{$domainset}}) {
+      for my $value (@{$computer_db->{$domainset}}) {
          for my $id (keys %{$value}) {
             if (($value->{$id}->{'hostname'} eq $hostname) and ($value->{$id}->{'address_type'} ne 'pool-dhcp')) {
                next if not exists $value->{$id}->{'pxe_config'};
 
-               my $pxe_config = $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'};
+               my $pxe_config = $computer_db->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'};
                my $timestamp  = time;
-               $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
-               delete $COMPUTER_DB->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'};
+               $computer_db->{$domainset}[$cpt_mac]->{$id}->{'modify_time'} = $timestamp;
+               delete $computer_db->{$domainset}[$cpt_mac]->{$id}->{'pxe_config'};
                print "Host $hostname ($domainset), PXE disable from config: $pxe_config\n";
-               ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+               ipamdb_save("$COMPUTER_YAML", $computer_db);
                exit;
                }
@@ -1988,8 +2031,10 @@
       or $comment eq '';
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    $comment = normalize_comment($comment);
 
-   $COMPUTER_DB->{'tag'} ||= {};
-   die "Error: TAG already exists: $tag\n" if exists $COMPUTER_DB->{'tag'}{$tag};
+   $computer_db->{'tag'} ||= {};
+   die "Error: TAG already exists: $tag\n" if exists $computer_db->{'tag'}{$tag};
 
    die "Error: TAG 'universal' is intrinsic. It's not possible to create it.\n" if $tag eq 'universal';
@@ -2002,10 +2047,10 @@
 
    my $timestamp = time;
-   $COMPUTER_DB->{'tag'}{$tag} = {
+   $computer_db->{'tag'}{$tag} = {
       'comment'         => $comment,
       'create_time'     => $timestamp,
       'modify_time'     => $timestamp,
       };
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -2025,10 +2070,12 @@
       if $tag eq '';
 
-   $COMPUTER_DB->{'tag'} ||= {};
-   die "Error: TAG does not exist: $tag\n" if not exists $COMPUTER_DB->{'tag'}{$tag};
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   $computer_db->{'tag'} ||= {};
+   die "Error: TAG does not exist: $tag\n" if not exists $computer_db->{'tag'}{$tag};
 
    # Test if some computer use this config
    LOOP_ON_DOMAIN:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2038,5 +2085,5 @@
 
       LOOP_ON_COMPUTER:
-      for my $computer (@{$COMPUTER_DB->{$domainset_current}}) {
+      for my $computer (@{$computer_db->{$domainset_current}}) {
          my ($mac_address, $attribute) = %{$computer};
 
@@ -2048,6 +2095,6 @@
       }
 
-   delete $COMPUTER_DB->{'tag'}{$tag};
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   delete $computer_db->{'tag'}{$tag};
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
@@ -2063,8 +2110,10 @@
       );
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    printf "%-12s %s\n", 'TAG', 'Comment' if not $no_header;
    LOOP_ON_TAG:
-   for my $tag ( keys %{$COMPUTER_DB->{'tag'}} ) {
-      my $comment = $COMPUTER_DB->{'tag'}{$tag}{'comment'};
+   for my $tag ( keys %{$computer_db->{'tag'}} ) {
+      my $comment = $computer_db->{'tag'}{$tag}{'comment'};
 
       printf "%-12s %s\n", $tag, $comment;
@@ -2079,6 +2128,8 @@
    my $flag_change;
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    LOOP_ON_DOMAIN:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2087,5 +2138,5 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
 
       LOOP_ON_COMPUTER:
@@ -2111,5 +2162,5 @@
    print "# FLAG :$flag_change\n";
 
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB) if $flag_change;
+   ipamdb_save("$COMPUTER_YAML", $computer_db) if $flag_change;
    }
 
@@ -2118,6 +2169,8 @@
 sub cmd_show_domainset {
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    LOOP_ON_DOMAIN:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2147,8 +2200,10 @@
    $mac = normalize_mac_address($mac);
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    control_syntax_mac_address($mac) or exit;
 
    LOOP_ON_DOMAIN:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2157,5 +2212,5 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
 
       LOOP_ON_COMPUTER:
@@ -2200,6 +2255,8 @@
    my %ipdb = ();
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    LOOP_ON_DOMAIN:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2217,5 +2274,5 @@
          'Date',
          'Comment';
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
 
       LOOP_ON_COMPUTER:
@@ -2303,7 +2360,9 @@
    backup_database();
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    my %file_pool;
 
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2313,5 +2372,5 @@
 
       open FILE_VLAN, '>', "$FOLDER_GEN_DHCP/$domainset_current";
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
       for my $value (@domainsetdb) {
          ALL_MAC_ADDRESS:
@@ -2338,6 +2397,6 @@
                   if (exists $value->{$mac_addres}{'pxe_config'}) {
                      my $pxe_config     = $value->{$mac_addres}{'pxe_config'};
-                     my $ip_next_server = $COMPUTER_DB->{'pxe'}{$pxe_config}{'ip_next_server'};
-                     my $filename       = $COMPUTER_DB->{'pxe'}{$pxe_config}{'filename'};
+                     my $ip_next_server = $computer_db->{'pxe'}{$pxe_config}{'ip_next_server'};
+                     my $filename       = $computer_db->{'pxe'}{$pxe_config}{'filename'};
                      $buffer .= "   next-server $ip_next_server;\n";
                      $buffer .= "   filename \"$filename\";\n";
@@ -2364,5 +2423,5 @@
             elsif ($address_type eq 'pool-dhcp') {
                #--- Génère les fichiers pool dhcp ---#
-               for my $current_pool (keys %{$COMPUTER_DB->{'pool'}}) {
+               for my $current_pool (keys %{$computer_db->{'pool'}}) {
                   next if $current_pool ne $ip;
 
@@ -2379,5 +2438,5 @@
                      }
 
-                  my $current_pool_file_name = $COMPUTER_DB->{'pool'}{$current_pool}{'file'};
+                  my $current_pool_file_name = $computer_db->{'pool'}{$current_pool}{'file'};
 
                   $file_pool{$current_pool_file_name} ||= [];
@@ -2409,5 +2468,7 @@
    my $pool_domain;
 
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2418,5 +2479,5 @@
       if ($domainset_current eq 'pool') {
          #next;
-         for my $value (@{$COMPUTER_DB->{$domainset_current}}) {
+         for my $value (@{$computer_db->{$domainset_current}}) {
             for my $pool_name (keys %{$value}) {
                $pool_domain = $value->{$pool_name}->{'domain'}."\n";
@@ -2443,5 +2504,5 @@
          open ( FILE_FORWARD_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.fwd");
          open ( FILE_REVERSE_DNS, ">> $FOLDER_GEN_DNS/db.$domainset_current.rev");
-         my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+         my @domainsetdb = @{$computer_db->{$domainset_current}};
          for my $value (@domainsetdb) {
             for my $id (keys %{$value}) {
@@ -2457,6 +2518,6 @@
 
                my $dns_domain = $domainset_current;
-               if (exists $COMPUTER_DB->{'dset'}{$domainset_current}) {
-                  $dns_domain = $COMPUTER_DB->{'dset'}{$domainset_current}{'dns_extension'};
+               if (exists $computer_db->{'dset'}{$domainset_current}) {
+                  $dns_domain = $computer_db->{'dset'}{$domainset_current}{'dns_extension'};
                   }
                my @T_split = split(/\./ , $ip);
@@ -2505,7 +2566,8 @@
 
 sub cmd_check_dns {
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
 
    LOOP_ON_DOMAIN:
-   for my $domainset_current (keys %{$COMPUTER_DB}) {
+   for my $domainset_current (keys %{$computer_db}) {
       next if $domainset_current eq 'dset';
       next if $domainset_current eq 'pool';
@@ -2514,5 +2576,5 @@
       next if $domainset_current eq 'version';
 
-      my @domainsetdb = @{$COMPUTER_DB->{$domainset_current}};
+      my @domainsetdb = @{$computer_db->{$domainset_current}};
 
       LOOP_ON_COMPUTER:
@@ -2552,5 +2614,5 @@
          my ($hostname_fq, $ip) = ($1, $2);
          control_syntax_ip($ip) or next LOOP_ON_IP;
-         if (control_exist_ip($COMPUTER_DB, $ip) == 1) {
+         if (control_exist_ip($computer_db, $ip) == 1) {
             printf "Unkown IP: %015s / %s\n", $ip, $hostname_fq;
             next LOOP_ON_IP;
@@ -2568,4 +2630,6 @@
 sub load_data_dhcp {
    my ($domainset, $input_file) = @_;
+
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
 
    my @T_mac;
@@ -2615,10 +2679,10 @@
          $cpt = 0;
 
-         if ( control_exist_hostname($COMPUTER_DB, $domainset, $hostname) == 0 ) {
+         if ( control_exist_hostname($computer_db, $domainset, $hostname) == 0 ) {
             print "Error: Hostname already exist in domain set attachement $domainset: $hostname\n";
             next;
             }
          control_syntax_mac_address($mac) or next;
-         if ( control_exist_mac($COMPUTER_DB, $mac) == 0) {
+         if ( control_exist_mac($computer_db, $mac) == 0) {
             print "Error: Physical MAC address already exists: $mac\n";
             next;
@@ -2626,10 +2690,10 @@
 
          control_syntax_ip($ip) or next;
-         if ( control_exist_ip($COMPUTER_DB, $ip) == 0 ) {
+         if ( control_exist_ip($computer_db, $ip) == 0 ) {
             print "Error: IP address already exists: $ip\n";
             next;
             }
          my $timestamp = time;
-         push @{$COMPUTER_DB->{$domainset}}, { $mac => {
+         push @{$computer_db->{$domainset}}, { $mac => {
             'hostname'     => $hostname,
             'ip'           => $ip,
@@ -2657,4 +2721,6 @@
    close(FILE);
 
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
    for my $ligne (@buffer) {
       #--
@@ -2673,5 +2739,5 @@
          my $mac = $T_mac[1].":".$T_mac[2].":".$T_mac[3].":".$T_mac[4].":".$T_mac[5].":".$T_mac[6];
          control_syntax_mac_address($mac) or next;
-         if (control_exist_mac($COMPUTER_DB, $mac) == 0) {
+         if (control_exist_mac($computer_db, $mac) == 0) {
             print "Error: Physical MAC address already exists: $mac\n";
             next;
@@ -2679,12 +2745,12 @@
 
          #--- cette partie teste si le pool existe.
-         if (not exists $COMPUTER_DB->{'pool'}{$pool}) {
+         if (not exists $computer_db->{'pool'}{$pool}) {
             print "Error: Create pool with create_pool command before load database: $pool\n";
             exit;
             }
 
-         if ($COMPUTER_DB->{'pool'}{'domain'} eq $domainset) {
+         if ($computer_db->{'pool'}{'domain'} eq $domainset) {
             my $timestamp = time;
-            push @{$COMPUTER_DB->{$domainset}}, { $mac => {
+            push @{$computer_db->{$domainset}}, { $mac => {
                'hostname'     => $pool,
                'ip'           => $pool,
@@ -2708,5 +2774,7 @@
    my ($domainset, $input_file, $type_file) = @_;
 
-   #$COMPUTER_DB
+   my $computer_db = ipamdb_load($COMPUTER_YAML);
+
+   #$computer_db
    if ($type_file eq 'dhcp') {
       load_data_dhcp($domainset, $input_file);
@@ -2717,5 +2785,5 @@
       }
 
-   ipamdb_save("$COMPUTER_YAML", $COMPUTER_DB);
+   ipamdb_save("$COMPUTER_YAML", $computer_db);
    }
 
