Merge remote-tracking branch 'ungleich/master'
This commit is contained in:
commit
b256199d82
1 changed files with 36 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
|
from builtins import hasattr
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from oca import OpenNebulaException
|
from oca import OpenNebulaException
|
||||||
|
@ -115,15 +116,30 @@ class VirtualMachineSerializer(serializers.Serializer):
|
||||||
return template.name.strip('public-')
|
return template.name.strip('public-')
|
||||||
|
|
||||||
def get_ipv4(self, obj):
|
def get_ipv4(self, obj):
|
||||||
nic = obj.template.nics[0]
|
"""
|
||||||
if 'vm-ipv6-nat64-ipv4' in nic.network and is_in_v4_range(nic.mac):
|
Get the IPv4s from the given VM
|
||||||
return str(v4_from_mac(nic.mac))
|
|
||||||
|
:param obj: The VM in contention
|
||||||
|
:return: Returns csv string of all IPv4s added to this VM otherwise returns "-" if no IPv4 is available
|
||||||
|
"""
|
||||||
|
ipv4 = []
|
||||||
|
for nic in obj.template.nics:
|
||||||
|
if hasattr(nic, 'ip'):
|
||||||
|
ipv4.append(nic.ip)
|
||||||
|
if len(ipv4) > 0:
|
||||||
|
return ', '.join(ipv4)
|
||||||
else:
|
else:
|
||||||
return '-'
|
return '-'
|
||||||
|
|
||||||
def get_ipv6(self, obj):
|
def get_ipv6(self, obj):
|
||||||
nic = obj.template.nics[0]
|
ipv6 = []
|
||||||
return nic.ip6_global
|
for nic in obj.template.nics:
|
||||||
|
if hasattr(nic, 'ip6_global'):
|
||||||
|
ipv6.append(nic.ip6_global)
|
||||||
|
if len(ipv6) > 0:
|
||||||
|
return ', '.join(ipv6)
|
||||||
|
else:
|
||||||
|
return '-'
|
||||||
|
|
||||||
def get_name(self, obj):
|
def get_name(self, obj):
|
||||||
return obj.name.strip('public-')
|
return obj.name.strip('public-')
|
||||||
|
|
Loading…
Reference in a new issue