Remove public- from vm name

This commit is contained in:
modulos 2017-05-26 23:23:39 +02:00
parent 00f9f6bb76
commit 2582e31868
2 changed files with 12 additions and 1 deletions

View file

@ -79,7 +79,7 @@ class VirtualMachineTemplateSerializer(serializers.Serializer):
class VirtualMachineSerializer(serializers.Serializer):
"""Serializer to map the virtual machine instance into JSON format."""
name = serializers.CharField(read_only=True)
name = serializers.SerializerMethodField()
cores = serializers.IntegerField(source='template.vcpu')
disk = serializers.IntegerField(write_only=True)
set_memory = serializers.IntegerField(write_only=True, label='Memory')
@ -164,6 +164,8 @@ class VirtualMachineSerializer(serializers.Serializer):
nic = obj.template.nics[0]
return nic.ip6_global
def get_name(self, obj):
return obj.name.strip('public-')
def hexstr2int(string):
return int(string.replace(':', ''), 16)

View file

@ -114,6 +114,15 @@ class VirtualMachineTestCase(TestCase):
self.virtualmachine = VirtualMachine(opennebula_id=self.opennebula_id,
template=self.template)
def test_serializer_strips_of_public(self):
""" Test the serialized object contains no 'public-'."""
template = self.manager.get_templates().first()
serialized = VirtualMachineTemplateSerializer(template)
self.assertEqual(serialized.data.name, template.name.strip('public-'))
def test_model_can_create_a_virtualmachine(self):
"""Test the virtualmachine model can create a virtualmachine."""
old_count = VirtualMachine.objects.count()