Commit acb2f78f by Kálmán Viktor

Merge branch 'agentfix' into 'master'

Fix agent errors

See merge request !343
parents 8981961e a0ed9745
......@@ -438,10 +438,14 @@ def add_ssh_keys(sender, **kwargs):
userkey = kwargs.get('instance')
instances = Instance.get_objects_with_level(
'user', userkey.user).filter(status='RUNNING')
'user', userkey.user, disregard_superuser=True
).filter(status='RUNNING')
for i in instances:
logger.info('called add_keys(%s, %s)', i, userkey)
i.install_keys(user=userkey.user, keys=[userkey.key])
try:
i.install_keys(user=userkey.user, keys=[userkey.key])
except Instance.NoAgentError:
logger.info("%s has no agent running", i)
def del_ssh_keys(sender, **kwargs):
......@@ -449,10 +453,14 @@ def del_ssh_keys(sender, **kwargs):
userkey = kwargs.get('instance')
instances = Instance.get_objects_with_level(
'user', userkey.user).filter(status='RUNNING')
'user', userkey.user, disregard_superuser=True
).filter(status='RUNNING')
for i in instances:
logger.info('called del_keys(%s, %s)', i, userkey)
i.remove_keys(user=userkey.user, keys=[userkey.key])
try:
i.remove_keys(user=userkey.user, keys=[userkey.key])
except Instance.NoAgentError:
logger.info("%s has no agent running", i)
post_save.connect(add_ssh_keys, sender=UserKey)
......
......@@ -191,7 +191,8 @@ class EnsureAgentMixin(object):
try:
InstanceActivity.objects.filter(
activity_code="vm.Instance.agent.starting",
started__gt=last_boot_time).latest("started")
started__gt=last_boot_time, instance=self.instance
).latest("started")
except InstanceActivity.DoesNotExist: # no agent since last boot
raise self.instance.NoAgentError(self.instance)
......
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 sign in to comment