Commit 893d31b6 by Dudás Ádám

Merge branch 'master' of ssh://giccero.cloud.ik.bme.hu/cloud

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