Skip to content

Commit

Permalink
Exporter for DCHost (allegro#2961)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurek authored Feb 15, 2017
1 parent 4ac4cc5 commit a31cf18
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ralph/data_center/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ class DCHostAdmin(RalphAdmin):
'service_env__environment',
'service_env__service',
]
resource_class = resources.DCHostResource

def has_add_permission(self, request):
return False
Expand Down
24 changes: 23 additions & 1 deletion src/ralph/data_importer/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
OfficeInfrastructure,
Warehouse
)
from ralph.data_center.models import physical
from ralph.data_center.models import hosts, physical
from ralph.data_importer.fields import ThroughField
from ralph.data_importer.mixins import (
ImportForeignKeyMeta,
Expand Down Expand Up @@ -729,3 +729,25 @@ class ConfigurationClassResource(RalphModelResource):

class Meta:
model = configuration.ConfigurationClass


class DCHostResource(RalphModelResource):
hostname = fields.Field(
readonly=True,
column_name='hostname',
attribute='hostname',
)
service_env = fields.Field(
column_name='service_env',
attribute='service_env',
widget=AssetServiceEnvWidget(assets.ServiceEnvironment, 'name'),
)
ips = fields.Field(
column_name='ip_addresses',
attribute='ipaddresses',
widget=widgets.ManyToManyWidget(model=networks.IPAddress),
)

class Meta:
model = hosts.DCHost
exclude = ('parent',)
5 changes: 5 additions & 0 deletions src/ralph/virtual/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ class Meta:
def __str__(self):
return self.hostname

@property
def ipaddresses(self):
# NetworkableBaseObject compatibility
return IPAddress.objects.filter(ethernet__base_object=self)

@property
def ip_addresses(self):
return self.ethernet_set.select_related('ipaddress').values_list(
Expand Down

0 comments on commit a31cf18

Please sign in to comment.