Skip to content

Commit

Permalink
CloudHost and CloudProject list bug fix; Add custom fields to CloudHo…
Browse files Browse the repository at this point in the history
…st, CloudProject and VirtualServer (#2507)
  • Loading branch information
mkurek authored and ar4s committed Jun 30, 2016
1 parent b8716c2 commit 8b7f43e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/ralph/virtual/admin.py
Expand Up @@ -11,6 +11,7 @@
)
from ralph.assets.models.components import Ethernet
from ralph.data_center.models.virtual import BaseObjectCluster
from ralph.lib.custom_fields.admin import CustomFieldValueAdminMixin
from ralph.lib.transitions.admin import TransitionAdminMixin
from ralph.networks.forms import SimpleNetworkForm
from ralph.networks.views import NetworkView
Expand Down Expand Up @@ -41,7 +42,9 @@ class VirtualServerNetworkView(NetworkView):


@register(VirtualServer)
class VirtualServerAdmin(TransitionAdminMixin, RalphAdmin):
class VirtualServerAdmin(
CustomFieldValueAdminMixin, TransitionAdminMixin, RalphAdmin
):
form = VirtualServerForm
search_fields = ['hostname', 'sn']
list_filter = [
Expand Down Expand Up @@ -105,9 +108,9 @@ def get_hypervisor(self, obj):
get_hypervisor.allow_tags = True

def get_ip_addresses(self, obj):
ips = obj.ethernet.values_list(
'ipaddress', flat=True
).select_related('ipaddress').all()
ips = obj.ethernet_set.values_list(
'ipaddress__address', flat=True
)
if not ips:
return '–'
return '\n'.join(ips)
Expand Down Expand Up @@ -143,7 +146,7 @@ def has_add_permission(self, request, obj=None):


@register(CloudHost)
class CloudHostAdmin(RalphAdmin):
class CloudHostAdmin(CustomFieldValueAdminMixin, RalphAdmin):
list_display = ['hostname', 'get_ip_addresses', 'service_env',
'get_cloudproject', 'cloudflavor_name', 'host_id',
'created', 'image_name', 'get_tags']
Expand Down Expand Up @@ -219,7 +222,7 @@ def cloudflavor_name(self, obj):
cloudflavor_name.allow_tags = True

def get_ip_addresses(self, obj):
ips = obj.ethernet.values_list(
ips = obj.ethernet_set.values_list(
'ipaddress__address', flat=True
).select_related('ipaddress').all()
if not ips:
Expand Down Expand Up @@ -303,7 +306,7 @@ def instances_count(self, obj):


@register(CloudProject)
class CloudProjectAdmin(RalphAdmin):
class CloudProjectAdmin(CustomFieldValueAdminMixin, RalphAdmin):
fields = ['name', 'project_id', 'cloudprovider', 'service_env', 'tags',
'remarks', 'instances_count']
list_display = ['name', 'service_env', 'instances_count']
Expand Down

0 comments on commit 8b7f43e

Please sign in to comment.