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

Rename method

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