-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hypervisor fields to dc-hosts Cloud Host response
- Loading branch information
Showing
5 changed files
with
59 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from rest_framework import fields, serializers | ||
|
||
from ralph.assets.api.serializers import ( | ||
BaseObjectSerializer, | ||
ComponentSerializerMixin, | ||
SecurityScanField | ||
) | ||
from ralph.assets.models import BaseObject | ||
from ralph.data_center.api.serializers import DataCenterAssetSimpleSerializer | ||
from ralph.data_center.models import DCHost | ||
|
||
|
||
class DCHostSerializer(ComponentSerializerMixin, BaseObjectSerializer): | ||
hostname = fields.CharField() | ||
securityscan = SecurityScanField() | ||
hypervisor = DataCenterAssetSimpleSerializer(required=False) | ||
|
||
class Meta: | ||
model = DCHost | ||
fields = [ | ||
'id', | ||
'url', | ||
'ethernet', | ||
'ipaddresses', | ||
'custom_fields', | ||
'tags', | ||
'securityscan', | ||
'object_type', | ||
'__str__', | ||
'service_env', 'configuration_path', | ||
'hostname', | ||
'created', 'modified', 'remarks', 'parent', | ||
'configuration_variables', 'hypervisor' | ||
] | ||
|
||
|
||
class DCHostPhysicalSerializer(DCHostSerializer): | ||
model = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = BaseObject | ||
fields = DCHostSerializer.Meta.fields + ['model'] | ||
|
||
def get_model(self, obj): | ||
try: | ||
return str(obj.model) | ||
except AttributeError: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters