Esempio n. 1
0
def hosts_capacity_history(request):
    objs = sfilter(HostCapacityHistory, request)
    objs = objs.exclude(Hosts__startswith='[]')
    fields = HostCapacityHistory._meta.get_all_field_names()
    fields.remove('id')
    fields.remove('Storage')
    fields.remove('Date')

    cols, rows_ = stable(HostCapacityHistory, objs, fields=['Storage', 'Hosts'])

    rows = []
    for row in rows_:
        if not row in rows:
            rows.append(row)

    fieldsvalues = {x: [] for x in fields}
    dates = sorted([x[0] for x in objs.values_list('Date').distinct()])
    storages = sorted([x[0] for x in objs.values_list('Storage').distinct()])
    for date in dates:
        date_objs = objs.filter(Date__contains=date)
        for field in ['Size',]:
            value = list(date_objs.aggregate(Sum(field)).values())[0]
            value = value/1024
            fieldsvalues[field].append(value)
    data = {
        'storages': storages,
        'dates': dates,
        'fieldsvalues': fieldsvalues,
        'visible_series': ['Size'],
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'da/hosts_capacity_history.html', data)
Esempio n. 2
0
def switches(request):
    objs = sfilter(SwitchCommon, request)
    cols, rows = stable(SwitchCommon, objs)
    data = {
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'table.html', data)
Esempio n. 3
0
def mezzanines(request):
    objs = sfilter(Mezzanine, request)
    cols, rows = stable(Mezzanine, objs)
    data = {
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'table.html', data)
Esempio n. 4
0
def enclosures(request):
    objs = sfilter(Enclosure, request)
    cols, rows = stable(Enclosure, objs)
    data = {
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'table.html', data)
Esempio n. 5
0
def hosts(request):
    objects = sfilter(Host, request)
    cols, rows = stable(Host, objects)
    data = {
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'table.html', data)
Esempio n. 6
0
def servers(request):
    objs = sfilter(Server, request)
    cols, rows = stable(Server, objs)
    cols0 = [col.replace('_', ' ') for col in cols]
    data = {
        'cols0': cols0,
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'en/table.html', data)
Esempio n. 7
0
def capacity(request):
    objs = sfilter(Capacity, request)
    sum_row = sum_by_field(Capacity, objs)
    data = {
        'objs': objs,
        'sum_row': sum_row,
        'integer': 'TB',
        'visible_series': ['FormattedPresented', 'FormattedNotPresented', 'FormattedAvailable'],
    }
    return render(request, 'da/capacity.html', data)
Esempio n. 8
0
def hosts_capacity(request):
    objects = sfilter(HostCapacity, request)
    cols, rows = stable(HostCapacity, objects)
    sum_row = sum_by_field_to_list(HostCapacity, objects, ['Size'])
    data = {
        'cols': cols,
        'rows': rows,
        'sum_row':sum_row,
    }
    return render(request, 'table.html', data)
Esempio n. 9
0
def ports(request):
    objs = sfilter(PortCommon, request)
    cols, rows = stable(PortCommon, objs)
    for row in rows:
        for index, cell in enumerate(row):
            if type(cell) == list:
                row[index] = '<br>'.join(cell)
    data = {
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'table.html', data)
Esempio n. 10
0
def zones(request):
    objs = sfilter(ZoneStatus, request)
    cols, rows = stable(ZoneStatus, objs)
    for row in rows:
        for index, cell in enumerate(row):
            if type(cell) == dict:
                row[index] = fix_cell(cell)
    data = {
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'table.html', data)
Esempio n. 11
0
def volumes(request):
    objects = sfilter(Volume, request)
    cols, rows = stable(Volume, objects)
    for row in rows:
        #for value in row:
            value = row[2]
            if value.startswith('.'):
                row[2] = value.replace('.', '_')
    data = {
        'cols': cols,
        'rows': rows,
    }
    return render(request, 'table.html', data)
Esempio n. 12
0
def fabriclog(request):
    if request.GET.get('dt') is None:
        try:
            dt10 = str(Portlog.objects.last().dt)[:7]
        except:
            dt10 = str(datetime.now())[:7]
        return redirect('/fc/fabriclog/?dt={}'.format(dt10))

    objs = sfilter(Fabriclog, request)
    cols, _ = stable(Portlog, [])

    if not objs:
        data = {
            'cols': cols,
            'warning': 'No data for this select. Please refine select.',
        }

    cols, rows = stable(Fabriclog, objs)

    actions = {}
    swports = {}
    for obj in objs:
        action = obj.action.split(';')[0]
        swport = '{} {}'.format(obj.switch, obj.Port)
        if not action in actions:
            actions[action] = 0
        actions[action] += 1
        if not swport in swports:
            swports[swport] = 0
        swports[swport] += 1
    
    for swport in swports.copy():
        try:
            switch, index = swport.split()
            portname = PortCommon.objects.get(Switch=switch, Index=index).portName
            swports['{} {}'.format(swport, portname)] = swports.pop(swport)
        except:
            pass

    data = {
        'cols': cols,
        'rows': rows,
        'actions': sorted(list(actions.items()), key=itemgetter(1), reverse=True),
        'swports': sorted(list(swports.items()), key=itemgetter(1), reverse=True),
    }
    return render(request, 'fc/fabriclog.html', data)
