Simplified controllers, updated related templates.

We now take put and delete parameters which control the code's flow.
This commit is contained in:
Nick Daly 2012-06-16 14:42:14 -05:00
parent 7dbb3e67d2
commit affabcb45f
7 changed files with 70 additions and 82 deletions

View File

@ -221,27 +221,23 @@ class HostedService(RestMonitor):
"locations": self.santiago.hosting[client][service] }) "locations": self.santiago.hosting[client][service] })
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def POST(self, client="", service="", location="", put="", delete=""): def POST(self, client="", service="", put="", delete=""):
if put: if put:
self.PUT(put, client,service) self.PUT(client, service, put)
elif delete: elif delete:
self.DELETE(delete,client,service) self.DELETE(client, service, delete)
else:
location = {location}
self.santiago.create_hosting_location(client,service,location)
raise cherrypy.HTTPRedirect("/hosting/"+client+"/"+service) raise cherrypy.HTTPRedirect("/hosting/{0}/{1}/".format(client, service))
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def PUT(self, put, client, service): def PUT(self, client, service, location):
location = {location} self.santiago.create_hosting_location(client, service, [location])
self.santiago.create_hosting_location(client,service,location)
# Have to remove instead of delete for locations as $service is a list # Have to remove instead of delete for locations as $service is a list
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def DELETE(self, delete, client, service): def DELETE(self, client, service, location):
if delete in self.santiago.hosting[client][service]: if location in self.santiago.hosting[client][service]:
self.santiago.hosting[client][service].remove(delete) self.santiago.hosting[client][service].remove(location)
class HostedClient(RestMonitor): class HostedClient(RestMonitor):
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
@ -251,24 +247,22 @@ class HostedClient(RestMonitor):
"services": self.santiago.hosting[client] }) "services": self.santiago.hosting[client] })
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def POST(self, client="", service="", put="", delete=""): def POST(self, client="", put="", delete=""):
if put: if put:
self.PUT(put, client) self.PUT(client, put)
elif delete: elif delete:
self.DELETE(delete,client) self.DELETE(client, delete)
else:
self.santiago.create_hosting_service(client,service)
raise cherrypy.HTTPRedirect("/hosting/" + client) raise cherrypy.HTTPRedirect("/hosting/" + client)
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def PUT(self, put, client): def PUT(self, client, service):
self.santiago.create_hosting_service(client, service) self.santiago.create_hosting_service(client, service)
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def DELETE(self, delete, client): def DELETE(self, client, service):
if delete in self.santiago.hosting[client]: if service in self.santiago.hosting[client]:
del self.santiago.hosting[client][delete] del self.santiago.hosting[client][service]
class Hosting(RestMonitor): class Hosting(RestMonitor):
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
@ -277,24 +271,22 @@ class Hosting(RestMonitor):
{"clients": [x for x in self.santiago.hosting]}) {"clients": [x for x in self.santiago.hosting]})
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def POST(self, client="", put="", delete=""): def POST(self, put="", delete=""):
if put: if put:
self.PUT(put) self.PUT(put)
elif delete: elif delete:
self.DELETE(delete) self.DELETE(delete)
else:
self.santiago.create_hosting_client(client)
raise cherrypy.HTTPRedirect("/hosting") raise cherrypy.HTTPRedirect("/hosting")
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def PUT(self, put): def PUT(self, client):
self.santiago.create_hosting_client(client) self.santiago.create_hosting_client(client)
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def DELETE(self, delete): def DELETE(self, client):
if delete in self.santiago.hosting: if client in self.santiago.hosting:
del self.santiago.hosting[delete] del self.santiago.hosting[client]
class ConsumedService(RestMonitor): class ConsumedService(RestMonitor):
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
@ -306,27 +298,23 @@ class ConsumedService(RestMonitor):
self.santiago.consuming[host][service] }) self.santiago.consuming[host][service] })
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def POST(self, host="", service="", location="", put="", delete=""): def POST(self, host="", service="", put="", delete=""):
if put: if put:
self.PUT(put, host, service) self.PUT(host, service, put)
elif delete: elif delete:
self.DELETE(delete, host, service) self.DELETE(host, service, delete)
else:
location = {location}
self.santiago.create_consuming_location(host, service, location)
raise cherrypy.HTTPRedirect("/consuming/"+host+"/"+service) raise cherrypy.HTTPRedirect("/consuming/{0}/{1}/".format(host, service))
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def PUT(self, put, host, service): def PUT(self, host, service, location):
location = {location} self.santiago.create_consuming_location(host, service, [location])
self.santiago.create_consuming_location(host, service, location)
# Have to remove instead of delete for locations as $service is a list # Have to remove instead of delete for locations as $service is a list
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def DELETE(self, delete, host, service): def DELETE(self, host, service, location):
if delete in self.santiago.consuming[host][service]: if location in self.santiago.consuming[host][service]:
self.santiago.consuming[host][service].remove(delete) self.santiago.consuming[host][service].remove(location)
class ConsumedHost(RestMonitor): class ConsumedHost(RestMonitor):
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
@ -336,24 +324,22 @@ class ConsumedHost(RestMonitor):
"host": host }) "host": host })
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def POST(self, host="", service="", put="", delete=""): def POST(self, host="", put="", delete=""):
if put: if put:
self.PUT(put, host) self.PUT(host, put)
elif delete: elif delete:
self.DELETE(delete, host) self.DELETE(host, delete)
else:
self.santiago.create_consuming_service(host, service)
raise cherrypy.HTTPRedirect("/consuming/" + host) raise cherrypy.HTTPRedirect("/consuming/" + host)
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def PUT(self, put, host): def PUT(self, host, service):
self.santiago.create_consuming_service(host, service) self.santiago.create_consuming_service(host, service)
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def DELETE(self, delete, host): def DELETE(self, host, service):
if delete in self.santiago.consuming[host]: if service in self.santiago.consuming[host]:
del self.santiago.consuming[host][delete] del self.santiago.consuming[host][service]
class Consuming(RestMonitor): class Consuming(RestMonitor):
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
@ -362,24 +348,22 @@ class Consuming(RestMonitor):
{ "hosts": [x for x in self.santiago.consuming]}) { "hosts": [x for x in self.santiago.consuming]})
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def POST(self, host="", put="", delete=""): def POST(self, put="", delete=""):
if put: if put:
self.PUT(put) self.PUT(put)
elif delete: elif delete:
self.DELETE(delete) self.DELETE(delete)
else:
self.santiago.create_consuming_host(host)
raise cherrypy.HTTPRedirect("/consuming") raise cherrypy.HTTPRedirect("/consuming")
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def PUT(self, put): def PUT(self, host):
self.santiago.create_consuming_host(host) self.santiago.create_consuming_host(host)
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()
def DELETE(self, delete): def DELETE(self, host):
if delete in self.santiago.consuming: if host in self.santiago.consuming:
del self.santiago.consuming[delete] del self.santiago.consuming[host]
class Root(RestMonitor): class Root(RestMonitor):
@cherrypy.tools.ip_filter() @cherrypy.tools.ip_filter()

