Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion handyrep/daemon/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os

os.environ['HANDYREP_CONFIG'] = '/srv/handyrep//handyrep/handyrep.conf'
if not os.environ.has_key('HANDYREP_CONFIG'):
os.environ['HANDYREP_CONFIG'] = '/srv/handyrep//handyrep/handyrep.conf'
3 changes: 2 additions & 1 deletion handyrep/handyrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,8 @@ def test_ssh_newhost(self, hostname, ssh_key, ssh_user ):
command = self.conf["handyrep"]["test_ssh_command"]
testit = run(command, warn_only=True, quiet=True)
except Exception as ex:
print exstr(ex)
self.log("SSH","Unable to ssh to host %s" % hostname,True)
#print exstr(ex)
return False

result = testit.succeeded
Expand Down
12 changes: 6 additions & 6 deletions handyrep/hdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def run_periodic(func):

print func, "exiting with return", result

def start():
startup()

startup()

for func_name in PERIODIC.keys():
t = Thread(target=run_periodic, args=(func_name,) )
t.daemon = True
t.start()
for func_name in PERIODIC.keys():
t = Thread(target=run_periodic, args=(func_name,) )
t.daemon = True
t.start()

if __name__ == "__main__":
app.run(host="0.0.0.0")
41 changes: 40 additions & 1 deletion handyrep/hdaemon.wsgi
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
from hdaemon import app as application
import hdaemon
import os

class ReverseProxied(object):
'''Wrap the application in this middleware and configure the
front-end server to add these headers, to let you quietly bind
this to a URL other than / and to an HTTP scheme that is
different than what is used locally.

In nginx:
location /myprefix {
proxy_pass http://192.168.0.1:5001;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name /myprefix;
}

:param app: the hdaemon module so we can get the app and start the daemon
'''
def __init__(self, hd):
self.hdaemon = hdaemon

def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]

scheme = environ.get('HTTP_X_SCHEME', '')
if scheme:
environ['wsgi.url_scheme'] = scheme

os.environ['HANDYREP_CONFIG'] = environ['HANDYREP_CONFIG']
self.hdaemon.start()
return self.hdaemon.app(environ, start_response)

application = ReverseProxied(hdaemon)

4 changes: 3 additions & 1 deletion handyrep/plugins/handyrepplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from subprocess import call
import re
import threading
import traceback

class HandyRepPlugin(object):

