Show ipv6 address

This commit is contained in:
modulos 2017-05-23 11:30:10 +02:00
parent 4c8a4d0be8
commit adf9b77e4e
2 changed files with 15 additions and 5 deletions

View file

@ -41,11 +41,17 @@
<div class="col-md-12 inline-headers"> <div class="col-md-12 inline-headers">
<h3>{{virtual_machine.hosting_company_name}}</h3> <h3>{{virtual_machine.hosting_company_name}}</h3>
{% if virtual_machine.ip %} {% if virtual_machine.ipv6 %}
<div class="pull-right right-place"> <div class="pull-right right-place">
<button type="link" data-clipboard-text="{{virtual_machine.ip}}" id="copy_vm_id" class="to_copy btn btn-link" <button type="link"
data-clipboard-text="{{virtual_machine.ipv4}}" id="copy_vm_id" class="to_copy btn btn-link"
data-toggle="tooltip" data-placement="bottom" title="Copied" data-trigger="click"> data-toggle="tooltip" data-placement="bottom" title="Copied" data-trigger="click">
Ip: {{virtual_machine.ip}} <i class="fa fa-files-o" aria-hidden="true"></i> Ipv4: {{virtual_machine.ipv4}} <i class="fa fa-files-o" aria-hidden="true"></i>
</button>
<button type="link"
data-clipboard-text="{{virtual_machine.ipv6}}" id="copy_vm_id" class="to_copy btn btn-link"
data-toggle="tooltip" data-placement="bottom" title="Copied" data-trigger="click">
Ipv6: {{virtual_machine.ipv6}} <i class="fa fa-files-o" aria-hidden="true"></i>
</button> </button>
</div> </div>
{% else %} {% else %}

View file

@ -88,7 +88,8 @@ class VirtualMachineSerializer(serializers.Serializer):
disk_size = serializers.SerializerMethodField() disk_size = serializers.SerializerMethodField()
ip = serializers.SerializerMethodField() ipv4 = serializers.SerializerMethodField()
ipv6 = serializers.SerializerMethodField()
vm_id = serializers.IntegerField(read_only=True, source='id') vm_id = serializers.IntegerField(read_only=True, source='id')
state = serializers.CharField(read_only=True, source='str_state') state = serializers.CharField(read_only=True, source='str_state')
price = serializers.SerializerMethodField() price = serializers.SerializerMethodField()
@ -153,13 +154,16 @@ class VirtualMachineSerializer(serializers.Serializer):
template = OpenNebulaManager().get_template(template_id) template = OpenNebulaManager().get_template(template_id)
return template.name return template.name
def get_ip(self, obj): def get_ipv4(self, obj):
nic = obj.template.nics[0] nic = obj.template.nics[0]
if 'vm-ipv6-nat64-ipv4' in nic.network and is_in_v4_range(nic.mac): if 'vm-ipv6-nat64-ipv4' in nic.network and is_in_v4_range(nic.mac):
return str(v4_from_mac(nic.mac)) return str(v4_from_mac(nic.mac))
else: else:
return '-' return '-'
def get_ipv6(self, obj):
nic = obj.template.nics[0]
return nic.ip6_global
def hexstr2int(string): def hexstr2int(string):