Code Duplication    Length = 32-32 lines in 2 locations

glances/exports/glances_influxdb.py 1 location

@@ 61-92 (lines=32) @@
58
        # Init the InfluxDB client
59
        self.client = self.init()
60
61
    def load_conf(self, section="influxdb"):
62
        """Load the InfluxDb configuration in the Glances configuration file."""
63
        if self.config is None:
64
            return False
65
        try:
66
            self.host = self.config.get_value(section, 'host')
67
            self.port = self.config.get_value(section, 'port')
68
            self.user = self.config.get_value(section, 'user')
69
            self.password = self.config.get_value(section, 'password')
70
            self.db = self.config.get_value(section, 'db')
71
        except NoSectionError:
72
            logger.critical("No InfluxDB configuration found")
73
            return False
74
        except NoOptionError as e:
75
            logger.critical("Error in the InfluxDB configuration (%s)" % e)
76
            return False
77
        else:
78
            logger.debug("Load InfluxDB from the Glances configuration file")
79
80
        # Prefix is optional
81
        try:
82
            self.prefix = self.config.get_value(section, 'prefix')
83
        except NoOptionError:
84
            pass
85
86
        # Tags are optional, comma separated key:value pairs.
87
        try:
88
            self.tags = self.config.get_value(section, 'tags')
89
        except NoOptionError:
90
            pass
91
92
        return True
93
94
    def init(self):
95
        """Init the connection to the InfluxDB server."""

glances/exports/glances_cassandra.py 1 location

@@ 57-88 (lines=32) @@
54
        # Init the Cassandra client
55
        self.cluster, self.session = self.init()
56
57
    def load_conf(self, section="cassandra"):
58
        """Load the Cassandra configuration in the Glances configuration file."""
59
        if self.config is None:
60
            return False
61
        try:
62
            self.host = self.config.get_value(section, 'host')
63
            self.port = self.config.get_value(section, 'port')
64
            self.keyspace = self.config.get_value(section, 'keyspace')
65
        except NoSectionError:
66
            logger.critical("No Cassandra configuration found")
67
            return False
68
        except NoOptionError as e:
69
            logger.critical("Error in the Cassandra configuration (%s)" % e)
70
            return False
71
        else:
72
            logger.debug("Load Cassandra from the Glances configuration file")
73
74
        # Optionals keys
75
        try:
76
            self.protocol_version = self.config.get_value(section, 'protocol_version')
77
        except NoOptionError:
78
            pass
79
        try:
80
            self.replication_factor = self.config.get_value(section, 'replication_factor')
81
        except NoOptionError:
82
            pass
83
        try:
84
            self.table = self.config.get_value(section, 'table')
85
        except NoOptionError:
86
            self.table = self.host
87
88
        return True
89
90
    def init(self):
91
        """Init the connection to the InfluxDB server."""