Commit 29574622 by Bach Dániel

Merge branch 'feature-copy-keys' into 'master'

Add InstallKeysOperation 

See merge request !323
parents 151c90c6 bf92aeee
......@@ -76,7 +76,7 @@ class Operation(object):
user = auxargs.pop('user')
parent_activity = auxargs.pop('parent_activity')
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
skip_auth_check = True
......
......@@ -46,7 +46,6 @@ from model_utils import Choices
from acl.models import AclBase
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 .store_api import Store, NoStoreException, NotOkException, Timeout
......@@ -429,9 +428,7 @@ def add_ssh_keys(sender, **kwargs):
'user', userkey.user).filter(status='RUNNING')
for i in instances:
logger.info('called add_keys(%s, %s)', i, userkey)
queue = i.get_remote_queue_name("agent")
add_keys.apply_async(args=(i.vm_name, [userkey.key]),
queue=queue)
i.install_keys(user=userkey.user, keys=[userkey.key])
def del_ssh_keys(sender, **kwargs):
......@@ -442,9 +439,7 @@ def del_ssh_keys(sender, **kwargs):
'user', userkey.user).filter(status='RUNNING')
for i in instances:
logger.info('called del_keys(%s, %s)', i, userkey)
queue = i.get_remote_queue_name("agent")
del_keys.apply_async(args=(i.vm_name, [userkey.key]),
queue=queue)
i.remove_keys(user=userkey.user, keys=[userkey.key])
post_save.connect(add_ssh_keys, sender=UserKey)
......
......@@ -157,6 +157,16 @@
</a>
</div>
{% 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 class="col-md-8">
{% if graphite_enabled %}
......
......@@ -776,6 +776,10 @@ vm_ops = OrderedDict([
op='mount_store', icon='briefcase', effect='info',
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):
@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):
id = 'agent_started'
name = _("agent")
......@@ -1462,6 +1490,7 @@ class AgentStartedOperation(InstanceOperation):
self.instance._cleanup(parent_activity=activity)
self.instance.password_reset(
parent_activity=activity, password=self.instance.pw)
self.instance.install_keys(parent_activity=activity)
self.instance._set_time(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