Skip to content

Commit

Permalink
Merge aaf1a57 into 218ceb6
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurek committed Jul 31, 2014
2 parents 218ceb6 + aaf1a57 commit 5a47523
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/ralph/util/api_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.db import models as db

from ralph.business.models import Venture, VentureExtraCost
from ralph.cmdb.models import CI, CIOwner, CIType
from ralph.discovery.models import (
Device,
DeviceType,
Expand Down Expand Up @@ -302,3 +303,58 @@ def get_fc_cards():
'id': fc['id'],
'device_id': fc['device__id'],
}


# CMDB
def get_business_lines():
"""
Returns Business Lines from CMDB (CIs with type Business Line)
"""
business_line_type = CIType.objects.get(name='BusinessLine')
for business_line in CI.objects.filter(type=business_line_type):
yield {
'ci_uid': business_line.uid,
'name': business_line.name,
}


def get_owners():
"""
Returns CIOwners from CMDB
"""
for owner in CIOwner.objects.all():
yield {
'id': owner.id,
'first_name': owner.first_name,
'last_name': owner.last_name,
'email': owner.email,
'sAMAccountName': owner.sAMAccountName,
}


def get_services():
"""
Returns Services (CIs with type Service) with additional information like
owners, business line etc.
"""
service_type = CIType.objects.get(name='Service')
business_line_type = CIType.objects.get(name='BusinessLine')
for service in CI.objects.filter(
type=service_type
).select_related('owners'):
business_line = service.child.filter(
parent__type=business_line_type
).values_list('parent__uid', flat=True)
yield {
'ci_uid': service.uid,
'name': service.name,
'business_line': business_line[0] if business_line else None,
'business_owners': service.business_owners.values_list(
'id',
flat=True,
),
'technical_owners': service.technical_owners.values_list(
'id',
flat=True,
),
}

0 comments on commit 5a47523

Please sign in to comment.