r3610 initial revision of domain sync cronjob
[racktables] / syncdomain.php
CommitLineData
46f2c279
DO
1#!/usr/local/bin/php
2<?php
3
4$script_mode = TRUE;
5require 'inc/init.php';
6
7function usage()
8{
9 echo "Usage: <this file> <options>\n";
10 echo "\t\t--vdid=<VLAN domain ID>\n";
11 echo "\t\t--mode=pull\n";
12 echo "\t\t--mode=pullall\n";
13 echo "\t\t--mode=push\n";
14 echo "\t\t[--max=<max_to_do>]\n";
15 exit (1);
16}
17
18$options = getopt ('', array ('push', 'vdid:', 'max::', 'mode:'));
19if (!array_key_exists ('vdid', $options) or !array_key_exists ('mode', $options))
20 usage();
21
22switch ($options['mode'])
23{
24case 'pullall':
25 $do_push = FALSE;
26 break;
27case 'pull':
28 $do_push = FALSE;
29 break;
30case 'push':
31 $do_push = TRUE;
32 break;
33default:
34 usage();
35}
36
37$max = array_key_exists ('max', $options) ? $options['max'] : 0;
38
39if (NULL === $mydomain = getVLANDomain ($options['vdid']))
40{
41 echo "Cannot load domain data with ID ${options['vdid']}\n";
42 exit (1);
43}
44
45$todo = array
46(
47 'pull' => array ('sync'),
48 'push' => array ('sync'),
49 'pullall' => array ('sync', 'resync', 'done'),
50);
51
52$done = 0;
53foreach ($mydomain['switchlist'] as $switch)
54 if (in_array (detectVLANSwitchQueue ($switch), $todo[$options['mode']]))
55 {
56 $object = spotEntity ('object', $switch['object_id']);
57 echo "Processing '${object['dname']}': ";
58 echo exec8021QDeploy ($switch['object_id'], $do_push) . "\n";
59 if (++$done == $max)
60 {
61 echo "Maximum of ${max} items reached, terminating\n";
62 break;
63 }
64 }
65
66exit (0);
67?>