Expand Down Expand Up @@ -160,6 +161,7 @@ def push_template(self, servername, templatename, destination, template_params,
if new_owner:
sudo("chown %s %s" % (new_owner, destination,), quiet=True)
except:
self.log('PLUGIN','could not push template %s to server %s - %s' % (templatename,servername, traceback.format_exc()),True)
retdict = return_dict(False, "could not push template %s to server %s" % (templatename, servername,))
else:
retdict = return_dict(True, "pushed template")
Expand Down Expand Up @@ -371,4 +373,4 @@ def execute_it(self, cur, statement, params=[]):
def exstr(self, errorobj):
return exstr(errorobj)



41 changes: 24 additions & 17 deletions handyrep/plugins/multi_pgbouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ def bouncer_list(self):

def test(self):
#check that we have all config variables required
if self.failed( self.test_plugin_conf("multi_pgbouncer","pgbouncerbin","template","owner","config_location","database_list","readonly_suffix","all_replicas")):
if self.failed( self.test_plugin_conf("multi_pgbouncer","pgbouncerbin","template","owner","config_location","readonly_suffix","all_replicas")):
return self.rd(False, "multi-pgbouncer failover is not configured" )

if self.failed( self.test_plugin_conf("multi_pgbouncer","database_list") or self.test_plugin_conf("multi_pgbouncer","databases")):
return self.rd(False, "multi-pgbouncer failover has no configured databases" )

#check that we can connect to the pgbouncer servers
blist = self.bouncer_list()
if len(blist) == 0:
Expand Down Expand Up @@ -157,23 +161,32 @@ def dbconnect_list(self, master):
# servers for pgbouncer
# build master string first
myconf = self.conf["plugins"]["multi_pgbouncer"]
dblist = myconf["database_list"]

dbconfig = {}
if myconf["databases"]:
dbconfig.update(myconf["databases"])

if myconf["database_list"]:
for dbname in myconf["database_list"]:
dbconfig[dbname] = myconf["extra_connect_param"]

# add in the handyrep db if the user has forgotten it
if self.conf["handyrep"]["handyrep_db"] not in dblist:
dblist.append(self.conf["handyrep"]["handyrep_db"])
constr = self.dbconnect_line(dblist, self.servers[master]["hostname"], self.servers[master]["port"], "", myconf["extra_connect_param"])
if not dbconfig.has_key(self.conf["handyrep"]["handyrep_db"]):
dbconfig[self.conf["handyrep"]["handyrep_db"]] = myconf["extra_connect_param"]

constr = self.dbconnect_line(dbconfig, self.servers[master]["hostname"], self.servers[master]["port"], "")
replicas = self.sorted_replicas()
if self.is_true(myconf["all_replicas"]):
#if we're doing all replicas, we need to put them in as _ro0, _ro1, etc.
# if there's no replicas, set ro1 to go to the master:
if len(replicas) == 0 or (len(replicas) == 1 and master in replicas):
rsuff = "%s%d" % (myconf["readonly_suffix"],1,)
constr += self.dbconnect_line(myconf["database_list"], self.servers[master]["hostname"], self.servers[master]["port"], rsuff, myconf["extra_connect_param"])
constr += self.dbconnect_line(dbconfig, self.servers[master]["hostname"], self.servers[master]["port"], rsuff)
else:
for rep in replicas:
if not rep == master:
rsuff = "%s%d" % (myconf["readonly_suffix"],repno,)
constr += self.dbconnect_line(myconf["database_list"], self.servers[rep]["hostname"], self.servers[rep]["port"], rsuff, myconf["extra_connect_param"])
constr += self.dbconnect_line(dbconfig, self.servers[rep]["hostname"], self.servers[rep]["port"], rsuff)
repno += 1
else:
# only one readonly replica, setting it up with _ro
Expand All @@ -183,23 +196,17 @@ def dbconnect_list(self, master):
replicas.pop(0)

if len(replicas) > 0:
constr += self.dbconnect_line(myconf["database_list"], self.servers[replicas[0]]["hostname"], self.servers[replicas[0]]["port"], myconf["readonly_suffix"], myconf["extra_connect_param"])
constr += self.dbconnect_line(dbconfig, self.servers[replicas[0]]["hostname"], self.servers[replicas[0]]["port"], myconf["readonly_suffix"])
else:
# if no replicas, read-only connections should go to the master
constr += self.dbconnect_line(myconf["database_list"], self.servers[master]["hostname"], self.servers[master]["port"], myconf["readonly_suffix"], myconf["extra_connect_param"])
constr += self.dbconnect_line(dbconfig, self.servers[master]["hostname"], self.servers[master]["port"], myconf["readonly_suffix"])

return constr


def dbconnect_line(self, database_list, hostname, portno, suffix, extra):
def dbconnect_line(self, database_list, hostname, portno, suffix):
confout = ""
if extra:
nex = extra
else:
nex = ""
for dbname in database_list:
for dbname,nex in database_list.items():
confout += "%s%s = dbname=%s host=%s port=%s %s \n" % (dbname, suffix, dbname, hostname, portno, nex,)

return confout


14 changes: 7 additions & 7 deletions handyrepGUI/GUI_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
<head>

<title>handyrepGUI<!--{% block title %}{% endblock %}--></title>
<link rel="stylesheet" href="/static/style.css">
<link rel="stylesheet" href="{{url_for('static',filename='style.css')}}">
</head>

<body >
<div style="background-color: #f9fbfb; position: fixed; top:30px; right:5px;z-index: 2;"><a href="/logout">logout</a></div>
<div style="background-color: #f9fbfb; position: fixed; top:30px; right:5px;z-index: 2;"><a href="{{url_for('logout')}}">logout</a></div>
<div id="container">
<div id="header">
<div style="background-color: #f9fbfb; margin: 0% auto">

<ul class=" row">
<li class="col span_1">&nbsp;</li>
<li class="col span_15"><a href="/"> <img style="height:120px; float: left" src="/static/handyrepfinal.gif"></a></li>
<li class="col span_5"><a href="http://www.pgexperts.com"><img style="height: 100px; padding-top: .65em; float: right" src="/static/logo.png"></a></li>
<li class="col span_15"><a href="{{url_for('index')}}"> <img style="height:120px; float: left" src="{{url_for('static',filename='handyrepfinal.gif')}}"></a></li>
<li class="col span_5"><a href="http://www.pgexperts.com"><img style="height: 100px; padding-top: .65em; float: right" src="{{url_for('static',filename='logo.png')}}"></a></li>
<li class="col span_1">&nbsp;</li>
</ul>

Expand All @@ -31,12 +31,12 @@

<ul class=" row">
<li class="col span_1">&nbsp;</li>
<li class="col span_15"><a href="/"> <img style="height: 40px; float: left" src="/static/handyrepfinalwithtext.gif"></a></li>
<li class="col span_5"><a href="http://www.pgexperts.com"><img style="height: 30px; padding-top: .65em; float: right" src="/static/logo.png"></a></li>
<li class="col span_15"><a href="{{url_for('index')}}"> <img style="height: 40px; float: left" src="{{url_for('static',filename='handyrepfinalwithtext.gif')}}"></a></li>
<li class="col span_5"><a href="http://www.pgexperts.com"><img style="height: 30px; padding-top: .65em; float: right" src="{{url_for('static',filename='logo.png')}}"></a></li>
<li class="col span_1">&nbsp;</li>
</ul>

</div></div>
</div></div>
</body>
</html>
</html>
6 changes: 3 additions & 3 deletions handyrepGUI/GUI_app/templates/base2.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<th>Enabled</th>
</tr>
<tr>
<td><a href="/cluster"> <p>cluster</p></a></td>
<td><a href="{{url_for('cluster_actions')}}"> <p>cluster</p></a></td>
<td><p>{{ status.cluster.get("status") }}</p></td>
<td><p>{{ status.cluster.get("status_message") }}</p></td>
<td><p>{{ status.cluster.get("status_ts") }}</p></td>
Expand All @@ -20,7 +20,7 @@
</tr>
{% for key, value in status.get("servers")|dictsort %}
<tr>
<td><a href="/server/{{ key }}"><p>{{key}}</p></a></td>
<td><a href="{{url_for('server_actions',server_name=key)}}"><p>{{key}}</p></a></td>
<td><p>{{value.get("status")}}</p></td>
<td><p>{{value.get("status_message")}}</p></td>
<td><p>{{value.get("status_ts")}}</p></td>
Expand All @@ -31,4 +31,4 @@
</table>
</div>
{% block eachcontent %}{% endblock %}
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions handyrepGUI/GUI_app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1 style="color: #231f20; text-align: center; padding-right: 1.5em; padding-lef
</div></div>
<div style="padding-left: 3em; padding-right: 3em">

<h3> <a href="/cluster">Cluster</a> status is {{ status.get(category).get("status") }} because {{ status.get(category).get("status_message") }}.
<h3> <a href="{{url_for('cluster_actions')}}">Cluster</a> status is {{ status.get(category).get("status") }} because {{ status.get(category).get("status_message") }}.
This was reported at {{ status.get(category).get("status_ts") }}</h3>

</div>
Expand All @@ -23,7 +23,7 @@ <h1 style="color: #231f20; text-align: center; padding-right: 1.5em; padding-lef
<div style="padding-left: 3em; padding-right: 3em">
<div id="global_nav">
{% for key, value in status.get(category)|dictsort %}
<h2><a href="/server/{{ key }}"> {{ key|upper }}</a> </h2>
<h2><a href="{{url_for('server_actions',server_name=key)}}"> {{ key|upper }}</a> </h2>
<div style="padding-left: 2em">
<h3>{{value.get("hostname")|capitalize}} is a {{value.get("role")}} server and is
{% if value.get("enabled") == False%}
Expand Down
6 changes: 3 additions & 3 deletions handyrepGUI/GUI_app/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ <h2 style="color: red; text-align: center">{{ message }}</h2>
<h2 style="color: #231f20;">Please enter the address where HandyRep is running. <br/><span style="font-style: italic; padding-left: 1.5em">Please remember to include http://</span></h2>
<form action="" method="post" name="address">
{{form.hidden_tag()}}
<p >{{form.address(size=80)}}</p>
<p >{{form.address(size=80,value=config.DEFAULT_HANDYREP)}}</p>
<h2 style="color: #231f20"> Please enter your HandyRep user name.</h2>
<p>{{form.username(size=80)}}</p>
<h2 style="color: #231f20"> Please enter your HandyRep password.</h2>
<p>{{form.password(size=80)}}</p>
<p>{{form.password(type='password',size=80)}}</p>
<p><input type="submit" value="Submit"></p>

</form>
</div>
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions handyrepGUI/GUI_app/templates/server_base_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div style="padding-left: 4em">
{% if info %}
{% for key in info %}
<h2><a href="/server/{{ key }}"> {{key|capitalize}}'s</a> server information:</h2>
<h2><a href="{{url_for('server_actions',server_name=key)}}"> {{key|capitalize}}'s</a> server information:</h2>
<div style="padding-left: 1em; width: 100%">
<table style="text-align:left;width: 100%;font-size: 1em;">
<tr >
Expand All @@ -31,4 +31,4 @@ <h2><a href="/server/{{ key }}"> {{key|capitalize}}'s</a> server information:</h
{% block specificdata %}{% endblock %}

</div>
{% endblock %}
{% endblock %}
8 changes: 4 additions & 4 deletions handyrepGUI/GUI_app/templates/server_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% if info %}
{% set server=[] %}
{% for key in info %}
<h2>Functions callable on <a href="/server/{{ key }}"> {{ key |capitalize}}</a>:</h2>
<h2>Functions callable on <a href="{{url_for('server_actions',server_name=key)}}"> {{ key |capitalize}}</a>:</h2>
{% set _ = server.append(key) %}

