mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-26 15:40:21 +00:00
Merge pull request #5 from zalando/features/refactoring
Features/refactoring
This commit is contained in:
+6
-2
@@ -35,7 +35,7 @@ class Etcd:
|
||||
response = requests.get(self.client_url(path))
|
||||
if response.status_code == 200:
|
||||
break
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.exception('get_client_path')
|
||||
ex = e
|
||||
|
||||
@@ -61,7 +61,11 @@ class Etcd:
|
||||
|
||||
@staticmethod
|
||||
def find_node(node, key):
|
||||
if not node['dir']:
|
||||
"""
|
||||
>>> Etcd.find_node({}, None)
|
||||
>>> Etcd.find_node({'dir': True, 'nodes': [], 'key': '/test/'}, 'test')
|
||||
"""
|
||||
if not node.get('dir', False):
|
||||
return None
|
||||
key = node['key'] + key
|
||||
for n in node['nodes']:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import inspect
|
||||
import logging
|
||||
import time
|
||||
|
||||
@@ -8,11 +7,6 @@ from psycopg2 import OperationalError
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def lineno():
|
||||
"""Returns the current line number in our program."""
|
||||
return inspect.currentframe().f_back.f_lineno
|
||||
|
||||
|
||||
class Ha:
|
||||
|
||||
def __init__(self, state_handler, etcd):
|
||||
|
||||
+12
-5
@@ -2,15 +2,22 @@ import logging
|
||||
import os
|
||||
import psycopg2
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import urlparse
|
||||
|
||||
is_py3 = sys.hexversion >= 0x03000000
|
||||
|
||||
if is_py3:
|
||||
from urllib.parse import urlparse
|
||||
else:
|
||||
from urlparse import urlparse
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parseurl(url):
|
||||
r = urlparse.urlparse(url)
|
||||
r = urlparse(url)
|
||||
return {
|
||||
'hostname': r.hostname,
|
||||
'port': r.port or 5432,
|
||||
@@ -93,7 +100,7 @@ class Postgresql:
|
||||
|
||||
pgpass = 'pgpass'
|
||||
with open(pgpass, 'w') as f:
|
||||
os.fchmod(f.fileno(), 0600)
|
||||
os.fchmod(f.fileno(), 0o600)
|
||||
f.write('{hostname}:{port}:*:{username}:{password}\n'.format(**r))
|
||||
|
||||
try:
|
||||
@@ -135,7 +142,7 @@ class Postgresql:
|
||||
|
||||
def server_options(self):
|
||||
options = '--listen_addresses={} --port={}'.format(self.host, self.port)
|
||||
for setting, value in self.config['parameters'].iteritems():
|
||||
for setting, value in self.config['parameters'].items():
|
||||
options += " --{}='{}'".format(setting, value)
|
||||
return options
|
||||
|
||||
@@ -209,7 +216,7 @@ recovery_target_timeline = 'latest'
|
||||
primary_slot_name = '{}'
|
||||
primary_conninfo = '{}'
|
||||
""".format(self.name, self.primary_conninfo(leader.address)))
|
||||
for name, value in self.config.get('recovery_conf', {}).iteritems():
|
||||
for name, value in self.config.get('recovery_conf', {}).items():
|
||||
f.write("{} = '{}'\n".format(name, value))
|
||||
|
||||
def follow_the_leader(self, leader):
|
||||
|
||||
Reference in New Issue
Block a user