mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
Monitor controller changes.
I have built out the Hosting & Consuming Monitors to allow create/delete through website of Hosts/Clients/Services/Locations. I moved the code for this back to santiago.py to allow us to test these create/delete operations.
This commit is contained in:
parent
0460318044
commit
e60fa63e22
@ -220,6 +220,29 @@ class HostedService(RestMonitor):
|
||||
"client": client,
|
||||
"locations": self.santiago.hosting[client][service] })
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def POST(self, client="", service="", location="", put="", delete=""):
|
||||
if put:
|
||||
self.PUT(put, client,service)
|
||||
elif delete:
|
||||
self.DELETE(delete,client,service)
|
||||
else:
|
||||
location = {location}
|
||||
self.santiago.create_hosting_location(client,service,location)
|
||||
|
||||
raise cherrypy.HTTPRedirect("/hosting/"+client+"/"+service)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def PUT(self, put, client, service):
|
||||
location = {location}
|
||||
self.santiago.create_hosting_location(client,service,location)
|
||||
|
||||
#Have to remove instead of delete for locations as $service is a list
|
||||
@cherrypy.tools.ip_filter()
|
||||
def DELETE(self, delete, client, service):
|
||||
if delete in self.santiago.hosting[client][service]:
|
||||
self.santiago.hosting[client][service].remove(delete)
|
||||
|
||||
class HostedClient(RestMonitor):
|
||||
@cherrypy.tools.ip_filter()
|
||||
def GET(self, client):
|
||||
@ -227,11 +250,51 @@ class HostedClient(RestMonitor):
|
||||
{ "client": client,
|
||||
"services": self.santiago.hosting[client] })
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def POST(self, client="", service="", put="", delete=""):
|
||||
if put:
|
||||
self.PUT(put, client)
|
||||
elif delete:
|
||||
self.DELETE(delete,client)
|
||||
else:
|
||||
self.santiago.create_hosting_service(client,service)
|
||||
|
||||
raise cherrypy.HTTPRedirect("/hosting/"+client)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def PUT(self, put, client):
|
||||
self.santiago.create_hosting_service(client,service)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def DELETE(self, delete, client):
|
||||
if delete in self.santiago.hosting[client]:
|
||||
del self.santiago.hosting[client][delete]
|
||||
|
||||
class Hosting(RestMonitor):
|
||||
@cherrypy.tools.ip_filter()
|
||||
def GET(self):
|
||||
return self.respond("hosting-get.tmpl",
|
||||
{"clients": [x for x in self.santiago.consuming]})
|
||||
{"clients": [x for x in self.santiago.hosting]})
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def POST(self, client="", put="", delete=""):
|
||||
if put:
|
||||
self.PUT(put)
|
||||
elif delete:
|
||||
self.DELETE(delete)
|
||||
else:
|
||||
self.santiago.create_hosting_client(client)
|
||||
|
||||
raise cherrypy.HTTPRedirect("/hosting")
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def PUT(self, put):
|
||||
self.santiago.create_hosting_client(client)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def DELETE(self, delete):
|
||||
if delete in self.santiago.hosting:
|
||||
del self.santiago.hosting[delete]
|
||||
|
||||
class ConsumedService(RestMonitor):
|
||||
@cherrypy.tools.ip_filter()
|
||||
@ -242,6 +305,29 @@ class ConsumedService(RestMonitor):
|
||||
"locations":
|
||||
self.santiago.consuming[host][service] })
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def POST(self, host="", service="", location="", put="", delete=""):
|
||||
if put:
|
||||
self.PUT(put, host, service)
|
||||
elif delete:
|
||||
self.DELETE(delete, host, service)
|
||||
else:
|
||||
location = {location}
|
||||
self.santiago.create_consuming_location(host, service, location)
|
||||
|
||||
raise cherrypy.HTTPRedirect("/consuming/"+host+"/"+service)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def PUT(self, put, host, service):
|
||||
location = {location}
|
||||
self.santiago.create_consuming_location(host, service, location)
|
||||
|
||||
#Have to remove instead of delete for locations as $service is a list
|
||||
@cherrypy.tools.ip_filter()
|
||||
def DELETE(self, delete, host, service):
|
||||
if delete in self.santiago.consuming[host][service]:
|
||||
self.santiago.consuming[host][service].remove(delete)
|
||||
|
||||
class ConsumedHost(RestMonitor):
|
||||
@cherrypy.tools.ip_filter()
|
||||
def GET(self, host):
|
||||
@ -249,6 +335,26 @@ class ConsumedHost(RestMonitor):
|
||||
{ "services": self.santiago.consuming[host],
|
||||
"host": host })
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def POST(self, host="", service="", put="", delete=""):
|
||||
if put:
|
||||
self.PUT(put, host)
|
||||
elif delete:
|
||||
self.DELETE(delete, host)
|
||||
else:
|
||||
self.santiago.create_consuming_service(host, service)
|
||||
|
||||
raise cherrypy.HTTPRedirect("/consuming/"+host)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def PUT(self, put, host):
|
||||
self.santiago.create_consuming_service(host, service)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def DELETE(self, delete, host):
|
||||
if delete in self.santiago.consuming[host]:
|
||||
del self.santiago.consuming[host][delete]
|
||||
|
||||
class Consuming(RestMonitor):
|
||||
@cherrypy.tools.ip_filter()
|
||||
def GET(self):
|
||||
@ -262,14 +368,13 @@ class Consuming(RestMonitor):
|
||||
elif delete:
|
||||
self.DELETE(delete)
|
||||
else:
|
||||
self.santiago.consuming[host] = None
|
||||
self.santiago.create_consuming_host(host)
|
||||
|
||||
raise cherrypy.HTTPRedirect("/consuming")
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def PUT(self, put):
|
||||
self.santiago.consuming[host] = None
|
||||
|
||||
self.santiago.create_consuming_host(host)
|
||||
|
||||
@cherrypy.tools.ip_filter()
|
||||
def DELETE(self, delete):
|
||||
|
||||
@ -1,12 +1,28 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
form {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>You are <a href="/consuming">consuming</a> services from $host:</p>
|
||||
#if $services
|
||||
<ul>
|
||||
#for $service in $services
|
||||
<li><a href="/consuming/$host/$service">$service</a></li>
|
||||
<form method="post" action="/consuming/$host">
|
||||
<input type="hidden" name="delete" value="$service" />
|
||||
<input type="Submit" value="Delete" />
|
||||
</form>
|
||||
#end for
|
||||
</ul>
|
||||
#end if
|
||||
<hr />
|
||||
<form method="post" action="/consuming/$host">
|
||||
<label>Service: <input name="service" /></label>
|
||||
<input type="submit" value="Create New Service" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,4 +1,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
form {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>You are <a href="/consuming">consuming</a> $service from
|
||||
<a href="/consuming/$host">$host</a> at:</p>
|
||||
@ -6,8 +13,17 @@
|
||||
<ul>
|
||||
#for $location in $locations
|
||||
<li><a href="$location">$location</a></li>
|
||||
<form method="post" action="/consuming/$host/$service">
|
||||
<input type="hidden" name="delete" value="$location" />
|
||||
<input type="Submit" value="Delete" />
|
||||
</form>
|
||||
#end for
|
||||
</ul>
|
||||
#end if
|
||||
<hr />
|
||||
<form method="post" action="/consuming/$host/$service">
|
||||
<label>Location: <input name="location" /></label>
|
||||
<input type="submit" value="Create New Location" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
</head>
|
||||
<body>
|
||||
#if $hosts
|
||||
<p>You are consuming services from these hosts:</p>
|
||||
<p>You are <a href="/consuming">consuming</a> services from these hosts:</p>
|
||||
<ul>
|
||||
#for $host in $hosts
|
||||
<li><a href="/consuming/$host">$host</a>
|
||||
|
||||
@ -1,12 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
form {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>You're <a href="/hosting">hosting</a> these services for $client:</p>
|
||||
<p>You are <a href="/hosting">hosting</a> these services for $client:</p>
|
||||
#if $services
|
||||
<ul>
|
||||
#for $service in $services
|
||||
<li><a href="/hosting/$client/$service">$service</a></li>
|
||||
<li><a href="/hosting/$client/$service">$service</a>
|
||||
<form method="post" action="/hosting/$client">
|
||||
<input type="hidden" name="delete" value="$service" />
|
||||
<input type="Submit" value="Delete" />
|
||||
</form>
|
||||
</li>
|
||||
#end for
|
||||
</ul>
|
||||
#end if
|
||||
|
||||
<hr />
|
||||
<form method="post" action="/hosting/$client">
|
||||
<label>Service: <input name="service" /></label>
|
||||
<input type="submit" value="Create New Service" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,13 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
form {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>You're <a href="/hosting">hosting</a>
|
||||
<p>You are <a href="/hosting">hosting</a>
|
||||
$service for <a href="/hosting/$client/">$client</a> at:</p>
|
||||
#if $locations
|
||||
<ul>
|
||||
#for location in $locations
|
||||
#for $location in $locations
|
||||
<li><a href="$location">$location</a></li>
|
||||
<form method="post" action="/hosting/$client/$service">
|
||||
<input type="hidden" name="delete" value="$location" />
|
||||
<input type="Submit" value="Delete" />
|
||||
</form>
|
||||
</li>
|
||||
#end for
|
||||
</ul>
|
||||
#end if
|
||||
<hr />
|
||||
<form method="post" action="/hosting/$client/$service">
|
||||
<label>Location: <input name="location" /></label>
|
||||
<input type="submit" value="Create New Location" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,12 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
form {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>You are hosting services for:</p>
|
||||
#if $clients
|
||||
<p>You are <a href="/hosting">hosting</a> services for:</p>
|
||||
<ul>
|
||||
#for $client in $clients
|
||||
<li><a href="/hosting/$client">$client</a></li>
|
||||
<li><a href="/hosting/$client">$client</a>
|
||||
<form method="post" action="/hosting">
|
||||
<input type="hidden" name="delete" value="$client" />
|
||||
<input type="Submit" value="Delete" />
|
||||
</form>
|
||||
</li>
|
||||
#end for
|
||||
</ul>
|
||||
#end if
|
||||
|
||||
<hr />
|
||||
<form method="post" action="/hosting">
|
||||
<label>Client: <input name="client" /></label>
|
||||
<input type="submit" value="Create New Client" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -232,29 +232,60 @@ class Santiago(object):
|
||||
|
||||
def learn_service(self, host, service, locations):
|
||||
"""Learn a service somebody else hosts for me."""
|
||||
if host not in self.consuming:
|
||||
self.consuming[host] = dict()
|
||||
|
||||
if service not in self.consuming[host]:
|
||||
self.consuming[host][service] = list()
|
||||
|
||||
for location in locations:
|
||||
if location not in self.consuming[host][service]:
|
||||
self.consuming[host][service].append(location)
|
||||
self.create_consuming_location(host, service, locations)
|
||||
|
||||
def provide_service(self, client, service, locations):
|
||||
"""Start hosting a service for somebody else."""
|
||||
self.create_hosting_location(client, service, locations)
|
||||
|
||||
def create_hosting_client(self, client):
|
||||
"""Create a hosting client if one doesn't currently exist."""
|
||||
if client not in self.hosting:
|
||||
self.hosting[client] = dict()
|
||||
|
||||
def create_hosting_service(self, client, service):
|
||||
"""Create a hosting service if one doesn't currently exist.
|
||||
Check that hosting client exists before trying to add service.
|
||||
"""
|
||||
self.create_hosting_client(client)
|
||||
if service not in self.hosting[client]:
|
||||
self.hosting[client][service] = list()
|
||||
|
||||
def create_hosting_location(self, client, service, locations):
|
||||
"""Create a hosting service if one doesn't currently exist.
|
||||
Check that hosting client exists before trying to add service.
|
||||
Check that hosting service exists before trying to add location.
|
||||
"""
|
||||
self.create_hosting_client(client)
|
||||
self.create_hosting_service(client,service)
|
||||
for location in locations:
|
||||
if location not in self.hosting[client][service]:
|
||||
self.hosting[client][service].append(location)
|
||||
|
||||
def create_consuming_host(self, host):
|
||||
"""Create a consuming host if one doesn't currently exist."""
|
||||
if host not in self.consuming:
|
||||
self.consuming[host] = dict()
|
||||
|
||||
def create_consuming_service(self, host, service):
|
||||
"""Create a consuming service if one doesn't currently exist.
|
||||
Check that consuming host exists before trying to add service.
|
||||
"""
|
||||
self.create_consuming_host(host)
|
||||
if service not in self.consuming[host]:
|
||||
self.consuming[host][service] = list()
|
||||
|
||||
def create_consuming_location(self, host, service, locations):
|
||||
"""Create a consuming location if one doesn't currently exist.
|
||||
Check that consuming host exists before trying to add service.
|
||||
Check that consuming service exists before trying to add location.
|
||||
"""
|
||||
self.create_consuming_host(host)
|
||||
self.create_consuming_service(host,service)
|
||||
for location in locations:
|
||||
if location not in self.consuming[host][service]:
|
||||
self.consuming[host][service].append(location)
|
||||
|
||||
def get_host_locations(self, client, service):
|
||||
"""Return where I'm hosting the service for the client.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user