Ejemplo n.º 1
0
def get_icon_for(ci):
    if not ci or not ci.content_object:
        return
    if ci.content_type.name == 'venture':
        return get_venture_icon(ci.content_object)
    elif ci.content_type.name == 'device':
        return get_device_icon(ci.content_object)
    elif ci.content_type.name == 'network':
        return get_network_icon(ci.content_object)
Ejemplo n.º 2
0
def get_icon_for(ci):
    if not ci or not ci.content_object:
        return
    if ci.content_type.name == "venture":
        return get_venture_icon(ci.content_object)
    elif ci.content_type.name == "device":
        return get_device_icon(ci.content_object)
    elif ci.content_type.name == "network":
        return get_network_icon(ci.content_object)
Ejemplo n.º 3
0
def get_icon_for(ci):
    if not ci or not ci.content_object:
        return
    if ci.content_type.name == 'venture':
        return get_venture_icon(ci.content_object)
    elif ci.content_type.name == 'device':
        return get_device_icon(ci.content_object)
    elif ci.content_type.name == 'network':
        return get_network_icon(ci.content_object)
Ejemplo n.º 4
0
def collect_ventures(parent, ventures, items, depth=0):
    for v in ventures.filter(parent=parent):
        symbol = _normalize_venture(v.symbol)
        indent = ' ' * depth
        icon = presentation.get_venture_icon(v)
        if icon == 'fugue-store':
            if depth>0:
                icon = 'fugue-store-medium'
            if depth>1:
                icon = 'fugue-store-small'
        items.append((icon, v.name, symbol, indent, v))
        collect_ventures(v, ventures, items, depth + 1)
Ejemplo n.º 5
0
def venture_tree_menu(ventures, details, show_all=False):
    items = []
    if not show_all:
        ventures = ventures.filter(show_in_ralph=True)
    for v in ventures.order_by('-is_infrastructure', 'name'):
        symbol = _normalize_venture(v.symbol)
        icon = presentation.get_venture_icon(v)
        item = MenuItem(
            v.name, name=symbol,
            fugue_icon=icon,
            view_name='ventures',
            view_args=[symbol, details, ''],
            indent = ' ',
            collapsed = True,
            collapsible = True,
        )
        item.venture_id = v.id
        item.subitems = venture_tree_menu(
                v.child_set.all(), details, show_all)
        for subitem in item.subitems:
            subitem.parent = item
        items.append(item)
    return items
Ejemplo n.º 6
0
def _report_ventures_data_provider(start, end, ventures_ids, extra_types):
    ventures = Venture.objects.filter(id__in=ventures_ids).order_by('path')
    total_cloud_cost = get_total_cost(
        HistoryCost.objects.filter(
            device__model__type=DeviceType.cloud_server.id, ),
        start,
        end,
    )
    result = []
    for venture in ventures:
        query = HistoryCost.objects.filter(
            db.Q(venture=venture) | db.Q(venture__parent=venture)
            | db.Q(venture__parent__parent=venture)
            | db.Q(venture__parent__parent__parent=venture)
            | db.Q(venture__parent__parent__parent__parent=venture)).exclude(
                device__deleted=True)
        data = _report_ventures_get_totals(start, end, query, extra_types)
        (
            splunk_cost,
            splunk_count,
            splunk_count_now,
            splunk_size,
        ) = SplunkUsage.get_cost(venture, start, end)
        data.update({
            'id':
            venture.id,
            'name':
            venture.name,
            'symbol':
            venture.symbol,
            'path':
            venture.path,
            'department':
            unicode(venture.department or ''),
            'margin':
            venture.get_margin(),
            'top_level':
            venture.parent is None,
            'venture_icon':
            get_venture_icon(venture),
            'cloud_use': ((data['cloud_cost'] or 0) /
                          total_cloud_cost) if total_cloud_cost else 0,
            'splunk_cost':
            splunk_cost,
        })
        result.append(data)
        if venture.parent is not None:
            continue
        if not venture.child_set.exists():
            continue
        query = HistoryCost.objects.filter(venture=venture)
        data = _report_ventures_get_totals(start, end, query, extra_types)
        (
            splunk_cost,
            splunk_count,
            splunk_count_now,
            splunk_size,
        ) = SplunkUsage.get_cost(venture, start, end, shallow=True)
        data.update({
            'id':
            venture.id,
            'name':
            '-',
            'symbol':
            venture.symbol,
            'path':
            venture.path,
            'department':
            unicode(venture.department or ''),
            'margin':
            venture.get_margin(),
            'top_level':
            False,
            'venture_icon':
            get_venture_icon(venture),
            'cloud_use': ((data['cloud_cost'] or 0) /
                          total_cloud_cost) if total_cloud_cost else 0,
            'splunk_cost':
            splunk_cost,
        })
        result.append(data)
    return result
Ejemplo n.º 7
0
def venture_icon(venture):
    return icon_filter(presentation.get_venture_icon(venture))
Ejemplo n.º 8
0
def venture_icon(venture):
    return icon_filter(presentation.get_venture_icon(venture))
Ejemplo n.º 9
0
def _report_ventures_data_provider(start, end, ventures_ids, extra_types):
    ventures = Venture.objects.filter(id__in=ventures_ids).order_by('path')
    total_cloud_cost = get_total_cost(
        HistoryCost.objects.filter(
            device__model__type=DeviceType.cloud_server.id,
        ),
        start,
        end,
    )
    result = []
    for venture in ventures:
        query = HistoryCost.objects.filter(
            db.Q(venture=venture) |
            db.Q(venture__parent=venture) |
            db.Q(venture__parent__parent=venture) |
            db.Q(venture__parent__parent__parent=venture) |
            db.Q(venture__parent__parent__parent__parent=venture)
        ).exclude(device__deleted=True)
        data = _report_ventures_get_totals(start, end, query, extra_types)
        (
            splunk_cost,
            splunk_count,
            splunk_count_now,
            splunk_size,
        ) = SplunkUsage.get_cost(venture, start, end)
        data.update({
            'id': venture.id,
            'name': venture.name,
            'symbol': venture.symbol,
            'path': venture.path,
            'department': unicode(venture.department or ''),
            'margin': venture.get_margin(),
            'top_level': venture.parent is None,
            'venture_icon': get_venture_icon(venture),
            'cloud_use': (
                (data['cloud_cost'] or 0) / total_cloud_cost
            ) if total_cloud_cost else 0,
            'splunk_cost': splunk_cost,
        })
        result.append(data)
        if venture.parent is not None:
            continue
        if not venture.child_set.exists():
            continue
        query = HistoryCost.objects.filter(venture=venture)
        data = _report_ventures_get_totals(start, end, query, extra_types)
        (
            splunk_cost,
            splunk_count,
            splunk_count_now,
            splunk_size,
        ) = SplunkUsage.get_cost(venture, start, end, shallow=True)
        data.update({
            'id': venture.id,
            'name': '-',
            'symbol': venture.symbol,
            'path': venture.path,
            'department': unicode(venture.department or ''),
            'margin': venture.get_margin(),
            'top_level': False,
            'venture_icon': get_venture_icon(venture),
            'cloud_use': (
                (data['cloud_cost'] or 0) / total_cloud_cost
            ) if total_cloud_cost else 0,
            'splunk_cost': splunk_cost,
        })
        result.append(data)
    return result