Commit 2ed1f5eb authored by root's avatar root

Upgraded to rest api instead of soapi

parent 0ff0580a
......@@ -12,6 +12,8 @@ for example:
gnt-instance add-tags instance01 route:81.82.83.84/32:br0
* install python-ovh from https://github.com/ovh/python-ovh
* put all the directory and files of the tarball in /etc/ganeti
* edit /etc/ganeti/scripts/ovh_cmd and change both $hostmap, $username and $passwd according to your use case
* put a crontab that touch /tmp/ganeti.checkroute one time every $(choose_your_time, i use 1 hour)
......
......@@ -2,7 +2,7 @@
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"
SSHCMD="ssh -o ConnectTimeout=3 -o ServerAliveInterval=5 -o ServerAliveCountMax=3 -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
getmaster ()
{
......
......@@ -16,6 +16,7 @@ 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
else
......
#!/usr/bin/env php
<?php
#!/usr/bin/env python
import sys, os
import ovh
$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");
}
hostmap={
'node1.example.net': { 'ip': '94.93.92.91', 'name': 'ns999999.ovh.net'},
'node3.example.net': { 'ip': '91.92.93.94', 'name': 'ns888888.ovh.net'},
}
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);
}
?>
client = ovh.Client(
endpoint='ovh-eu',
application_key='<application key>',
application_secret='<application secret>',
consumer_key='<consumer key>',
)
def main(cmd, host, dest, addr):
if cmd=="list":
if host in hostmap.keys():
opts={'routedTo.serviceName':hostmap[host]['name'], 'type':"failover"}
for ip in client.get('/ip', **opts):
if len(ip.split("/")[0])>=7:
print ip.split("/")[0]
elif cmd=="move":
opts={'to':dest, 'ip': addr+"/32"}
client.post('/ip/move', **opts)
if __name__ == '__main__':
cmd=None
host=None
dest=None
addr=None
if len(sys.argv)>1: cmd=sys.argv[1]
if len(sys.argv)>2: host=sys.argv[2]
if len(sys.argv)>3: dest=sys.argv[3]
if len(sys.argv)>4: addr=sys.argv[4]
if cmd:
main(cmd, host, dest, addr)
#!/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);
}
?>
......@@ -15,10 +15,10 @@ do
addr=`echo $route | awk -F ':' '{print $1}'`
iface=`echo $route | awk -F ':' '{print $2}'`
if [ $primary ] ; then
add_route $addr $iface
add_route $addr $iface || true
echo "add_route $addr $iface"
else
del_route $addr loc
del_route $addr loc || true
fi
done
......@@ -32,9 +32,9 @@ do
iface=`echo $route | awk -F '_' '{print $2}'`
#
if [ $primary ] ; then
add_v6route $addr/128 $iface
add_v6route $addr/128 $iface || true
else
del_v6route $addr/128 $iface
del_v6route $addr/128 $iface || true
fi
echo $route
fi
......
......@@ -27,4 +27,6 @@ do
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