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

:sparkles: feat(fusiondirectory-migration) Implemented --migrate-interfaces

issue #6124
parent d56f284d
No related merge requests found
Showing with 101 additions and 0 deletions
+101 -0
...@@ -398,4 +398,105 @@ class Migration extends Application ...@@ -398,4 +398,105 @@ class Migration extends Application
} }
} }
} }
/**
* Migrates interfaces from FD<1.4 to FD>=1.4
* @return void
*/
protected function cmdMigrateInterfaces ()
{
$entriesToMigrate = [];
$entriesToIgnore = [];
$systemOCs = ['fdWorkstation', 'fdServer', 'fdTerminal', 'fdPrinter', 'fdPhone', 'fdMobilePhone', 'device'];
$list = $this->ldap->search(
$this->base, '(&(|(objectClass='.implode(')(objectClass=', $systemOCs).'))(|(ipHostNumber=*)(macAddress=*)))'
);
$list->assert();
foreach ($list as $dn => $entry) {
$list2 = $this->ldap->search($dn, '(objectClass=fdNetworkInterface)', [], 'one');
$list2->assert();
if ($list2->count() == 0) {
$macs = $entry['macAddress'];
if (count($macs) > 1) {
$entriesToIgnore[$dn] = $entry;
continue;
}
$entriesToMigrate[$dn] = $entry;
}
}
if (count($entriesToMigrate) > 0) {
echo 'The following systems are missing an interface node and can be migrated automatically:'."\n";
foreach ($entriesToMigrate as $dn => $entry) {
$macs = $entry['macAddress'];
$ips = $entry['ipHostNumber'];
echo $dn;
if (count($macs) > 0) {
echo ' with MAC '.implode(', ', $macs);
} else {
echo ' with no MAC';
}
if (count($ips) > 0) {
echo ' and IP '.implode(', ', $ips)."\n";
} else {
echo ' and no IP'."\n";
}
}
echo "\n";
if ($this->askYnQuestion('Migrate these systems by adding an interface node')) {
$interface_cn = $this->askUserInput('Please enter the name for interfaces created by this migration', 'eth0');
$count = 0;
foreach ($entriesToMigrate as $dn => $entry) {
$macs = $entry['macAddress'];
$ips = $entry['ipHostNumber'];
$interface = [
'cn' => $interface_cn,
'objectClass' => 'fdNetworkInterface',
];
if (count($macs) > 0) {
$interface['macAddress'] = $macs;
}
if (count($ips) > 0) {
$interface['ipHostNumber'] = $ips;
}
$interface_add = $this->ldap->add("cn=$interface_cn,".$dn, $interface);
$interface_add->assert();
$count++;
}
echo $count." entries migrated\n";
}
}
if (count($entriesToIgnore) > 0) {
echo 'The following systems are missing interfaces nodes but cannot be migrated because they have several MAC addresses:'."\n";
foreach ($entriesToIgnore as $dn => $entry) {
$macs = $entry['macAddress'];
$ips = $entry['ipHostNumber'];
echo $dn;
if (count($macs) > 0) {
echo ' with MAC '.implode(', ', $macs);
} else {
echo ' with no MAC';
}
if (count($ips) > 0) {
echo ' and IP '.implode(', ', $ips)."\n";
} else {
echo ' and no IP'."\n";
}
}
echo "\n";
echo 'Please edit them by hand in FusionDirectory to add interfaces'."\n";
}
if ((count($entriesToMigrate) == 0) && (count($entriesToIgnore) == 0)) {
echo "\n".'No systems are missing interfaces, nothing to do'."\n";
}
}
} }
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