Last active
August 29, 2015 14:03
-
-
Save ChoiZ/a324cd91682ac3e0bf40 to your computer and use it in GitHub Desktop.
Script de Migration IP Online VM sous proxmox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Script de configuration des nouvelles IP Online pour les VM utilisant proxmox. | |
| */ | |
| $eth = array('eth0','eth0:0','eth0:1','eth0:2','eth0:3','eth0:4','eth0:5','eth0:6','eth0:7'); // ça devrait aller pour 1 seule vm ? ;) | |
| $ipfo = array(); | |
| $ipmaster = array(); | |
| /* | |
| * Configurer uniquement les variables $ipfo et $ipmaster. | |
| * | |
| * Dans la configuration ci-dessous : | |
| * - L'ip de la machine mère passe de 88.1.2.10 à 195.1.2.10 | |
| * - L'ip failover de la VM passe de 88.191.2.11 à 212.129.2.11 | |
| * | |
| * Lancer une fois le script par VM. | |
| * N'oubliez pas de configurer l'ip de la machine mère… pour que vos vm fonctionnent toujours. | |
| */ | |
| $ipfo[] = '88.191.2.11'; // ancienne ipfailover | |
| $ipfo[] = '212.129.2.11'; // nouvelle ipfailover | |
| $ipmaster['88.191.2.11'] = '88.1.2.10'; // [ancienne ipfailover] = ip machine mère attachée (ancienne ip mère) | |
| $ipmaster['212.129.2.11'] = '195.1.2.10'; // [nouvelle ipfailover] = ip machine mère attachée (nouvelle ip mère) | |
| $route = ''; | |
| $ifup = ''; | |
| $str = '# This file describes the network interfaces available on your system | |
| # and how to activate them. For more information, see interfaces(5). | |
| # The loopback network interface | |
| auto lo | |
| iface lo inet loopback | |
| # The primary network interface'; | |
| function getIpMaster($i) { | |
| global $ipmaster; | |
| $ex = explode('.', $ipmaster[$i]); | |
| return $ex[0].'.'.$ex[1].'.'.$ex[2].'.1'; | |
| } | |
| foreach($ipfo as $i => $val) { | |
| $route .= "echo 20$i ipsupp$i >> /etc/iproute2/rt_tables\n"; | |
| $str .= " | |
| auto $eth[$i] | |
| iface $eth[$i] inet static | |
| address $ipfo[$i] | |
| netmask 255.255.255.255 | |
| broadcast $ipfo[$i] | |
| post-up route add ".getIpMaster($ipfo[$i])." dev $eth[$i] | |
| post-up route add default gw ".getIpMaster($ipfo[$i])." | |
| post-up ip rule add from $ipfo[$i] table ipsupp$i | |
| post-up ip route add default via ".getIpMaster($ipfo[$i])." dev $eth[$i] table ipsupp$i | |
| post-down route del ".getIpMaster($ipfo[$i])." dev $eth[$i] | |
| post-down route del default gw ".getIpMaster($ipfo[$i])." | |
| post-down ip rule del from $ipfo[$i] table ipsupp$i | |
| post-down ip route del default via ".getIpMaster($ipfo[$i])." dev $eth[$i] table ipsupp$i | |
| "; | |
| $ifup .= "ifdown $eth[$i]\n"; | |
| $ifup .= "ifup $eth[$i]\n\n"; | |
| } | |
| echo "##################################################\n"; | |
| echo "/!\\ Attention n'utilisez pas ce script si vous ne savez pas ce que vous faites ! /!\\\n"; | |
| echo "##################################################\n\n"; | |
| echo "#####\n\n"; | |
| echo "#####\n"; | |
| echo "Sauvegarde des fichiers :\n"; | |
| echo "#####\n\n"; | |
| echo "cp /etc/iproute2/rt_tables /etc/iproute2/rt_tables.old\n"; | |
| echo "cp /etc/networks/interfaces /etc/networks/interfaces.old\n\n"; | |
| echo "#####\n"; | |
| echo "Ajouter les routes :\n"; | |
| echo "#####\n\n"; | |
| echo $route."\n"; | |
| echo "#####\n"; | |
| echo "Configurer les interfaces dans /etc/networks/interfaces :\n"; | |
| echo "#####\n\n"; | |
| echo $str."\n"; | |
| echo "#####\n"; | |
| echo "Relancer les interfaces :\n"; | |
| echo "#####\n\n"; | |
| echo $ifup; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment