def askForArgs(self): #TODO: Ask if statistics are requested periodically (in this case ask polling time) or as needed. #add a flag for this self.polling_time = raw_input("Insert polling time (sec) for periodical stats collection (0 for non periodical): ") if self.polling_time == "" : self.polling_time = self.POLLINGTIMEDEFAULT log.info("Polling Time set to default - %s seconds", self.POLLINGTIMEDEFAULT) while not ercs_topology.is_number(self.polling_time): self.polling_time = raw_input("This is not a valid number, please insert a valid value: ") self.polling_time = float(self.polling_time) #if periodical requests if self.polling_time != 0: #ask if previous statistical data should be taken into consideration when calcutating the new stats #only makes sense self.historical_ponderation = raw_input("Insert historical stats weight factor (between 0 and 1): ") if self.historical_ponderation == "" : self.historical_ponderation = self.HISTORICALPONDERATIONDEFAULT log.info("Historical Ponderation set to default - %s ", self.HISTORICALPONDERATIONDEFAULT) while (not ercs_topology.is_number(self.historical_ponderation)): if (float(self.historical_ponderation) > 1) or (float(self.historical_ponderation) < 0): self.historical_ponderation = raw_input("This is not a valid number, please insert a valid value: ") self.historical_ponderation = float(self.historical_ponderation) else : #In case of non periodical stats, don't take into consideration previous data self.historical_ponderation = 0
def isIPandPort(ipaddress, port): ''' Check if Ip address and port are in the correct form IPv4 Only (for now) ''' if (not ercs_topology.is_number(port)) : log.debug("Bad Port Number") return False elif not ((int(port) > 1024) and (int(port) < 65536)): log.debug("Bad Port Number") return False else : for no in ipaddress.split(".",3) : if (not ercs_topology.is_number(no)) : log.debug("Bad IP Address") return False elif not ((int(no) >= 0) and (int(no) <= 255)): log.debug("Bad IP Address") return False return True