View File

@ -11,17 +11,18 @@
#if $services #if $services
<ul> <ul>
#for $service in $services #for $service in $services
<li><a href="/consuming/$host/$service">$service</a></li> <li><a href="/consuming/$host/$service">$service</a>
<form method="post" action="/consuming/$host"> <form method="post" action="/consuming/$host">
<input type="hidden" name="delete" value="$service" /> <input type="hidden" name="delete" value="$service" />
<input type="Submit" value="Delete" /> <input type="submit" value="Delete" />
</form> </form>
</li>
#end for #end for
</ul> </ul>
#end if #end if
<hr /> <hr />
<form method="post" action="/consuming/$host"> <form method="post" action="/consuming/$host">
<label>Service: <input name="service" /></label> <label>Service: <input name="put" /></label>
<input type="submit" value="Create New Service" /> <input type="submit" value="Create New Service" />
</form> </form>
</body> </body>

View File

@ -12,17 +12,18 @@
#if $locations #if $locations
<ul> <ul>
#for $location in $locations #for $location in $locations
<li><a href="$location">$location</a></li> <li><a href="$location">$location</a>
<form method="post" action="/consuming/$host/$service"> <form method="post" action="/consuming/$host/$service">
<input type="hidden" name="delete" value="$location" /> <input type="hidden" name="delete" value="$location" />
<input type="Submit" value="Delete" /> <input type="submit" value="Delete" />
</form> </form>
</li>
#end for #end for
</ul> </ul>
#end if #end if
<hr /> <hr />
<form method="post" action="/consuming/$host/$service"> <form method="post" action="/consuming/$host/$service">
<label>Location: <input name="location" /></label> <label>Location: <input name="put" /></label>
<input type="submit" value="Create New Location" /> <input type="submit" value="Create New Location" />
</form> </form>
</body> </body>

