def get_conn_string(self, in_db_name=None): if not in_db_name: dbname = self.db_fields["param_maintenance_dbname"] else: dbname = in_db_name ret = "host={0} dbname={1} port={2} user={3}".format( self.db_fields["param_ip_address"], dbname, self.db_fields["param_port"], self.db_fields["param_user"] ) if self.db_fields["param_password"]: ret += " password={0}".format(self.db_fields["param_password"]) sslmode = table.genericEnum("enum_sslmode", self.db_conn.cursor()) ssl = sslmode.get_name_by_id(self.db_fields["param_sslmode_id"]) ret += " sslmode={0}".format(ssl) return ret
def discover_cluster_params(self): cur = self._get_cursor() if not cur: self.prod_conn.close() logger.error("Return from discover_cluster_params") return False params = {} try: cur.execute("SELECT current_setting('server_version') AS ver") except Exception as e: logger.error( "Cannot get 'server_version' param for {0}. Details: {1}".format(self.db_fields["hostname"], e.pgerror) ) else: pg_ver = cur.fetchone()[0] if self.db_fields["pg_version"] != pg_ver: logger.info( "Updated parameter 'pg_version' set to '{0}' for hostcluster {1}".format( pg_ver, self.db_fields["hostname"] ) ) params["pg_version"] = pg_ver try: cur.execute("SELECT current_setting('data_directory') AS pg_data_path") except Exception as e: logger.error( "Cannot get 'data_directory' param for {0}. Details: {1}".format(self.db_fields["hostname"], e.pgerror) ) else: data_path = cur.fetchone()[0] if self.db_fields["pg_data_path"] != data_path: logger.info( "Updated parameter 'pg_data_path' set to '{0}' for hostcluster {1}".format( data_path, self.db_fields["hostname"] ) ) params["pg_data_path"] = data_path try: cur.execute( "SELECT CASE WHEN current_setting('track_counts')='on' THEN 't'::boolean ELSE 'f'::boolean END AS track_counts" ) except Exception as e: logger.error( "Cannot get 'track_counts' param for {0}. Details: {1}".format(self.db_fields["hostname"], e.pgerror) ) else: t_c = cur.fetchone()[0] if self.db_fields["track_counts"] != t_c: logger.info( "Updated parameter 'track_counts' set to '{0}' for hostcluster {1}".format( t_c, self.db_fields["hostname"] ) ) params["track_counts"] = t_c try: cur.execute("SELECT current_setting('track_functions') AS track_functions") except Exception as e: logger.error( "Cannot get 'track_functions' param for {0}. Details: {1}".format(self.db_fields["hostname"], e.pgerror) ) else: t_f = cur.fetchone()[0] tf = table.genericEnum("enum_track_functions", self.db_conn.cursor()) tf_id = tf.get_id_by_name(t_f) if self.db_fields["track_function_id"] != tf_id: logger.info( "Updated parameter 'track_functions' set to '{0}' for hostcluster {1}".format( t_f, self.db_fields["hostname"] ) ) params["track_function_id"] = tf_id cur.close() if len(params) > 0: update_stat = "UPDATE {0} SET ".format(self.table) for k in params.keys(): update_stat += "{0}='{1}',".format(k, params[k]) update_stat = update_stat[:-1] + " WHERE id={0}".format(self.id) cur = self.db_conn.cursor() try: cur.execute(update_stat) except Exception as e: logger.error("Cannot update hostcluster new discovered data: {0}".format(e.pgerror)) cur.close() self.db_conn.rollback() return False self.db_fields = {} self._populate() cur.close() self.db_conn.commit() logger.info("Updated cluster parameters: {0}".format(params.keys())) # else: # logger.debug("No new data obtained during discover for hostcluster {0}".format(self.db_fields['hostname'])) return True
def get_track_function(self): if self.id: tf = table.genericEnum("enum_track_functions", self.db_conn.cursor()) return tf.get_name_by_id(self.db_fields["track_function_id"]) return None