Commit 0b999462 authored by Lukas Burgey's avatar Lukas Burgey

Implement client deregistration

parent 5c996046
......@@ -134,6 +134,13 @@ class Service(models.Model):
def __str__(self):
return self.name
def remove_service(self):
for deployment in Deployment.objects.filter(
vo__services=self,
):
deployment.service_removed(self)
self.delete()
def handle_vo_deployments(self):
for vo in self.vos.all():
......@@ -273,6 +280,10 @@ class Deployment(models.Model):
if self.state_target == 'deployed':
item.user_deploy()
def service_removed(self, service):
LOGGER.debug(self.msg('Removing service {}'.format(service)))
LOGGER.debug('TODO implement service removal')
def publish_to_client(self):
# avoiding circular dependencies here
from .serializers.clients import DeploymentSerializer
......
......@@ -6,4 +6,5 @@ URLPATTERNS = [
url(r'^deployments', clients.DeploymentsView.as_view()),
url(r'^config', clients.ConfigurationView.as_view()),
url(r'^response', clients.ResponseView.as_view()),
url(r'^deregister', clients.DeregisterView.as_view()),
]
......@@ -164,6 +164,30 @@ class ConfigurationView(views.APIView):
return Response(response)
class DeregisterView(views.APIView):
authentication_classes = AUTHENTICATION_CLASSES
def put(self, request):
# the site where client is located
client_site = None
try:
client_site = request.user.site
except models.Site.DoesNotExist:
raise ImproperlyConfigured('client has no site')
# deregister the client / its services / its site
# we expect all deployments at the clients to be removed (and therefore simply delete them all)
LOGGER.info('[DEREG] Client %s from site %s is deregistering', request.user, client_site)
for service in client_site.services.all():
LOGGER.info('[DEREG] Triggering service removal %s', service)
service.remove_service()
response = 'Success deregistering'
return Response(response)
def response_view_error(err):
return Response(
data={'error': err},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment