Switching script creation method to use string.Template

This commit is contained in:
Kieron Bulloch 2014-06-24 23:07:28 -04:00 committed by Jerry Seutter
parent e16c269f6d
commit d6c5dffae6
2 changed files with 26 additions and 24 deletions

View File

@ -9,6 +9,7 @@ from fabric.api import env
from fabric.contrib.files import exists
from github import Github
from novaclient.v1_1 import client
from string import Template
from time import sleep
POLL_SEC = 30
@ -173,34 +174,14 @@ def create_instance(username, password, tenant, region, server_name, script,
def create_script(git_url, git_branch, on_boot):
""" Create the start-up script. """
# Consider using jinja or similar if this becomes unwieldly
script = "#!/bin/bash\n\n"
script += "export DEBIAN_FRONTEND=noninteractive\n\n"
script += "apt-get -y update\n"
script += "apt-get -o Dpkg::Options::=\"--force-confnew\" --force-yes -fuy dist-upgrade\n\n"
script_template = Template(open('script_template', 'r').read())
reqs = ["git", "python3-setuptools", "python3-netifaces", "python3-pip"]
for r in reqs:
script += "apt-get -y install %s\n" % r
script += "\n"
script += "mkdir -p /opt/gns3\n"
script += "pushd /opt/gns3\n"
script += "git clone --branch %s %s\n" % (git_branch, git_url)
script += "cd gns3-server\n"
script += "pip3 install tornado\n"
script += "pip3 install pyzmq\n"
script += "pip3 install jsonschema\n"
script += "python3 ./setup.py install\n\n"
p = dict(git_url=git_url, git_branch=git_branch, rc_local='')
if on_boot:
script += "echo '/usr/local/bin/gns3-server' >> /etc/rc.local\n\n"
p['rc_local'] = "echo '/usr/local/bin/gns3-server' >> /etc/rc.local"
script += "touch /tmp/gns-install-complete\n\n"
return script
return script_template.substitute(p)
def create_image(username, password, tenant, region, server,

View File

@ -0,0 +1,21 @@
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt-get -y update
apt-get -o Dpkg::Options::="--force-confnew" --force-yes -fuy dist-upgrade
apt-get -y install git
apt-get -y install python3-setuptools
apt-get -y install python3-netifaces
apt-get -y install python3-pip
mkdir -p /opt/gns3
pushd /opt/gns3
git clone --branch ${git_branch} ${git_url}
cd gns3-server
pip3 install tornado
pip3 install pyzmq
pip3 install jsonschema
python3 ./setup.py install
${rc_local}
touch /tmp/gns-install-complete