Esempio n. 13
0
def changes(request):
    field_latest = 'id'
    if request.is_ajax():
        data = {}
        try:
            if Change.objects.latest(field_latest).id != int(request.POST.get('last_obj_id')):
                data = {'refresh': True}
        except:
            pass
        return HttpResponse(json.dumps(data), content_type='application/json')

    objs = sfilter(Change, request)
    last_obj_id = objs.latest(field_latest).id if objs else None

    data = {
        'objs': objs,
        'last_obj_id': last_obj_id,
    }
    return render(request, 'fc/changes.html', data)
Esempio n. 14
0
def capacity_3par_history(request):
    objs = sfilter(TPARCapacityHistory, request)
    fields = TPARCapacityHistory._meta.get_all_field_names()
    fields.remove('id')
    fields.remove('Storage')
    fields.remove('Date')
    fieldsvalues = {x: [] for x in fields}
    dates = sorted([x[0] for x in objs.values_list('Date').distinct()])
    storages = sorted([x[0] for x in objs.values_list('Storage').distinct()])
    for date in dates:
        date_objs = objs.filter(Date__contains=date)
        for field in fields:
            value = list(date_objs.aggregate(Sum(field)).values())[0]
            fieldsvalues[field].append(value)
    data = {
        'storages': storages,
        'dates': dates,
        'fieldsvalues': fieldsvalues,
        'visible_series': ['tpvv_used', 'tpvv_free'],
    }
    return render(request, 'da/capacity_3par_history.html', data)
Esempio n. 15
0
def changes(request):
    def ch_format(old, new):
        return '<del>{}</del> <span style class="t_red">>></span> <strong>{}</strong>'.format(old, new)

    objs = sfilter(VolumeChange, request)

    objs_x = objs.exclude(Action_Flag='new')
    for obj in objs_x:
        if obj.Action_Flag == 'old':
            try:
                new_obj = objs.get(Till=obj.Till, Storage=obj.Storage, Uid=obj.Uid, Action_Flag='new')
                if obj.Name != new_obj.Name:
                    obj.Name = ch_format(obj.Name, new_obj.Name)
                if obj.Size != new_obj.Size:
                    obj.Size = ch_format(obj.Size, new_obj.Size)
                if obj.Hosts != new_obj.Hosts:
                    obj.Hosts = ch_format(obj.Hosts, new_obj.Hosts)
            except:
                pass

    data = {
        'objs': objs_x,
    }
    return render(request, 'da/changes.html', data)
Esempio n. 16
0
def capacity_3par(request):
    objs = sfilter(TPARCapacity, request)
    data = {
        'objs': objs
    }
    return render(request, 'da/capacity_3par.html', data)
Esempio n. 17
0
def portlog(request):

    if request.GET.get('dt') is None:
        try:
            dt10 = str(Portlog.objects.last().dt)[:19]
        except:
            dt10 = '2016-01-01 00:00'
        return redirect('/fc/portlog/?dt={}'.format(dt10))

    objs = sfilter(Portlog, request)
    cols, _ = stable(Portlog, [])

    if len(objs) > 10000:
        data = {
            'cols': cols,
            'warning': 'More than 10000 records. Please refine select.',
        }
        return render(request, 'fc/portlog.html', data)

    if not objs:
        data = {
            'cols': cols,
            'warning': 'No data for this select. Please refine select.',
        }
    
        return render(request, 'fc/portlog.html', data)

    cols, rows = stable(Portlog, objs)


    events = {}
    swports = {}
    for obj in objs:
        event = '{} {}'.format(obj.task, obj.event)
        swport = '{} {}'.format(obj.switch, obj.port)
        if not event in events:
            events[event] = 0
        events[event] += 1
        if not swport in swports:
            swports[swport] = 0
        swports[swport] += 1


    matrix = {}
    dts = set()
    for obj in objs:
        swport = '{} {}'.format(obj.switch, obj.port)
        if not swport in matrix:
            matrix[swport] = set()
        dt = obj.dt.replace(microsecond=0)
        matrix[swport].add(dt)
        dts.add(dt)
    
    period = [min(dts)+timedelta(seconds=s) for s in range((max(dts)-min(dts)).seconds+1)]
    xlist = []
    for swport, values in matrix.items():
        xlist.append([swport, ['x' if s in values else '' if s in dts else '-' for s in period]])

    secdict = {}
    for sec in period:
        minute = sec.replace(second=0)
        if not minute in secdict:
            secdict[minute] = []
        secdict[minute].append(sec.second)
    seclist = [[minute, secdict[minute]] for minute in sorted(secdict.keys())]

    for swport in swports.copy():
        try:
            switch, index = swport.split()
            portname = PortCommon.objects.get(Switch=switch, Index=index).portName
            swports['{} {}'.format(swport, portname)] = swports.pop(swport)
        except:
            pass

    data = {
        'cols': cols,
        'rows': rows,
        'xlist': xlist,
        'minutes': seclist,
        'events': sorted(list(events.items()), key=itemgetter(1), reverse=True),
        'swports': sorted(list(swports.items()), key=itemgetter(1), reverse=True),
    }
    
    return render(request, 'fc/portlog.html', data)