Skip to content

Commit 4ba5dab

Browse files
Make it possible to change pool with Pony
1 parent 7ef19b4 commit 4ba5dab

File tree

5 files changed

+52
-16
lines changed

5 files changed

+52
-16
lines changed

scripts/keytab.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
from datetime import datetime, timedelta
55

66
KEYTAB_FILE = None
7-
principle = None
7+
principal = None
88

99

1010
def set(name):
1111
"""Tells the keytab module to look for the daemon/NAME.mit.edu
1212
keytab in ~/Private/NAME.keytab"""
13-
global KEYTAB_FILE, principle
13+
global KEYTAB_FILE, principal
1414
KEYTAB_FILE = os.path.expanduser("~/Private/%s.keytab" % name)
15-
principle = "daemon/%s.mit.edu" % name
15+
principal = "daemon/%s.mit.edu" % name
1616

1717

1818
def exists():
@@ -31,5 +31,5 @@ def auth():
3131
kinit = "/usr/kerberos/bin/kinit"
3232
else:
3333
kinit = "/usr/bin/kinit"
34-
subprocess.Popen([kinit, principle, "-k", "-t", KEYTAB_FILE]).wait()
34+
subprocess.Popen([kinit, principal, "-k", "-t", KEYTAB_FILE]).wait()
3535
state.got_tickets = now

scriptspony/controllers/root.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,24 @@ def index(self, locker=None, sudo=False, **kwargs):
103103
return dict(hosts=hosts, locker=locker, user_info=user_info, https=https)
104104

105105
@expose("scriptspony.templates.edit")
106-
def edit(self, locker, hostname, path=None, token=None, alias="", **kwargs):
106+
def edit(self, locker, hostname, pool=None, path=None, token=None, alias="", **kwargs):
107107
if request.response_ext:
108108
hostname += request.response_ext
109-
if path is not None:
109+
if path is not None or pool is not None:
110110
if token != auth.token():
111111
flash("Invalid token!")
112112
else:
113113
try:
114-
vhosts.set_path(locker, hostname, path)
114+
if path is not None:
115+
vhosts.set_path(locker, hostname, path)
116+
if pool is not None:
117+
vhosts.set_pool(locker, hostname, pool)
115118
except vhosts.UserError as e:
116119
flash(e.message)
117120
else:
118121
flash("Host '%s' reconfigured." % hostname)
119122
redirect("/index/" + locker)
120-
_, aliases = vhosts.get_vhost_info(locker, hostname)
123+
_, aliases, pool = vhosts.get_vhost_info(locker, hostname)
121124
else:
122125
if alias:
123126
if token != auth.token():
@@ -131,12 +134,14 @@ def edit(self, locker, hostname, path=None, token=None, alias="", **kwargs):
131134
flash("Alias '%s' added to hostname '%s'." % (alias, hostname))
132135
redirect("/index/" + locker)
133136
try:
134-
path, aliases = vhosts.get_vhost_info(locker, hostname)
137+
path, aliases, pool = vhosts.get_vhost_info(locker, hostname)
135138
except vhosts.UserError as e:
136139
flash(e.message)
137140
redirect("/index/" + locker)
141+
pools = vhosts.list_pools()
142+
pool = pools.get(pool, pool)
138143
return dict(
139-
locker=locker, hostname=hostname, path=path, aliases=aliases, alias=alias
144+
locker=locker, hostname=hostname, pool=pool, pools=pools, path=path, aliases=aliases, alias=alias
140145
)
141146

142147
@expose("scriptspony.templates.delete")
@@ -154,10 +159,10 @@ def delete(self, locker, hostname, confirm=False, token=None, **kwargs):
154159
else:
155160
flash("Host '%s' deleted." % hostname)
156161
redirect("/index/" + locker)
157-
_, aliases = vhosts.get_vhost_info(locker, hostname)
162+
_, aliases, _ = vhosts.get_vhost_info(locker, hostname)
158163
else:
159164
try:
160-
path, aliases = vhosts.get_vhost_info(locker, hostname)
165+
path, aliases, _ = vhosts.get_vhost_info(locker, hostname)
161166
except vhosts.UserError as e:
162167
flash(e.message)
163168
redirect("/index/" + locker)

