Exemple #1
0
    def get_context_data(self, **kwargs):
        context = super(MonitorView, self).get_context_data(**kwargs)
        context['idcs'] = IDC.objects.all()
        context['tag'] = self.request.GET.get('tag')
        if context['tag']:
            idc = IDC.objects.get(name=context['tag'])
        else:
            idc = IDC.objects.get(name='ShangHai')
        context['servers'] = Server.objects.filter(location_id = idc.id)

        collectors = list(set([server.collector for server in context['servers']]))
        data = []
        for collector in collectors:
            data.extend(ClientAPI.getHyperInfo(collector.hostname, collector.port))
#         print data
        hosts = [HostInfo(info_dict) for info_dict in data]

        context['hosts'] = hosts
        return context