diff --git a/ugly_hacks/santiago/protocols/https/controller.py b/ugly_hacks/santiago/protocols/https/controller.py
index aa0732062..43fb10d2e 100644
--- a/ugly_hacks/santiago/protocols/https/controller.py
+++ b/ugly_hacks/santiago/protocols/https/controller.py
@@ -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):
diff --git a/ugly_hacks/santiago/protocols/https/templates/consumedHost-get.tmpl b/ugly_hacks/santiago/protocols/https/templates/consumedHost-get.tmpl
index c9a9b8ade..6ad12f737 100644
--- a/ugly_hacks/santiago/protocols/https/templates/consumedHost-get.tmpl
+++ b/ugly_hacks/santiago/protocols/https/templates/consumedHost-get.tmpl
@@ -1,12 +1,28 @@
+
+
+
You are consuming services from $host:
#if $services
#end for
#end if
+
+
diff --git a/ugly_hacks/santiago/protocols/https/templates/consumedService-get.tmpl b/ugly_hacks/santiago/protocols/https/templates/consumedService-get.tmpl
index 001ab95a3..5c007136a 100644
--- a/ugly_hacks/santiago/protocols/https/templates/consumedService-get.tmpl
+++ b/ugly_hacks/santiago/protocols/https/templates/consumedService-get.tmpl
@@ -1,4 +1,11 @@
+
+
+
You are consuming $service from
$host at:
@@ -6,8 +13,17 @@
#end for
#end if
+
+
diff --git a/ugly_hacks/santiago/protocols/https/templates/consuming-get.tmpl b/ugly_hacks/santiago/protocols/https/templates/consuming-get.tmpl
index 9ddd79488..9d79cb69b 100644
--- a/ugly_hacks/santiago/protocols/https/templates/consuming-get.tmpl
+++ b/ugly_hacks/santiago/protocols/https/templates/consuming-get.tmpl
@@ -8,7 +8,7 @@
#if $hosts
- You are consuming services from these hosts:
+ You are consuming services from these hosts:
#end if
+
+
+
diff --git a/ugly_hacks/santiago/protocols/https/templates/hostedService-get.tmpl b/ugly_hacks/santiago/protocols/https/templates/hostedService-get.tmpl
index e28fbb2df..7c0252d8b 100644
--- a/ugly_hacks/santiago/protocols/https/templates/hostedService-get.tmpl
+++ b/ugly_hacks/santiago/protocols/https/templates/hostedService-get.tmpl
@@ -1,13 +1,30 @@
+
+
+
- You're hosting
+
You are hosting
$service for $client at:
#if $locations
- #for location in $locations
+ #for $location in $locations
- $location
+
+
#end for
#end if
+
+
diff --git a/ugly_hacks/santiago/protocols/https/templates/hosting-get.tmpl b/ugly_hacks/santiago/protocols/https/templates/hosting-get.tmpl
index f21fba381..d34446718 100644
--- a/ugly_hacks/santiago/protocols/https/templates/hosting-get.tmpl
+++ b/ugly_hacks/santiago/protocols/https/templates/hosting-get.tmpl
@@ -1,12 +1,29 @@
+
+
+
- You are hosting services for:
#if $clients
+ You are hosting services for:
#end for
#end if
+
+
+
diff --git a/ugly_hacks/santiago/santiago.py b/ugly_hacks/santiago/santiago.py
index 5703287b1..166d9663b 100644
--- a/ugly_hacks/santiago/santiago.py
+++ b/ugly_hacks/santiago/santiago.py
@@ -233,29 +233,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.
diff --git a/ugly_hacks/santiago/test_santiago.py b/ugly_hacks/santiago/test_santiago.py
index a380a8365..c508d43c0 100644
--- a/ugly_hacks/santiago/test_santiago.py
+++ b/ugly_hacks/santiago/test_santiago.py
@@ -889,7 +889,52 @@ class OutgoingRequest(unittest.TestCase):
self.assertEqual(request["request"],
urlparse.parse_qs(urllib.urlencode(request))["request"][0])
+
+class CreateHosting(unittest.TestCase):
+ """Are we able to create Hosting Client/Service/Location
+
+ """
+ def setUp(self):
+ self.keyid = utilities.load_config().get("pgpprocessor", "keyid")
+
+ self.santiago = santiago.Santiago(
+ me = self.keyid)
+
+ def test_add_hosting_client(self):
+ self.santiago.create_hosting_client(self.keyid)
+ self.assertTrue(self.keyid in self.santiago.hosting)
+
+ def test_add_hosting_service(self):
+ self.santiago.create_hosting_service(self.keyid,self.keyid+"1")
+ self.assertTrue(self.keyid+"1" in self.santiago.hosting[self.keyid])
+
+ def test_add_hosting_location(self):
+ self.santiago.create_hosting_location(self.keyid,self.keyid+"1",{self.keyid+"2"})
+ self.assertTrue(self.keyid+"2" in self.santiago.hosting[self.keyid][self.keyid+"1"])
+
+class CreateConsuming(unittest.TestCase):
+ """Are we able to create Consuming Host/Service/Location
+
+ """
+ def setUp(self):
+ self.keyid = utilities.load_config().get("pgpprocessor", "keyid")
+
+ self.santiago = santiago.Santiago(
+ me = self.keyid)
+
+ def test_add_consuming_host(self):
+ self.santiago.create_consuming_host(self.keyid)
+ self.assertTrue(self.keyid in self.santiago.consuming)
+
+ def test_add_consuming_service(self):
+ self.santiago.create_consuming_service(self.keyid,self.keyid+"1")
+ self.assertTrue(self.keyid+"1" in self.santiago.consuming[self.keyid])
+
+ def test_add_consuming_location(self):
+ self.santiago.create_consuming_location(self.keyid,self.keyid+"1",{self.keyid+"2"})
+ self.assertTrue(self.keyid+"2" in self.santiago.consuming[self.keyid][self.keyid+"1"])
if __name__ == "__main__":
logging.disable(logging.CRITICAL)
+# logging.getLogger().setLevel(logging.DEBUG)
unittest.main()