r3618 syncdomain: add getVLANSwitchInfo() to restore queue detection
[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";
0eb16817 15 echo "\t\t[--verbose]\n";
46f2c279
DO
16 exit (1);
17}
18
0eb16817 19$options = getopt ('', array ('vdid:', 'max::', 'mode:', 'verbose'));
46f2c279
DO
20if (!array_key_exists ('vdid', $options) or !array_key_exists ('mode', $options))
21 usage();
22
23switch ($options['mode'])
24{
25case 'pullall':
26 $do_push = FALSE;
27 break;
28case 'pull':
29 $do_push = FALSE;
30 break;
31case 'push':
32 $do_push = TRUE;
33 break;
34default:
35 usage();
36}
37
38$max = array_key_exists ('max', $options) ? $options['max'] : 0;
0eb16817 39$verbose = array_key_exists ('verbose', $options);
46f2c279
DO
40
41if (NULL === $mydomain = getVLANDomain ($options['vdid']))
42{
43 echo "Cannot load domain data with ID ${options['vdid']}\n";
44 exit (1);
45}
46
47$todo = array
48(
37cb9e18 49 'pull' => array ('sync', 'resync'),
46f2c279 50 'push' => array ('sync'),
37cb9e18 51 'pullall' => array ('sync', 'resync', 'aging', 'done'),
46f2c279
DO
52);
53
0eb16817 54$switchesdone = 0;
46f2c279 55foreach ($mydomain['switchlist'] as $switch)
1f29bb49 56 if (in_array (detectVLANSwitchQueue (getVLANSwitchInfo ($switch['object_id'])), $todo[$options['mode']]))
46f2c279
DO
57 {
58 $object = spotEntity ('object', $switch['object_id']);
0eb16817
DO
59 $portsdone = exec8021QDeploy ($switch['object_id'], $do_push);
60 if ($portsdone or $verbose)
61 echo "Done '${object['dname']}': ${portsdone}\n";
62 if (++$switchesdone == $max)
46f2c279 63 {
0eb16817
DO
64 if ($verbose)
65 echo "Maximum of ${max} items reached, terminating\n";
46f2c279
DO
66 break;
67 }
68 }
69
70exit (0);
71?>