Esempio n. 1
0
def write_password(pdu, port, password):
    _content = ''
    try:
        matched = False
        password_file = config.get_conf_instance().password_file
        fd = open(password_file, 'r+')
        lines = fd.readlines()
        fd.close()
        for line in lines:
            # Ignore blank line
            if line == os.linesep:
                _content += line
                continue

            # Ignore comments which begins with '#'
            result_obj = re.search(r"^#.*", line)
            if result_obj:
                _content += line
                continue

            l = line.split(':')
            # If the password is already in configuration file, then update it.
            if pdu == int(l[1]) and port == int(l[2]):
                matched = True
                # Update password
                line = ':'.join(
                    [str(time.time()),
                     str(pdu),
                     str(port),
                     str(password)])
                line += os.linesep
                logger.info("Update password %s for PDU %d port %d" %
                            (password, pdu, port))
            _content += line

        # If the pdu and port have not been assigned a password,
        # then added the password
        if not matched:
            new_line = ':'.join(
                [str(time.time()),
                 str(pdu),
                 str(port),
                 str(password)])
            new_line += os.linesep
            _content = _content + new_line
            logger.info("Add password %s for PDU %d port %d" %
                        (password, pdu, port))

        # Write the password settings back to the configuration file
        fd = open(config.get_conf_instance().password_file, 'w')
        fd.writelines(_content)
        fd.close()
    except IOError as e:
        logger.error("Error in open password file.exception: {}".format(e))
Esempio n. 2
0
def write_password(pdu, port, password):
    _content = ''
    try:
        matched = False
        password_file = config.get_conf_instance().password_file
        fd = open(password_file, 'r+')
        lines = fd.readlines()
        fd.close()
        for line in lines:
            # Ignore blank line
            if line == os.linesep:
                _content += line
                continue

            # Ignore comments which begins with '#'
            result_obj = re.search(r"^#.*", line)
            if result_obj:
                _content += line
                continue

            l = line.split(':')
            # If the password is already in configuration file, then update it.
            if pdu == int(l[1]) and port == int(l[2]):
                matched = True
                # Update password
                line = ':'.join([str(time.time()), str(pdu),
                                 str(port), str(password)])
                line += os.linesep
                logger.info("Update password %s for PDU %d port %d" %
                            (password, pdu, port))
            _content += line

        # If the pdu and port have not been assigned a password,
        # then added the password
        if not matched:
            new_line = ':'.join([str(time.time()), str(pdu),
                                 str(port), str(password)])
            new_line += os.linesep
            _content = _content + new_line
            logger.info("Add password %s for PDU %d port %d" %
                        (password, pdu, port))

        # Write the password settings back to the configuration file
        fd = open(config.get_conf_instance().password_file, 'w')
        fd.writelines(_content)
        fd.close()
    except IOError as e:
        logger.error("Error in open password file.exception: {}".format(e))
Esempio n. 3
0
File: oid.py Progetto: xiar/vpduserv
 def __init__(self):
     '''
     Constructor
     '''
     super(SqliteOIDHandler, self).__init__()
     self.config_instance = config.get_conf_instance()
     self.__db_file = os.path.join(self.config_instance.snmp_data_dir,
                                   self.config_instance.db_file)
Esempio n. 4
0
 def __init__(self):
     '''
     Constructor
     '''
     super(SqliteOIDHandler, self).__init__()
     self.config_instance = config.get_conf_instance()
     self.__db_file = os.path.join(self.config_instance.snmp_data_dir,
                                   self.config_instance.db_file)
Esempio n. 5
0
def read_password(pdu, port):
    try:
        password_file = config.get_conf_instance().password_file
        fd = open(password_file, 'r')
        while True:
            line = fd.readline()
            if not line:
                break

            # Ignore blank line
            if line == os.linesep:
                continue

            # Ignore comments which begins with "#"
            result_obj = re.search(r"^#.*", line)
            if result_obj:
                continue

            # The format should be:
            # <timestamp> <pdu number> <pdu port> <password>
            l = line.strip(os.linesep).split(':')
            try:
                lpdu = int(l[1])
                lport = int(l[2])
            except ValueError:
                logger.error("Converting int or float error from string.")
                return ""

            password = l[3]
            if lpdu == pdu and lport == port:
                fd.close()
                logger.info("Return password %s for PDU %d port %d" %
                            (password, pdu, port))
                return password
        fd.close()
        logger.error("Not found password for PDU %d port %d" % (pdu, port))
        return ""
    except IOError as e:
        logger.error("Error in open password file.exception: {}".format(e))
        return ""
Esempio n. 6
0
def read_password(pdu, port):
    try:
        password_file = config.get_conf_instance().password_file
        fd = open(password_file, 'r')
        while True:
            line = fd.readline()
            if not line:
                break

            # Ignore blank line
            if line == os.linesep:
                continue

            # Ignore comments which begins with "#"
            result_obj = re.search(r"^#.*", line)
            if result_obj:
                continue

            # The format should be:
            # <timestamp> <pdu number> <pdu port> <password>
            l = line.strip(os.linesep).split(':')
            try:
                lpdu = int(l[1])
                lport = int(l[2])
            except ValueError:
                logger.error("Converting int or float error from string.")
                return ""

            password = l[3]
            if lpdu == pdu and lport == port:
                fd.close()
                logger.info("Return password %s for PDU %d port %d" %
                            (password, pdu, port))
                return password
        fd.close()
        logger.error("Not found password for PDU %d port %d" % (pdu, port))
        return ""
    except IOError as e:
        logger.error("Error in open password file.exception: {}".format(e))
        return ""
Esempio n. 7
0
 def __init__(self):
     self.__config_instance = config.get_conf_instance()
     self.__pdu_name = self.__config_instance.pdu_name
     self.__db_type = self.__config_instance.db_type
Esempio n. 8
0
 def __init__(self):
     self.__vnodes_control = []
     self.config_instance = config.get_conf_instance()
     self.__mfh = mapping_file.get_mapping_file_handle()