Unverified Commit fb4fab80 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(fusiondirectory-setup) Add --migrate-interfaces option

First version which asks a question for each system

issue #6089
Showing with 71 additions and 0 deletions
+71 -0
......@@ -1637,6 +1637,72 @@ sub migrate_phones {
$unbind->code && warn "! Unable to unbind from LDAP server: ", $unbind->error."\n";
}
# function that migrates interfaces from FD<1.4 to FD>=1.4
sub migrate_interfaces {
# initiate the LDAP connexion
my %hash_ldap_param = get_ldap_connexion();
# LDAP's connection's parameters
my $base = $hash_ldap_param{base};
my $ldap = $hash_ldap_param{ldap};
my $interface_cn = ask_user_input ("Please enter the name for interfaces created by this migration", "eth0");
my @systemOCs = ('fdWorkstation', 'fdServer', 'fdTerminal', 'fdPrinter', 'fdPhone', 'fdMobilePhone', 'device');
foreach my $i (0 .. $#systemOCs) {
my $systemOC = $systemOCs[$i];
my $mesg = $ldap->search(
filter => "(&(objectClass=$systemOC)(|(ipHostNumber=*)(macAddress=*)))",
base => $base
);
$mesg->code && die $mesg->error;
my @entries = $mesg->entries;
foreach my $entry (@entries) {
my $mesg2 = $ldap->search(
filter => "(objectClass=fdNetworkInterface)",
base => $entry->dn,
scope => "one"
);
$mesg2->code && die $mesg2->error;
if ($mesg2->count == 0) {
print $entry->dn." is missing interfaces nodes\n";
my @macs = $entry->get_value('macAddress');
my @ips = $entry->get_value('ipHostNumber');
if (scalar(@macs) > 1) {
print "Cannot migrate ".$entry->dn." as it has more than one MAC address: ".join(',', @macs)."\n";
next;
}
if (ask_yn_question("Add an interface node with MAC ".join(',', @macs)." and IP ".join(',', @ips))) {
my %interface = (
'cn' => $interface_cn,
'objectClass' => 'fdNetworkInterface',
);
if (scalar(@macs) > 0) {
$interface{'macAddress'} = \@macs;
}
if (scalar(@ips) > 0) {
$interface{'ipHostNumber'} = \@ips;
}
my @options = %interface;
my $interface_add = $ldap->add( "cn=$interface_cn,".$entry->dn, attr => \@options );
$interface_add->code && die "! failed to add interface: ".$interface_add->error."\n";
}
}
}
}
# unbind to the LDAP server
my $unbind = $ldap->unbind;
$unbind->code && warn "! Unable to unbind from LDAP server: ", $unbind->error."\n";
}
# function that removes SupAnn root information from FD<1.4
sub remove_supann_root {
# initiate the LDAP connexion
......@@ -1926,6 +1992,7 @@ die ("! You have to run this script as root\n") if ($<!=0);
$commands{"--migrate-systems"} = ["Migrating your systems from FD < 1.1", \&migrate_systems, 1];
$commands{"--migrate-winstations"} = ["Migrating your winstations from FD < 1.1", \&migrate_winstations, 1];
$commands{"--migrate-dhcp"} = ["Migrating DHCP configurations for FD >= 1.0.17",\&migrate_dhcp, 1];
$commands{"--migrate-interfaces"} = ["Migrating your systems from FD < 1.4", \&migrate_interfaces, 1];
$commands{"--remove-supann-root"} = ["Remove SupAnn root establishment from FD < 1.4",\&remove_supann_root, 1];
$commands{"--delete-gosa-locks"} = ["Delete lock tokens using old gosaLockEntry class", \&delete_gosa_locks];
$commands{"--install-plugins"} = ["Installing FusionDirectory's plugins", \&install_plugins];
......@@ -2043,6 +2110,10 @@ This option replace old winstations objectClasses by new objectClasses from FD 1
This option moves DHCP configurations from systems branch to DHCP branch, which is necessary for FusionDirectory 1.0.17 and above.
=item --migrate-interfaces
This option creates interfaces objects for old systems from FD < 1.4.
=item --delete-gosa-locks
This option will delete old GOsa style lock tokens from 1.0.15 or older
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment