def __init__(self): """ Constructor """ # Read the configuration parameters from tulsi.conf self.timestr = time.strftime("%Y:%m:%d-%H:%M:%S") self.conf = ConfigParser.ConfigParser() try: self.conf.read('/etc/tulsi/tulsi.conf') self.udp_ip = self.conf.get('tulsi', 'host') self.udp_port = int(self.conf.get('tulsi', 'port')) # printing the host and port of tulsi logging.info('%s The IP of the host: %s' % (self.timestr, self.udp_ip)) logging.info('%s The Port number of the host :%s' % (self.timestr, self.udp_port)) except: # Error message of tulsi not working logging.error('The tulsi configuration file is not found') # Creating objects of MessageEncode and HostInfo msg_encode = MessageEncode() host_info = HostInfo() # Initializing empty lists self.drives = [] self.service = [] self.ip_array = [] self.ring_ip = [] self.ring_conf_ip = [] self.ring_drives = [] self.ip_set_array = [] self.my_ring_conf = dict() # Read the ring Configuration file self.gz_file = GzipFile("/etc/swift/container.ring.gz", 'rb') if hasattr(self.gz_file, '_checkReadable'): self.gz_file = BufferedReader(self.gz_file) magic = self.gz_file.read(4) if magic == 'R1NG': version, = struct.unpack('!H', self.gz_file.read(2)) if version == 1: #self.ring_data = self.read_ring_file(self.gz_file) self.read_ring_file(self.gz_file) else: logging.error('%s Unknown ring format version %d' % (self.timestr, version)) raise Exception('Unknown ring format version %d' % version) # While loop to continuously check the status of swift services and # drives and send information to tulsi client while True: self.ip_array = host_info.read_ip() self.service = host_info.read_services() self.drives = host_info.read_drives(self.drives) self.message = msg_encode.create_message(self.my_ring_conf, self.ring_conf_ip, self.ip_array, self.service, self.drives) sock = socket.socket( socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(self.message, (self.udp_ip, self.udp_port)) time.sleep(5) self.ip_array = [] self.service = [] self.drives = []
def __init__(self): """ Constructor """ # Read the configuration parameters from tulsi.conf self.timestr = time.strftime("%Y:%m:%d-%H:%M:%S") logging.basicConfig(filename="/var/log/tulsi.log", level=logging.DEBUG) try: self.conf = ConfigParser.ConfigParser() self.conf.read("/etc/tulsi/tulsi.conf") self.udp_ip = self.conf.get("tulsi", "host") self.udp_port = int(self.conf.get("tulsi", "port")) # printing the host and port of tulsi logging.info("%s The IP of the host: %s" % (self.timestr, self.udp_ip)) logging.info("%s The Port number of the host :%s" % (self.timestr, self.udp_port)) except: # Error message of tulsi not working logging.error("The tulsi configuration file is not found") # Creating objects of MessageEncode and HostInfo msg_encode = MessageEncode() host_info = HostInfo() # Initializing empty lists self.drives = [] self.service = [] self.ip_array = [] self.ring_ip = [] self.ring_conf_ip = [] self.ring_drives = [] self.ip_set_array = [] self.my_ring_conf = dict() # Read the ring Configuration file self.gz_file = GzipFile("/etc/swift/container.ring.gz", "rb") if hasattr(self.gz_file, "_checkReadable"): self.gz_file = BufferedReader(self.gz_file) magic = self.gz_file.read(4) if magic == "R1NG": version, = struct.unpack("!H", self.gz_file.read(2)) if version == 1: self.ring_data = self.read_ring_file(self.gz_file) else: logging.error("%s Unknown ring format version %d" % (self.timestr, version)) raise Exception("Unknown ring format version %d" % version) # While loop to continuously check the status of swift services and # drives and send information to tulsi client while True: self.ip_array = host_info.read_ip() self.service = host_info.read_services() self.drives = host_info.read_drives(self.drives) self.message = msg_encode.create_message( self.my_ring_conf, self.ring_conf_ip, self.ip_array, self.service, self.drives ) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Internet # UDP sock.sendto(self.message, (self.udp_ip, self.udp_port)) time.sleep(5) self.ip_array = [] self.service = [] self.drives = []