1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

Added function for public key to gstfsd

This commit is contained in:
Retspen 2015-05-27 16:23:49 +03:00
parent 2d1f72a7e1
commit 0408e1d9cd
4 changed files with 73 additions and 10 deletions

View file

@ -222,6 +222,11 @@
{% trans "Root Password" %}
</a>
</li>
<li role="presentation">
<a href="#sshkeys" aria-controls="sshkeys" role="tab" data-toggle="tab">
{% trans "SSH Keys" %}
</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
@ -250,6 +255,30 @@
</form>
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="sshkeys">
<p>{% trans "You need shut down your instance and choose your public key." %}</p>
<form class="form-inline" method="post" role="form">{% csrf_token %}
<div class="form-group">
<div class="col-sm-12">
<select name="sshkeyid" class="form-control keyselect">
{% if publickeys %}
{% for key in publickeys %}
<option value="{{ key.id }}">{{ key.keyname }}</option>
{% endfor %}
{% else %}
<option value="None">{% trans "None" %}</option>
{% endif %}
</select>
</div>
</div>
{% ifequal status 5 %}
<input type="submit" class="btn btn-lg btn-success pull-right" name="addpublickey" value="{% trans "Add Public Key" %}">
{% else %}
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Add Public Key" %}</button>
{% endifequal %}
</form>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>

View file

@ -11,7 +11,7 @@ from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _
from computes.models import Compute
from instances.models import Instance
from accounts.models import UserInstance
from accounts.models import UserInstance, UserSSHKey
from vrtManager.hostdetails import wvmHostDetails
from vrtManager.instance import wvmInstance, wvmInstances
from vrtManager.connection import connection_manager
@ -139,6 +139,7 @@ def instance(request, compute_id, vname):
compute = get_object_or_404(Compute, pk=compute_id)
computes = Compute.objects.all()
computes_count = len(computes)
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
keymaps = QEMU_KEYMAPS
console_types = QEMU_CONSOLE_TYPES
try:
@ -265,9 +266,8 @@ def instance(request, compute_id, vname):
if 'rootpasswd' in request.POST:
passwd = request.POST.get('passwd', '')
passwd_hash = crypt.crypt(passwd, '$6$kgPoiREy')
data = {'passwd': passwd_hash, 'vname': vname}
data = {'action': 'password', 'passwd': passwd_hash, 'vname': vname}
if conn.get_status() == 5:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@ -286,6 +286,28 @@ def instance(request, compute_id, vname):
msg = _("Please shutdow down your instance and then try again")
error_messages.append(msg)
if 'addpublickey' in request.POST:
sshkeyid = request.POST.get('sshkeyid', '')
publickey = UserSSHKey.objects.get(id=sshkeyid)
data = {'action': 'publickey', 'key': publickey.keypublic, 'vname': vname}
if conn.get_status() == 5:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((compute.hostname, 16510))
s.send(json.dumps(data))
result = json.loads(s.recv(1024))
s.close()
msg = _("Installed new ssh public key %s" % publickey.keyname)
addlogmsg(request.user.username, instance.name, msg)
if result['return'] == 'success':
messages.append(msg)
else:
error_messages.append(msg)
else:
msg = _("Please shutdow down your instance and then try again")
error_messages.append(msg)
if 'resize' in request.POST:
vcpu = request.POST.get('vcpu', '')
cur_vcpu = request.POST.get('cur_vcpu', '')