Commit 56926d00 authored by nextime's avatar nextime

Initial commit

parents
To use this you should separe your ip failover ripe in single ip failover /32, and route
every ip to your virtual machines as singular 255.255.255.255 netmask ip.
i also use ospf to manage internal routing.
Put your external ip address as instance tags in this way:
gnt-instance add-tags ${instance_name} route:${ipaddr}/32:${INTERFACE}
for example:
gnt-instance add-tags instance01 route:81.82.83.84/32:br0
1- put all the directory and files of the tarball in /etc/ganeti
2- edit /etc/ganeti/scripts/ovh_cmd and change both $hostmap, $username and $passwd according to your use case
3- put a crontab that touch /tmp/ganeti.checkroute one time every $(choose_your_time, i use 1 hour)
4- put a touch /tmp/ganeti.checkroute in /etc/rc.local
5- put a crontab to execute every minute /etc/ganeti/cron/00-external-routes (look at example crontab)
Every time you migrate, move, failover, start, stop an instance, it should automagically update ovh failover routes.
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin
SSHCMD="ssh -o ConnectTimeout=3 -o ServerAliveInterval=5 -o ServerAliveCountMax=3"
getmaster ()
{
echo $(gnt-cluster getmaster)
}
i_am_master ()
{
local master=$(getmaster)
local me=$(hostname)
if [ x"$master" = x"$me" ] ; then
echo "true"
else
echo ""
fi
}
mastercmd ()
{
local cmd=""
if [ -z $(i_am_master) ] ; then
local cmd="$SSHCMD $(getmaster)"
fi
echo $cmd
}
add_check_route_flag ()
{
$(mastercmd) touch /tmp/ganeti.checkroute
}
del_check_route_flag ()
{
$(mastercmd) rm -f /tmp/ganeti.checkroute
}
get_nodelist ()
{
echo $(gnt-node list --no-header| awk '{print $1}')
}
get_instances_running_list ()
{
local nodenames=""
local nodelist=$(gnt-instance list --no-header)
export IFS=$'\n'
for nodeline in $nodelist
do
node=$(echo $nodeline | awk '{print $4}')
nodenames="$node\n$nodenames"
done
unset IFS
nodelist=$(echo -e $nodenames| sort | uniq)
echo -e $nodelist
}
gettags ()
{
local cmd=$(mastercmd)
local res=$(${cmd} gnt-instance list -otags --no-headers $1 | grep "^route")
echo $res
}
getv6tags ()
{
local cmd=$(mastercmd)
local res=$(${cmd} gnt-instance list -otags --no-headers $1 | grep "^v6")
echo $res
}
i_am_primary ()
{
local host=$(hostname)
if [ -z $GANETI_NEW_PRIMARY ] ; then
if [ x"$GANETI_INSTANCE_PRIMARY" != x"$host" ] ; then
echo ""
else
echo "true"
fi
else
if [ x"$GANETI_NEW_PRIMARY" != x"$host" ] ; then
echo ""
else
echo "true"
fi
fi
#echo $GANETI_NEW_PRIMARY $GANETI_INSTANCE_PRIMARY > /tmp/debug.ganeti2
}
route_exists ()
{
# $1 => route
# $2 => (optional) if "loc", apply only to non-zebra routes
local chkaddr=`echo $1 | awk -F '/' '{print $1}'`
if [ x"$2" = x"loc" ] ; then
local check=`ip route | grep $chkaddr | grep -v zebra`
else
local check=`ip route | grep $chkaddr`
fi
if [ -z "$check" ] ; then
echo ""
else
echo "true"
fi
}
route6_exists ()
{
# $1 => route
# $2 => (optional) if "loc", apply only to non-zebra routes
local chkaddr=`echo $1 | awk -F '/' '{print $1}'`
if [ x"$2" = x"loc" ] ; then
local check=`ip -6 route | grep $chkaddr | grep -v zebra`
else
local check=`ip -6 route | grep $chkaddr`
fi
if [ -z "$check" ] ; then
echo ""
else
echo "true"
fi
}
del_route ()
{
# $1 => route
# $2 => (optional) if "loc", apply only to non-zebra routes
if [ $(route_exists $1 $2) ] ; then
ip route del $1
#echo "$(date) del $1" >> /tmp/delroute.debug
fi
add_check_route_flag
}
del_v6route ()
{
# We need to avoid returning != 0
setsid ip -6 neigh del proxy $1 dev eth0 > /dev/null 2>&1
if [ $(route6_exists $1 $2) ] ; then
ip -6 route del $1 dev $2
fi
}
add_v6route ()
{
ip -6 neigh add proxy $1 dev eth0
if [ $(route6_exists $1) ] ; then
del_route $1
fi
ip -6 route add $1 dev $2
}
add_route ()
{
# $1 => route
# $2 => interface
if [ $(route_exists $1) ] ; then
del_route $1
fi
ip route add $1 dev $2
add_check_route_flag
}
get_ovh_iplist ()
{
# $1 => node name
echo $(/etc/ganeti/scripts/ovh_cmd list $1)
}
move_ovh_ip ()
{
# $1 => from
# $2 => to
# $3 => ip
echo $(/etc/ganeti/scripts/ovh_cmd move $1 $2 $3)
}
get_node_extip ()
{
# $1 => node name
if [ x"$1" != x"$(hostname)" ] ; then
local cmd="$SSHCMD $1"
fi
local extroutes=`${cmd} ip route | grep -v proto | grep "scope link" | \
grep -v -E "(^192\.168\.)|(^127\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^10\.)|(^169\.254\.)" | \
awk '{print $1}'`
echo $extroutes
}
#!/bin/bash
if [ -f /etc/ganeti/common.sh ] ; then
. /etc/ganeti/common.sh
else
exit 0
fi
declare -A ips
declare -A nodeips
if [ $(i_am_master) ] ; then
if [ -f /tmp/ganeti.checkroute ] ; then
#nlist=$(get_instances_running_list)
for node in $(get_nodelist)
do
for i in $(get_ovh_iplist $node)
do
ips[$i]=$node
done
nodeips[$node]=$(get_node_extip $node)
done
for node in ${!nodeips[@]}
do
for nip in ${nodeips[$node]}
do
if [ x"${ips[$nip]}" != x"$node" ] ; then
echo "moving $nip from ${ips[$nip]} to $node"
move_ovh_ip ${ips[$nip]} $node $nip
fi
done
done
rm -f /tmp/ganeti.checkroute
fi
fi
#echo ${ips[@]} ${#ips[@]} ${!ips[@]}
#echo ${nodeips[@]} ${#nodeips[@]} ${!nodeips[@]}
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
00 * * * * touch /tmp/ganeti.checkroute
* * * * * /etc/ganeti/cron/00-external-routes > /dev/null 2>&1
/etc/ganeti/scripts/migration
\ No newline at end of file
/etc/ganeti/scripts/migration
\ No newline at end of file
/etc/ganeti/scripts/migration
\ No newline at end of file
/etc/ganeti/scripts/start
\ No newline at end of file
/etc/ganeti/scripts/stop
\ No newline at end of file
#!/bin/bash
env > /tmp/antani.env
if [ -f /etc/ganeti/common.sh ] ; then
. /etc/ganeti/common.sh
else
exit 0
fi
routes=$(gettags $GANETI_INSTANCE_NAME)
primary=$(i_am_primary)
IFS=','
for tag in $routes
do
rtype=`echo $tag | awk -F ':' '{print $1}'`
if [ x"$rtype" == x"route" ] ; then
route=`echo $tag | awk -F ':' '{print $2":"$3}'`
addr=`echo $route | awk -F ':' '{print $1}'`
iface=`echo $route | awk -F ':' '{print $2}'`
if [ $primary ] ; then
add_route $addr $iface
else
del_route $addr loc
fi
fi
done
v6routes=$(getv6tags $GANETI_INSTANCE_NAME)
for tag in $v6routes
do
rtype=`echo $tag | awk -F '_' '{print $1}'`
if [ x"$rtype" == x"v6" ] ; then
route=`echo $tag | awk -F '_' '{print $2":"$3}'`
addr=`echo $route | awk -F '_' '{print $1}'`
iface=`echo $route | awk -F '_' '{print $2}'`
#
if [ $primary ] ; then
add_v6route $addr/128 $iface
else
del_v6route $addr/128 $iface
fi
echo $route
fi
done
unset IFS
#!/usr/bin/env php
<?php
$hostmap=array(
'node1.example.net' => array('ip' => '94.93.92.91', 'name' => 'ns999999.ovh.net'),
'node2.example.net' => array('ip' => '91.92.93.94', 'name' => 'ns888888.ovh.net'),
);
$username="ab12345-ovh";
$passwd="password";
$cmd=$argv[1];
if(count($argv) > 2) $host=$argv[2];
if(count($argv) > 3) $dest=$argv[3];
if(count($argv) > 4) $addr=$argv[4];
try {
$soap = new SoapClient("https://www.ovh.com/soapi/soapi-re-1.24.wsdl");
//login
$session = $soap->login($username, $passwd,"it", false);
switch($cmd)
{
case "list":
//dedicatedFailoverList
$result = $soap->dedicatedFailoverList($session, $hostmap[$host]['name']);
//print_r($result); // your code here ...
foreach($result as $fip)
{
if(strlen($fip->ip) >= 7) {
print_r("$fip->ip\n");
}
}
break;
case "move":
$soap->dedicatedFailoverUpdate($session, $hostmap[$host]['name'], "$addr", $hostmap[$dest]['ip']);
break;
case "rev6":
$soap->dedicatedReverseAdd($session, $hostmap[$host]['name'], $dest, $addr );
}
//logout
$soap->logout($session);
} catch(SoapFault $fault) {
exit(1);
}
?>
#!/bin/bash
env > /tmp/antani.env
if [ -f /etc/ganeti/common.sh ] ; then
. /etc/ganeti/common.sh
else
exit 0
fi
routes=$(gettags $GANETI_INSTANCE_NAME)
primary=$(i_am_primary)
IFS=','
for tag in $routes
do
route=`echo $tag | awk -F ':' '{print $2":"$3}'`
addr=`echo $route | awk -F ':' '{print $1}'`
iface=`echo $route | awk -F ':' '{print $2}'`
if [ $primary ] ; then
add_route $addr $iface
echo "add_route $addr $iface"
else
del_route $addr loc
fi
done
v6routes=$(getv6tags $GANETI_INSTANCE_NAME)
for tag in $v6routes
do
rtype=`echo $tag | awk -F '_' '{print $1}'`
if [ x"$rtype" == x"v6" ] ; then
route=`echo $tag | awk -F '_' '{print $2":"$3}'`
addr=`echo $route | awk -F '_' '{print $1}'`
iface=`echo $route | awk -F '_' '{print $2}'`
#
if [ $primary ] ; then
add_v6route $addr/128 $iface
else
del_v6route $addr/128 $iface
fi
echo $route
fi
done
unset IFS
#!/bin/bash
env > /tmp/antani.env
if [ -f /etc/ganeti/common.sh ] ; then
. /etc/ganeti/common.sh
else
exit 0
fi
routes=$(gettags $GANETI_INSTANCE_NAME)
IFS=','
for tag in $routes
do
route=`echo $tag | awk -F ':' '{print $2":"$3}'`
addr=`echo $route | awk -F ':' '{print $1}'`
iface=`echo $route | awk -F ':' '{print $2}'`
del_route $addr
done
v6routes=$(getv6tags $GANETI_INSTANCE_NAME)
for tag in $v6routes
do
rtype=`echo $tag | awk -F '_' '{print $1}'`
if [ x"$rtype" == x"v6" ] ; then
route=`echo $tag | awk -F '_' '{print $2":"$3}'`
addr=`echo $route | awk -F '_' '{print $1}'`
iface=`echo $route | awk -F '_' '{print $2}'`
del_v6route $addr/128 $iface
fi
done
unset IFS
Markdown is supported
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