Commit 0dbc3afe by Őry Máté

network: fix ipv6 conversion

parent bb9f818b
...@@ -414,6 +414,8 @@ class Vlan(AclBase, models.Model): ...@@ -414,6 +414,8 @@ class Vlan(AclBase, models.Model):
def convert_ipv4_to_ipv6(self, ipv4): def convert_ipv4_to_ipv6(self, ipv4):
"""Convert IPv4 address string to IPv6 address string.""" """Convert IPv4 address string to IPv6 address string."""
if isinstance(ipv4, basestring):
ipv4 = IPAddress(ipv4, 4)
nums = {ascii_letters[i]: int(ipv4.words[i]) for i in range(4)} nums = {ascii_letters[i]: int(ipv4.words[i]) for i in range(4)}
return IPAddress(self.ipv6_template % nums) return IPAddress(self.ipv6_template % nums)
......
...@@ -444,18 +444,18 @@ class HostCreate(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -444,18 +444,18 @@ class HostCreate(LoginRequiredMixin, SuperuserRequiredMixin,
def _get_ajax(self, *args, **kwargs): def _get_ajax(self, *args, **kwargs):
GET = self.request.GET GET = self.request.GET
result = {} result = {}
if "vlan" in GET: vlan = get_object_or_404(Vlan.objects, pk=GET.get("vlan", ""))
vlan = get_object_or_404(Vlan.objects, pk=GET["vlan"])
try:
result.update(vlan.get_new_address())
except ValidationError:
result["ipv4"] = ""
result["ipv6"] = ""
if "ipv4" in GET: if "ipv4" in GET:
try: try:
result["ipv6"] = vlan.convert_ipv4_to_ipv6(GET["ipv4"]) result["ipv6"] = vlan.convert_ipv4_to_ipv6(GET["ipv4"])
except: except:
result["ipv6"] = "" result["ipv6"] = ""
else:
try:
result.update(vlan.get_new_address())
except ValidationError:
result["ipv4"] = ""
result["ipv6"] = ""
return JsonResponse({k: unicode(result[k] or "") for k in result}) return JsonResponse({k: unicode(result[k] or "") for k in result})
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
......
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