{% endfor %}
Expand All @@ -13,7 +13,7 @@ <h2>Functions callable on <a href="/server/{{ key }}"> {{ key |capitalize}}</a>:
<tr>
{% for function in functions %}

<td><h2 ><a href="/server/{{ server[0] }}/{{ function }}" title="{{ function.description }}">{{ function.short_description }} {{ function }}</a></h2></td>
<td><h2 ><a href="{{url_for('function_detail',server_name=server[0],function=function)}}" title="{{ function.description }}">{{ function.short_description }} {{ function }}</a></h2></td>

{% if loop.index is divisibleby 5 %}
</tr></table><table style="text-align:center;width: 100%"><tr>
Expand All @@ -28,7 +28,7 @@ <h2>Functions callable on the Cluster:</h2>
<tr>
{% for function in functions %}

<td><h2 ><a href="/cluster/{{ function }}" title="{{ function.description }}">{{ function.short_description }} {{ function }}</a></h2></td>
<td><h2 ><a href="{{url_for('cluster_function_detail',function=function)}}" title="{{ function.description }}">{{ function.short_description }} {{ function }}</a></h2></td>

{% if loop.index is divisibleby 5 %}
</tr><tr>
Expand All @@ -40,4 +40,4 @@ <h2>Functions callable on the Cluster:</h2>

{% endif %}

{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions handyrepGUI/GUI_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def logout():
username = None
global password
password = None
return redirect('/index')
return redirect('index')


@app.route('/login/', methods=['GET', 'POST'])
Expand Down Expand Up @@ -65,7 +65,7 @@ def login():
message = "Please check username and password"

return render_template('login.html', form=form, message=message)
return redirect(request.args.get('next') or '/index')
return redirect(request.args.get('next') or url_for('index'))

return render_template('login.html', form=form)

Expand Down
3 changes: 2 additions & 1 deletion handyrepGUI/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
basedir = os.path.abspath(os.path.dirname(__file__))

CSRF_ENABLED = True
SECRET_KEY = 'GUI-secret-key-597621139'
SECRET_KEY = 'GUI-secret-key-597621139'
DEFAULT_HANDYREP = 'http://localhost:8080'
Loading