Commit 79879955 authored by Kristopher Ruzic's avatar Kristopher Ruzic

Merges wendelin-show and erp5-show into one script

In a new playbook that only installs the new erp5-show, this new script also does better
checking. Makes sure that the services are actually running (instead of just seeing if the table is populated)
parent b2ce2ed6
......@@ -4,4 +4,4 @@
roles:
- erp5-standalone
- erp5-show
......@@ -7,18 +7,25 @@ import glob
import time
import getopt
import sqlite3
from urllib2 import urlopen
from xml.dom import minidom
#from slapos.proxy.db_version import DB_VERSION
import json
def fmt_date():
return time.strftime("%Y%m%d")
def get_connection_information():
# get all of the installed software types by checking the SR urls
# return a list, and run routine on all of them
def discover_software():
conn = sqlite3.connect("/opt/slapos/slapproxy.db")
cur = conn.cursor()
qry = cur.execute("SELECT DISTINCT software_release FROM partition11")
return [row[0] for row in qry]
def get_connection_information(software_release):
conn = sqlite3.connect("/opt/slapos/slapproxy.db")
cur = conn.cursor()
qry = cur.execute("SELECT connection_xml FROM partition11 WHERE connection_xml IS NOT NULL AND software_type='create-erp5-site'")
qry = cur.execute("SELECT connection_xml FROM partition11 WHERE connection_xml IS NOT NULL AND software_release=?", (software_release,) )
for row in qry:
xml = str(row[0])
break
......@@ -27,21 +34,25 @@ def get_connection_information():
try:
el = instance.getElementsByTagName('parameter')[0]
value = el.childNodes[0].nodeValue
json_text = json.loads(value)
except:
return "error"
if not value.startswith("{"):
value = "\"" + value + "\""
json_text = json.loads(value)
if 'family-admin' in json_text:
return (json_text['family-admin'], json_text['inituser-password'])
except Exception, e:
print e
print "empty"
return (None, None)
elif 'insecure' in json_text:
return (json_text, None)
else:
return (None, None)
def check_tables():
conn = sqlite3.connect("/opt/slapos/slapproxy.db")
cur = conn.cursor()
qry = cur.execute("SELECT CASE WHEN tbl_name = 'partition11' THEN 1 ELSE 0 END FROM sqlite_master WHERE tbl_name = 'partition11' AND type = 'table'")
if qry:
pass
else:
if qry is None:
print "tables aren't ready yet, your build may have failed, check logs in /opt/slapos/log/"
sys.exit(0)
......@@ -54,7 +65,7 @@ def get_build_status():
if "Finished software releases" not in lines[-1]:
return False
if "ERROR" in lines[-3]:
return "err"
return "error"
return True
# Check if the last two lines show the software finished building.
......@@ -62,19 +73,29 @@ def get_build_status():
# Otherwise it passed and we can move on.
# We want to open today's log, as it is most up to date
def status():
def status(software_release):
build = get_build_status()
if build:
zope_ip, pw = get_connection_information()
zope_ip, pw = get_connection_information(software_release)
print ("Build successful, connect to:\n"
" " + zope_ip + " with\n"
" username: zope password: " + pw)
" " + zope_ip)
if pw is not None:
print (" with\n"
" username: zope password: " + pw)
elif not build:
print "Your software is still building, be patient it can take awhile"
elif build == "err":
elif build == "error":
print "An error occurred while building, check /opt/slapos/log/slapos-node-software-" + \
fmt_date() + ".log for details"
# check if the services are actually running (run slapos node and parse output)
if pw is None:
zope_ip = "https://" + zope_ip[zope_ip.index("@")+1:]
r1 = urlopen(zope_ip)
if r1.getcode() != 200:
print "At least one of your services isn't running! Check with slapos node"
print "restart a service with slapos node restart slappart:service"
def info():
if get_build_status():
print get_connection_information()
......@@ -99,6 +120,9 @@ def main(argv):
except getopt.error, msg:
usage()
sys.exit(2)
if len(opts) == 0:
usage()
sys.exit(2)
# process arguments
for opt, arg in opts:
if opt in ("-h", "--help"):
......@@ -106,12 +130,14 @@ def main(argv):
sys.exit()
elif opt in ("-s", "--status"):
check_tables()
status()
for sr in discover_software():
status(sr)
elif opt in ("-i", "--info"):
check_tables()
info()
for sr in discover_software():
info(sr)
elif opt in ("-d", "--dump"):
dump()
if __name__ == "__main__":
main(sys.argv[1:])
\ No newline at end of file
main(sys.argv[1:])
......@@ -5,6 +5,5 @@ PLAYBOOK_ROOT=/opt/slapos.playbook/
PLAYBOOK_FILE=erp5-standalone.yml
cd $PLAYBOOK_ROOT # cd into the playbook directory
echo "Starting Ansible playbook:"
ansible-playbook $PLAYBOOK_FILE -i hosts --connection=local
......@@ -9,15 +9,12 @@
- name: create partition script
copy: src=request-erp5-cluster dest=/tmp/playbook-request-erp5-cluster mode=700
- name: create erp5-show
copy: src=erp5-show dest=/usr/local/bin/erp5-show mode=755
- name: Request ERP5 Cluster
shell: cat /tmp/playbook-request-erp5-cluster | slapos console
- name: Add startup script
copy: src=erp5-startup dest=/usr/local/bin/erp5-startup mode=755
- name: Add to rc.local
lineinfile:
dest=/etc/rc.local insertbefore=BOF
......
#!/usr/bin/python2.7
import os
import sys
import subprocess
import glob
import time
import getopt
import sqlite3
from xml.dom import minidom
#from slapos.proxy.db_version import DB_VERSION
import json
def fmt_date():
return time.strftime("%Y%m%d")
def get_connection_information():
conn = sqlite3.connect("/opt/slapos/slapproxy.db")
cur = conn.cursor()
qry = cur.execute("SELECT connection_xml FROM partition11 WHERE connection_xml IS NOT NULL AND software_type='default'")
for row in qry:
xml = str(row[0])
break
instance = minidom.parseString(xml)
try:
el = instance.getElementsByTagName('parameter')[0]
value = el.childNodes[0].nodeValue
return value
except Exception, e:
print e
print "empty"
return None
def check_tables():
conn = sqlite3.connect("/opt/slapos/slapproxy.db")
cur = conn.cursor()
qry = cur.execute("SELECT CASE WHEN tbl_name = 'partition11' THEN 1 ELSE 0 END FROM sqlite_master WHERE tbl_name = 'partition11' AND type = 'table'")
if qry:
pass
else:
print "tables aren't ready yet, your build may have failed, check logs in /opt/slapos/log/"
sys.exit(0)
def get_build_status():
try:
f = open("/opt/slapos/log/slapos-node-software-" + fmt_date() + ".log")
except:
f = open("/opt/slapos/log/slapos-node-software.log")
lines = f.readlines()
if "Finished software releases" not in lines[-1]:
return False
if "ERROR" in lines[-3]:
return "err"
return True
# Check if the last two lines show the software finished building.
# If an error came just before this, we'll report failure.
# Otherwise it passed and we can move on.
# We want to open today's log, as it is most up to date
def status():
build = get_build_status()
if build:
zope_ip = get_connection_information()
print ("Build successful, connect to:\n"
" " + zope_ip + " to access your Wendelin instance")
elif not build:
print "Your software is still building, be patient it can take awhile"
elif build == "err":
print "An error occurred while building, check /opt/slapos/log/slapos-node-software-" + \
fmt_date() + ".log for details"
def info():
if get_build_status():
print "Your wendelin instance can be found at: "
print get_connection_information()
else:
print "Information unavailable at this time, run " + sys.argv[0] + " -s for details"
def usage():
print ("Get the status and information of your Wendelin build\n"
"Usage:")
print (" --help (-h): Print this message and exit\n"
" --status (-s): Print the status of the build\n"
" --info (-i): Print the partition tables\n"
" --dump (-d): Dump the entire database (alias for slapos proxy show)\n")
def dump():
subprocess.call(["slapos", "proxy", "show", "-u", "/opt/slapos/slapproxy.db"])
def main(argv):
# parse command line options
try:
opts, args = getopt.getopt(argv, "sihd", ["status", "info", "help", "dump"])
except getopt.error, msg:
usage()
sys.exit(2)
if len(opts) == 0:
usage()
sys.exit(2)
# process arguments
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in ("-s", "--status"):
check_tables()
status()
elif opt in ("-i", "--info"):
check_tables()
info()
elif opt in ("-d", "--dump"):
dump()
if __name__ == "__main__":
main(sys.argv[1:])
......@@ -5,6 +5,5 @@ PLAYBOOK_ROOT=/opt/slapos.playbook/
PLAYBOOK_FILE=wendelin-standalone.yml
cd $PLAYBOOK_ROOT # cd into the playbook directory
echo "Starting Ansible playbook:"
ansible-playbook $PLAYBOOK_FILE -i hosts --connection=local
......@@ -12,12 +12,9 @@
- name: Request Wendelin instance
shell: cat /tmp/playbook-request-wendelin | slapos console
- name: create wendelin-show
copy: src=wendelin-show dest=/usr/local/bin/wendelin-show mode=755
- name: Add startup script
copy: src=wendelin-startup dest=/usr/local/bin/wendelin-startup mode=755
- name: Add to rc.local
lineinfile:
dest=/etc/rc.local insertbefore=BOF
......
......@@ -4,3 +4,4 @@
roles:
- wendelin-standalone
- erp5-show
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment