Masayoshi Kobayashi | a9020b3 | 2013-04-09 21:42:08 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | import sys |
| 3 | import time |
| 4 | import os |
| 5 | import re |
| 6 | import json |
| 7 | import socket |
| 8 | |
| 9 | CONFIG_FILE=os.getenv("HOME") + "/ONOS/web/config.json" |
| 10 | |
| 11 | def read_config(): |
| 12 | global controllers |
| 13 | f = open(CONFIG_FILE) |
| 14 | conf = json.load(f) |
| 15 | controllers = conf['controllers'] |
| 16 | f.close() |
| 17 | |
| 18 | if __name__ == "__main__": |
| 19 | read_config() |
| 20 | |
| 21 | url = "" |
| 22 | for idx in sys.argv[1:]: |
| 23 | url += "tcp:%s:6633" % socket.gethostbyname(controllers[int(idx)-1]) + " " |
| 24 | |
| 25 | print url[:-1] |
| 26 | |
| 27 | switches = os.popen("sudo ovs-vsctl list-br").read().split("\n"); |
| 28 | switches.remove('') |
| 29 | for s in switches: |
| 30 | print "set switch %s controller %s" % (s, url) |
| 31 | os.popen("sudo ovs-vsctl set-controller %s %s" % (s, url) ) |