Commit 7137b4f6 by Bach Dániel

one: get_connect_host() ipv6 support

parent dd0841b0
......@@ -304,7 +304,7 @@ class Record(models.Model):
else:
return self.name
else: # if self.host is None
if self.name is None:
if not self.name:
return unicode(self.domain)
else:
return self.name + '.' + unicode(self.domain)
......
......@@ -13,6 +13,8 @@ sudo rabbitmqctl add_vhost django || true
sudo rabbitmqctl set_permissions -p django nyuszi '.*' '.*' '.*' || true
sudo cp /opt/webadmin/cloud/miscellaneous/devenv/boot_url.py /opt/
#Set up store server
rm -rf /var/www/*
mkdir -p /var/www
......
......@@ -14,7 +14,7 @@ from django.db.models.signals import post_save
from django import forms
from django.utils.translation import ugettext_lazy as _
from firewall.models import Host, Rule, Vlan
from firewall.models import Host, Rule, Vlan, Record
from school.models import Person, Group
from store.api import StoreApi
from .util import keygen
......@@ -403,30 +403,41 @@ class Instance(models.Model):
def get_absolute_url(self):
return ('vm_show', None, {'iid':self.id})
def get_port(self):
def get_port(self, use_ipv6=False):
"""Get public port number for default access method."""
proto = self.template.access_type
if self.template.network.nat:
if self.template.network.nat and not use_ipv6:
return {"rdp": 23000, "nx": 22000, "ssh": 22000}[proto] + int(self.ip.split('.')[2]) * 256 + int(self.ip.split('.')[3])
else:
return {"rdp": 3389, "nx": 22, "ssh": 22}[proto]
def get_connect_host(self):
def get_connect_host(self, use_ipv6=False):
"""Get public hostname."""
if self.firewall_host is None:
return _('None')
try:
if use_ipv6:
return self.firewall_host.record_set.filter(type='AAAA')[0].get_data()['name']
else:
if self.template.network.nat:
ip = self.firewall_host.pub_ipv4
return Record.objects.get(type='A', address=ip).get_data()['name']
else:
return self.firewall_host.record_set.filter(type='A')[0].get_data()['name']
except:
raise
if self.template.network.nat:
return self.firewall_host.pub_ipv4
else:
return self.firewall_host.ipv4
def get_connect_uri(self):
def get_connect_uri(self, use_ipv6=False):
"""Get access parameters in URI format."""
try:
proto = self.template.access_type
if proto == 'ssh':
proto = 'sshterm'
port = self.get_port()
host = self.get_connect_host()
port = self.get_port(use_ipv6=use_ipv6)
host = self.get_connect_host(use_ipv6=use_ipv6)
pw = self.pw
return ("%(proto)s:cloud:%(pw)s:%(host)s:%(port)d" %
{"port": port, "proto": proto, "pw": pw,
......
......@@ -35,11 +35,11 @@
</tr>
<tr>
<th>{% trans "IP" %}:</th>
<td>{{ i.get_connect_host }}</td>
<td>{{ i.hostname }}</td>
</tr>
<tr>
<th>{% trans "Port" %}:</th>
<td>{{ i.get_port}}</td>
<td>{{ i.port}}</td>
</tr>
<tr>
<th>{% trans "Username" %}:</th>
......
......@@ -94,6 +94,9 @@ def ajax_template_name_unique(request, name):
def vm_credentials(request, iid):
try:
vm = get_object_or_404(Instance, pk=iid, owner=request.user)
proto = len(request.META["REMOTE_ADDR"].split('.')) == 1
vm.hostname = vm.get_connect_host(use_ipv6=proto)
vm.port = vm.get_port(use_ipv6=proto)
return render_to_response('vm-credentials.html', RequestContext(request, { 'i' : vm }))
except:
return HttpResponse(_("Could not get Virtual Machine credentials."), status=404)
......@@ -296,6 +299,9 @@ def vm_show(request, iid):
except UserCloudDetails.DoesNotExist:
details = UserCloudDetails(user=request.user)
details.save()
proto = len(request.META["REMOTE_ADDR"].split('.')) == 1
inst.hostname = inst.get_connect_host(use_ipv6=proto)
inst.port = inst.get_port(use_ipv6=proto)
return render_to_response("show.html", RequestContext(request,{
'uri': inst.get_connect_uri(),
'state': inst.state,
......
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