scriptspony/templates/edit.mak

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ from scripts.auth import token
1111
<li>Hostname: ${hostname}</li>
1212
<li>Locker: ${locker}</li>
1313
<li>Path: /mit/${locker}/web_scripts/<input type="text" name="path" value="${path}" /></li>
14+
<li>Server Pool: ${pool} <select name="pool">
15+
<option value="unchanged">Unchanged</option>
16+
<option value="default">Default</option>
17+
%for ip, description in pools.items():
18+
<option value="${ip}">${description}</option>
19+
%endfor
20+
</select></li>
1421
</ul>
15-
<button class="btn"><span class="fa fa-save"></span> Save Path</button>
22+
<button class="btn"><span class="fa fa-save"></span>Save Changes</button>
1623
%if hostname.lower().endswith('.'+locker+'.scripts.mit.edu') or not hostname.lower().endswith('.mit.edu'):
1724
<a class="btn btn-danger" href="${tg.url('/delete/'+locker+'/'+hostname)}"><span class="fa fa-times-circle"></span> Delete</a>
1825
%endif

scriptspony/templates/index.mak

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from scripts import auth
1010
<p>
1111
<table border="1">
1212
<tr><th>Hostname</th><th>Path</th><th>Fedora Pool</th><th>Edit</th></tr>
13-
%for host,aliases,path,ipv4 in hosts:
13+
%for host,aliases,path,pool in hosts:
1414
<tr>
1515
<td>
1616
<a href="http://${host}">${host}</a>
@@ -22,7 +22,7 @@ from scripts import auth
2222
<small>/mit/${locker}/web_scripts/</small>${path}
2323
</td>
2424
<td>
25-
<big>${ipv4}</big>
25+
<big>${pool}</big>
2626
</td>
2727
%if host not in (locker+'.scripts.mit.edu',):
2828
<td class="nbr">

scriptspony/vhosts.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ def get_vhost_info(locker, hostname):
113113
"(&(objectClass=scriptsVhost)(scriptsVhostAccount=uid=%s,ou=People,dc=scripts,dc=mit,dc=edu)(scriptsVhostName=%s))",
114114
[locker, hostname],
115115
),
116-
["scriptsVhostDirectory", "scriptsVhostAlias"],
116+
["scriptsVhostDirectory", "scriptsVhostAlias", "scriptsVhostPoolIPv4"],
117117
)
118118
try:
119119
return (
120120
res[0][1]["scriptsVhostDirectory"][0],
121121
res[0][1].get("scriptsVhostAlias", []),
122+
res[0][1]["scriptsVhostPoolIPv4"][0]
122123
)
123124
except IndexError:
124125
raise UserError(
@@ -150,6 +151,29 @@ def set_path(locker, vhost, path):
150151
# doesn't exist
151152
# TODO: also check for index files or .htaccess and warn if none are there
152153

154+
@sensitive
155+
@log.exceptions
156+
@reconnecting
157+
def set_pool(locker, vhost, pool):
158+
"""Sets the pool of an existing vhost owned by the locker."""
159+
if vhost == locker + ".scripts.mit.edu":
160+
raise UserError("You cannot reconfigure " + vhost + "!")
161+
locker = locker.encode("utf-8")
162+
pool = pool.encode("utf-8")
163+
scriptsVhostName = get_vhost_name(locker, vhost)
164+
if pool == "unchanged":
165+
pass
166+
elif pool == "default":
167+
conn.modify_s(scriptsVhostName, [(ldap.MOD_DELETE, "scriptsVhostPoolIPv4", None)])
168+
else:
169+
conn.modify_s(
170+
scriptsVhostName, [(ldap.MOD_REPLACE, "scriptsVhostPoolIPv4", [pool])]
171+
)
172+
173+
log.info(
174+
"%s set pool for vhost '%s' (locker '%s') to '%s'."
175+
% (current_user(), vhost, locker, pool)
176+
)
153177

154178
@sensitive
155179
@log.exceptions

0 commit comments

Comments
 (0)