-#!/usr/local/bin/python
+#!/usr/bin/env python
#
# This script deploys a cluster
# -------------------------------------------
import re
from remote_host import RemoteHost
-parser = argparse.ArgumentParser(description='Cluster Deployer')
-parser.add_argument("--distribution", default="",
- help="the absolute path of the distribution on the local "
- "host that needs to be deployed. (Must contain "
- "version in the form: \"<#>.<#>.<#>-<name>\", e.g. "
- "0.2.0-SNAPSHOT)",
- required=True)
-parser.add_argument("--rootdir", default="/root",
- help="the root directory on the remote host where the "
- "distribution is to be deployed",
- required=True)
-parser.add_argument("--hosts", default="", help="a comma separated list of "
- "host names or ip addresses",
- required=True)
-parser.add_argument("--clean", action="store_true", default=False,
- help="clean the deployment on the remote host")
-parser.add_argument("--template", default="openflow",
- help="the name of the template to be used. "
- "This name should match a folder in the templates "
- "directory.")
-parser.add_argument("--rf", default=3, type=int,
- help="replication factor. This is the number of replicas "
- "that should be created for each shard.")
-parser.add_argument("--user", default="root", help="the SSH username for the "
- "remote host(s)")
-parser.add_argument("--password", default="Ecp123",
- help="the SSH password for the remote host(s)")
+parser = argparse.ArgumentParser(description="Cluster Deployer")
+parser.add_argument(
+ "--distribution",
+ default="",
+ help="the absolute path of the distribution on the local "
+ "host that needs to be deployed. (Must contain "
+ 'version in the form: "<#>.<#>.<#>-<name>", e.g. '
+ "0.2.0-SNAPSHOT)",
+ required=True,
+)
+parser.add_argument(
+ "--rootdir",
+ default="/root",
+ help="the root directory on the remote host where the "
+ "distribution is to be deployed",
+ required=True,
+)
+parser.add_argument(
+ "--hosts",
+ default="",
+ help="a comma separated list of " "host names or ip addresses",
+ required=True,
+)
+parser.add_argument(
+ "--clean",
+ action="store_true",
+ default=False,
+ help="clean the deployment on the remote host",
+)
+parser.add_argument(
+ "--template",
+ default="openflow",
+ help="the name of the template to be used. "
+ "This name should match a folder in the templates "
+ "directory.",
+)
+parser.add_argument(
+ "--rf",
+ default=3,
+ type=int,
+ help="replication factor. This is the number of replicas "
+ "that should be created for each shard.",
+)
+parser.add_argument(
+ "--user", default="root", help="the SSH username for the " "remote host(s)"
+)
+parser.add_argument(
+ "--password", default="Ecp123", help="the SSH password for the remote host(s)"
+)
args = parser.parse_args()
with open(self.template_root + template_path, "r") as myfile:
data = myfile.read()
- parsed = pystache.parse(u"%(data)s" % locals())
+ parsed = pystache.parse("%(data)s" % locals())
renderer = pystache.Renderer()
output = renderer.render(parsed, variables)
# The Deployer deploys the controller to one host and configures it
#
class Deployer:
- def __init__(self, host, member_no, template, user, password, rootdir,
- distribution, dir_name, hosts, ds_seed_nodes, rpc_seed_nodes,
- replicas, clean=False):
+ def __init__(
+ self,
+ host,
+ member_no,
+ template,
+ user,
+ password,
+ rootdir,
+ distribution,
+ dir_name,
+ hosts,
+ ds_seed_nodes,
+ rpc_seed_nodes,
+ replicas,
+ clean=False,
+ ):
self.host = host
self.member_no = member_no
self.template = template
self.replicas = replicas
# Connect to the remote host and start doing operations
- self.remote = RemoteHost(self.host, self.user, self.password,
- self.rootdir)
+ self.remote = RemoteHost(self.host, self.user, self.password, self.rootdir)
def kill_controller(self):
self.remote.copy_file("kill_controller.sh", self.rootdir + "/")
def deploy(self):
# Determine distribution version
- distribution_name \
- = os.path.splitext(os.path.basename(self.distribution))[0]
- distribution_ver = re.search('(\d+\.\d+\.\d+-\w+\Z)|'
- '(\d+\.\d+\.\d+-\w+)(-SR\d+\Z)|'
- '(\d+\.\d+\.\d+-\w+)(-SR\d+(\.\d+)\Z)',
- distribution_name) # noqa
+ distribution_name = os.path.splitext(os.path.basename(self.distribution))[0]
+ distribution_ver = re.search(
+ r"(\d+\.\d+\.\d+-\w+\Z)|"
+ r"(\d+\.\d+\.\d+-\w+)(-RC\d+\Z)|"
+ r"(\d+\.\d+\.\d+-\w+)(-RC\d+(\.\d+)\Z)|"
+ r"(\d+\.\d+\.\d+-\w+)(-SR\d+\Z)|"
+ r"(\d+\.\d+\.\d+-\w+)(-SR\d+(\.\d+)\Z)",
+ distribution_name,
+ ) # noqa
if distribution_ver is None:
- print distribution_name + " is not a valid distribution version." \
- " (Must contain version in the form: " \
- "\"<#>.<#>.<#>-<name>\" or \"<#>.<#>." \
- "<#>-<name>-SR<#>\" or \"<#>.<#>.<#>" \
- "-<name>\", e.g. 0.2.0-SNAPSHOT)" # noqa
+ print(
+ "%s is not a valid distribution version."
+ " (Must contain version in the form: "
+ '"<#>.<#>.<#>-<name>" or "<#>.<#>.'
+ '<#>-<name>-SR<#>" or "<#>.<#>.<#>'
+ '-<name>-RC<#>", e.g. 0.2.0-SNAPSHOT)' % distribution_name
+ )
sys.exit(1)
distribution_ver = distribution_ver.group()
# Render all the templates
renderer = TemplateRenderer(self.template)
akka_conf = renderer.render(
- "akka.conf.template", "akka.conf",
+ "akka.conf.template",
+ "akka.conf",
{
"HOST": self.host,
"MEMBER_NAME": "member-" + str(self.member_no),
"DS_SEED_NODES": array_str(self.ds_seed_nodes),
- "RPC_SEED_NODES": array_str(self.rpc_seed_nodes)
- })
- module_shards_conf = renderer.render("module-shards.conf.template",
- "module-shards.conf",
- self.replicas)
- modules_conf = renderer.render("modules.conf.template",
- "modules.conf")
- features_cfg = \
- renderer.render("org.apache.karaf.features.cfg.template",
- "org.apache.karaf.features.cfg",
- {"ODL_DISTRIBUTION": distribution_ver})
+ "RPC_SEED_NODES": array_str(self.rpc_seed_nodes),
+ },
+ )
+ module_shards_conf = renderer.render(
+ "module-shards.conf.template", "module-shards.conf", self.replicas
+ )
+ modules_conf = renderer.render("modules.conf.template", "modules.conf")
+ features_cfg = renderer.render(
+ "org.apache.karaf.features.cfg.template",
+ "org.apache.karaf.features.cfg",
+ {"ODL_DISTRIBUTION": distribution_ver},
+ )
jolokia_xml = renderer.render("jolokia.xml.template", "jolokia.xml")
- management_cfg = \
- renderer.render("org.apache.karaf.management.cfg.template",
- "org.apache.karaf.management.cfg",
- {"HOST": self.host})
- datastore_cfg = \
- renderer.render(
- "org.opendaylight.controller.cluster.datastore.cfg.template",
- "org.opendaylight.controller.cluster.datastore.cfg")
+ management_cfg = renderer.render(
+ "org.apache.karaf.management.cfg.template",
+ "org.apache.karaf.management.cfg",
+ {"HOST": self.host},
+ )
+ datastore_cfg = renderer.render(
+ "org.opendaylight.controller.cluster.datastore.cfg.template",
+ "org.opendaylight.controller.cluster.datastore.cfg",
+ )
# Delete all the sub-directories under the deploy directory if
# the --clean flag is used
# Copy the distribution to the host and unzip it
odl_file_path = self.dir_name + "/odl.zip"
self.remote.copy_file(self.distribution, odl_file_path)
- self.remote.exec_cmd("unzip -o " + odl_file_path + " -d " +
- self.dir_name + "/")
+ self.remote.exec_cmd("unzip -o " + odl_file_path + " -d " + self.dir_name + "/")
# Rename the distribution directory to odl
- self.remote.exec_cmd("mv " + self.dir_name + "/" +
- distribution_name + " " + self.dir_name + "/odl")
+ self.remote.exec_cmd(
+ "mv "
+ + self.dir_name
+ + "/"
+ + distribution_name
+ + " "
+ + self.dir_name
+ + "/odl"
+ )
# Copy all the generated files to the server
- self.remote.mkdir(self.dir_name +
- "/odl/configuration/initial")
- self.remote.copy_file(akka_conf, self.dir_name +
- "/odl/configuration/initial/")
- self.remote.copy_file(module_shards_conf, self.dir_name +
- "/odl/configuration/initial/")
- self.remote.copy_file(modules_conf, self.dir_name +
- "/odl/configuration/initial/")
- self.remote.copy_file(features_cfg, self.dir_name +
- "/odl/etc/")
- self.remote.copy_file(jolokia_xml, self.dir_name +
- "/odl/deploy/")
- self.remote.copy_file(management_cfg, self.dir_name +
- "/odl/etc/")
+ self.remote.mkdir(self.dir_name + "/odl/configuration/initial")
+ self.remote.copy_file(akka_conf, self.dir_name + "/odl/configuration/initial/")
+ self.remote.copy_file(
+ module_shards_conf, self.dir_name + "/odl/configuration/initial/"
+ )
+ self.remote.copy_file(
+ modules_conf, self.dir_name + "/odl/configuration/initial/"
+ )
+ self.remote.copy_file(features_cfg, self.dir_name + "/odl/etc/")
+ self.remote.copy_file(jolokia_xml, self.dir_name + "/odl/deploy/")
+ self.remote.copy_file(management_cfg, self.dir_name + "/odl/etc/")
if datastore_cfg is not None:
self.remote.copy_file(datastore_cfg, self.dir_name + "/odl/etc/")
# Add symlink
- self.remote.exec_cmd("ln -sfn " + self.dir_name + " " +
- args.rootdir + "/deploy/current")
+ self.remote.exec_cmd(
+ "ln -sfn " + self.dir_name + " " + args.rootdir + "/deploy/current"
+ )
# Run karaf
self.remote.start_controller(self.dir_name)
def main():
# Validate some input
if os.path.exists(args.distribution) is False:
- print args.distribution + " is not a valid file"
+ print("%s is not a valid file" % args.distribution)
sys.exit(1)
if os.path.exists(os.getcwd() + "/templates/" + args.template) is False:
- print args.template + " is not a valid template"
+ print("%s is not a valid template" % args.template)
# Prepare some 'global' variables
hosts = args.hosts.split(",")
replicas = {}
for x in range(0, len(hosts)):
- ds_seed_nodes.append("akka.tcp://opendaylight-cluster-data@" +
- hosts[x] + ":2550")
- rpc_seed_nodes.append("akka.tcp://odl-cluster-rpc@" +
- hosts[x] + ":2551")
+ ds_seed_nodes.append(
+ "akka.tcp://opendaylight-cluster-data@" + hosts[x] + ":2550"
+ )
+ rpc_seed_nodes.append("akka.tcp://odl-cluster-rpc@" + hosts[x] + ":2551")
all_replicas.append("member-" + str(x + 1))
for x in range(0, 10):
if len(all_replicas) > args.rf:
- replicas["REPLICAS_" + str(x + 1)] \
- = array_str(random.sample(all_replicas, args.rf))
+ replicas["REPLICAS_" + str(x + 1)] = array_str(
+ random.sample(all_replicas, args.rf)
+ )
else:
replicas["REPLICAS_" + str(x + 1)] = array_str(all_replicas)
deployers = []
for x in range(0, len(hosts)):
- deployers.append(Deployer(hosts[x], x + 1, args.template, args.user,
- args.password, args.rootdir,
- args.distribution, dir_name, hosts,
- ds_seed_nodes, rpc_seed_nodes, replicas,
- args.clean))
+ deployers.append(
+ Deployer(
+ hosts[x],
+ x + 1,
+ args.template,
+ args.user,
+ args.password,
+ args.rootdir,
+ args.distribution,
+ dir_name,
+ hosts,
+ ds_seed_nodes,
+ rpc_seed_nodes,
+ replicas,
+ args.clean,
+ )
+ )
for x in range(0, len(hosts)):
deployers[x].kill_controller()
for x in range(0, len(hosts)):
deployers[x].deploy()
+
# Run the script
main()