mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Switching script creation method to use string.Template
This commit is contained in:
parent
8dc3f288b3
commit
aedd750251
@ -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,
|
||||
|
21
cloud-image/script_template
Normal file
21
cloud-image/script_template
Normal 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
|
Loading…
Reference in New Issue
Block a user