2 # Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Eclipse Public License v1.0
5 # which accompanies this distribution, and is available at
6 # http://www.eclipse.org/legal/epl-v10.html
12 from subprocess import call
15 CTRL_GIT = "https://git.opendaylight.org/gerrit/p/controller.git"
16 OVSDB_GIT = "https://git.opendaylight.org/gerrit/p/ovsdb.git"
20 parser = argparse.ArgumentParser()
21 parser.add_argument('-r', '--reclone',
22 help='Reclone the Controller/OVSDB repos',
24 parser.add_argument('-b', '--rebuild',
25 help='Build the Controller Project',
27 parser.add_argument('-of13', '--openflow13',
28 help='Enable OpenFlow 1.3 Support',
30 parser.add_argument('-v', '--verbose',
31 help='Verbose output',
33 parser.add_argument('-g', '--gerrit',
35 help='Gerrit Change ID',
37 parser.add_argument('-start', '--start',
38 help='Start the controller',
41 parser.add_argument('-stop', '--stop',
42 help='Stop the controller',
44 parser.add_argument('-d', '--directory',
47 parser.add_argument('-t', '--tmux',
48 help='Create tmux session',
50 args = parser.parse_args()
52 builder = OvsdbBuilder(args.verbose, args.openflow13,
56 builder.stop_controller()
60 print("---> Recloning Controller")
61 builder.reclone(builder.ctrl_root, CTRL_GIT)
62 print("---> Recloning OVSDB")
63 builder.reclone(builder.ovsdb_root, OVSDB_GIT)
66 print("---> Building Controller")
67 builder.build(builder.ctrl_build)
70 print("---> Checking out patch from Gerrit")
71 builder.gerrit(args.gerrit)
73 print("---> Building OVSDB")
74 builder.build(builder.ovsdb_root, args.verbose)
75 print("---> Copying OVSDB JARs")
79 print("---> Running Controller")
80 builder.run_controller()
84 print("To attach to the session please run: \n\n"
85 " tmux -2 attach-session -t odl\n\n")
88 class OvsdbBuilder(object):
93 directory=os.path.expanduser('~')):
94 self.root_dir = directory
95 self.ctrl_root = self.root_dir + "/controller"
96 self.ctrl_build = (self.root_dir +
97 "/opendaylight/distribution/opendaylight")
98 self.ctrl_exec = (self.ctrl_build +
99 "/target/distribution.opendaylight-osgipackage" +
101 self.ctrl_plugin = self.ctrl_build + "/plugin"
102 self.ovsdb_root = self.root_dir + "/ovsdb"
103 self.verbose = verbose
105 def reclone(self, location, repo):
108 command = "git checkout master"
111 command += " > /dev/null"
112 call(command, shell=True)
114 command = "git clone %s" % repo
116 command += " > /dev/null"
117 call(command, shell=True)
119 def gerrit(self, patch):
120 os.chdir(self.ovsdb_root)
121 command = "git review -d %i" % patch
122 call(command, shell=True)
124 def build(self, location, verbose):
126 command = "mvn clean install"
128 command += " > /dev/null"
129 call(command, shell=True)
132 os.chdir(self.ovsdb_root)
133 command = ("find . -name ovsdb*.jar -exec cp {} %s \;"
135 call(command, shell=True)
137 def stop_controller(self):
138 os.chdir(self.root_dir)
139 command = "sh " + self.ctrl_exec + "/run.sh -stop"
140 call(command, shell=True)
142 def run_controller(self):
143 os.chdir(self.root_dir)
144 command = "sh " + self.ctrl_exec + "/run.sh -start -debug"
147 call(command, shell=True)
150 tmux = ["tmux new-session -d -s odl",
151 "tmux new-window -t odl:1 -n 'OSGi' 'telnet 127.0.0.1 2400'",
152 "tmux new-window -t odl:2 -n 'OVSDB Source' 'cd %s'"
154 "tmux new-window -t odl:3 -n 'Ctrl Source' 'cd %s'"
156 "tmux select-window -t odl:1",
158 call(" ; ".join(tmux), shell=True)
160 if __name__ == "__main__":