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)
def hosts(request): objects = sfilter(Host, request) cols, rows = stable(Host, objects) data = { 'cols': cols, 'rows': rows, } return render(request, 'table.html', data)
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)
def switches(request): objs = sfilter(SwitchCommon, request) cols, rows = stable(SwitchCommon, objs) data = { 'cols': cols, 'rows': rows, } return render(request, 'table.html', data)
def enclosures(request): objs = sfilter(Enclosure, request) cols, rows = stable(Enclosure, objs) data = { 'cols': cols, 'rows': rows, } return render(request, 'table.html', data)
def mezzanines(request): objs = sfilter(Mezzanine, request) cols, rows = stable(Mezzanine, objs) data = { 'cols': cols, 'rows': rows, } return render(request, 'table.html', data)
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)
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)
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)
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)
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)
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)