Commit bf92aeee by Bach Dániel

vm: add InstallKeysOperation

parent 77a4efd9
...@@ -76,7 +76,7 @@ class Operation(object): ...@@ -76,7 +76,7 @@ class Operation(object):
user = auxargs.pop('user') user = auxargs.pop('user')
parent_activity = auxargs.pop('parent_activity') parent_activity = auxargs.pop('parent_activity')
if parent_activity and user is None and not skip_auth_check: if parent_activity and user is None and not skip_auth_check:
user = parent_activity.user user = allargs['user'] = parent_activity.user
if user is None: # parent was a system call if user is None: # parent was a system call
skip_auth_check = True skip_auth_check = True
......
...@@ -46,7 +46,6 @@ from model_utils import Choices ...@@ -46,7 +46,6 @@ from model_utils import Choices
from acl.models import AclBase from acl.models import AclBase
from common.models import HumanReadableObject, create_readable, Encoder from common.models import HumanReadableObject, create_readable, Encoder
from vm.tasks.agent_tasks import add_keys, del_keys
from vm.models.instance import ACCESS_METHODS from vm.models.instance import ACCESS_METHODS
from .store_api import Store, NoStoreException, NotOkException, Timeout from .store_api import Store, NoStoreException, NotOkException, Timeout
...@@ -409,9 +408,7 @@ def add_ssh_keys(sender, **kwargs): ...@@ -409,9 +408,7 @@ def add_ssh_keys(sender, **kwargs):
'user', userkey.user).filter(status='RUNNING') 'user', userkey.user).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)
queue = i.get_remote_queue_name("agent") i.install_keys(user=userkey.user, keys=[userkey.key])
add_keys.apply_async(args=(i.vm_name, [userkey.key]),
queue=queue)
def del_ssh_keys(sender, **kwargs): def del_ssh_keys(sender, **kwargs):
...@@ -422,9 +419,7 @@ def del_ssh_keys(sender, **kwargs): ...@@ -422,9 +419,7 @@ def del_ssh_keys(sender, **kwargs):
'user', userkey.user).filter(status='RUNNING') 'user', userkey.user).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)
queue = i.get_remote_queue_name("agent") i.remove_keys(user=userkey.user, keys=[userkey.key])
del_keys.apply_async(args=(i.vm_name, [userkey.key]),
queue=queue)
post_save.connect(add_ssh_keys, sender=UserKey) post_save.connect(add_ssh_keys, sender=UserKey)
......
...@@ -157,6 +157,16 @@ ...@@ -157,6 +157,16 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
{% if op.install_keys %}
<strong>{% trans "SSH keys" %}</strong>
<div class="operation-wrapper">
<a href="{{ op.install_keys.get_url }}" class="btn btn-info btn-xs operation"
{% if op.install_keys.disabled %}disabled{% endif %}>
<i class="fa fa-{{op.install_keys.icon}}"></i>
{{ op.install_keys.name }}
</a>
</div>
{% endif %}
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
{% if graphite_enabled %} {% if graphite_enabled %}
......
...@@ -771,6 +771,10 @@ vm_ops = OrderedDict([ ...@@ -771,6 +771,10 @@ vm_ops = OrderedDict([
op='mount_store', icon='briefcase', effect='info', op='mount_store', icon='briefcase', effect='info',
show_in_toolbar=False, show_in_toolbar=False,
)), )),
('install_keys', VmOperationView.factory(
op='install_keys', icon='key', effect='info',
show_in_toolbar=False,
)),
]) ])
......
...@@ -1390,6 +1390,34 @@ class PasswordResetOperation(RemoteAgentOperation): ...@@ -1390,6 +1390,34 @@ class PasswordResetOperation(RemoteAgentOperation):
@register_operation @register_operation
class InstallKeysOperation(RemoteAgentOperation):
id = 'install_keys'
name = _("install SSH keys")
acl_level = "user"
task = agent_tasks.add_keys
required_perms = ()
def _get_remote_args(self, user, keys=None, **kwargs):
if keys is None:
keys = list(user.userkey_set.values_list('key', flat=True))
return (super(InstallKeysOperation, self)._get_remote_args(**kwargs)
+ [keys])
@register_operation
class RemoveKeysOperation(RemoteAgentOperation):
id = 'remove_keys'
name = _("remove SSH keys")
acl_level = "user"
task = agent_tasks.del_keys
required_perms = ()
def _get_remote_args(self, user, keys, **kwargs):
return (super(RemoveKeysOperation, self)._get_remote_args(**kwargs)
+ [keys])
@register_operation
class AgentStartedOperation(InstanceOperation): class AgentStartedOperation(InstanceOperation):
id = 'agent_started' id = 'agent_started'
name = _("agent") name = _("agent")
...@@ -1462,6 +1490,7 @@ class AgentStartedOperation(InstanceOperation): ...@@ -1462,6 +1490,7 @@ class AgentStartedOperation(InstanceOperation):
self.instance._cleanup(parent_activity=activity) self.instance._cleanup(parent_activity=activity)
self.instance.password_reset( self.instance.password_reset(
parent_activity=activity, password=self.instance.pw) parent_activity=activity, password=self.instance.pw)
self.instance.install_keys(parent_activity=activity)
self.instance._set_time(parent_activity=activity) self.instance._set_time(parent_activity=activity)
self.instance._set_hostname(parent_activity=activity) self.instance._set_hostname(parent_activity=activity)
......
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