python運維平臺的設計

所使用的框架和代碼:
    django python的web框架
    bootstrap 前端的樣式

1.25
    1.制定控制平臺[server端]和被監控目標[client端]的應用層協議。
    2.完成主控制程序的設計。前端


2.31python

    1.服務器程序加了個poll來加大併發量web

#!/usr/bin/env python

import socket, traceback, os, sys, select

class ServerPoll():
    stdmask = select.POLLERR | select.POLLHUP | select.POLLNVAL

    def __init__(self, mastersocket):
        """Inition """
        self.p = select.poll()
        self.mastersocket = mastersocket
        self.watchread(self.mastersocket)
        self.buffers = {}
        self.sockets = {self.mastersocket.fileno(): self.mastersocket}

    def fd2socket(self, fd):
        return self.sockets[fd]

    def watchread(self, fd):
        """Note interest in reading"""
        self.p.register(fd, select.POLLIN | self.stdmask)

    def dontwatch(self, fd):
        """Don't watch anything in fd"""
        self.p.unregister(fd)

    def newconn(self, sock):
        fd = sock.fileno()
        
        """Watching write in fd"""
        self.watchread(fd)

        """Add fd to sockets dirs"""
        self.sockets[fd] = sock

    def readevent(self, fd):
        while 1:
           data = self.fd2socket().recv(4096)
           #print '%s say: %s' % (clientsocket.getpeername()[0], data)
           if not len(data):
              break
           ldata = ldata + data
        print sys.getsizeof(ldata)
        return ldata

    def errorevent(self, fd):
        self.closeout(fd)

    def closeout(self, fd):
        self.dontwatch(fd)
        
        try:
           self.fd2socket(fd).close()
        except:
           pass

        del self.sockets[fd]
         

django

相關文章
相關標籤/搜索