Commit 64f88bf7 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Rename method

parent c3581df8
......@@ -83,7 +83,7 @@ class RabbitMQInstance(SingletonModel):
def __str__(self):
return self.host
def _msg(self, msg):
def msg(self, msg):
return '[RabbitMQ:{}] {}'.format(self.host, msg)
@property
......@@ -102,7 +102,7 @@ class RabbitMQInstance(SingletonModel):
@property
def connection(self):
LOGGER.debug(self._msg('connection opened'))
LOGGER.debug(self.msg('connection opened'))
return pika.BlockingConnection(
self._connection_parameters,
)
......@@ -117,7 +117,7 @@ class RabbitMQInstance(SingletonModel):
exchange_type='topic',
)
rabbitmq_channel.confirm_delivery()
LOGGER.debug(self._msg('channel opened'))
LOGGER.debug(self.msg('channel opened'))
return rabbitmq_channel
......@@ -216,7 +216,7 @@ class RabbitMQInstance(SingletonModel):
return self._rest_del(path)
def _disconnect(self):
LOGGER.debug(self._msg('closing connection'))
LOGGER.debug(self.msg('closing connection'))
self.connection.close()
# PUBLIC API
......@@ -225,15 +225,15 @@ class RabbitMQInstance(SingletonModel):
self._create_user(site)
self._set_permissions(site)
self._set_topic_permissions(site)
LOGGER.info(self._msg('registered {}'.format(site.client)))
LOGGER.info(self.msg('registered {}'.format(site.client)))
def update_site(self, site):
self._set_topic_permissions(site)
LOGGER.info(self._msg('updated permissions for {}'.format(site.client)))
LOGGER.info(self.msg('updated permissions for {}'.format(site.client)))
def deregister_site(self, site):
self._delete_user(site)
LOGGER.info(self._msg('deregistered {}'.format(site.client)))
LOGGER.info(self.msg('deregistered {}'.format(site.client)))
def is_client_connected(self, site):
connections = self._rest_get("connections/")
......@@ -259,7 +259,7 @@ class RabbitMQInstance(SingletonModel):
),
)
except ConnectionClosed as exception:
LOGGER.info(self._msg('ConnectionClosed: {}'.format(exception)))
LOGGER.info(self.msg('ConnectionClosed: {}'.format(exception)))
time.sleep(RECONNECT_TIMEOUT)
......@@ -334,7 +334,7 @@ class User(AbstractUser):
else:
raise Exception()
def _msg(self, msg):
def msg(self, msg):
return '[{}] {}'.format(self, msg)
# oidcuser: withdraw and delete all credentials and delete the user
......@@ -345,12 +345,12 @@ class User(AbstractUser):
# FIXME: deleting the user brings problems:
# the deletion cascades down to DeploymentTask and DeploymentTaskItem
# but these need to be conserved so all clients withdrawals can be tracked
LOGGER.info(self._msg('Deleting'))
LOGGER.info(self.msg('Deleting'))
self.delete()
def activate(self):
if self._is_active:
LOGGER.error(self._msg('already activated'))
LOGGER.error(self.msg('already activated'))
return
if self.user_type == 'oidcuser':
......@@ -361,12 +361,12 @@ class User(AbstractUser):
for dep in self.deployments.all():
dep.activate()
LOGGER.info(self._msg('activated'))
LOGGER.info(self.msg('activated'))
# oidcuser: withdraw all credentials
def deactivate(self):
if not self._is_active:
LOGGER.error(self._msg('already deactivated'))
LOGGER.error(self.msg('already deactivated'))
return
if self.user_type == 'oidcuser':
......@@ -377,7 +377,7 @@ class User(AbstractUser):
for dep in self.deployments.all():
dep.deactivate()
LOGGER.info(self._msg('deactivated'))
LOGGER.info(self.msg('deactivated'))
@classmethod
......@@ -451,7 +451,7 @@ class SSHPublicKey(models.Model):
editable=False,
)
def _msg(self, msg):
def msg(self, msg):
return '[SSHPublicKey:{}] {}'.format(self, msg)
# does not directly delete the key if the key is deployed or withdrawn
......@@ -459,11 +459,11 @@ class SSHPublicKey(models.Model):
# the receiver 'delete_withdrawn_ssh_key' does the actual deletion
def delete_key(self):
if (not self.tasks.exists() and not self.deployments.exists()):
LOGGER.info(self._msg('Direct deletion of key'))
LOGGER.info(self.msg('Direct deletion of key'))
self.delete()
return
LOGGER.info(self._msg('Deletion of key started'))
LOGGER.info(self.msg('Deletion of key started'))
self.deleted = True
self.save()
......@@ -474,7 +474,7 @@ class SSHPublicKey(models.Model):
# when a key is withdrawn by a client we try to finally delete it
def try_final_deletion(self):
if (self.deleted and not self.tasks.exists()):
LOGGER.info(self._msg(
LOGGER.info(self.msg(
'All clients have withdrawn this key. Final deletion'))
self.delete()
return
......@@ -528,27 +528,27 @@ class Deployment(models.Model):
def __str__(self):
return '{}:{}'.format(self.service, self.user)
def _msg(self, msg):
def msg(self, msg):
return '[Deployment:{}] {}'.format(self, msg)
# deploy credentials which were deployed prior to deactivation
def activate(self):
if self.is_active:
LOGGER.error(self._msg('already active'))
LOGGER.error(self.msg('already active'))
return
LOGGER.debug(self._msg(str(self.ssh_keys.all())))
LOGGER.debug(self.msg(str(self.ssh_keys.all())))
for key in self.ssh_keys.all():
self._deploy_key(key)
self.is_active = True
self.save()
LOGGER.info(self._msg('activated'))
LOGGER.info(self.msg('activated'))
# withdraw all credentials
def deactivate(self):
if not self.is_active:
LOGGER.error(self._msg('already deactivated'))
LOGGER.error(self.msg('already deactivated'))
return
self.is_active = False
......@@ -557,13 +557,13 @@ class Deployment(models.Model):
for key in self.ssh_keys.all():
self._withdraw_key(key)
LOGGER.info(self._msg('deactivated'))
LOGGER.info(self.msg('deactivated'))
# only deploy the key
def _deploy_key(self, key):
# delete outstanding tasks which are made obsolete by this task
for withdrawal in self.withdrawals.filter(key=key):
LOGGER.debug(withdrawal._msg('now obsolete'))
LOGGER.debug(withdrawal.msg('now obsolete'))
withdrawal.delete()
# generate task
......@@ -573,7 +573,7 @@ class Deployment(models.Model):
key=key,
)
task.save()
LOGGER.debug(task._msg('generated'))
LOGGER.debug(task.msg('generated'))
# generate task items
for site in self.service.site.all():
......@@ -582,7 +582,7 @@ class Deployment(models.Model):
site=site,
)
deploy.save()
LOGGER.debug(deploy._msg('generated'))
LOGGER.debug(deploy.msg('generated'))
# publish the task
task.publish()
......@@ -590,7 +590,7 @@ class Deployment(models.Model):
def _withdraw_key(self, key):
# delete outstanding tasks which are made obsolete by this task
for deploy in self.deploys.filter(key=key):
LOGGER.debug(deploy._msg("now obsolete"))
LOGGER.debug(deploy.msg("now obsolete"))
deploy.delete()
# generate task
......@@ -600,7 +600,7 @@ class Deployment(models.Model):
key=key,
)
task.save()
LOGGER.debug(task._msg('generated'))
LOGGER.debug(task.msg('generated'))
# generate task items
for site in self.service.site.all():
......@@ -609,7 +609,7 @@ class Deployment(models.Model):
site=site,
)
withdrawal.save()
LOGGER.debug(withdrawal._msg('generated'))
LOGGER.debug(withdrawal.msg('generated'))
# publish the task
task.publish()
......@@ -617,7 +617,7 @@ class Deployment(models.Model):
# deploy key and track changes in the key lists
def deploy_key(self, key):
if not self.is_active:
LOGGER.error(self._msg('cannot deploy while deactivated'))
LOGGER.error(self.msg('cannot deploy while deactivated'))
raise Exception('deployment deactivated')
self.ssh_keys.add(key)
......@@ -631,7 +631,7 @@ class Deployment(models.Model):
# withdraw key and track changes in the key lists
def withdraw_key(self, key):
if not self.is_active:
LOGGER.error(self._msg('cannot withdraw while deactivated'))
LOGGER.error(self.msg('cannot withdraw while deactivated'))
raise Exception('deployment deactivated')
self.ssh_keys.remove(key)
......@@ -680,7 +680,7 @@ class DeploymentTask(models.Model):
self.id,
)
def _msg(self, msg):
def msg(self, msg):
return '[DeploymentTask:{}] {}'.format(self, msg)
def publish(self):
......@@ -696,7 +696,7 @@ class DeploymentTask(models.Model):
# the client acked the receipt and execution of the task for his site
def item_finished(self, site):
item = self.task_items.get(site=site)
LOGGER.debug(item._msg('done'))
LOGGER.debug(item.msg('done'))
item.delete()
if not self.task_items.exists():
......@@ -704,7 +704,7 @@ class DeploymentTask(models.Model):
# maintenance after all task items are done
def finished(self):
LOGGER.info(self._msg('done'))
LOGGER.info(self.msg('done'))
self.delete()
# check if this was the final withdraw in a key deletion
......@@ -731,7 +731,7 @@ class DeploymentTaskItem(models.Model):
self.id,
)
def _msg(self, msg):
def msg(self, msg):
return '[DeploymentTaskItem:{}] {}'.format(self, msg)
......
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