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): ...@@ -438,10 +438,14 @@ def add_ssh_keys(sender, **kwargs):
userkey = kwargs.get('instance') userkey = kwargs.get('instance')
instances = Instance.get_objects_with_level( 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: for i in instances:
logger.info('called add_keys(%s, %s)', i, userkey) logger.info('called add_keys(%s, %s)', i, userkey)
try:
i.install_keys(user=userkey.user, keys=[userkey.key]) 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): def del_ssh_keys(sender, **kwargs):
...@@ -449,10 +453,14 @@ def del_ssh_keys(sender, **kwargs): ...@@ -449,10 +453,14 @@ def del_ssh_keys(sender, **kwargs):
userkey = kwargs.get('instance') userkey = kwargs.get('instance')
instances = Instance.get_objects_with_level( 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: for i in instances:
logger.info('called del_keys(%s, %s)', i, userkey) logger.info('called del_keys(%s, %s)', i, userkey)
try:
i.remove_keys(user=userkey.user, keys=[userkey.key]) 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) post_save.connect(add_ssh_keys, sender=UserKey)
......
...@@ -191,7 +191,8 @@ class EnsureAgentMixin(object): ...@@ -191,7 +191,8 @@ class EnsureAgentMixin(object):
try: try:
InstanceActivity.objects.filter( InstanceActivity.objects.filter(
activity_code="vm.Instance.agent.starting", 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 except InstanceActivity.DoesNotExist: # no agent since last boot
raise self.instance.NoAgentError(self.instance) 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