View File

@ -7,14 +7,14 @@
</style> </style>
</head> </head>
<body> <body>
<p>You are consuming services from these hosts:</p>
#if $hosts #if $hosts
<p>You are <a href="/consuming">consuming</a> services from these hosts:</p>
<ul> <ul>
#for $host in $hosts #for $host in $hosts
<li><a href="/consuming/$host">$host</a> <li><a href="/consuming/$host">$host</a>
<form method="post" action="/consuming"> <form method="post" action="/consuming">
<input type="hidden" name="delete" value="$host" /> <input type="hidden" name="delete" value="$host" />
<input type="Submit" value="Delete" /> <input type="submit" value="Delete" />
</form> </form>
</li> </li>
#end for #end for
@ -23,7 +23,7 @@
<hr /> <hr />
<form method="post" action="/consuming"> <form method="post" action="/consuming">
<label>Host: <input name="host" /></label> <label>Host: <input name="put" /></label>
<input type="submit" value="Create New Host" /> <input type="submit" value="Create New Host" />
</form> </form>
</body> </body>

View File

@ -11,18 +11,19 @@
#if $services #if $services
<ul> <ul>
#for $service in $services #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"> <form method="post" action="/hosting/$client">
<input type="hidden" name="delete" value="$service" /> <input type="hidden" name="delete" value="$service" />
<input type="Submit" value="Delete" /> <input type="submit" value="Delete" />
</form> </form>
</li>
#end for #end for
</ul> </ul>
#end if #end if
<hr /> <hr />
<form method="post" action="/hosting/$client"> <form method="post" action="/hosting/$client">
<label>Service: <input name="service" /></label> <label>Service: <input name="put" /></label>
<input type="submit" value="Create New Service" /> <input type="submit" value="Create New Service" />
</form> </form>
</body> </body>

View File

@ -12,10 +12,10 @@
#if $locations #if $locations
<ul> <ul>
#for $location in $locations #for $location in $locations
<li><a href="$location">$location</a></li> <li><a href="$location">$location</a>
<form method="post" action="/hosting/$client/$service"> <form method="post" action="/hosting/$client/$service">
<input type="hidden" name="delete" value="$location" /> <input type="hidden" name="delete" value="$location" />
<input type="Submit" value="Delete" /> <input type="submit" value="Delete" />
</form> </form>
</li> </li>
#end for #end for
@ -23,7 +23,7 @@
#end if #end if
<hr /> <hr />
<form method="post" action="/hosting/$client/$service"> <form method="post" action="/hosting/$client/$service">
<label>Location: <input name="location" /></label> <label>Location: <input name="put" /></label>
<input type="submit" value="Create New Location" /> <input type="submit" value="Create New Location" />
</form> </form>
</body> </body>

View File

@ -8,21 +8,22 @@
</head> </head>
<body> <body>
#if $clients #if $clients
<p>You are <a href="/hosting">hosting</a> services for:</p> <p>You are hosting services for:</p>
<ul> <ul>
#for $client in $clients #for $client in $clients
<li><a href="/hosting/$client">$client</a></li> <li><a href="/hosting/$client">$client</a>
<form method="post" action="/hosting"> <form method="post" action="/hosting">
<input type="hidden" name="delete" value="$client" /> <input type="hidden" name="delete" value="$client" />
<input type="Submit" value="Delete" /> <input type="submit" value="Delete" />
</form> </form>
</li>
#end for #end for
</ul> </ul>
#end if #end if
<hr /> <hr />
<form method="post" action="/hosting"> <form method="post" action="/hosting">
<label>Client: <input name="client" /></label> <label>Client: <input name="put" /></label>
<input type="submit" value="Create New Client" /> <input type="submit" value="Create New Client" />
</form> </form>
</body> </body>