Beispiel #1
0
 def get_object(self, queryset=None):
     """ Hook to ensure object is owned by request.user. """
     obj = super(ServerDeleteView, self).get_object()
     collector = obj.collector
     print collector.hostname
     print collector.port
     print obj.hostname
     ClientAPI.setHostIPToCfg(collector.hostname, collector.port, obj.hostname, add_to_config=False)
     return obj
Beispiel #2
0
 def post(self, request, *args, **kwargs):
     form = ServerAddForm(request.POST)
     if form.is_valid():
         try:
             form.save(form)
             collertor = form.cleaned_data['collector']
             ClientAPI.setHostIPToCfg(collertor.hostname, collertor.port,form.cleaned_data['hostname'], add_to_config=True)
         except Exception,e:
             print str(e)
             return self.form_invalid(form=form)
Beispiel #3
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